Class AutoCompletion

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int numKeys
      number of completer keys (cycle forward, cycle backward, complete, cancel, start
      protected java.util.Properties settings  
    • Constructor Summary

      Constructors 
      Constructor Description
      AutoCompletion​(java.util.Properties settings, EventDispatcher dispatcher)
      Creates new AutoCompletion
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void actionPerformed​(java.awt.event.ActionEvent e)
      Offer auto completion when timer has fired.
      void addCompletionGUI​(CompletionGUI cGUI)
      Adds a new GUI to the list of available GUIs.
      void attachEditorManager​(OrderEditorList cel)
      Registers a new OrderEditorList to be used by this AutoCompletion.
      void caretUpdate​(javax.swing.event.CaretEvent e)
      updates the completion gui when the user clicks inside editor or moves cursor.
      void cycleBackward()
      Selects the previous completion in the list, if available.
      void cycleForward()
      Selects the next completion in the list, if available.
      void focusGained​(java.awt.event.FocusEvent e)
      Possibly activates the GUI.
      void focusLost​(java.awt.event.FocusEvent p1)
      Hides the GUI.
      void gameDataChanged​(GameDataEvent e)
      Invoked when the current game data object becomes invalid.
      int getActivationTime()
      Returns the time (in ms) after a key stroke until activating the GUI.
      int[][] getCompleterKeys()
      Returns keys for cycling, completing and breaking.
      java.util.Vector<CompletionGUI> getCompletionGUIs()
      Returns the list of available GUIs.
      CompletionGUI getCurrentGUI()
      Returns the currently used GUI.
      static java.lang.String getCurrentLine​(javax.swing.text.JTextComponent j)
      Returns the current line in j according to the current caret position or null if there is no valid line for some reason.
      static int[] getCurrentLineBounds​(java.lang.String text, int offset)
      Returns the line in text that includes offset, that is, the first position of a line break before offset (or 0) and the last position of a line break after offset (or text.length().
      boolean getEmptyStubMode()
      Returns if completion should start on an empty word or requires at least one letter.
      boolean getHotKeyMode()
      Getter for hot key mode
      boolean getLimitMakeCompletion()
      Returns if completion of MACHE orders is limited
      PreferencesAdapter getPreferencesAdapter()  
      java.util.List<Completion> getSelfDefinedCompletions()
      Returns a list containing the self defined completions as Completion objects.
      java.util.Map<java.lang.String,​java.lang.String> getSelfDefinedCompletionsMap()
      Returns the value of selfDefinedCompletions.
      java.util.Properties getSettings()
      Returns the value of settings.
      static java.lang.String getStub​(java.lang.String txt)  
      static java.lang.String getStub​(java.util.List<OrderToken> txt)  
      void insertCompletion​(Completion completion)
      Inserts completion into the current editor at the current position.
      boolean isEnableAutoCompletion()
      Returns true if auto completion is enabled.
      boolean isLimitCompletions()
      Returns the value of limitCompletions.
      void keyPressed​(java.awt.event.KeyEvent e)
      Handles special keys to control the GUI, mainly.
      void keyReleased​(java.awt.event.KeyEvent p1)  
      void keyTyped​(java.awt.event.KeyEvent p1)  
      protected void loadComplete()
      Tries to use the active GUI from the settings.
      protected void loadSettings()  
      void offerCompletion​(javax.swing.text.JTextComponent j)
      Finds and displays a new list of completions according to the current editor and caret position.
      protected void offerCompletion​(javax.swing.text.JTextComponent j, boolean manual)
      Finds and displays a new list of completions according to the current editor and caret position.
      void selectionChanged​(SelectionEvent e)
      Invoked when different objects are activated or selected.
      void setActivationTime​(int t)
      Sets the time (in ms) after a key stroke until activating the GUI.
      void setCompleter​(Completer c)
      Registers a new Completer to use.
      void setCompleterKeys​(int[][] ck)
      Sets keys for cycling, completing and breaking.
      void setCompletionGUIs​(java.util.Vector<CompletionGUI> completionGUIs)
      Sets the value of completionGUIs.
      void setCurrentGUI​(CompletionGUI cGUI)
      Sets cGUI as active GUI.
      void setEmptyStubMode​(boolean b)
      Controls if completion should start on an empty word or requires at least one letter.
      void setEnableAutoCompletion​(boolean b)
      Completely enables or disables auto completion.
      void setHotKeyMode​(boolean b)
      Setter for hot key mode
      void setLimitCompletions​(boolean limitCompletions)
      Sets the value of limitCompletions.
      void setLimitMakeCompletion​(boolean value)
      Control if completion of MACHE orders should be limited
      void setSelfDefinedCompletions​(java.util.Map<java.lang.String,​java.lang.String> selfDefinedCompletions)
      Sets the value of selfDefinedCompletions.
      void setSettings​(java.util.Properties settings)
      Sets the value of settings.
      • Methods inherited from class java.lang.Object

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

      • numKeys

        public static final int numKeys
        number of completer keys (cycle forward, cycle backward, complete, cancel, start
        See Also:
        Constant Field Values
      • settings

        protected java.util.Properties settings
    • Constructor Detail

      • AutoCompletion

        public AutoCompletion​(java.util.Properties settings,
                              EventDispatcher dispatcher)
        Creates new AutoCompletion
    • Method Detail

      • loadSettings

        protected void loadSettings()
      • loadComplete

        protected void loadComplete()
        Tries to use the active GUI from the settings. If this is not available, some GUI from the list of available GUIs is chosen.
      • attachEditorManager

        public void attachEditorManager​(OrderEditorList cel)
        Registers a new OrderEditorList to be used by this AutoCompletion.
      • addCompletionGUI

        public void addCompletionGUI​(CompletionGUI cGUI)
        Adds a new GUI to the list of available GUIs.
      • getCompletionGUIs

        public java.util.Vector<CompletionGUI> getCompletionGUIs()
        Returns the list of available GUIs.
      • setCurrentGUI

        public void setCurrentGUI​(CompletionGUI cGUI)
        Sets cGUI as active GUI.
        Parameters:
        cGUI -
      • getCurrentGUI

        public CompletionGUI getCurrentGUI()
        Returns the currently used GUI.
      • setCompleter

        public void setCompleter​(Completer c)
        Registers a new Completer to use.
      • offerCompletion

        public void offerCompletion​(javax.swing.text.JTextComponent j)
        Finds and displays a new list of completions according to the current editor and caret position.
      • offerCompletion

        protected void offerCompletion​(javax.swing.text.JTextComponent j,
                                       boolean manual)
        Finds and displays a new list of completions according to the current editor and caret position. If manual is true, the GUI is always shown. Otherwise, it is only shown if appropriate (i.e. there is something to complete).
      • cycleForward

        public void cycleForward()
        Selects the next completion in the list, if available.
      • cycleBackward

        public void cycleBackward()
        Selects the previous completion in the list, if available.
      • insertCompletion

        public void insertCompletion​(Completion completion)
        Inserts completion into the current editor at the current position.
      • getCurrentLine

        public static java.lang.String getCurrentLine​(javax.swing.text.JTextComponent j)
        Returns the current line in j according to the current caret position or null if there is no valid line for some reason.
      • getCurrentLineBounds

        public static int[] getCurrentLineBounds​(java.lang.String text,
                                                 int offset)
        Returns the line in text that includes offset, that is, the first position of a line break before offset (or 0) and the last position of a line break after offset (or text.length().
        Returns:
        an array of two ints, the first one is the start position, the second one is (one character after) the end position.
      • keyReleased

        public void keyReleased​(java.awt.event.KeyEvent p1)
        Specified by:
        keyReleased in interface java.awt.event.KeyListener
        See Also:
        KeyListener.keyReleased(java.awt.event.KeyEvent)
      • keyPressed

        public void keyPressed​(java.awt.event.KeyEvent e)
        Handles special keys to control the GUI, mainly.
        Specified by:
        keyPressed in interface java.awt.event.KeyListener
      • keyTyped

        public void keyTyped​(java.awt.event.KeyEvent p1)
        Specified by:
        keyTyped in interface java.awt.event.KeyListener
        See Also:
        KeyListener.keyTyped(java.awt.event.KeyEvent)
      • actionPerformed

        public void actionPerformed​(java.awt.event.ActionEvent e)
        Offer auto completion when timer has fired.
        Specified by:
        actionPerformed in interface java.awt.event.ActionListener
        Parameters:
        e -
        See Also:
        ActionListener.actionPerformed(java.awt.event.ActionEvent)
      • caretUpdate

        public void caretUpdate​(javax.swing.event.CaretEvent e)
        updates the completion gui when the user clicks inside editor or moves cursor.
        Specified by:
        caretUpdate in interface javax.swing.event.CaretListener
        Parameters:
        e -
      • focusGained

        public void focusGained​(java.awt.event.FocusEvent e)
        Possibly activates the GUI.
        Specified by:
        focusGained in interface java.awt.event.FocusListener
        See Also:
        FocusListener.focusGained(java.awt.event.FocusEvent)
      • focusLost

        public void focusLost​(java.awt.event.FocusEvent p1)
        Hides the GUI.
        Specified by:
        focusLost in interface java.awt.event.FocusListener
        See Also:
        FocusListener.focusLost(java.awt.event.FocusEvent)
      • setEnableAutoCompletion

        public void setEnableAutoCompletion​(boolean b)
        Completely enables or disables auto completion.
      • isEnableAutoCompletion

        public boolean isEnableAutoCompletion()
        Returns true if auto completion is enabled.
      • setLimitMakeCompletion

        public void setLimitMakeCompletion​(boolean value)
        Control if completion of MACHE orders should be limited
      • setEmptyStubMode

        public void setEmptyStubMode​(boolean b)
        Controls if completion should start on an empty word or requires at least one letter.
      • getEmptyStubMode

        public boolean getEmptyStubMode()
        Returns if completion should start on an empty word or requires at least one letter.
      • setHotKeyMode

        public void setHotKeyMode​(boolean b)
        Setter for hot key mode
        Parameters:
        b -
      • getHotKeyMode

        public boolean getHotKeyMode()
        Getter for hot key mode
      • getActivationTime

        public int getActivationTime()
        Returns the time (in ms) after a key stroke until activating the GUI.
      • setActivationTime

        public void setActivationTime​(int t)
        Sets the time (in ms) after a key stroke until activating the GUI.
      • getCompleterKeys

        public int[][] getCompleterKeys()
        Returns keys for cycling, completing and breaking.
         completerKeys[]   completerKeys[][0]  completerKeys[1]
         cycle forward     modifier            key
         cycle backward    modifier            key
         complete          modifier            key
         break             modifier            key
         start             modifier            key
         
      • setCompleterKeys

        public void setCompleterKeys​(int[][] ck)
        Sets keys for cycling, completing and breaking.
         completerKeys[]   completerKeys[][0]  completerKeys[1]
         cycle forward     modifier            key
         cycle backward    modifier            key
         complete          modifier            key
         break             modifier            key
         start             modifier            key
         
      • setCompletionGUIs

        public void setCompletionGUIs​(java.util.Vector<CompletionGUI> completionGUIs)
        Sets the value of completionGUIs.
        Parameters:
        completionGUIs - The value for completionGUIs.
      • getSettings

        public java.util.Properties getSettings()
        Returns the value of settings.
        Returns:
        Returns settings.
      • setSettings

        public void setSettings​(java.util.Properties settings)
        Sets the value of settings.
        Parameters:
        settings - The value for settings.
      • setSelfDefinedCompletions

        public void setSelfDefinedCompletions​(java.util.Map<java.lang.String,​java.lang.String> selfDefinedCompletions)
        Sets the value of selfDefinedCompletions.
        Parameters:
        selfDefinedCompletions - The value for selfDefinedCompletions.
      • getSelfDefinedCompletionsMap

        public java.util.Map<java.lang.String,​java.lang.String> getSelfDefinedCompletionsMap()
        Returns the value of selfDefinedCompletions.
      • setLimitCompletions

        public void setLimitCompletions​(boolean limitCompletions)
        Sets the value of limitCompletions.
        Parameters:
        limitCompletions - The value for limitCompletions.