classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cp-patches] FYI: Text components home and end actions


From: Lillian Angel
Subject: Re: [cp-patches] FYI: Text components home and end actions
Date: Wed, 21 Dec 2005 16:03:50 -0500

All is fixed.

2005-12-21  Lillian Angel  <address@hidden>

        * javax/swing/UIDefaults.java
        (createValue): Added check in. Bind might be an instance of 
        KeyStroke.
        * javax/swing/plaf/basic/BasicLookAndFeel.java
        (initComponentDefaults): Changed key bindings for
        PasswordField, TextArea, TextPane, TextField to be instances of 
        KeyStroke.
        (installKeyBoardActions): Added call to replace textComponent's 
        top-level action map to parentActionMap. Also, removed unneeded 
        code.




On Wed, 2005-12-21 at 21:18 +0100, Roman Kennke wrote:
> > > +      "TextArea.focusInputMap", new UIDefaults.LazyInputMap(new
> > > Object[] {
> > > +         "UP", "caret-up",
> > > +         "DOWN", "caret-down",
> > > +         "PAGE_UP", "page-up",
> > > +         "PAGE_DOWN", "page-down",
> > > +         "ENTER", "insert-break",
> > > +         "TAB", "insert-tab",
> > > +         "LEFT", "caret-backward",
> > > +         "RIGHT", "caret-forward",
> > > +         "BACK_SPACE", "delete-previous",
> > > +         "ctrl X", "cut-to-clipboard",
> > > +         "ctrl C", "copy-to-clipboard",
> > > +         "ctrl V", "paste-from-clipboard",
> > > +         "shift LEFT", "selection-backward",
> > > +         "shift RIGHT", "selection-forward",
> > > +         "HOME", "caret-begin-line",
> > > +         "END", "caret-end-line",
> > > +         "DELETE", "delete-next"
> > > +      }),
> > > 
> > > Why not put in all the bindings at once. I pasted the bindings (for
> > > JTextField) from JDK1.5 here:
> > > http://pastebin.com/473135
> > 
> > I added them all in.
> 
> You could use KeyStroke instances instead of e.g. "ctrl X", this is more
> efficient and safer IMO. You said that KeyStroke.getKeyStroke(String)
> doesn't get the modifiers right?
> 
> > > +    for (int i = 0; i < keys.length; i++)
> > > +      {
> > > +        String act = (String) focusInputMap.get((KeyStroke) keys[i]);
> > > +        Action[] actions = textComponent.getActions();
> > > +        for (int j = 0; j < actions.length; j++)
> > > +          {
> > > +            Action currAction = actions[j];
> > > +            if (currAction != null
> > > +                && (currAction.getValue(Action.NAME).equals(act)))
> > > +              parentActionMap.put(act, new
> > > ActionListenerProxy(currAction, act));
> > > +          }
> > > +        
> > > +        parentInputMap.put(KeyStroke.getKeyStroke(((KeyStroke)
> > > keys[i]).getKeyCode(),
> > > +
> > > convertModifiers(((KeyStroke) keys[i]).getModifiers())),
> > > +                           act);
> > > +        parentInputMap.put(KeyStroke.getKeyStroke(((KeyStroke)
> > > keys[i]).getKeyCode(),
> > > +                                                  ((KeyStroke)
> > > keys[i]).getModifiers()),
> > > +                           act);
> > > +      }
> > > 
> > > Replace this with the one loop like pasted above. I suppose you are
> > > doing all this work to load the inputMap from the UI Object[]? Then you
> > > might want to use LookAndFeel.loadKeyBindings(). That takes an Object[]
> > > and loads the key bindings into an InputMap.
> > 
> > I made this loop more efficent by far. I attempted to use the
> > loadKeyBindings, but I realized its not possible. I need to pass the
> > entire array of strings from the Text*.focusInputMap. But if I use the
> > UIManager to get the focusInputMap, an instance of InputMapUIResource is
> > returned (not an array). This InputMap contains half as many entries as
> > those in the array of strings (the key/value pairs). To get the values
> > of the input map, keys() is called and this returns an array of all the
> > KeyStrokes- not the strings. Therefore, in this case loadKeyBindings is
> > not helpful.
> 
> If the UIManager returns an InputMap(UIResource), then you can use that.
> No need to copy around stuff. And yes, no need to use
> LookAndFeel.loadKeyBindings() -- that is probably used by UIManager to
> load the key bindings.
> 
> > > parentInputMap.setParent(textComponent.getInputMap(JComponent.WHEN_FOCUSED).getParent());
> > > +
> > > parentActionMap.setParent(textComponent.getActionMap().getParent());
> > > +
> > > textComponent.getInputMap(JComponent.WHEN_FOCUSED).setParent(parentInputMap);
> > > +    textComponent.getActionMap().setParent(parentActionMap);
> > > 
> > > You don't really want to do this. Instead, simply call
> > > SwingUtilities.replaceUIInputMap() or
> > > SwingUtilities.replaceUIActionMap() to properly install the top-level
> > > Input/ActionMaps.
> > 
> > This is setting the parents of the map. I don't see why I should call
> > replaceUI*Map here.
> 
> 
> This is what SwingUtilities.replaceUIInputMap() does. Normally, for a
> component you have the following InputMaps:
> 
> UI InputMap (top-level)
> Component InputMap
> User InputMap (optionally installed by application code)
> 
> What you want to do here is replace the toplevel (UI) InputMap with a
> new one. This is what SwingUtilities.replaceUIInputMap does. You should
> really use this to avoid troubles. There is no need to keep the former
> parent of the component input map as parent of the new UI InputMap or
> something. The end result should be a structure with a (shared) UI
> InputMap at the top and an (probably) empty component InputMap as a
> child. The background is that when the component UI input map is
> modified, this won't modify the UI InputMap (which is a shared instance
> between all components of this UI).
> 
> /Roman
> 

Attachment: patch.diff
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]