package screen; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * Config.java * * Created on 09-Mar-2009, 16:32:37 */ import java.awt.Component; import javax.swing.JOptionPane; import javax.swing.UIManager; /** * * @author Andy */ public class Config extends javax.swing.JFrame { public static void main(final String args[]) { for (final String lf : new String[] { UIManager.getSystemLookAndFeelClassName(), "com.sun.java.swing.plaf.windows.WindowsLookAndFeel", "com.sun.java.swing.plaf.gtk.GTKLookAndFeel" }) { try { UIManager.setLookAndFeel(lf); } catch (final Exception e) { } } new Config(new Utils()).setVisible(true); } /** Creates new form Config */ Utils util; /** * @param args * the command line arguments */ // Variables declaration - do not modify private javax.swing.JButton aboutButton; private javax.swing.JMenu aboutMenu; private javax.swing.JButton closeButton; private javax.swing.JMenu closeMenu; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel6; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JButton saveLoginButton; private javax.swing.JPasswordField txtPassword; private javax.swing.JTextField txtUsername; // End of variables declaration public Config(final Utils util) { this.util = util; this.initComponents(); } private void aboutButtonActionPerformed(final java.awt.event.ActionEvent evt) { JOptionPane .showConfirmDialog( (Component) null, "PinkLog.com Screensaver\nVersion 1.0\n Written by UpsetPC.com\nAndy Armstrong & Richard Whitty", "PinkLog.com Screensaver", JOptionPane.DEFAULT_OPTION); // TODO // add // your // handling // code // here // : } private void aboutMenuActionPerformed(final java.awt.event.ActionEvent evt) { JOptionPane .showConfirmDialog( (Component) null, "PinkLog.com Screensaver\nVersion 1.0\n Written by UpsetPC.com\nAndy Armstrong & Richard Whitty", "PinkLog.com Screensaver", JOptionPane.DEFAULT_OPTION); // TODO // add // your // handling // code // here // : } private void closeButtonActionPerformed(final java.awt.event.ActionEvent evt) { this.dispose(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // private void initComponents() { this.jLabel1 = new javax.swing.JLabel(); this.jLabel2 = new javax.swing.JLabel(); this.txtUsername = new javax.swing.JTextField(); this.saveLoginButton = new javax.swing.JButton(); this.txtPassword = new javax.swing.JPasswordField(); this.aboutButton = new javax.swing.JButton(); this.jLabel3 = new javax.swing.JLabel(); this.jLabel4 = new javax.swing.JLabel(); this.closeButton = new javax.swing.JButton(); this.jLabel6 = new javax.swing.JLabel(); this.jMenuBar1 = new javax.swing.JMenuBar(); this.aboutMenu = new javax.swing.JMenu(); this.closeMenu = new javax.swing.JMenu(); this .setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); this.setBackground(new java.awt.Color(0, 0, 0)); this.setForeground(java.awt.Color.black); this.jLabel1.setForeground(new java.awt.Color(255, 0, 204)); this.jLabel1.setText("PinkLog.com Username:"); this.jLabel2.setForeground(new java.awt.Color(255, 0, 204)); this.jLabel2.setText("PinkLog.com Password:"); this.txtUsername.setForeground(new java.awt.Color(255, 51, 255)); this.saveLoginButton.setText("Save login"); this.saveLoginButton .addActionListener(new java.awt.event.ActionListener() { public void actionPerformed( final java.awt.event.ActionEvent evt) { Config.this.saveLoginButtonActionPerformed(evt); } }); this.txtPassword.setForeground(new java.awt.Color(255, 0, 255)); this.aboutButton.setText("About "); this.aboutButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final java.awt.event.ActionEvent evt) { Config.this.aboutButtonActionPerformed(evt); } }); this.jLabel3.setText("V1.0"); this.jLabel4.setFont(new java.awt.Font("Bell MT", 0, 24)); // NOI18N this.jLabel4.setForeground(new java.awt.Color(255, 51, 255)); this.jLabel4.setText("PinkLog.com screensaver Options"); this.closeButton.setText("Close Options"); this.closeButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final java.awt.event.ActionEvent evt) { Config.this.closeButtonActionPerformed(evt); } }); this.jLabel6.setIcon(new javax.swing.JLabel() { @Override public javax.swing.Icon getIcon() { try { return new javax.swing.ImageIcon(new java.net.URL( "http://pinkradio.com/_graphik/logo_pink.jpg")); } catch (final java.net.MalformedURLException e) { } return null; } }.getIcon()); this.aboutMenu.setText("About"); this.aboutMenu.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); this.aboutMenu .setHorizontalTextPosition(javax.swing.SwingConstants.LEFT); this.aboutMenu.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final java.awt.event.ActionEvent evt) { Config.this.aboutMenuActionPerformed(evt); } }); this.jMenuBar1.add(this.aboutMenu); this.closeMenu.setText("Close"); this.closeMenu.setAlignmentX(150.0F); this.closeMenu.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(final java.awt.event.ActionEvent evt) { Config.this.closeButtonActionPerformed(evt); } }); this.jMenuBar1.add(this.closeMenu); this.setJMenuBar(this.jMenuBar1); final javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this .getContentPane()); this.getContentPane().setLayout(layout); layout .setHorizontalGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout .createSequentialGroup() .addComponent(this.jLabel6) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, 134, Short.MAX_VALUE) .addComponent(this.jLabel3) .addContainerGap()) .addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout .createSequentialGroup() .addGap(36, 36, 36) .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent( this.jLabel4) .addGroup( layout .createSequentialGroup() .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.TRAILING) .addGroup( javax.swing.GroupLayout.Alignment.LEADING, layout .createSequentialGroup() .addComponent( this.jLabel2) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent( this.txtPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)) .addGroup( javax.swing.GroupLayout.Alignment.LEADING, layout .createSequentialGroup() .addComponent( this.jLabel1) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent( this.txtUsername, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE))) .addGap( 18, 18, 18) .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout .createSequentialGroup() .addComponent( this.saveLoginButton, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED)) .addComponent( this.closeButton) .addComponent( this.aboutButton, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)))) .addContainerGap( 28, javax.swing.GroupLayout.PREFERRED_SIZE))); layout .setVerticalGroup(layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout .createSequentialGroup() .addContainerGap() .addComponent(this.jLabel4) .addGap(38, 38, 38) .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent( this.jLabel1) .addComponent( this.txtUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( this.saveLoginButton)) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent( this.jLabel2) .addComponent( this.txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, 67, Short.MAX_VALUE) .addComponent(this.aboutButton) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup( layout .createParallelGroup( javax.swing.GroupLayout.Alignment.TRAILING) .addGroup( layout .createSequentialGroup() .addComponent( this.closeButton) .addGap( 44, 44, 44) .addComponent( this.jLabel3) .addContainerGap()) .addComponent( this.jLabel6)))); this.txtUsername.setText(this.util.getUserName()); this.txtPassword.setText(this.util.getPassword()); this.pack(); } private void saveLoginButtonActionPerformed( final java.awt.event.ActionEvent evt) { this.util.saveUsernameAndPassword(this.txtUsername.getText(), new String(this.txtPassword.getPassword())); JOptionPane.showConfirmDialog((Component) null, "Options saved!", "Success!", JOptionPane.DEFAULT_OPTION); // TODO add your // handling code // here: } }package screen; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.Collection; import java.util.Vector; public class HTTPServer extends Server { public static void main(final String args[]) throws IOException { final HTTPServer s = new HTTPServer("richard", "foo", "http://paxam.is-a-geek.org/~richard/testfile"); for (final URL l : s.getImages()) { System.out.println(l); } } public HTTPServer(final String user, final String pass, final String link) throws MalformedURLException { super(user, pass, link); } /** * Gets all the image urls from the nice server. */ @Override public Collection getImages() throws IOException { final Collection urls = new Vector(); final URLConnection conn = this.getURL().openConnection(); conn.connect(); final BufferedReader in = new BufferedReader(new InputStreamReader(conn .getInputStream())); String line = in.readLine(); while (line != null) { line = line.trim(); if (line.length() > 0) { urls.add(new URL(line)); } line = in.readLine(); } in.close(); return urls; } } package screen; import java.io.IOException; import java.net.URL; import java.util.concurrent.BlockingQueue; import com.sun.opengl.util.texture.TextureIO; public class ImageCache implements Runnable { static private ImageX loadTex(final URL url) throws IOException { return new ImageX(TextureIO.newTextureData(url, Settings.MIPMAP, Settings.SUFFIX)); } BlockingQueue in; BlockingQueue out; public ImageCache(final BlockingQueue in, final BlockingQueue out) { this.in = in; this.out = out; } public void run() { for (;;) { URL url = null; try { url = this.in.take(); } catch (final InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } if (url == null) { try { // give it a chance to catch up. Thread.sleep(Settings.WAITTIME); } catch (final InterruptedException e) { } continue; } for (;;) { try { this.out.put(ImageCache.loadTex(url)); System.out.printf( "ImageCache: Loaded texture data from %s%n", url .toExternalForm()); break; } catch (final InterruptedException e) { e.printStackTrace(); } catch (final IOException e) { e.printStackTrace(); } } } } }package screen; import java.awt.Dimension; import com.sun.opengl.util.texture.Texture; import com.sun.opengl.util.texture.TextureData; import com.sun.opengl.util.texture.TextureIO; /** * This caches the information we need every frame to save on computation. Can * be instantiated outside the gl rendering thread (which is the point). * * @author richard * */ public class ImageX { private float size; private Texture tex; private final TextureData td; private Dimension dim; public ImageX(final TextureData td) { this.td = (td); } public Dimension getDim() { if (this.tex == null) { this.init(); } return this.dim; } private Dimension getImageSize(final TextureData t) { int w = t.getWidth(); int h = t.getHeight(); final float aspect = (float) w / (float) h; Main.debug("w=%d\th=%d\tas=%.2f%n", w, h, aspect); if (w > h) { // scale to max width w = (int) this.size; h = (int) (this.size / aspect); } else { h = (int) this.size; w = (int) (this.size * aspect); } Main.debug("w=%d\th=%d\tDONE%n", w, h, aspect); return new Dimension(w, h); } public TextureData getTd() { return this.td; } public Texture getTex() { if (this.tex == null) { this.init(); } return this.tex; } public void init() { this.tex = (TextureIO.newTexture(this.getTd())); this.dim = (this.getImageSize(this.getTd())); } public void setSize(final float size) { this.size = size; this.dim = (this.getImageSize(this.getTd())); } } package screen; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.net.URL; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.UIManager; import javax.swing.WindowConstants; public class Main { static public void debug(final String fmt, final Object... args) { // System.out.printf(fmt,args); } public static void main(final String[] args) { for (final String lf : new String[] { UIManager.getSystemLookAndFeelClassName(), "com.sun.java.swing.plaf.windows.WindowsLookAndFeel", "com.sun.java.swing.plaf.gtk.GTKLookAndFeel" }) { try { UIManager.setLookAndFeel(lf); } catch (final Exception e) { } } final BlockingQueue texs = new ArrayBlockingQueue(5); final BlockingQueue urls = new ArrayBlockingQueue(5); final TexTest tt = new TexTest(texs); new Thread(new URLCache(urls)).start(); new Thread(new ImageCache(urls, texs)).start(); final Utils util = new Utils(); final JFrame f = new JFrame("'Screensaver'"); f.setLayout(new BorderLayout()); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); final JButton cb = new JButton("Options"); final JButton sb = new JButton("Start"); sb.addActionListener(new StartStop(sb, tt)); cb.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { new Config(util).setVisible(true); } }); f.add(sb, BorderLayout.NORTH); f.add(tt, BorderLayout.CENTER); f.add(cb, BorderLayout.SOUTH); f.pack(); f.setVisible(true); } } package screen; import java.util.List; import java.util.Vector; import javax.media.opengl.GL; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLEventListener; public class MultiTex implements GLEventListener { static class Place { ShowImage i; float x, y; } private final List images = new Vector(); @Override public void display(final GLAutoDrawable drawable) { // draw all the objects in the correct positions final GL gl = drawable.getGL(); for (final Place p : this.images) { gl.glLoadIdentity(); gl.glTranslatef(p.x, p.y, 0); p.i.draw(gl); } } @Override public void displayChanged(final GLAutoDrawable drawable, final boolean modeChanged, final boolean deviceChanged) { // TODO Auto-generated method stub } @Override public void init(final GLAutoDrawable drawable) { // TODO Auto-generated method stub } @Override public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { // TODO Auto-generated method stub } } package screen; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.Collection; public abstract class Server { private String username, passwd; private final URL url; protected Server(final String user, final String pass, final String link) throws MalformedURLException { this.url = new URL(link); this.setUserPass(user, pass); } public abstract Collection getImages() throws IOException; protected String getPasswd() { return this.passwd; } protected URL getURL() { return this.url; } public String getUserName() { return this.username; } public void setUserPass(final String user, final String passwd) { this.username = user; this.passwd = passwd; } @Override public String toString() { return String.format("%s@%s", this.getUserName(), this.getURL()); } } package screen; public class Settings { public final static boolean MIPMAP = true; public final static String SUFFIX = "jpg"; public static final float SIZE = 32f; public static final int WAITTIME = 100; } package screen; import java.awt.Dimension; import java.util.concurrent.BlockingQueue; import javax.media.opengl.GL; import com.sun.opengl.util.texture.Texture; import com.sun.opengl.util.texture.TextureCoords; public class ShowImage { static void drawQuad(final GL gl, final ImageX td) { if (td != null) { final Texture t = td.getTex(); gl.glEnable(GL.GL_TEXTURE_2D); t.bind(); float w, h; final Dimension d = td.getDim(); w = d.width / 2; h = d.height / 2; final TextureCoords c = t.getImageTexCoords(); Main.debug("Using texcoords: %s%n", c); gl.glBegin(GL.GL_QUADS); gl.glTexCoord2f(c.bottom(), c.right()); gl.glVertex3f(-w, -h, 0.0f); gl.glTexCoord2f(c.bottom(), c.left()); gl.glVertex3f(-w, h, 0.0f); gl.glTexCoord2f(c.top(), c.left()); gl.glVertex3f(w, h, 0.0f); gl.glTexCoord2f(c.top(), c.right()); gl.glVertex3f(w, -h, 0.0f); // } else { // gl.glBegin(GL.GL_QUADS); // gl.glVertex3f(-0.5f, -0.5f, 0.0f); // gl.glVertex3f(-0.5f, 0.5f, 0.0f); // gl.glVertex3f(0.5f, 0.5f, 0.0f); // gl.glVertex3f(0.5f, -0.5f, 0.0f); // } gl.glEnd(); } } private final float size; private final BlockingQueue texs; private ImageX curr; private ImageX next = null; int ticker = 0; private final int transition_len = 60; private final int show_time = 500; private boolean in_transition; public ShowImage(final float size, final BlockingQueue texs) { this.texs = texs; this.size = size; while (this.next == null) { // get the first pic try { this.next = this.texs.take(); } catch (final InterruptedException e) { } } this.next.setSize(size); } public void draw(final GL gl) { ++this.ticker; if (this.in_transition) { // draw the transition. final float rot = 180f * ((float) this.transition_len / (float) this.ticker); gl.glRotatef(rot, 0, 1, 0); // gl.glColor3f(1f, 0f, 0f); ShowImage.drawQuad(gl, this.next); // gl.glColor3f(1f, 1f, 0f); gl.glRotatef(180, 0, 1, 0); ShowImage.drawQuad(gl, this.curr); if (this.ticker > this.transition_len) { // handle switching back to // normal view this.ticker = 0; this.in_transition = false; this.curr = this.next; } } else { // just show it normally. if (this.ticker > this.show_time) { // handle when we want to do a // transition. this.ticker = 0; this.in_transition = true; } ShowImage.drawQuad(gl, this.curr); } } } package screen; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; public final class StartStop implements ActionListener, Runnable { static boolean isRunning() { return StartStop.running; } private final int delay = 20; static private volatile Boolean running; private final JButton b; private final TexTest t; public StartStop(final JButton b, final TexTest t) { this.b = b; this.t = t; StartStop.running = Boolean.valueOf(false); } @Override public void actionPerformed(final ActionEvent e) { synchronized (StartStop.running) { if (StartStop.running == Boolean.TRUE) { this.b.setText("Start"); StartStop.running = Boolean.FALSE; } else { this.b.setText("Stop"); synchronized (StartStop.running) { StartStop.running = Boolean.TRUE; } new Thread(this).start(); } } } public void run() { try { for (;;) { synchronized (StartStop.running) { if (!StartStop.running) { break; } } this.t.nextImg(); Thread.sleep(this.delay); } } catch (final InterruptedException ex) { System.err.printf("Interrupted: %s%n", ex.getMessage()); } } } package screen; import java.awt.Dimension; import java.util.concurrent.BlockingQueue; import javax.media.opengl.GL; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLEventListener; import javax.media.opengl.GLJPanel; import javax.media.opengl.glu.GLU; import com.sun.opengl.util.texture.Texture; import com.sun.opengl.util.texture.TextureCoords; public class TexTest extends GLJPanel implements GLEventListener { private final BlockingQueue texs; private ImageX curr, next; private static final GLU glu = new GLU(); static void drawQuad(final GL gl, final ImageX td) { if (td != null) { final Texture t = td.getTex(); gl.glEnable(GL.GL_TEXTURE_2D); t.bind(); float w, h; final Dimension d = td.getDim(); w = d.width / 2; h = d.height / 2; final TextureCoords c = t.getImageTexCoords(); Main.debug("Using texcoords: %s%n", c); gl.glBegin(GL.GL_QUADS); gl.glTexCoord2f(c.bottom(), c.right()); gl.glVertex3f(-w, -h, 0.0f); gl.glTexCoord2f(c.bottom(), c.left()); gl.glVertex3f(-w, h, 0.0f); gl.glTexCoord2f(c.top(), c.left()); gl.glVertex3f(w, h, 0.0f); gl.glTexCoord2f(c.top(), c.right()); gl.glVertex3f(w, -h, 0.0f); // } else { // gl.glBegin(GL.GL_QUADS); // gl.glVertex3f(-0.5f, -0.5f, 0.0f); // gl.glVertex3f(-0.5f, 0.5f, 0.0f); // gl.glVertex3f(0.5f, 0.5f, 0.0f); // gl.glVertex3f(0.5f, -0.5f, 0.0f); // } gl.glEnd(); } } float rot = 0; public TexTest(final BlockingQueue texs) { this.texs = texs; this.addGLEventListener(this); this.setPreferredSize(new Dimension(500, 500)); } @Override public void display(final GLAutoDrawable drawable) { final GL gl = drawable.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); gl.glTranslatef(0f, 0f, -100f); gl.glRotatef(this.rot, 0, 1, 0); // gl.glColor3f(1f, 0f, 0f); TexTest.drawQuad(gl, this.next); // gl.glColor3f(1f, 1f, 0f); gl.glRotatef(180, 0, 1, 0); TexTest.drawQuad(gl, this.curr); Main.debug("Painted: %.2f%n", this.rot); } @Override public void displayChanged(final GLAutoDrawable drawable, final boolean modeChanged, final boolean deviceChanged) { // jogl doesn't do this anyway } @Override public void init(final GLAutoDrawable drawable) { final GL gl = drawable.getGL(); gl.glShadeModel(GL.GL_SMOOTH); gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glClearDepth(1.0f); gl.glEnable(GL.GL_DEPTH_TEST); gl.glDepthFunc(GL.GL_LEQUAL); gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_FASTEST); gl.glCullFace(GL.GL_BACK); gl.glEnable(GL.GL_CULL_FACE); } public void nextImg() throws InterruptedException { this.next = this.texs.take(); for (this.rot = 0; this.rot < 180; this.rot += 4) { this.repaint(); Thread.sleep(20); } this.curr = this.next; } @Override public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { final GL gl = drawable.getGL(); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); TexTest.glu.gluPerspective(Settings.SIZE, 1, 0.1f, 200.0f); // TexTest.glu.gluPerspective(2f, 1f, -5f, 6f); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); // TODO Auto-generated method stub } } package screen; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.concurrent.BlockingQueue; public class URLCache implements Runnable { private final BlockingQueue q; public URLCache(final BlockingQueue q) { this.q = q; } public void run() { Server s; try { s = new Utils().getServer(); } catch (final MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); return; } try { for (final URL l : s.getImages()) { try { this.q.put(l); System.out.printf("URLCache: Got image URL %s%n", l .toExternalForm()); } catch (final InterruptedException e) { e.printStackTrace(); continue; } System.out.println(l); } } catch (final IOException e) { e.printStackTrace(); } } }package screen; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.net.MalformedURLException; import java.util.Properties; public class Utils { static final String settingsFileName = ".myappcfg"; private Properties properties; private File propertiesFile; public String getPassword() { if (this.properties == null) { this.GetPropertiesFile(); } return this.properties.getProperty("password"); } private File GetPropertiesFile() { File settings = null; boolean firstTime = false; final String userHome = System.getProperty("user.home"); if (userHome == null) { throw new IllegalStateException("user.home==null"); } final File home = new File(userHome); settings = new File(home.getAbsoluteFile(), Utils.settingsFileName); try { if (settings.createNewFile()) { firstTime = true; } } catch (final IOException e) { e.printStackTrace(); } this.properties = new Properties(); try { this.properties .load(new FileInputStream(settings.getAbsoluteFile())); } catch (final IOException e) { e.printStackTrace(); } this.propertiesFile = settings; if (firstTime) { this.properties.setProperty("username", "Fill me in!"); this.properties.setProperty("password", "Fill me in!"); this.savePropertiesFile(); } return settings; } public Server getServer() throws MalformedURLException { final String host = "http://www.swissurban.ch/userphotolist/list1"; final String username = this.getUserName(); final String password = this.getPassword(); return new HTTPServer(username, password, host); } public String getUserName() { if (this.properties == null) { this.GetPropertiesFile(); } return this.properties.getProperty("username"); } private void savePropertiesFile() { try { System.out.println("File is:" + this.propertiesFile.getAbsoluteFile()); this.properties.store(new FileOutputStream(this.propertiesFile .getAbsoluteFile()), null); } catch (final IOException e) { } } public void saveUsernameAndPassword(final String username, final String password) { this.properties.setProperty("username", username); this.properties.setProperty("password", password); this.savePropertiesFile(); } }