Add no mouse support for table cell editors.
authorjlin16 <jlin16@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 28 Sep 2006 09:01:25 +0000 (09:01 +0000)
committerjlin16 <jlin16@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 28 Sep 2006 09:01:25 +0000 (09:01 +0000)
Add auto-search function in FrameworkModules tables by detecting keyboard typing.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1637 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/packaging/ui/GenGuidDialog.java
Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/packaging/ui/GuidEditor.java
Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFrameworkModules.java
Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/GenListDialog.java
Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/GenLongTextDialog.java
Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/ListEditor.java
Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/LongTextEditor.java

index 9c0674e..4e65c3c 100644 (file)
@@ -20,6 +20,7 @@ import javax.swing.JPanel;
 import javax.swing.JDialog;\r
 import java.awt.GridLayout;\r
 \r
+import javax.swing.JComponent;\r
 import javax.swing.JFrame;\r
 import javax.swing.JOptionPane;\r
 import javax.swing.JTextField;\r
@@ -27,12 +28,14 @@ import javax.swing.JLabel;
 import javax.swing.JRadioButton;\r
 import javax.swing.ButtonGroup;\r
 import javax.swing.JButton;\r
+import javax.swing.KeyStroke;\r
 \r
 import org.tianocore.frameworkwizard.common.Tools;\r
 \r
 import java.awt.FlowLayout;\r
 import java.awt.event.ActionEvent;\r
 import java.awt.event.ActionListener;\r
+import java.awt.event.KeyEvent;\r
 import java.awt.event.WindowAdapter;\r
 import java.awt.event.WindowEvent;\r
 \r
@@ -62,6 +65,7 @@ public class GenGuidDialog extends JDialog implements ActionListener{
     private JButton jButtonCancel = null;\r
     private JButton jButtonNew = null;\r
     private JButton jButtonOk = null;\r
+    private ActionListener outerListener = null;\r
     \r
 //    private String guid = null;\r
 \r
@@ -121,7 +125,7 @@ public class GenGuidDialog extends JDialog implements ActionListener{
 //            else {\r
 //                JOptionPane.showMessageDialog(frame, "Incorrect GUID Value Format.");\r
 //            }\r
-            this.dispose();\r
+//            this.dispose();\r
         }\r
         \r
         if (arg0.getSource() == jButtonCancel){\r
@@ -227,6 +231,7 @@ public class GenGuidDialog extends JDialog implements ActionListener{
             jButtonCancel.setPreferredSize(new java.awt.Dimension(80,20));\r
             jButtonCancel.setText("Cancel");\r
             jButtonCancel.addActionListener(this);\r
+            jButtonCancel.registerKeyboardAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), JComponent.WHEN_FOCUSED);\r
         }\r
         return jButtonCancel;\r
     }\r
@@ -243,6 +248,7 @@ public class GenGuidDialog extends JDialog implements ActionListener{
             jButtonNew.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);\r
             jButtonNew.setText("New");\r
             jButtonNew.addActionListener(this);\r
+            jButtonNew.registerKeyboardAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), JComponent.WHEN_FOCUSED);\r
         }\r
         return jButtonNew;\r
     }\r
@@ -258,7 +264,9 @@ public class GenGuidDialog extends JDialog implements ActionListener{
             jButtonOk.setPreferredSize(new java.awt.Dimension(80,20));\r
             jButtonOk.setText("Ok");\r
             jButtonOk.setActionCommand("GenGuidValue");\r
-            jButtonOk.addActionListener(this);\r
+//            jButtonOk.addActionListener(this);\r
+            jButtonOk.registerKeyboardAction(outerListener, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), JComponent.WHEN_FOCUSED);\r
+            \r
         }\r
         return jButtonOk;\r
     }\r
@@ -289,6 +297,7 @@ public class GenGuidDialog extends JDialog implements ActionListener{
     \r
     public GenGuidDialog(ActionListener i){\r
         super();\r
+        outerListener = i;\r
         initialize();\r
         jButtonOk.addActionListener(i);\r
         this.addWindowListener(new WindowAdapter(){\r
index 7b2683a..c9f73b0 100644 (file)
@@ -16,11 +16,14 @@ package org.tianocore.frameworkwizard.packaging.ui;
 import java.awt.Component;\r
 import java.awt.event.ActionEvent;\r
 import java.awt.event.ActionListener;\r
+//import java.awt.event.KeyEvent;\r
 \r
 import javax.swing.AbstractCellEditor;\r
 import javax.swing.JButton;\r
+//import javax.swing.JComponent;\r
 import javax.swing.JFrame;\r
 import javax.swing.JTable;\r
+//import javax.swing.KeyStroke;\r
 import javax.swing.table.TableCellEditor;\r
 \r
 \r
@@ -45,6 +48,7 @@ public class GuidEditor extends AbstractCellEditor implements TableCellEditor, A
         button = new JButton();\r
         button.setActionCommand(EDIT);\r
         button.addActionListener(this);\r
+//        button.registerKeyboardAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0, false), JComponent.WHEN_FOCUSED);\r
         button.setBorderPainted(false);\r
 \r
         \r
@@ -86,7 +90,8 @@ public class GuidEditor extends AbstractCellEditor implements TableCellEditor, A
         }\r
         else { //User pressed dialog's "OK" button.\r
             currentGuid = dialog.getGuid();\r
-\r
+//            button.setText(currentGuid);\r
+            dialog.dispose();\r
         }\r
 \r
     }\r
index ae74471..cd9d0dd 100644 (file)
@@ -38,6 +38,7 @@ import org.tianocore.frameworkwizard.platform.ui.global.WorkspaceProfile;
 import org.tianocore.frameworkwizard.module.Identifications.ModuleIdentification;\r
 \r
 import java.awt.FlowLayout;\r
+import java.awt.event.KeyEvent;\r
 import java.awt.event.MouseEvent;\r
 import java.util.ArrayList;\r
 import java.util.HashMap;\r
@@ -52,6 +53,12 @@ public class FpdFrameworkModules extends IInternalFrame {
      */\r
     private static final long serialVersionUID = 1L;\r
     \r
+    private static final int timeToWait = 3000;\r
+    \r
+    private long savedMs = 0;\r
+    \r
+    String searchField = "";\r
+    \r
     public static final int forceDbgColForFpdModTable = 7;\r
 \r
     static JFrame frame;\r
@@ -309,11 +316,51 @@ public class FpdFrameworkModules extends IInternalFrame {
                     }\r
                 }\r
             });\r
+            jTableAllModules.addKeyListener(new java.awt.event.KeyAdapter() {\r
+                public void keyPressed(java.awt.event.KeyEvent e) {\r
+                    if (e.getKeyCode() == KeyEvent.VK_ENTER) {\r
+                        int selectedRow = jTableAllModules.getSelectedRow();\r
+                        if (selectedRow < 0) {\r
+                            return;\r
+                        }\r
+                        TableSorter sorter = (TableSorter) jTableAllModules.getModel();\r
+                        selectedRow = sorter.getModelRowIndex(selectedRow);\r
+                        addModuleIntoPlatform (selectedRow);\r
+                    }\r
+                }\r
+            });\r
+            \r
+            jTableAllModules.addKeyListener(new java.awt.event.KeyAdapter() {\r
+                public void keyTyped(java.awt.event.KeyEvent e) {\r
+\r
+                    if (System.currentTimeMillis() - savedMs < timeToWait) {\r
+                        searchField += e.getKeyChar();\r
+                    }\r
+                    else {\r
+                        searchField = "" + e.getKeyChar(); \r
+                    }\r
+                    \r
+                    int viewIndex = gotoFoundRow (searchField, (TableSorter) jTableAllModules.getModel());\r
+                    if (viewIndex >= 0){\r
+                        jTableAllModules.changeSelection(viewIndex, 0, false, false);\r
+                    }\r
+                    savedMs = System.currentTimeMillis();\r
+                }\r
+            });\r
             \r
             \r
         }\r
         return jTableAllModules;\r
     }\r
+    \r
+    private int gotoFoundRow (String s, TableSorter model) {\r
+        for (int i = 0; i < model.getRowCount(); ++i) {\r
+            if (model.getValueAt(i, 0) != null && model.getValueAt(i, 0).toString().regionMatches(true, 0, s, 0, s.length())) {\r
+                return model.getViewIndexArray()[i];\r
+            }\r
+        }\r
+        return -1;\r
+    }\r
 \r
     /**\r
      * This method initializes jPanelTopSouth\r
@@ -560,6 +607,38 @@ public class FpdFrameworkModules extends IInternalFrame {
                 }\r
             });\r
             \r
+            jTableFpdModules.addKeyListener(new java.awt.event.KeyAdapter() {\r
+                public void keyPressed(java.awt.event.KeyEvent e) {\r
+                    if (e.getKeyCode() == KeyEvent.VK_ENTER) {\r
+                        int selectedRow = jTableFpdModules.getSelectedRow();\r
+                        if (selectedRow < 0) {\r
+                            return;\r
+                        }\r
+                        TableSorter sorter = (TableSorter) jTableFpdModules.getModel();\r
+                        selectedRow = sorter.getModelRowIndex(selectedRow);\r
+                        showSettingsDlg (selectedRow);\r
+                    }\r
+                }\r
+            });\r
+            \r
+            jTableFpdModules.addKeyListener(new java.awt.event.KeyAdapter() {\r
+                public void keyTyped(java.awt.event.KeyEvent e) {\r
+\r
+                    if (System.currentTimeMillis() - savedMs < timeToWait) {\r
+                        searchField += e.getKeyChar();\r
+                    }\r
+                    else {\r
+                        searchField = "" + e.getKeyChar(); \r
+                    }\r
+                    \r
+                    int viewIndex = gotoFoundRow (searchField, (TableSorter) jTableFpdModules.getModel());\r
+                    if (viewIndex >= 0){\r
+                        jTableFpdModules.changeSelection(viewIndex, 0, false, false);\r
+                    }\r
+                    savedMs = System.currentTimeMillis();\r
+                }\r
+            });\r
+            \r
             jTableFpdModules.getModel().addTableModelListener(this);\r
         }\r
         return jTableFpdModules;\r
index e21ee54..f4894a3 100644 (file)
@@ -16,8 +16,10 @@ import java.awt.BorderLayout;
 import java.awt.Dimension;\r
 import java.awt.Toolkit;\r
 \r
+import javax.swing.JComponent;\r
 import javax.swing.JPanel;\r
 import javax.swing.JDialog;\r
+import javax.swing.KeyStroke;\r
 \r
 import javax.swing.JButton;\r
 \r
@@ -25,6 +27,7 @@ import javax.swing.JButton;
 import java.awt.FlowLayout;\r
 import java.awt.event.ActionEvent;\r
 import java.awt.event.ActionListener;\r
+import java.awt.event.KeyEvent;\r
 import java.util.Vector;\r
 \r
 import javax.swing.JScrollPane;\r
@@ -59,7 +62,7 @@ public class GenListDialog extends JDialog implements ActionListener{
         \r
         if (arg0.getSource() == jButtonOk){\r
 \r
-            this.dispose();\r
+//            this.dispose();\r
         }\r
         \r
         if (arg0.getSource() == jButtonCancel){\r
@@ -111,6 +114,7 @@ public class GenListDialog extends JDialog implements ActionListener{
             jButtonCancel.setPreferredSize(new java.awt.Dimension(80,20));\r
             jButtonCancel.setText("Cancel");\r
             jButtonCancel.addActionListener(this);\r
+            jButtonCancel.registerKeyboardAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), JComponent.WHEN_FOCUSED);\r
         }\r
         return jButtonCancel;\r
     }\r
@@ -185,7 +189,7 @@ public class GenListDialog extends JDialog implements ActionListener{
     public GenListDialog(ActionListener i){\r
         this();\r
         jButtonOk.addActionListener(i);\r
-        \r
+        jButtonOk.registerKeyboardAction(i, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), JComponent.WHEN_FOCUSED);\r
     }\r
 \r
     /**\r
index 574be8a..e8aafa7 100644 (file)
@@ -16,13 +16,18 @@ import java.awt.BorderLayout;
 import java.awt.Dimension;\r
 import java.awt.Toolkit;\r
 \r
+import javax.swing.JComponent;\r
 import javax.swing.JPanel;\r
 import javax.swing.JDialog;\r
 import javax.swing.JTextArea;\r
 import javax.swing.JButton;\r
+import javax.swing.KeyStroke;\r
+\r
 import java.awt.FlowLayout;\r
 import java.awt.event.ActionEvent;\r
 import java.awt.event.ActionListener;\r
+import java.awt.event.KeyEvent;\r
+\r
 import javax.swing.JScrollPane;\r
 \r
 \r
@@ -48,13 +53,11 @@ public class GenLongTextDialog extends JDialog implements ActionListener{
 \r
     private JScrollPane jScrollPane = null;\r
 \r
-\r
-\r
     public void actionPerformed(ActionEvent arg0) {\r
         \r
         if (arg0.getSource() == jButtonOk){\r
 \r
-            this.dispose();\r
+//            this.dispose();\r
         }\r
         \r
         if (arg0.getSource() == jButtonCancel){\r
@@ -107,6 +110,7 @@ public class GenLongTextDialog extends JDialog implements ActionListener{
             jButtonCancel.setPreferredSize(new java.awt.Dimension(80,20));\r
             jButtonCancel.setText("Cancel");\r
             jButtonCancel.addActionListener(this);\r
+            jButtonCancel.registerKeyboardAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), JComponent.WHEN_FOCUSED);\r
         }\r
         return jButtonCancel;\r
     }\r
@@ -170,7 +174,7 @@ public class GenLongTextDialog extends JDialog implements ActionListener{
     public GenLongTextDialog(ActionListener i){\r
         this();\r
         jButtonOk.addActionListener(i);\r
-        \r
+        jButtonOk.registerKeyboardAction(i, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), JComponent.WHEN_FOCUSED);\r
     }\r
 \r
     /**\r
index e604e1f..89523b2 100644 (file)
@@ -98,6 +98,7 @@ public class ListEditor extends AbstractCellEditor implements TableCellEditor, A
                 s += " ";\r
             }\r
             archs = s.trim();\r
+            dialog.dispose();\r
         }\r
 \r
     }\r
index 86a2d12..3d84dce 100644 (file)
@@ -86,6 +86,7 @@ public class LongTextEditor extends AbstractCellEditor implements TableCellEdito
         else { //User pressed dialog's "OK" button.\r
             \r
             text = dialog.getText().trim();\r
+            dialog.dispose();\r
         }\r
 \r
     }\r