All Implemented Interfaces:
Animatable<ColorPicker>, CanDrop<ColorPicker>, SupportHelpIcon<ColorPicker>, Draggable<ColorPicker>, Editable<ColorPicker>, Focusable<ColorPicker>, HandleHotKey<ColorPicker>, HandleKeyboardEvents<ColorPicker>

Color picker form item

With the use of this component, the user can choose a color, which is inputted to the framework as CSS code. The color picker component's value is always a String. The format of the component can be changed, by default it uses the hexadecimal format. Other formats that can be used are RGB and RGBA.

If the component has a null value, the color will be completely transparent. If the user edits the color by hand, and specifies an invalid color, the previously selected color will replace it.

The component appears on the interface, as an input field, where the user can input the color code. Next to the field is a button, that brings up a color palette. The user can select a color from here, or use predefined colors. These predefined colors can be created by using the addColor(String, String) method.

By default the palette has a small size. The component allows the palette to be displayed in a bigger size, in which case the setLargePalette(boolean) method can be called, and given the true value.

The color picker component is a form item, so it can be placed on, and will be handled by the Form component. The color picker component can be used on its own, but then the developer must implement event and value handlers.

Supported events:

AnimationStart AnimationEnd, Focus FocusOut FocusIn LosesFocus copy cut EnterPressed input paste KeyPress, KeyUp, KeyDown, Drop, DragStart, DragEnd HotKey

Since:
4.0
Author:
JBStrap
See Also:
  • Constructor Details

    • ColorPicker

      public ColorPicker(String name, String label)
      Creates a color picker component with the specified name and label.
      Parameters:
      name - The color picker name, must be unique within the form
      label - The color picker label. If null, no label will be used
      Throws:
      NullPointerException - If the name is null
    • ColorPicker

      public ColorPicker(String name, String label, String language)
      Creates a color picker component with the specified name label and language.
      Parameters:
      name - The color picker name, must be unique within the form
      label - The color picker label. If null, no label will be used
      language - The language code to be used by the color picker. If not specified, or null the default language will be used. The framework's default language can be set by the JBStrapParamType.DEFAULT_LANGUAGE JBStrap parameter
      Throws:
      NullPointerException - If the name is null
    • ColorPicker

      public ColorPicker(DataDescriptorColumn column)

      Creates a color picker, based on the specified DataDescriptor column.

      The method creates and sets the color picker component, based on the parameters of the specified column. The following parameters are used:

      • DataDescriptorColumn.getTitle - The title set in the DataDescriptor column will be used by the input field as its label.
      • DataDescriptorColumn.isNullable() - If the field can a null value, the field will be marked as not mandatory. If it cannot have a null value, the field will be marked as mandatory.
      • MetaParamName.LARGE_PALETTE - Determines if the color picker palette will be large or small. By default, it is small. If set to true, it will be large.
      • MetaParamName.FORMAT - Determines the color format. By default, it is using the hexadecimal format. To use other formats, the following values can be specified:
        • "hex" - Hexadecimal - "#rggbb"
        • "rgb" - RGB format - "rgb(r, g, b)"
        • "rgba" - RGB + ALPHA - "rgba(r, g, b, a)"
        If an invalid format is specified, the default, hexadecimal format will be used.
      • MetaParamName.PLACEHOLDER - This text will be used as a placeholder.
      • MetaParamName.SIZE - The value specified here defines the size of the input field. (Applicable values: SMALL, MEDIUM, LARGE)
      • MetaParamName.STATE - The value specified here defines the state of the input field. (Applicable values: DEFAULT, ERROR, WARNING, SUCCESS, INFO)
      • MetaParamName.DEFAULT_VALUE - The value specified here defines the field's default value. The value must have the type of field, in this case, it must be a text value.
      • MetaParamName.READ_ONLY - If true, the field will be read only. Otherwise, the field can have its contents modified by the user.
      • MetaParamName.ENABLED - If false, the field will be disabled (it will be created in an unusable state.) Otherwise, the field will be enabled when created.
      • MetaParamName.HELP - If the parameter is specified, an icon will be displayed next to the field. If the user moves over the icon, the text specified here will be displayed, as a help text.
      • MetaParamName.HELP_ICON - If the icon name is specified (from the Icon enum), then this icon will replace the default "?" icon.
      • MetaParamName.DESCRIPTION - The text specified here will appear below the field, in a smaller, italic font.
      • MetaParamName.TAB_INDEX - The value specified here determines the order of the input focus (when the user presses the Tab key). The order goes in ascending order. If not specified, the component will use the order value from the DataDescriptor. If that not specified either, the order in which it was placed in the DataDescriptor will be used.

      Parameters:
      column - The DataDescriptor column, that will be the basis of the color picker
      Throws:
      NullPointerException - If the column was specified as null
    • ColorPicker

      public ColorPicker(DataDescriptorColumn column, String language)

      Creates a color picker, based on the specified DataDescriptor column and language

      The method creates and sets the color picker component, based on the parameters of the specified column. The following parameters are used:

      • DataDescriptorColumn.getTitle - The title set in the DataDescriptor column will be used by the input field as its label.
      • DataDescriptorColumn.isNullable() - If the field can a null value, the field will be marked as not mandatory. If it cannot have a null value, the field will be marked as mandatory.
      • MetaParamName.LARGE_PALETTE - Determines if the color picker palette will be large or small. By default, it is small. If set to true, it will be large.
      • MetaParamName.FORMAT - Determines the color format. By default, it is using the hexadecimal format. To use other formats, the following values can be specified:
        • "hex" - Hexadecimal - "#rggbb"
        • "rgb" - RGB format - "rgb(r, g, b)"
        • "rgba" - RGB + ALPHA - "rgba(r, g, b, a)"
        If an invalid format is specified, the default, hexadecimal format will be used.
      • MetaParamName.PLACEHOLDER - This text will be used as a placeholder.
      • MetaParamName.SIZE - The value specified here defines the size of the input field. (Applicable values: SMALL, MEDIUM, LARGE)
      • MetaParamName.STATE - The value specified here defines the state of the input field. (Applicable values: DEFAULT, ERROR, WARNING, SUCCESS, INFO)
      • MetaParamName.DEFAULT_VALUE - The value specified here defines the field's default value. The value must have the type of field, in this case, it must be a text value.
      • MetaParamName.READ_ONLY - If true, the field will be read only. Otherwise, the field can have its contents modified by the user.
      • MetaParamName.ENABLED - If false, the field will be disabled (it will be created in an unusable state.) Otherwise, the field will be enabled when created.
      • MetaParamName.HELP - If the parameter is specified, an icon will be displayed next to the field. If the user moves over the icon, the text specified here will be displayed, as a help text.
      • MetaParamName.HELP_ICON - If the icon name is specified (from the Icon enum), then this icon will replace the default "?" icon.
      • MetaParamName.DESCRIPTION - The text specified here will appear below the field, in a smaller, italic font.
      • MetaParamName.TAB_INDEX - The value specified here determines the order of the input focus (when the user presses the Tab key). The order goes in ascending order. If not specified, the component will use the order value from the DataDescriptor. If that not specified either, the order in which it was placed in the DataDescriptor will be used.

      Parameters:
      column - The DataDescriptor column, that will be the basis of the color picker
      language - The language code to be used by the color picker. If not specified, or null the default language will be used. The framework's default language can be set by the JBStrapParamType.DEFAULT_LANGUAGE JBStrap parameter
      Throws:
      NullPointerException - If the column was specified as null
  • Method Details

    • init

      public void init() throws JavaScriptLoadError
      Description copied from class: Component
      The component initialization method.

      Empty method, only needs to be overwritten when making a custom component, that needs to call an initializing JavaScript on the client side. The method is called by the framework after the component is drawn, but before the afterDraw() method. The use of this method during application development is not allowed. This method is meant for inner use only.

      Overrides:
      init in class FormItem<String,ColorPicker>
      Throws:
      JavaScriptLoadError - If there was a JavaScript error during the initialization.
    • addColor

      public ColorPicker addColor(String name, String color)
      Adds the specified color to the predefined colors
      Parameters:
      name - The name of the color
      color - The color code, in CSS3
      Returns:
      The color picker component
      Throws:
      NullPointerException - If the name or color is null
    • addColors

      public ColorPicker addColors(Map<String,String> definedColors)
      Adds the specified colors to the predefined colors
      Parameters:
      definedColors - The map containing the colors. The map key is the color name, the map value is the color code (in css3). If null, the method won't do anything
      Returns:
      The color picker component
      Throws:
      NullPointerException - If any of the names or colors are null
    • removeColor

      public ColorPicker removeColor(String name)
      Removes the specified color from the predefined colors
      Parameters:
      name - The name of the color
      Returns:
      The color picker component
    • removeColors

      public ColorPicker removeColors(String... names)
      Removes the specified colors from the predefined colors
      Parameters:
      names - The names of the colors
      Returns:
      The color picker component
    • removeColors

      public ColorPicker removeColors(List<String> names)
      Removes the specified colors from the predefined colors
      Parameters:
      names - A list of color names to be removed
      Returns:
      The color picker component
    • removeAllColors

      public ColorPicker removeAllColors()
      Removes every predefined colors
      Returns:
      The color picker component
    • setFormat

      public ColorPicker setFormat(ColorFormat format)
      Sets the displayed color's format. The default format is hexadecimal
      Parameters:
      format - The displayed color format. The usable formats can be found in the ColorFormat enum
      Returns:
      The color picker component
    • getFormat

      public ColorFormat getFormat()
      Gets the color format
      Returns:
      The color format used by the component
    • setLargePalette

      public ColorPicker setLargePalette(boolean largePalette)
      Sets if the color picker palette will be large or small. By default, it is small. If set to true, it will be large.
      Parameters:
      largePalette - If true, the large palette will be used
      Returns:
      The color picker component
    • isLargePalette

      public boolean isLargePalette()
      Determines if the large palette is used
      Returns:
      If true, the large palette is used
    • openPalette

      public ColorPicker openPalette()
      Opens the palette on the interface. If the component is not drawn, the method will not work
      Returns:
      The color picker component
    • closePalette

      public ColorPicker closePalette()
      Closes the palette on the interface. If the component is not drawn, the method will not work
      Returns:
      The color picker component
    • setEnabled

      public ColorPicker setEnabled(boolean enabled)
      Enables or disables the color picker component. By default, it is enabled. If disabled, the user won't be able to use it.
      Overrides:
      setEnabled in class FormItem<String,ColorPicker>
      Parameters:
      enabled - If true, the component is enabled, and the user can use it.
      Returns:
      The color picker component
    • isEnabled

      public boolean isEnabled()
      Determines if the color picker is enabled or not.
      Overrides:
      isEnabled in class Component<ColorPicker>
      Returns:
      If true, it is enabled, otherwise false
    • isReadOnly

      public boolean isReadOnly()
      Determines if the component is read only for the user
      Overrides:
      isReadOnly in class FormItem<String,ColorPicker>
      Returns:
      If true, it is read only, otherwise false
    • setReadOnly

      public final ColorPicker setReadOnly(boolean readOnly)
      Sets the component to be read only. By default, it is not read only.
      Overrides:
      setReadOnly in class FormItem<String,ColorPicker>
      Parameters:
      readOnly - If true, the component is read only, the user won't be able to modify it. If false, the user can modify the color picker.
      Returns:
      The color picker component
    • drawEditor

      public void drawEditor(StringWriter writer)
      Description copied from class: FormItem

      Draws the editor component.

      You do not need to use this method during development, but all components extending the form item must implement it. Use the method to generate the input field’s HTML code. This code is then inserted into the corresponding DOM code when drawing the form item.

      Specified by:
      drawEditor in class FormItem<String,ColorPicker>
      Parameters:
      writer - The HTML string writer class instance; write here the HTML code for the input field
    • setDefaultValue

      public ColorPicker setDefaultValue(Object defaultValue)
      Sets the default value of the field
      Specified by:
      setDefaultValue in class FormItem<String,ColorPicker>
      Parameters:
      defaultValue - The default value of the field
      Returns:
      Form item component