import java.awt.*;
import java.awt.event.*;
import java.io.File;
+import java.nio.CharBuffer;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.filechooser.*;
class ServerDialog extends Dialog implements Runnable {
@SuppressWarnings({"unchecked","rawtypes"})
- public ServerDialog() {
+ public ServerDialog(String defaultServerName,
+ CharBuffer vncServerName) {
super(true);
+ this.vncServerName = vncServerName;
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
setTitle("VNC Viewer: Connection Details");
setResizable(false);
});
JLabel serverLabel = new JLabel("VNC server:", JLabel.RIGHT);
- String valueStr = new String("");
- if (UserPreferences.get("ServerDialog", "history") != null)
- valueStr = UserPreferences.get("ServerDialog", "history");
- server = new MyJComboBox(valueStr.split(","));
- server.addActionListener(new ActionListener() {
+ String valueStr = new String(defaultServerName);
+ ArrayList<String> servernames = new ArrayList<String>();
+ if (!valueStr.isEmpty())
+ servernames.add(valueStr);
+ String history = UserPreferences.get("ServerDialog", "history");
+ if (history != null) {
+ for (String s : history.split(",")) {
+ if (servernames.indexOf(s) < 0)
+ servernames.add(s);
+ }
+ }
+ serverName = new MyJComboBox(servernames.toArray());
+ serverName.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox s = (JComboBox)e.getSource();
if (e.getActionCommand().equals("comboBoxEdited")) {
}
}
});
- if (valueStr.equals(""))
- server.setPrototypeDisplayValue("255.255.255.255:5900");
+ if (servernames.size() == 0)
+ serverName.setPrototypeDisplayValue("255.255.255.255:5900");
- server.setEditable(true);
- editor = server.getEditor();
+ serverName.setEditable(true);
+ editor = serverName.getEditor();
editor.getEditorComponent().addKeyListener(new KeyListener() {
public void keyTyped(KeyEvent e) {}
public void keyReleased(KeyEvent e) {}
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
- server.insertItemAt(editor.getItem(), 0);
- server.setSelectedIndex(0);
+ serverName.insertItemAt(editor.getItem(), 0);
+ serverName.setSelectedIndex(0);
handleConnect();
}
}
LINE_START, NONE,
new Insets(5, 10, 5, 5),
NONE, NONE));
- contentPane.add(server,
+ contentPane.add(serverName,
new GridBagConstraints(2, 0,
REMAINDER, 1,
HEAVY, LIGHT,
f = showChooser(title, f, filter);
}
if (f != null && (!f.exists() || f.canWrite()))
- saveViewerParameters(f.getAbsolutePath(), (String)server.getSelectedItem());
+ saveViewerParameters(f.getAbsolutePath(), (String)serverName.getSelectedItem());
}
private void handleAbout() {
}
private void handleCancel() {
- vncServerName.setParam("");
endDialog();
}
private void handleConnect() {
- String serverName = (String)server.getSelectedItem();
- vncServerName.setParam(serverName);
- saveViewerParameters(null, serverName);
+ String servername = (String)serverName.getSelectedItem();
+ vncServerName.put(servername).flip();
+ saveViewerParameters(null, servername);
endDialog();
}
@SuppressWarnings("rawtypes")
- MyJComboBox server;
+ MyJComboBox serverName;
ComboBoxEditor editor;
JButton aboutButton, optionsButton, connectButton, cancelButton;
OptionsDialog options;
+ CharBuffer vncServerName;
static LogWriter vlog = new LogWriter("ServerDialog");
}
import java.lang.Character;
import java.lang.reflect.*;
import java.net.URL;
+import java.nio.CharBuffer;
+import java.util.*;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
-import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.plaf.FontUIResource;
System.getProperty("os.name").toLowerCase();
private static VncViewer applet;
+ private String defaultServerName;
+ int VNCSERVERNAMELEN = 64;
+ CharBuffer vncServerName = CharBuffer.allocate(VNCSERVERNAMELEN);
+
public static void setLookAndFeel() {
try {
if (os.startsWith("mac os x")) {
Configuration.enableViewerParams();
/* Load the default parameter settings */
- String defaultServerName;
try {
defaultServerName = loadViewerParameters(null);
} catch (com.tigervnc.rfb.Exception e) {
usage();
}
- if (!vncServerName.getValue().isEmpty())
- usage();
- vncServerName.setParam(argv[i]);
+ vncServerName.put(argv[i].toCharArray()).flip();
}
}
setLookAndFeel();
setBackground(Color.white);
applet = this;
- String servername = loadAppletParameters(applet);
- vncServerName.setParam(servername);
- alwaysShowServerDialog.setParam(false);
+ vncServerName.put(loadAppletParameters(applet).toCharArray()).flip();
if (embed.getValue()) {
fullScreen.setParam(false);
remoteResize.setParam(false);
public void run() {
cc = null;
+ Socket sock = null;
+
+ /* Specifying -via and -listen together is nonsense */
+ if (listenMode.getValue() && !via.getValueStr().isEmpty()) {
+ vlog.error("Parameters -listen and -via are incompatible");
+ String msg =
+ new String("Parameters -listen and -via are incompatible");
+ JOptionPane.showMessageDialog(null, msg, "ERROR",
+ JOptionPane.ERROR_MESSAGE);
+ exit(1);
+ }
if (listenMode.getValue()) {
int port = 5500;
- if (!vncServerName.getValue().isEmpty() &&
- Character.isDigit(vncServerName.getValue().charAt(0)))
- port = Integer.parseInt(vncServerName.getValue());
+ if (vncServerName.charAt(0) != 0 &&
+ Character.isDigit(vncServerName.charAt(0)))
+ port = Integer.parseInt(vncServerName.toString());
TcpListener listener = null;
try {
while (sock == null)
sock = listener.accept();
} else {
- if (alwaysShowServerDialog.getValue() || sock == null) {
- if (vncServerName.getValue().isEmpty()) {
- try {
- SwingUtilities.invokeAndWait(new ServerDialog());
- } catch (InvocationTargetException e) {
- reportException(e);
- } catch (InterruptedException e) {
- reportException(e);
- }
- if (vncServerName.getValue().isEmpty())
- exit(0);
+ if (vncServerName.charAt(0) == 0) {
+ try {
+ SwingUtilities.invokeAndWait(
+ new ServerDialog(defaultServerName, vncServerName));
+ } catch (InvocationTargetException e) {
+ reportException(e);
+ } catch (InterruptedException e) {
+ reportException(e);
}
+ if (vncServerName.charAt(0) == 0)
+ exit(0);
}
}
try {
- cc = new CConn(vncServerName.getValue(), sock);
+ cc = new CConn(vncServerName.toString(), sock);
while (!cc.shuttingDown)
cc.processMsg();
exit(0);
"Specifies a configuration file to load.", null);
Thread thread;
- Socket sock;
static LogWriter vlog = new LogWriter("VncViewer");
}