Class ContextBar.CommandButton

  • All Implemented Interfaces:
    ContextBar.Button, IconProvider, java.awt.event.ActionListener, java.util.EventListener
    Enclosing class:
    ContextBar

    public static class ContextBar.CommandButton
    extends java.lang.Object
    implements ContextBar.Button
    A context bar button that delegates to an AbstractCommand. The button will activate the command when clicked, and be enabled or disabled based on the current state of the command. The base class implementation will create a button that is always visible and performs no action when the context bar is attached or detached.
    • Constructor Detail

      • CommandButton

        public CommandButton​(AbstractCommand command)
        Creates a new CommandButton for the specified command. The button's unique ID will be determined by reading the command's AbstractCommand.BUTTON_ID_KEY key.
        Parameters:
        command - the command to generate a button for
        Throws:
        java.lang.NullPointerException - if the command is null or the command does not define a button ID value
      • CommandButton

        public CommandButton​(java.lang.String id,
                             AbstractCommand command)
        Creates a new CommandButton for the specified command. The command will use the specified ID.
        Parameters:
        command - the command to generate a button for
        id - the unique ID to use for the button
        Throws:
        java.lang.NullPointerException - if the command is null
    • Method Detail

      • getCommand

        public final AbstractCommand getCommand()
        Returns the command that this button is a proxy for.
        Returns:
        the command used to create this button
      • getID

        public java.lang.String getID()
        Description copied from interface: ContextBar.Button
        Returns a unique ID for this button, such as "BOLD". Only letters, digits, underscores, and currency symbols may appear in an ID.
        Specified by:
        getID in interface ContextBar.Button
        Returns:
        a short ID that will identify this button in the application preferences
      • getName

        public java.lang.String getName()
        Description copied from interface: ContextBar.Button
        Returns the button's name, or null.
        Specified by:
        getName in interface ContextBar.Button
        Returns:
        a localized description of the button's function
      • onAttach

        public void onAttach​(ContextBar.Context context)
        Description copied from interface: ContextBar.Button
        This method is called to notify the button when the tool bar is about to be attached to a new target component (the component that it floats over and that its commands normally apply to).
        Specified by:
        onAttach in interface ContextBar.Button
        Parameters:
        context - information about the current context
      • onDetach

        public void onDetach​(ContextBar.Context context)
        Description copied from interface: ContextBar.Button
        This method is called to notify the button when the tool bar is about to be detached from the current target component (the component that it floats over and that its commands normally apply to).
        Specified by:
        onDetach in interface ContextBar.Button
        Parameters:
        context - information about the current context
      • isEnabledInCurrentContext

        public boolean isEnabledInCurrentContext​(ContextBar.Context context)
        Description copied from interface: ContextBar.Button
        Returns true if the button should be enabled in the current context.
        Specified by:
        isEnabledInCurrentContext in interface ContextBar.Button
        Parameters:
        context - information about the current context
        Returns:
        true if the button should be enabled (ignored if not visible)
      • isVisibleInCurrentContext

        public boolean isVisibleInCurrentContext​(ContextBar.Context context)
        Description copied from interface: ContextBar.Button
        Returns true if the button should be visible in the current context. A button should be invisible if it can never be enabled in the current context, and disabled if it is not currently usable due to a temporary restriction. For example, any text field can be copied from if there is an active selection, so a copy button should always be visible but should be enabled only if there is a selection. On the other hand, a command that only works for script code should be visible only when editing a script.
        Specified by:
        isVisibleInCurrentContext in interface ContextBar.Button
        Parameters:
        context - information about the current context
        Returns:
        true if the button should be visible
      • update

        protected void update()
        Updates the state of the command that this button is a proxy for. If this is called more than once while the same event is being dispatched, it will only update the actual command once (the first time it is called for that event). This allows this method to be called multiple times while determining the button state without a significant performance penalty, even if the command's update process is complex.
      • actionPerformed

        public void actionPerformed​(java.awt.event.ActionEvent e)
        Activates the command associated with this button.
        Specified by:
        actionPerformed in interface java.awt.event.ActionListener
        Parameters:
        e - the action event for the button activation
      • toString

        public java.lang.String toString()
        Returns a string representation of the button suitable for debugging. The returned string is Button<id>, where id is the button's ID as returned by ContextBar.Button.getID().
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string representation of the button