162 163 if (condition == JComponent.WHEN_IN_FOCUSED_WINDOW) { 164 return createInputMap(condition, c); 165 } 166 return null; 167 } 168 169 ComponentInputMap createInputMap(int condition, JComponent c) { 170 return new RootPaneInputMap(c); 171 } 172 173 static void loadActionMap(LazyActionMap map) { 174 map.put(new Actions(Actions.PRESS)); 175 map.put(new Actions(Actions.RELEASE)); 176 map.put(new Actions(Actions.POST_POPUP)); 177 } 178 179 /** 180 * Invoked when the default button property has changed. This reloads 181 * the bindings from the defaults table with name 182 * <code>RootPane.defaultButtonWindowKeyBindings</code>. 183 */ 184 void updateDefaultButtonBindings(JRootPane root) { 185 InputMap km = SwingUtilities.getUIInputMap(root, JComponent. 186 WHEN_IN_FOCUSED_WINDOW); 187 while (km != null && !(km instanceof RootPaneInputMap)) { 188 km = km.getParent(); 189 } 190 if (km != null) { 191 km.clear(); 192 if (root.getDefaultButton() != null) { 193 Object[] bindings = (Object[])DefaultLookup.get(root, this, 194 "RootPane.defaultButtonWindowKeyBindings"); 195 if (bindings != null) { 196 LookAndFeel.loadKeyBindings(km, bindings); 197 } 198 } 199 } 200 } 201 202 /** 203 * Invoked when a property changes on the root pane. If the event 204 * indicates the <code>defaultButton</code> has changed, this will 205 * reinstall the keyboard actions. 206 */ 207 public void propertyChange(PropertyChangeEvent e) { 208 if(e.getPropertyName().equals("defaultButton")) { 209 JRootPane rootpane = (JRootPane)e.getSource(); 210 updateDefaultButtonBindings(rootpane); 211 if (rootpane.getClientProperty("temporaryDefaultButton") == null) { 212 rootpane.putClientProperty("initialDefaultButton", e.getNewValue()); 213 } 214 } 215 } 216 217 218 static class Actions extends UIAction { 219 public static final String PRESS = "press"; 220 public static final String RELEASE = "release"; 221 public static final String POST_POPUP = "postPopup"; 222 223 Actions(String name) { 224 super(name); | 162 163 if (condition == JComponent.WHEN_IN_FOCUSED_WINDOW) { 164 return createInputMap(condition, c); 165 } 166 return null; 167 } 168 169 ComponentInputMap createInputMap(int condition, JComponent c) { 170 return new RootPaneInputMap(c); 171 } 172 173 static void loadActionMap(LazyActionMap map) { 174 map.put(new Actions(Actions.PRESS)); 175 map.put(new Actions(Actions.RELEASE)); 176 map.put(new Actions(Actions.POST_POPUP)); 177 } 178 179 /** 180 * Invoked when the default button property has changed. This reloads 181 * the bindings from the defaults table with name 182 * {@code RootPane.defaultButtonWindowKeyBindings}. 183 */ 184 void updateDefaultButtonBindings(JRootPane root) { 185 InputMap km = SwingUtilities.getUIInputMap(root, JComponent. 186 WHEN_IN_FOCUSED_WINDOW); 187 while (km != null && !(km instanceof RootPaneInputMap)) { 188 km = km.getParent(); 189 } 190 if (km != null) { 191 km.clear(); 192 if (root.getDefaultButton() != null) { 193 Object[] bindings = (Object[])DefaultLookup.get(root, this, 194 "RootPane.defaultButtonWindowKeyBindings"); 195 if (bindings != null) { 196 LookAndFeel.loadKeyBindings(km, bindings); 197 } 198 } 199 } 200 } 201 202 /** 203 * Invoked when a property changes on the root pane. If the event 204 * indicates the {@code defaultButton} has changed, this will 205 * reinstall the keyboard actions. 206 */ 207 public void propertyChange(PropertyChangeEvent e) { 208 if(e.getPropertyName().equals("defaultButton")) { 209 JRootPane rootpane = (JRootPane)e.getSource(); 210 updateDefaultButtonBindings(rootpane); 211 if (rootpane.getClientProperty("temporaryDefaultButton") == null) { 212 rootpane.putClientProperty("initialDefaultButton", e.getNewValue()); 213 } 214 } 215 } 216 217 218 static class Actions extends UIAction { 219 public static final String PRESS = "press"; 220 public static final String RELEASE = "release"; 221 public static final String POST_POPUP = "postPopup"; 222 223 Actions(String name) { 224 super(name); |