Class RedirectInputMap

  • All Implemented Interfaces:
    java.io.Serializable

    public class RedirectInputMap
    extends javax.swing.ComponentInputMap
    Make shortcuts from main window work in dialog windows. It's not possible to simply set component input map parent to be Main.contentPane.getInputMap because there is check in setParent that InputMap is for the same component. Yes, this is a hack. Another possibility would be simply copy InputMap, but that would require to keep copies synchronized when some shortcuts are changed later.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private javax.swing.InputMap target  
    • Constructor Summary

      Constructors 
      Constructor Description
      RedirectInputMap​(javax.swing.JComponent component, javax.swing.InputMap target)
      Create a new RedirectInputMap
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      javax.swing.KeyStroke[] allKeys()  
      void clear()  
      java.lang.Object get​(javax.swing.KeyStroke keyStroke)  
      javax.swing.KeyStroke[] keys()  
      void put​(javax.swing.KeyStroke keyStroke, java.lang.Object actionMapKey)  
      static void redirect​(javax.swing.JComponent source, javax.swing.JComponent target)
      Redirects the key inputs from one component to an other component
      void remove​(javax.swing.KeyStroke key)  
      int size()  
      • Methods inherited from class javax.swing.ComponentInputMap

        getComponent, setParent
      • Methods inherited from class javax.swing.InputMap

        getParent
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • target

        private final javax.swing.InputMap target
    • Constructor Detail

      • RedirectInputMap

        public RedirectInputMap​(javax.swing.JComponent component,
                                javax.swing.InputMap target)
        Create a new RedirectInputMap
        Parameters:
        component - The component the input map will be added to
        target - The target input map that should be mirrored.
    • Method Detail

      • get

        public java.lang.Object get​(javax.swing.KeyStroke keyStroke)
        Overrides:
        get in class javax.swing.InputMap
      • keys

        public javax.swing.KeyStroke[] keys()
        Overrides:
        keys in class javax.swing.InputMap
      • size

        public int size()
        Overrides:
        size in class javax.swing.InputMap
      • allKeys

        public javax.swing.KeyStroke[] allKeys()
        Overrides:
        allKeys in class javax.swing.InputMap
      • put

        public void put​(javax.swing.KeyStroke keyStroke,
                        java.lang.Object actionMapKey)
        Overrides:
        put in class javax.swing.ComponentInputMap
      • remove

        public void remove​(javax.swing.KeyStroke key)
        Overrides:
        remove in class javax.swing.ComponentInputMap
      • clear

        public void clear()
        Overrides:
        clear in class javax.swing.ComponentInputMap
      • redirect

        public static void redirect​(javax.swing.JComponent source,
                                    javax.swing.JComponent target)
        Redirects the key inputs from one component to an other component
        Parameters:
        source - The source component
        target - The target component to send the keystrokes to.