* augmented by the collection of commands that the * editor itself supports. These are useful for binding * to events, such as in a keymap. * * @return the command list */ public Action[] getActions() { return getUI().getEditorKit(this).getActions(); } /** * Sets margin space between the text component's border * and its text. The text component's default <code>Border</code> * object will use this value to create the proper margin. * However, if a non-default border is set on the text component, * it is that <code>Border</code> object's responsibility to create the * appropriate margin space (else this property will effectively * be ignored). This causes a redraw of the component. * A PropertyChange event ("margin") is sent to all listeners. * * @param m the space between the border and the text * @beaninfo * description: desired space between the border and text area * bound: true */ public void setMargin(Insets m) { Insets old = margin; margin = m; firePropertyChange("margin", old, m); invalidate(); } /** * Returns the margin between the text component's border and * its text. * * @return the margin */ public Insets getMargin() { return margin; } /** * Sets the <code>NavigationFilter</code>. <code>NavigationFilter</code> * is used by <code>DefaultCaret</code> and the default cursor movement * actions as a way to restrict the cursor movement. * * @since 1.4 */ public void setNavigationFilter(NavigationFilter filter) { navigationFilter = filter; } /** * Returns the <code>NavigationFilter</code>. <code>NavigationFilter</code> * is used by <code>DefaultCaret</code> and the default cursor movement * actions as a way to restrict the cursor movement. A null return value * implies the cursor movement and selection should not be restricted. * * @since 1.4 * @return the NavigationFilter */ public NavigationFilter getNavigationFilter() { return navigationFilter; } /** * Fetches the caret that allows text-oriented navigation over * the view. * * @return the caret */ @Transient public Caret getCaret() { return caret; } /** * Sets the caret to be used. By default this will be set * by the UI that gets installed. This can be changed to * a custom caret if desired. Setting the caret results in a * PropertyChange event ("caret") being fired. * * @param c the caret * @see #getCaret * @beaninfo * description: the caret used to select/navigate * bound: true * expert: true */ public void setCaret(Caret c) { if (caret != null) { caret.removeChangeListener(caretEvent); caret.deinstall(this); } Caret old = caret; caret = c; if (caret != null) { caret.install(this); caret.addChangeListener(caretEvent); } firePropertyChange("caret", old, caret); } /** * Fetches the object responsible for making highlights. * * @return the highlighter */ public Highlighter getHighlighter() { return highlighter; } /** * Sets the highlighter to be used. By default this will be set * by the UI that gets installed. This can be changed to * a custom highlighter if desired. The highlighter can be set to * <code>null</code> to disable it. * A PropertyChange event ("highlighter") is fired * when a new highlighter is installed. * * @param h the highlighter * @see #getHighlighter * @beaninfo * description: object responsible for background highlights * bound: true * expert: true */ public void setHighlighter(Highlighter h) { if (highlighter != null) { highlighter.deinstall(this); } Highlighter old = highlighter; highlighter = h; if (highlighter != null) { highlighter.install(this); } firePropertyChange("highlighter", old, h); } /** * Sets the keymap to use for binding events to * actions. Setting to <code>null</code> effectively disables * keyboard input. * A PropertyChange event ("keymap") is fired when a new keymap * is installed. * * @param map the keymap * @see #getKeymap * @beaninfo * description: set of key event to action bindings to use * bound: true */ public void setKeymap(Keymap map) { Keymap old = keymap; keymap = map; firePropertyChange("keymap", old, keymap); updateInputMap(old, map); } /** * Turns on or off automatic drag handling. In order to enable automatic * drag handling, this property should be set to {@code true}, and the * component's {@code TransferHandler} needs to be {@code non-null}. * The default value of the {@code dragEnabled} property is {@code false}. * <p> * The job of honoring this property, and recognizing a user drag gesture, * lies with the look and feel implementation, and in particular, the component's * {@code TextUI}. When automatic drag handling is enabled, most look and * feels (including those that subclass {@code BasicLookAndFeel}) begin a * drag and drop operation whenever the user presses the mouse button over * a selection and then moves the mouse a few pixels. Setting this property to * {@code true} can therefore have a subtle effect on how selections behave. * <p> * If a look and feel is used that ignores this property, you can still * begin a drag and drop operation by calling {@code exportAsDrag} on the * component's {@code TransferHandler}. * * @param b whether or not to enable automatic drag handling * @exception HeadlessException if * <code>b</code> is <code>true</code> and * <code>GraphicsEnvironment.isHeadless()</code> * returns <code>true</code> * @see java.awt.GraphicsEnvironment#isHeadless * @see #getDragEnabled * @see #setTransferHandler * @see TransferHandler * @since 1.4 * * @beaninfo * description: determines whether automatic drag handling is enabled * bound: false */ public void setDragEnabled(boolean b) { if (b && GraphicsEnvironment.isHeadless()) { throw new HeadlessException(); } dragEnabled = b; } /** * Returns whether or not automatic drag handling is enabled. * * @return the value of the {@code dragEnabled} property * @see #setDragEnabled * @since 1.4 */ public boolean getDragEnabled() { return dragEnabled; } /** * Sets the drop mode for this component. For backward compatibility, * the default for this property is <code>DropMode.USE_SELECTION</code>. * Usage of <code>DropMode.INSERT</code> is recommended, however, * for an improved user experience. It offers similar behavior of dropping * between text locations, but does so without affecting the actual text * selection and caret location. * <p> * <code>JTextComponents</code> support the following drop modes: * <ul> * <li><code>DropMode.USE_SELECTION</code></li> * <li><code>DropMode.INSERT</code></li> * </ul> * <p> * The drop mode is only meaningful if this component has a * <code>TransferHandler</code> that accepts drops. * * @param dropMode the drop mode to use * @throws IllegalArgumentException if the drop mode is unsupported * or <code>null</code> * @see #getDropMode * @see #getDropLocation * @see #setTransferHandler * @see javax.swing.TransferHandler * @since 1.6 */ public final void setDropMode(DropMode dropMode) { if (dropMode != null) { switch (dropMode) { case USE_SELECTION: case INSERT: this.dropMode = dropMode; return; } } throw new IllegalArgumentException(dropMode + ": Unsupported drop mode for text"); } /** * Returns the drop mode for this component. * * @return the drop mode for this component * @see #setDropMode * @since 1.6 */ public final DropMode getDropMode() { return dropMode; } static { SwingAccessor.setJTextComponentAccessor( new SwingAccessor.JTextComponentAccessor() { public TransferHandler.DropLocation dropLocationForPoint(JTextComponent textComp, Point p) { return textComp.dropLocationForPoint(p); } public Object setDropLocation(JTextComponent textComp, TransferHandler.DropLocation location, Object state, boolean forDrop) { return textComp.setDropLocation(location, state, forDrop); } }); } /** * Calculates a drop location in this component, representing where a * drop at the given point should insert data. * <p> * Note: This method is meant to override * <code>JComponent.dropLocationForPoint()</code>, which is package-private * in javax.swing. <code>TransferHandler</code> will detect text components * and call this method instead via reflection. It's name should therefore * not be changed. * * @param p the point to calculate a drop location for * @return the drop location, or <code>null</code> */ DropLocation dropLocationForPoint(Point p) { Position.Bias[] bias = new Position.Bias[1]; int index = getUI().viewToModel(this, p, bias); // viewToModel currently returns null for some HTML content // when the point is within the component's top inset if (bias[0] == null) { bias[0] = Position.Bias.Forward; } return new DropLocation(p, index, bias[0]); } /** * Called to set or clear the drop location during a DnD operation. * In some cases, the component may need to use it's internal selection * temporarily to indicate the drop location. To help facilitate this, * this method returns and accepts as a parameter a state object. * This state object can be used to store, and later restore, the selection * state. Whatever this method returns will be passed back to it in * future calls, as the state parameter. If it wants the DnD system to * continue storing the same state, it must pass it back every time. * Here's how this is used: * <p> * Let's say that on the first call to this method the component decides * to save some state (because it is about to use the selection to show * a drop index). It can return a state object to the caller encapsulating * any saved selection state. On a second call, let's say the drop location * is being changed to something else. The component doesn't need to * restore anything yet, so it simply passes back the same state object * to have the DnD system continue storing it. Finally, let's say this * method is messaged with <code>null</code>. This means DnD * is finished with this component for now, meaning it should restore * state. At this point, it can use the state parameter to restore * said state, and of course return <code>null</code> since there's * no longer anything to store. * <p> * Note: This method is meant to override * <code>JComponent.setDropLocation()</code>, which is package-private * in javax.swing. <code>TransferHandler</code> will detect text components * and call this method instead via reflection. It's name should therefore * not be changed. * * @param location the drop location (as calculated by * <code>dropLocationForPoint</code>) or <code>null</code> * if there's no longer a valid drop location * @param state the state object saved earlier for this component, * or <code>null</code> * @param forDrop whether or not the method is being called because an * actual drop occurred * @return any saved state for this component, or <code>null</code> if none */ Object setDropLocation(TransferHandler.DropLocation location, Object state, boolean forDrop) { Object retVal = null; DropLocation textLocation = (DropLocation)location; if (dropMode == DropMode.USE_SELECTION) { if (textLocation == null) { if (state != null) { /* * This object represents the state saved earlier. * If the caret is a DefaultCaret it will be * an Object array containing, in order: * - the saved caret mark (Integer) * - the saved caret dot (Integer) * - the saved caret visibility (Boolean) * - the saved mark bias (Position.Bias) * - the saved dot bias (Position.Bias) * If the caret is not a DefaultCaret it will * be similar, but will not contain the dot * or mark bias. */ Object[] vals = (Object[])state; if (!forDrop) { if (caret instanceof DefaultCaret) { ((DefaultCaret)caret).setDot(((Integer)vals[0]).intValue(), (Position.Bias)vals[3]); ((DefaultCaret)caret).moveDot(((Integer)vals[1]).intValue(), (Position.Bias)vals[4]); } else { caret.setDot(((Integer)vals[0]).intValue()); caret.moveDot(((Integer)vals[1]).intValue()); } } caret.setVisible(((Boolean)vals[2]).booleanValue()); } } else { if (dropLocation == null) { boolean visible; if (caret instanceof DefaultCaret) { DefaultCaret dc = (DefaultCaret)caret; visible = dc.isActive(); retVal = new Object[] {Integer.valueOf(dc.getMark()), Integer.valueOf(dc.getDot()), Boolean.valueOf(visible), dc.getMarkBias(), dc.getDotBias()}; } else { visible = caret.isVisible(); retVal = new Object[] {Integer.valueOf(caret.getMark()), Integer.valueOf(caret.getDot()), Boolean.valueOf(visible)}; } caret.setVisible(true); } else { retVal = state; } if (caret instanceof DefaultCaret) { ((DefaultCaret)caret).setDot(textLocation.getIndex(), textLocation.getBias()); } else { caret.setDot(textLocation.getIndex()); } } } else { if (textLocation == null) { if (state != null) { caret.setVisible(((Boolean)state).booleanValue()); } } else { if (dropLocation == null) { boolean visible = caret instanceof DefaultCaret ? ((DefaultCaret)caret).isActive() : caret.isVisible(); retVal = Boolean.valueOf(visible); caret.setVisible(false); } else { retVal = state; } } } DropLocation old = dropLocation; dropLocation = textLocation; firePropertyChange("dropLocation", old, dropLocation); return retVal; } /** * Returns the location that this component should visually indicate * as the drop location during a DnD operation over the component, * or {@code null} if no location is to currently be shown. * <p> * This method is not meant for querying the drop location * from a {@code TransferHandler}, as the drop location is only * set after the {@code TransferHandler}'s <code>canImport</code> * has returned and has allowed for the location to be shown. * <p> * When this property changes, a property change event with * name "dropLocation" is fired by the component. * * @return the drop location * @see #setDropMode * @see TransferHandler#canImport(TransferHandler.TransferSupport) * @since 1.6 */ public final DropLocation getDropLocation() { return dropLocation; } /** * Updates the <code>InputMap</code>s in response to a * <code>Keymap</code> change. * @param oldKm the old <code>Keymap</code> * @param newKm the new <code>Keymap</code> */ void updateInputMap(Keymap oldKm, Keymap newKm) { // Locate the current KeymapWrapper. InputMap km = getInputMap(JComponent.WHEN_FOCUSED); InputMap last = km; while (km != null && !(km instanceof KeymapWrapper)) { last = km; km = km.getParent(); } if (km != null) { // Found it, tweak the InputMap that points to it, as well // as anything it points to. if (newKm == null) { if (last != km) { last.setParent(km.getParent()); } else { last.setParent(null); } } else { InputMap newKM = new KeymapWrapper(newKm); last.setParent(newKM); if (last != km) { newKM.setParent(km.getParent()); } } } else if (newKm != null) { km = getInputMap(JComponent.WHEN_FOCUSED); if (km != null) { // Couldn't find it. // Set the parent of WHEN_FOCUSED InputMap to be the new one. InputMap newKM = new KeymapWrapper(newKm);Lines 501–1000 of 5073. Previous lines Load more
* augmented by the collection of commands that the * editor itself supports. These are useful for binding * to events, such as in a keymap. * * @return the command list */ public Action[] getActions() { return getUI().getEditorKit(this).getActions(); } /** * Sets margin space between the text component's border * and its text. The text component's default <code>Border</code> * object will use this value to create the proper margin. * However, if a non-default border is set on the text component, * it is that <code>Border</code> object's responsibility to create the * appropriate margin space (else this property will effectively * be ignored). This causes a redraw of the component. * A PropertyChange event ("margin") is sent to all listeners. * * @param m the space between the border and the text * @beaninfo * description: desired space between the border and text area * bound: true */ public void setMargin(Insets m) { Insets old = margin; margin = m; firePropertyChange("margin", old, m); invalidate(); } /** * Returns the margin between the text component's border and * its text. * * @return the margin */ public Insets getMargin() { return margin; } /** * Sets the <code>NavigationFilter</code>. <code>NavigationFilter</code> * is used by <code>DefaultCaret</code> and the default cursor movement * actions as a way to restrict the cursor movement. * * @since 1.4 */ public void setNavigationFilter(NavigationFilter filter) { navigationFilter = filter; } /** * Returns the <code>NavigationFilter</code>. <code>NavigationFilter</code> * is used by <code>DefaultCaret</code> and the default cursor movement * actions as a way to restrict the cursor movement. A null return value * implies the cursor movement and selection should not be restricted. * * @since 1.4 * @return the NavigationFilter */ public NavigationFilter getNavigationFilter() { return navigationFilter; } /** * Fetches the caret that allows text-oriented navigation over * the view. * * @return the caret */ @Transient public Caret getCaret() { return caret; } /** * Sets the caret to be used. By default this will be set * by the UI that gets installed. This can be changed to * a custom caret if desired. Setting the caret results in a * PropertyChange event ("caret") being fired. * * @param c the caret * @see #getCaret * @beaninfo * description: the caret used to select/navigate * bound: true * expert: true */ public void setCaret(Caret c) { if (caret != null) { caret.removeChangeListener(caretEvent); caret.deinstall(this); } Caret old = caret; caret = c; if (caret != null) { caret.install(this); caret.addChangeListener(caretEvent); } firePropertyChange("caret", old, caret); } /** * Fetches the object responsible for making highlights. * * @return the highlighter */ public Highlighter getHighlighter() { return highlighter; } /** * Sets the highlighter to be used. By default this will be set * by the UI that gets installed. This can be changed to * a custom highlighter if desired. The highlighter can be set to * <code>null</code> to disable it. * A PropertyChange event ("highlighter") is fired * when a new highlighter is installed. * * @param h the highlighter * @see #getHighlighter * @beaninfo * description: object responsible for background highlights * bound: true * expert: true */ public void setHighlighter(Highlighter h) { if (highlighter != null) { highlighter.deinstall(this); } Highlighter old = highlighter; highlighter = h; if (highlighter != null) { highlighter.install(this); } firePropertyChange("highlighter", old, h); } /** * Sets the keymap to use for binding events to * actions. Setting to <code>null</code> effectively disables * keyboard input. * A PropertyChange event ("keymap") is fired when a new keymap * is installed. * * @param map the keymap * @see #getKeymap * @beaninfo * description: set of key event to action bindings to use * bound: true */ public void setKeymap(Keymap map) { Keymap old = keymap; keymap = map; firePropertyChange("keymap", old, keymap); updateInputMap(old, map); } /** * Turns on or off automatic drag handling. In order to enable automatic * drag handling, this property should be set to {@code true}, and the * component's {@code TransferHandler} needs to be {@code non-null}. * The default value of the {@code dragEnabled} property is {@code false}. * <p> * The job of honoring this property, and recognizing a user drag gesture, * lies with the look and feel implementation, and in particular, the component's * {@code TextUI}. When automatic drag handling is enabled, most look and * feels (including those that subclass {@code BasicLookAndFeel}) begin a * drag and drop operation whenever the user presses the mouse button over * a selection and then moves the mouse a few pixels. Setting this property to * {@code true} can therefore have a subtle effect on how selections behave. * <p> * If a look and feel is used that ignores this property, you can still * begin a drag and drop operation by calling {@code exportAsDrag} on the * component's {@code TransferHandler}. * * @param b whether or not to enable automatic drag handling * @exception HeadlessException if * <code>b</code> is <code>true</code> and * <code>GraphicsEnvironment.isHeadless()</code> * returns <code>true</code> * @see java.awt.GraphicsEnvironment#isHeadless * @see #getDragEnabled * @see #setTransferHandler * @see TransferHandler * @since 1.4 * * @beaninfo * description: determines whether automatic drag handling is enabled * bound: false */ public void setDragEnabled(boolean b) { if (b && GraphicsEnvironment.isHeadless()) { throw new HeadlessException(); } dragEnabled = b; } /** * Returns whether or not automatic drag handling is enabled. * * @return the value of the {@code dragEnabled} property * @see #setDragEnabled * @since 1.4 */ public boolean getDragEnabled() { return dragEnabled; } /** * Sets the drop mode for this component. For backward compatibility, * the default for this property is <code>DropMode.USE_SELECTION</code>. * Usage of <code>DropMode.INSERT</code> is recommended, however, * for an improved user experience. It offers similar behavior of dropping * between text locations, but does so without affecting the actual text * selection and caret location. * <p> * <code>JTextComponents</code> support the following drop modes: * <ul> * <li><code>DropMode.USE_SELECTION</code></li> * <li><code>DropMode.INSERT</code></li> * </ul> * <p> * The drop mode is only meaningful if this component has a * <code>TransferHandler</code> that accepts drops. * * @param dropMode the drop mode to use * @throws IllegalArgumentException if the drop mode is unsupported * or <code>null</code> * @see #getDropMode * @see #getDropLocation * @see #setTransferHandler * @see javax.swing.TransferHandler * @since 1.6 */ public final void setDropMode(DropMode dropMode) { if (dropMode != null) { switch (dropMode) { case USE_SELECTION: case INSERT: this.dropMode = dropMode; return; } } throw new IllegalArgumentException(dropMode + ": Unsupported drop mode for text"); } /** * Returns the drop mode for this component. * * @return the drop mode for this component * @see #setDropMode * @since 1.6 */ public final DropMode getDropMode() { return dropMode; } static { SwingAccessor.setJTextComponentAccessor( new SwingAccessor.JTextComponentAccessor() { public TransferHandler.DropLocation dropLocationForPoint(JTextComponent textComp, Point p) { return textComp.dropLocationForPoint(p); } public Object setDropLocation(JTextComponent textComp, TransferHandler.DropLocation location, Object state, boolean forDrop) { return textComp.setDropLocation(location, state, forDrop); } }); } /** * Calculates a drop location in this component, representing where a * drop at the given point should insert data. * <p> * Note: This method is meant to override * <code>JComponent.dropLocationForPoint()</code>, which is package-private * in javax.swing. <code>TransferHandler</code> will detect text components * and call this method instead via reflection. It's name should therefore * not be changed. * * @param p the point to calculate a drop location for * @return the drop location, or <code>null</code> */ DropLocation dropLocationForPoint(Point p) { Position.Bias[] bias = new Position.Bias[1]; int index = getUI().viewToModel(this, p, bias); // viewToModel currently returns null for some HTML content // when the point is within the component's top inset if (bias[0] == null) { bias[0] = Position.Bias.Forward; } return new DropLocation(p, index, bias[0]); } /** * Called to set or clear the drop location during a DnD operation. * In some cases, the component may need to use it's internal selection * temporarily to indicate the drop location. To help facilitate this, * this method returns and accepts as a parameter a state object. * This state object can be used to store, and later restore, the selection * state. Whatever this method returns will be passed back to it in * future calls, as the state parameter. If it wants the DnD system to * continue storing the same state, it must pass it back every time. * Here's how this is used: * <p> * Let's say that on the first call to this method the component decides * to save some state (because it is about to use the selection to show * a drop index). It can return a state object to the caller encapsulating * any saved selection state. On a second call, let's say the drop location * is being changed to something else. The component doesn't need to * restore anything yet, so it simply passes back the same state object * to have the DnD system continue storing it. Finally, let's say this * method is messaged with <code>null</code>. This means DnD * is finished with this component for now, meaning it should restore * state. At this point, it can use the state parameter to restore * said state, and of course return <code>null</code> since there's * no longer anything to store. * <p> * Note: This method is meant to override * <code>JComponent.setDropLocation()</code>, which is package-private * in javax.swing. <code>TransferHandler</code> will detect text components * and call this method instead via reflection. It's name should therefore * not be changed. * * @param location the drop location (as calculated by * <code>dropLocationForPoint</code>) or <code>null</code> * if there's no longer a valid drop location * @param state the state object saved earlier for this component, * or <code>null</code> * @param forDrop whether or not the method is being called because an * actual drop occurred * @return any saved state for this component, or <code>null</code> if none */ Object setDropLocation(TransferHandler.DropLocation location, Object state, boolean forDrop) { Object retVal = null; DropLocation textLocation = (DropLocation)location; if (dropMode == DropMode.USE_SELECTION) { if (textLocation == null) { if (state != null) { /* * This object represents the state saved earlier. * If the caret is a DefaultCaret it will be * an Object array containing, in order: * - the saved caret mark (Integer) * - the saved caret dot (Integer) * - the saved caret visibility (Boolean) * - the saved mark bias (Position.Bias) * - the saved dot bias (Position.Bias) * If the caret is not a DefaultCaret it will * be similar, but will not contain the dot * or mark bias. */ Object[] vals = (Object[])state; if (!forDrop) { if (caret instanceof DefaultCaret) { ((DefaultCaret)caret).setDot(((Integer)vals[0]).intValue(), (Position.Bias)vals[3]); ((DefaultCaret)caret).moveDot(((Integer)vals[1]).intValue(), (Position.Bias)vals[4]); } else { caret.setDot(((Integer)vals[0]).intValue()); caret.moveDot(((Integer)vals[1]).intValue()); } } caret.setVisible(((Boolean)vals[2]).booleanValue()); } } else { if (dropLocation == null) { boolean visible; if (caret instanceof DefaultCaret) { DefaultCaret dc = (DefaultCaret)caret; visible = dc.isActive(); retVal = new Object[] {Integer.valueOf(dc.getMark()), Integer.valueOf(dc.getDot()), Boolean.valueOf(visible), dc.getMarkBias(), dc.getDotBias()}; } else { visible = caret.isVisible(); retVal = new Object[] {Integer.valueOf(caret.getMark()), Integer.valueOf(caret.getDot()), Boolean.valueOf(visible)}; } caret.setVisible(true); } else { retVal = state; } if (caret instanceof DefaultCaret) { ((DefaultCaret)caret).setDot(textLocation.getIndex(), textLocation.getBias()); } else { caret.setDot(textLocation.getIndex()); } } } else { if (textLocation == null) { if (state != null) { caret.setVisible(((Boolean)state).booleanValue()); } } else { if (dropLocation == null) { boolean visible = caret instanceof DefaultCaret ? ((DefaultCaret)caret).isActive() : caret.isVisible(); retVal = Boolean.valueOf(visible); caret.setVisible(false); } else { retVal = state; } } } DropLocation old = dropLocation; dropLocation = textLocation; firePropertyChange("dropLocation", old, dropLocation); return retVal; } /** * Returns the location that this component should visually indicate * as the drop location during a DnD operation over the component, * or {@code null} if no location is to currently be shown. * <p> * This method is not meant for querying the drop location * from a {@code TransferHandler}, as the drop location is only * set after the {@code TransferHandler}'s <code>canImport</code> * has returned and has allowed for the location to be shown. * <p> * When this property changes, a property change event with * name "dropLocation" is fired by the component. * * @return the drop location * @see #setDropMode * @see TransferHandler#canImport(TransferHandler.TransferSupport) * @since 1.6 */ public final DropLocation getDropLocation() { return dropLocation; } /** * Updates the <code>InputMap</code>s in response to a * <code>Keymap</code> change. * @param oldKm the old <code>Keymap</code> * @param newKm the new <code>Keymap</code> */ void updateInputMap(Keymap oldKm, Keymap newKm) { // Locate the current KeymapWrapper. InputMap km = getInputMap(JComponent.WHEN_FOCUSED); InputMap last = km; while (km != null && !(km instanceof KeymapWrapper)) { last = km; km = km.getParent(); } if (km != null) { // Found it, tweak the InputMap that points to it, as well // as anything it points to. if (newKm == null) { if (last != km) { last.setParent(km.getParent()); } else { last.setParent(null); } } else { InputMap newKM = new KeymapWrapper(newKm); last.setParent(newKM); if (last != km) { newKM.setParent(km.getParent()); } } } else if (newKm != null) { km = getInputMap(JComponent.WHEN_FOCUSED); if (km != null) { // Couldn't find it. // Set the parent of WHEN_FOCUSED InputMap to be the new one. InputMap newKM = new KeymapWrapper(newKm);