Xcos: add "shift ENTER" as Context validator 39/20939/2
Clement DAVID [Fri, 12 Apr 2019 09:53:10 +0000 (11:53 +0200)]
Change-Id: I8da82f6c955ce32830b6b5faf15985a71967fea7

scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/dialog/SetContextDialog.java

index b11ade4..ab57446 100644 (file)
@@ -33,6 +33,7 @@ import java.io.OutputStreamWriter;
 import java.io.Writer;
 import java.io.FileOutputStream;
 import java.util.logging.Logger;
+import javax.swing.AbstractAction;
 
 import javax.swing.BorderFactory;
 import javax.swing.Box;
@@ -44,6 +45,7 @@ import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.JTextArea;
+import javax.swing.KeyStroke;
 import javax.swing.ScrollPaneConstants;
 import org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement;
 
@@ -188,11 +190,22 @@ public class SetContextDialog extends JDialog {
          * The ok button parse the contextArea, reconstruct the real context and
          * set the scicosParameters before exiting.
          */
-        okButton.addActionListener(new ActionListenerImpl());
+        
+        ActionImpl action = new ActionImpl();
+        
+        okButton.setAction(action);
+        KeyStroke shiftEnter = KeyStroke.getKeyStroke("shift ENTER");
+        contextArea.getInputMap().put(shiftEnter, "OK");
+        contextArea.getActionMap().put("OK", action);
+        
     }
 
-    private class ActionListenerImpl implements ActionListener {
+    private class ActionImpl extends AbstractAction implements ActionListener {
 
+        public ActionImpl() {
+            super(XcosMessages.OK);
+        }
+        
         @Override
         public void actionPerformed(ActionEvent e) {
             try {