< prev index next >

## src/java.desktop/share/classes/javax/swing/plaf/basic/BasicButtonListener.java

Print this page

     139     }
     140
     141     /**
     142      * Resets the binding for the mnemonic in the WHEN_IN_FOCUSED_WINDOW
     143      * UI InputMap.
     144      */
     145     void updateMnemonicBinding(AbstractButton b) {
     146         int m = b.getMnemonic();
     147         if(m != 0) {
     148             InputMap map = SwingUtilities.getUIInputMap(
     149                                 b, JComponent.WHEN_IN_FOCUSED_WINDOW);
     150
     151             if (map == null) {
     152                 map = new ComponentInputMapUIResource(b);
     153                 SwingUtilities.replaceUIInputMap(b,
     154                                JComponent.WHEN_IN_FOCUSED_WINDOW, map);
     155             }
     156             map.clear();
     157             map.put(KeyStroke.getKeyStroke(m, BasicLookAndFeel.getFocusAcceleratorKeyMask(), false),
     158                     "pressed");

     159             map.put(KeyStroke.getKeyStroke(m, BasicLookAndFeel.getFocusAcceleratorKeyMask(), true),

     160                     "released");
     161             map.put(KeyStroke.getKeyStroke(m, 0, true), "released");
     162         }
     163         else {
     164             InputMap map = SwingUtilities.getUIInputMap(b, JComponent.
     165                                              WHEN_IN_FOCUSED_WINDOW);
     166             if (map != null) {
     167                 map.clear();
     168             }
     169         }
     170     }
     171
     172     public void stateChanged(ChangeEvent e) {
     173         AbstractButton b = (AbstractButton) e.getSource();
     174         b.repaint();
     175     }
     176
     177     public void focusGained(FocusEvent e) {
     178         AbstractButton b = (AbstractButton) e.getSource();
     179         if (b instanceof JButton && ((JButton)b).isDefaultCapable()) {
     139     }
     140
     141     /**
     142      * Resets the binding for the mnemonic in the WHEN_IN_FOCUSED_WINDOW
     143      * UI InputMap.
     144      */
     145     void updateMnemonicBinding(AbstractButton b) {
     146         int m = b.getMnemonic();
     147         if(m != 0) {
     148             InputMap map = SwingUtilities.getUIInputMap(
     149                                 b, JComponent.WHEN_IN_FOCUSED_WINDOW);
     150
     151             if (map == null) {
     152                 map = new ComponentInputMapUIResource(b);
     153                 SwingUtilities.replaceUIInputMap(b,
     154                                JComponent.WHEN_IN_FOCUSED_WINDOW, map);
     155             }
     156             map.clear();
     157             map.put(KeyStroke.getKeyStroke(m, BasicLookAndFeel.getFocusAcceleratorKeyMask(), false),
     158                     "pressed");
     159             map.put(KeyStroke.getKeyStroke(m,
     160                     BasicLookAndFeel.getFocusAcceleratorKeyMask() |
     161                             InputEvent.ALT_GRAPH_DOWN_MASK,false),
     162                     "pressed");
     163
     164             map.put(KeyStroke.getKeyStroke(m, BasicLookAndFeel.getFocusAcceleratorKeyMask(), true),
     165                     "released");
     166             map.put(KeyStroke.getKeyStroke(m,
     167                     BasicLookAndFeel.getFocusAcceleratorKeyMask() |
     168                             InputEvent.ALT_GRAPH_DOWN_MASK, true),
     169                     "released");
     170             map.put(KeyStroke.getKeyStroke(m, 0, true), "released");
     171         }
     172         else {
     173             InputMap map = SwingUtilities.getUIInputMap(b, JComponent.
     174                                              WHEN_IN_FOCUSED_WINDOW);
     175             if (map != null) {
     176                 map.clear();
     177             }
     178         }
     179     }
     180
     181     public void stateChanged(ChangeEvent e) {
     182         AbstractButton b = (AbstractButton) e.getSource();
     183         b.repaint();
     184     }
     185
     186     public void focusGained(FocusEvent e) {
     187         AbstractButton b = (AbstractButton) e.getSource();
     188         if (b instanceof JButton && ((JButton)b).isDefaultCapable()) {

< prev index next >