Mercurial > hg > release > thermostat-1.2
changeset 1334:cade2ed3f8ad
Allow 'enter' to accept the connection dialog
Reviewed-by: neugens
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-November/008804.html
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Mon, 18 Nov 2013 17:47:25 -0500 |
parents | 8a6f30063c8c |
children | 67007986c584 |
files | client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/views/ClientConfigurationSwing.java client/swing/src/test/java/com/redhat/thermostat/client/swing/internal/views/ClientConfigurationSwingTest.java |
diffstat | 2 files changed, 51 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/views/ClientConfigurationSwing.java Mon Nov 18 16:05:37 2013 -0500 +++ b/client/swing/src/main/java/com/redhat/thermostat/client/swing/internal/views/ClientConfigurationSwing.java Mon Nov 18 17:47:25 2013 -0500 @@ -47,6 +47,7 @@ import javax.swing.JDialog; import javax.swing.JOptionPane; +import javax.swing.JTextField; import javax.swing.SwingUtilities; import javax.swing.WindowConstants; @@ -74,6 +75,23 @@ windowClosingListener = new WindowClosingListener(); configurationPanel = new ClientConfigurationPanel(); + + java.awt.event.ActionListener acceptOnEnterListener = new java.awt.event.ActionListener() { + @Override + public void actionPerformed(java.awt.event.ActionEvent arg0) { + fireAction(new ActionEvent<>(ClientConfigurationSwing.this, Action.CLOSE_ACCEPT)); + } + }; + + // handle 'enter' in text fields + JTextField[] fields = new JTextField[] { + configurationPanel.storageUrl, + configurationPanel.userName, + configurationPanel.password}; + + for (JTextField field: fields) { + field.addActionListener(acceptOnEnterListener); + } final JOptionPane optionPane = new JOptionPane(configurationPanel); optionPane.setOptionType(JOptionPane.OK_CANCEL_OPTION);
--- a/client/swing/src/test/java/com/redhat/thermostat/client/swing/internal/views/ClientConfigurationSwingTest.java Mon Nov 18 16:05:37 2013 -0500 +++ b/client/swing/src/test/java/com/redhat/thermostat/client/swing/internal/views/ClientConfigurationSwingTest.java Mon Nov 18 17:47:25 2013 -0500 @@ -119,6 +119,17 @@ assertEquals("foobar", frame.getConnectionUrl()); } + + @Category(GUITest.class) + @GUITest + @Test + public void testEnterInConnectionUrlTextAcceptsPrompt() { + JTextComponentFixture textBox = frameFixture.textBox("connectionUrl"); + textBox.enterText("foobar\n"); + + verify(l).actionPerformed(new ActionEvent<>(frame, ClientConfigurationView.Action.CLOSE_ACCEPT)); + } + @Category(GUITest.class) @Test public void testPasswordText() { @@ -129,6 +140,17 @@ assertEquals("foobar", frame.getPassword()); } + + @Category(GUITest.class) + @GUITest + @Test + public void testEnterInPasswordTextAcceptsPrompt() { + JTextComponentFixture textBox = frameFixture.textBox("password"); + textBox.enterText("foobar\n"); + + verify(l).actionPerformed(new ActionEvent<>(frame, ClientConfigurationView.Action.CLOSE_ACCEPT)); + } + @Category(GUITest.class) @Test public void testUsernameText() { @@ -139,6 +161,17 @@ assertEquals("foobar", frame.getUserName()); } + + @Category(GUITest.class) + @GUITest + @Test + public void testEnterInUsernameTextAcceptsPrompt() { + JTextComponentFixture textBox = frameFixture.textBox("username"); + textBox.enterText("foobar\n"); + + verify(l).actionPerformed(new ActionEvent<>(frame, ClientConfigurationView.Action.CLOSE_ACCEPT)); + } + @Category(GUITest.class) @Test public void testSaveEntitlements() {