aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Hinz <bphinz@users.sourceforge.net>2013-03-01 01:10:07 +0000
committerBrian Hinz <bphinz@users.sourceforge.net>2013-03-01 01:10:07 +0000
commit12da5fab8d4d927a6659d02dd95bffd15d961df8 (patch)
tree4d65f84466205bd670766f909bb914642c3494c6
parent8b61dd59f11bc5ad79a35d05977ddb0f73c0f392 (diff)
downloadtigervnc-12da5fab8d4d927a6659d02dd95bffd15d961df8.tar.gz
tigervnc-12da5fab8d4d927a6659d02dd95bffd15d961df8.zip
Replace multiple instantiations of code to retrieve resources (icons, timestamp) from jar file with statics.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@5054 3789f03b-4d11-0410-bbf8-ca57d06f2519
-rw-r--r--java/com/tigervnc/vncviewer/CConn.java20
-rw-r--r--java/com/tigervnc/vncviewer/Dialog.java4
-rw-r--r--java/com/tigervnc/vncviewer/ServerDialog.java2
-rw-r--r--java/com/tigervnc/vncviewer/Viewport.java1
-rw-r--r--java/com/tigervnc/vncviewer/VncViewer.java25
5 files changed, 18 insertions, 34 deletions
diff --git a/java/com/tigervnc/vncviewer/CConn.java b/java/com/tigervnc/vncviewer/CConn.java
index cccb7ba4..7cebe0bf 100644
--- a/java/com/tigervnc/vncviewer/CConn.java
+++ b/java/com/tigervnc/vncviewer/CConn.java
@@ -46,7 +46,6 @@ import java.util.jar.Manifest;
import javax.swing.*;
import javax.swing.ImageIcon;
import java.net.InetSocketAddress;
-import java.net.URL;
import java.net.SocketException;
import java.util.*;
@@ -500,13 +499,6 @@ public class CConn extends CConnection
viewport = new Viewport(cp.name(), this);
viewport.setUndecorated(fullScreen);
desktop.setViewport(viewport);
- ClassLoader loader = this.getClass().getClassLoader();
- URL url = loader.getResource("com/tigervnc/vncviewer/tigervnc.ico");
- ImageIcon icon = null;
- if (url != null) {
- icon = new ImageIcon(url);
- viewport.setIconImage(icon.getImage());
- }
reconfigureViewport();
if ((cp.width > 0) && (cp.height > 0))
viewport.setVisible(true);
@@ -717,11 +709,10 @@ public class CConn extends CConnection
}
void showAbout() {
- InputStream stream = cl.getResourceAsStream("com/tigervnc/vncviewer/timestamp");
String pkgDate = "";
String pkgTime = "";
try {
- Manifest manifest = new Manifest(stream);
+ Manifest manifest = new Manifest(VncViewer.timestamp);
Attributes attributes = manifest.getMainAttributes();
pkgDate = attributes.getValue("Package-Date");
pkgTime = attributes.getValue("Package-Time");
@@ -735,12 +726,9 @@ public class CConn extends CConnection
VncViewer.buildDate, VncViewer.buildTime);
JOptionPane op =
new JOptionPane(msg, JOptionPane.INFORMATION_MESSAGE,
- JOptionPane.DEFAULT_OPTION, logo);
+ JOptionPane.DEFAULT_OPTION, VncViewer.logoIcon);
JDialog dlg = op.createDialog("About TigerVNC Viewer for Java");
- ClassLoader cl = this.getClass().getClassLoader();
- ImageIcon icon =
- new ImageIcon(cl.getResource("com/tigervnc/vncviewer/tigervnc.ico"));
- dlg.setIconImage(icon.getImage());
+ dlg.setIconImage(VncViewer.frameIcon);
dlg.setVisible(true);
if (fullScreenWindow != null)
Viewport.setFullScreenWindow(fullScreenWindow);
@@ -1339,8 +1327,6 @@ public class CConn extends CConnection
// the following need no synchronization:
- ClassLoader cl = this.getClass().getClassLoader();
- ImageIcon logo = new ImageIcon(cl.getResource("com/tigervnc/vncviewer/tigervnc.png"));
public static UserPasswdGetter upg;
public UserMsgBox msg;
diff --git a/java/com/tigervnc/vncviewer/Dialog.java b/java/com/tigervnc/vncviewer/Dialog.java
index c478d4a9..cd488dba 100644
--- a/java/com/tigervnc/vncviewer/Dialog.java
+++ b/java/com/tigervnc/vncviewer/Dialog.java
@@ -35,6 +35,7 @@ import javax.swing.*;
class Dialog extends JDialog {
public Dialog(boolean modal) {
+ setIconImage(VncViewer.frameIcon);
if (modal) {
setModalityType(ModalityType.APPLICATION_MODAL);
} else {
@@ -53,9 +54,6 @@ class Dialog extends JDialog {
int y = (dpySize.height - mySize.height) / 2;
setLocation(x, y);
}
- ClassLoader cl = this.getClass().getClassLoader();
- ImageIcon icon = new ImageIcon(cl.getResource("com/tigervnc/vncviewer/tigervnc.ico"));
- setIconImage(icon.getImage());
fullScreenWindow = Viewport.getFullScreenWindow();
if (fullScreenWindow != null)
Viewport.setFullScreenWindow(null);
diff --git a/java/com/tigervnc/vncviewer/ServerDialog.java b/java/com/tigervnc/vncviewer/ServerDialog.java
index a1a05602..eda82d7b 100644
--- a/java/com/tigervnc/vncviewer/ServerDialog.java
+++ b/java/com/tigervnc/vncviewer/ServerDialog.java
@@ -90,7 +90,7 @@ class ServerDialog extends Dialog implements
JPanel topPanel = new JPanel(new GridBagLayout());
- addGBComponent(new JLabel(cc.logo),topPanel, 0, 0, 1, 1, 0, 0, 0, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START, new Insets(5,5,5,15));
+ addGBComponent(new JLabel(VncViewer.logoIcon),topPanel, 0, 0, 1, 1, 0, 0, 0, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START, new Insets(5,5,5,15));
addGBComponent(serverLabel,topPanel, 1, 0, 1, 1, 0, 0, 0, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_END, new Insets(10,0,5,5));
addGBComponent(server,topPanel, 2, 0, 1, 1, 0, 0, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, new Insets(10,0,5,40));
diff --git a/java/com/tigervnc/vncviewer/Viewport.java b/java/com/tigervnc/vncviewer/Viewport.java
index 31acc0e1..8f1b0e0e 100644
--- a/java/com/tigervnc/vncviewer/Viewport.java
+++ b/java/com/tigervnc/vncviewer/Viewport.java
@@ -40,6 +40,7 @@ public class Viewport extends JFrame
setTitle(name+" - TigerVNC");
setFocusable(false);
setFocusTraversalKeysEnabled(false);
+ setIconImage(VncViewer.frameIcon);
UIManager.getDefaults().put("ScrollPane.ancestorInputMap",
new UIDefaults.LazyInputMap(new Object[]{}));
sp = new JScrollPane();
diff --git a/java/com/tigervnc/vncviewer/VncViewer.java b/java/com/tigervnc/vncviewer/VncViewer.java
index ebd90b47..31043d1e 100644
--- a/java/com/tigervnc/vncviewer/VncViewer.java
+++ b/java/com/tigervnc/vncviewer/VncViewer.java
@@ -60,6 +60,14 @@ public class VncViewer extends java.applet.Applet implements Runnable
public static String build = null;
public static String buildDate = null;
public static String buildTime = null;
+ static ImageIcon frameIconSrc =
+ new ImageIcon(VncViewer.class.getResource("tigervnc.ico"));
+ public static final Image frameIcon = frameIconSrc.getImage();
+ public static final ImageIcon logoIcon =
+ new ImageIcon(VncViewer.class.getResource("tigervnc.png"));
+ public static final Image logoImage = logoIcon.getImage();
+ public static final InputStream timestamp =
+ VncViewer.class.getResourceAsStream("timestamp");
public static void setLookAndFeel() {
try {
@@ -282,17 +290,12 @@ public class VncViewer extends java.applet.Applet implements Runnable
vlog.debug("init called");
setLookAndFeel();
setBackground(Color.white);
- ClassLoader cl = this.getClass().getClassLoader();
- ImageIcon icon = new ImageIcon(cl.getResource("com/tigervnc/vncviewer/tigervnc.png"));
- logo = icon.getImage();
}
private void getTimestamp() {
if (version == null || build == null) {
- ClassLoader cl = this.getClass().getClassLoader();
- InputStream stream = cl.getResourceAsStream("com/tigervnc/vncviewer/timestamp");
try {
- Manifest manifest = new Manifest(stream);
+ Manifest manifest = new Manifest(timestamp);
Attributes attributes = manifest.getMainAttributes();
version = attributes.getValue("Version");
build = attributes.getValue("Build");
@@ -333,8 +336,8 @@ public class VncViewer extends java.applet.Applet implements Runnable
}
public void paint(Graphics g) {
- g.drawImage(logo, 0, 0, this);
- int h = logo.getHeight(this)+20;
+ g.drawImage(logoImage, 0, 0, this);
+ int h = logoImage.getHeight(this)+20;
g.drawString(String.format(aboutText, version, build,
buildDate, buildTime), 0, h);
}
@@ -378,10 +381,7 @@ public class VncViewer extends java.applet.Applet implements Runnable
JOptionPane op =
new JOptionPane(e.getMessage(), JOptionPane.WARNING_MESSAGE);
JDialog dlg = op.createDialog("TigerVNC Viewer");
- ClassLoader cl = this.getClass().getClassLoader();
- ImageIcon icon =
- new ImageIcon(cl.getResource("com/tigervnc/vncviewer/tigervnc.ico"));
- dlg.setIconImage(icon.getImage());
+ dlg.setIconImage(frameIcon);
dlg.setVisible(true);
} else {
if (!cc.shuttingDown)
@@ -557,7 +557,6 @@ public class VncViewer extends java.applet.Applet implements Runnable
Thread thread;
Socket sock;
boolean applet;
- Image logo;
static int nViewers;
static LogWriter vlog = new LogWriter("main");
}