Class HSBPanel

  • All Implemented Interfaces:
    java.awt.event.ActionListener, java.awt.event.FocusListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.ChangeListener, javax.swing.event.PopupMenuListener

    public class HSBPanel
    extends javax.swing.JPanel
    implements javax.swing.event.ChangeListener, java.awt.event.ActionListener, java.awt.event.FocusListener, javax.swing.event.PopupMenuListener
    A custom UI control for choosing HSB colours.
    Author:
    Chris Jennings
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class javax.swing.JPanel

        javax.swing.JPanel.AccessibleJPanel
      • Nested classes/interfaces inherited from class javax.swing.JComponent

        javax.swing.JComponent.AccessibleJComponent
      • Nested classes/interfaces inherited from class java.awt.Container

        java.awt.Container.AccessibleAWTContainer
      • Nested classes/interfaces inherited from class java.awt.Component

        java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
    • Field Summary

      • Fields inherited from class javax.swing.JComponent

        listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
      • Fields inherited from class java.awt.Component

        accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
      • Fields inherited from interface java.awt.image.ImageObserver

        ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
    • Constructor Summary

      Constructors 
      Constructor Description
      HSBPanel()
      Creates new form HSBPanel
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void actionPerformed​(java.awt.event.ActionEvent evt)  
      void copyTint()  
      void focusGained​(java.awt.event.FocusEvent evt)  
      void focusLost​(java.awt.event.FocusEvent evt)  
      float[] getHSB()
      Returns the selected HSB value.
      int getPresetCount()
      Returns the number of presets, or 0 if none are set.
      java.lang.String getPresetName​(int n)
      Returns a the name of the specified preset value.
      java.lang.Object[] getPresets()
      Returns the list of preset values, or null if no presets have been set.
      float[] getPresetValue​(int n)
      Returns a copy of the HSB components of the specified preset value.
      Tintable getTintable()  
      java.lang.String getTitle()
      Returns the title displayed for the panel.
      boolean isPresetsVisible()
      Returns whether the preset list is visible.
      void pasteTint()  
      void popupMenuCanceled​(javax.swing.event.PopupMenuEvent evt)  
      void popupMenuWillBecomeInvisible​(javax.swing.event.PopupMenuEvent evt)  
      void popupMenuWillBecomeVisible​(javax.swing.event.PopupMenuEvent evt)  
      void selectPreset​(int n)
      Selects the specified preset value.
      void setEnabled​(boolean enable)  
      void setHSB​(float[] hsb)
      Sets the selected HSB value using the first three elements of the specified array.
      void setHSB​(float h, float s, float b)
      Sets the selected HSB value.
      void setHSB​(java.awt.Color color)
      Sets the selected HSB value to match the specified color.
      void setPresets​(java.lang.Object... presets)
      Sets a list of preset values that the user can choose from.Setting an empty array has the same effect as passing null, namely, clearing the list of presets.
      void setPresetsVisible​(boolean visible)
      Sets whether a combo box of preset values is shown in the panel.
      void setTintable​(Tintable tintable, boolean matchTintableToPanel)  
      void setTitle​(java.lang.String panelTitle)
      Sets the title displayed for the panel.
      void stateChanged​(javax.swing.event.ChangeEvent evt)  
      static void takeOverSlider​(javax.swing.JLabel label, javax.swing.JSlider slider)  
      java.lang.String toString()  
      • Methods inherited from class javax.swing.JPanel

        getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
      • Methods inherited from class javax.swing.JComponent

        addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
      • Methods inherited from class java.awt.Container

        add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
      • Methods inherited from class java.awt.Component

        action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, transferFocus, transferFocusBackward, transferFocusUpCycle
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • HSBPanel

        public HSBPanel()
        Creates new form HSBPanel
    • Method Detail

      • setPresetsVisible

        public void setPresetsVisible​(boolean visible)
        Sets whether a combo box of preset values is shown in the panel.
        Parameters:
        visible - if true, the preset controls are shown
      • isPresetsVisible

        public boolean isPresetsVisible()
        Returns whether the preset list is visible.
        Returns:
        true if the preset controls are visible
      • setPresets

        public void setPresets​(java.lang.Object... presets)
        Sets a list of preset values that the user can choose from.Setting an empty array has the same effect as passing null, namely, clearing the list of presets. Otherwise, the preset values are determined using pairs of elements are follows: The string value of the first element in each pair is used as the name to display for the preset value. If the second value in the pair is a float array, then its first three values determine the h, s, and b component of the preset value, respectively. Otherwise, the string value of the object is parsed into such an array using Settings.tint(java.lang.String).

        Examples:

         // clear the preset list
         panel.setPresets();
         // create entries "Happy" and "Sad" with values [0.181,0.6,1] and [-0.25,0.33,0.83]
         panel.setPresets( "Happy", "65,0.6,1", "Sad", "-155,0.33,0.83" );
         // create entry "Angry" with value [0,1,0.7]
         panel.setPresets( "Angry", new float[] {0f,1f,0.7f} );
         // same as above, but in a script instead of Java code:
         panel.setPresets( "Angry", [0,1,0.7] );
         

        This method will automatically make the preset controls visible when setting a non-empty list, and hide them when setting an empty list.

        Parameters:
        presets - the list of presets to display, or null
        Throws:
        java.lang.NullPointerException - if an element is null
        Settings.ParseError - if a tint string value cannot be parsed
      • getPresetCount

        public int getPresetCount()
        Returns the number of presets, or 0 if none are set.
        Returns:
        the number of preset values
      • getPresetName

        public java.lang.String getPresetName​(int n)
        Returns a the name of the specified preset value.
        Parameters:
        n - the preset index
        Returns:
        the name of the preset with the specifed index
      • getPresetValue

        public float[] getPresetValue​(int n)
        Returns a copy of the HSB components of the specified preset value.
        Parameters:
        n - the preset index
        Returns:
        a copy of the preset's HSB values
      • getPresets

        public java.lang.Object[] getPresets()
        Returns the list of preset values, or null if no presets have been set. The list will be an exact copy of the passed-in list, or null if no list was set, or the list was empty or null.
        Returns:
        an array of preset values in the same format as setPresets(java.lang.Object...)
      • selectPreset

        public void selectPreset​(int n)
        Selects the specified preset value.
        Parameters:
        n - the preset index
      • setHSB

        public void setHSB​(java.awt.Color color)
        Sets the selected HSB value to match the specified color.
        Parameters:
        color - the color to match
      • setHSB

        public void setHSB​(float h,
                           float s,
                           float b)
        Sets the selected HSB value.
        Parameters:
        h - the hue value to set
        s - the saturation value to set
        b - the brightness value to set
      • setHSB

        public void setHSB​(float[] hsb)
        Sets the selected HSB value using the first three elements of the specified array.
        Parameters:
        hsb - an array of at least 3 float values
      • getHSB

        public float[] getHSB()
        Returns the selected HSB value.
        Returns:
        an array containing the hue, saturation, and brightness values
        See Also:
        setHSB(float[])
      • actionPerformed

        public void actionPerformed​(java.awt.event.ActionEvent evt)
        Specified by:
        actionPerformed in interface java.awt.event.ActionListener
      • focusGained

        public void focusGained​(java.awt.event.FocusEvent evt)
        Specified by:
        focusGained in interface java.awt.event.FocusListener
      • focusLost

        public void focusLost​(java.awt.event.FocusEvent evt)
        Specified by:
        focusLost in interface java.awt.event.FocusListener
      • stateChanged

        public void stateChanged​(javax.swing.event.ChangeEvent evt)
        Specified by:
        stateChanged in interface javax.swing.event.ChangeListener
      • popupMenuCanceled

        public void popupMenuCanceled​(javax.swing.event.PopupMenuEvent evt)
        Specified by:
        popupMenuCanceled in interface javax.swing.event.PopupMenuListener
      • popupMenuWillBecomeInvisible

        public void popupMenuWillBecomeInvisible​(javax.swing.event.PopupMenuEvent evt)
        Specified by:
        popupMenuWillBecomeInvisible in interface javax.swing.event.PopupMenuListener
      • popupMenuWillBecomeVisible

        public void popupMenuWillBecomeVisible​(javax.swing.event.PopupMenuEvent evt)
        Specified by:
        popupMenuWillBecomeVisible in interface javax.swing.event.PopupMenuListener
      • copyTint

        public void copyTint()
      • pasteTint

        public void pasteTint()
      • takeOverSlider

        public static void takeOverSlider​(javax.swing.JLabel label,
                                          javax.swing.JSlider slider)
      • getTintable

        public Tintable getTintable()
      • setTintable

        public void setTintable​(Tintable tintable,
                                boolean matchTintableToPanel)
      • setEnabled

        public void setEnabled​(boolean enable)
        Overrides:
        setEnabled in class javax.swing.JComponent
      • setTitle

        public void setTitle​(java.lang.String panelTitle)
        Sets the title displayed for the panel.
        Parameters:
        panelTitle - title text
      • getTitle

        public java.lang.String getTitle()
        Returns the title displayed for the panel.
        Returns:
        the title text
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.awt.Component