comboBoxEdited events are fired if the content of the JComboBox is edited and then the comboBox is de-selected. This causes the connection to be initiated inadvertently sometimes (like when the About... button was pressed. Removed the ItemListener since it didn't serve any purpose, and also deleted the definition of endDialog() since it was the same as the inherited function anyway.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@5050 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/java/com/tigervnc/vncviewer/ServerDialog.java b/java/com/tigervnc/vncviewer/ServerDialog.java
index a134585..a1a0560 100644
--- a/java/com/tigervnc/vncviewer/ServerDialog.java
+++ b/java/com/tigervnc/vncviewer/ServerDialog.java
@@ -29,8 +29,7 @@
import com.tigervnc.rfb.*;
class ServerDialog extends Dialog implements
- ActionListener,
- ItemListener
+ ActionListener
{
@SuppressWarnings({"unchecked","rawtypes"})
@@ -77,6 +76,17 @@
server.setEditable(true);
editor = server.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);
+ commit();
+ }
+ }
+ });
JPanel topPanel = new JPanel(new GridBagLayout());
@@ -117,16 +127,11 @@
pack();
}
- public void itemStateChanged(ItemEvent e) {
- return;
- }
-
@SuppressWarnings({"unchecked","rawtypes"})
public void actionPerformed(ActionEvent e) {
Object s = e.getSource();
if (s instanceof JButton && (JButton)s == okButton) {
commit();
- endDialog();
} else if (s instanceof JButton && (JButton)s == cancelButton) {
if (VncViewer.nViewers == 1)
cc.viewer.exit(1);
@@ -140,8 +145,6 @@
if (e.getActionCommand().equals("comboBoxEdited")) {
server.insertItemAt(editor.getItem(), 0);
server.setSelectedIndex(0);
- commit();
- endDialog();
}
}
}
@@ -172,12 +175,9 @@
}
UserPreferences.set("ServerDialog", "history", sb.toString());
UserPreferences.save("ServerDialog");
+ endDialog();
}
- public void endDialog() {
- super.endDialog();
- }
-
CConn cc;
@SuppressWarnings("rawtypes")
JComboBox server;