From: Brian Hinz Date: Fri, 22 Feb 2013 19:47:13 +0000 (+0000) Subject: comboBoxEdited events are fired if the content of the JComboBox is edited and then... X-Git-Tag: v1.2.90~35 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=faad79dd78a348a092141a633277b3b6025f82ee;p=tigervnc.git 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 a1345850..a1a05602 100644 --- a/java/com/tigervnc/vncviewer/ServerDialog.java +++ b/java/com/tigervnc/vncviewer/ServerDialog.java @@ -29,8 +29,7 @@ import java.util.*; import com.tigervnc.rfb.*; class ServerDialog extends Dialog implements - ActionListener, - ItemListener + ActionListener { @SuppressWarnings({"unchecked","rawtypes"}) @@ -77,6 +76,17 @@ class ServerDialog extends Dialog implements 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 @@ class ServerDialog extends Dialog implements 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 @@ class ServerDialog extends Dialog implements if (e.getActionCommand().equals("comboBoxEdited")) { server.insertItemAt(editor.getItem(), 0); server.setSelectedIndex(0); - commit(); - endDialog(); } } } @@ -172,12 +175,9 @@ class ServerDialog extends Dialog implements } UserPreferences.set("ServerDialog", "history", sb.toString()); UserPreferences.save("ServerDialog"); + endDialog(); } - public void endDialog() { - super.endDialog(); - } - CConn cc; @SuppressWarnings("rawtypes") JComboBox server;