Class ColorPicker
- 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:
-
Field Summary
Fields inherited from class com.jbstrap.ui.components.form.FormItem
appends, clearButton, column, defaultState, defaultValue, description, formItemSize, helpIcon, label, labelPosition, labelSizes, modified, originalValue, params, prepends, required, showLabel, state, tabIndex, value, visible
Fields inherited from class com.jbstrap.ui.Component
animation, attributes, backgroundColor, borderColor, color, defaultHotKeyHandler, handlers, hotKeys, styleClasses, textAlign, toolTip, toolTipPosition
-
Constructor Summary
ConstructorDescriptionColorPicker
(DataDescriptorColumn column) Creates a color picker, based on the specified DataDescriptor column.ColorPicker
(DataDescriptorColumn column, String language) Creates a color picker, based on the specified DataDescriptor column and languageColorPicker
(String name, String label) Creates a color picker component with the specified name and label.ColorPicker
(String name, String label, String language) Creates a color picker component with the specified name label and language. -
Method Summary
Modifier and TypeMethodDescriptionAdds the specified color to the predefined colorsAdds the specified colors to the predefined colorsCloses the palette on the interface.void
drawEditor
(StringWriter writer) Draws the editor component.Gets the color formatvoid
init()
The component initialization method.boolean
Determines if the color picker is enabled or not.boolean
Determines if the large palette is usedboolean
Determines if the component is read only for the userOpens the palette on the interface.Removes every predefined colorsremoveColor
(String name) Removes the specified color from the predefined colorsremoveColors
(String... names) Removes the specified colors from the predefined colorsremoveColors
(List<String> names) Removes the specified colors from the predefined colorssetDefaultValue
(Object defaultValue) Sets the default value of the fieldsetEnabled
(boolean enabled) Enables or disables the color picker component.setFormat
(ColorFormat format) Sets the displayed color's format.setLargePalette
(boolean largePalette) Sets if the color picker palette will be large or small.final ColorPicker
setReadOnly
(boolean readOnly) Sets the component to be read only.Methods inherited from class com.jbstrap.ui.components.form.FormItem
_addComponent, _setReverseShow, _setState, addComponent, addRecalcOnChangeColumn, addRecalcOnChangeColumns, addRecalcOnChangeColumns, addValueChangeHandler, afterDraw, clearValue, convertValueToJavaScript, convertValueToJavaScript, drawComponent, enableClearButton, eraseValue, getCalculateValue, getColumn, getComponents, getDataType, getDefaultState, getDescription, getFormItemSize, getLabel, getLabelPosition, getLabelSize, getLabelSize, getName, getOriginalValue, getParam, getParamAsBoolean, getParamAsDate, getParamAsDate, getParamAsDouble, getParamAsInteger, getParamAsLong, getParamAsNumber, getParamAsString, getRecalcOnChangeColumnsList, getState, getTabIndex, getValue, getValueAsBoolean, getValueAsDate, getValueAsDouble, getValueAsFloat, getValueAsInteger, getValueAsLong, getValueAsString, isAssignable, isAutoCalculate, isModified, isRequired, isReverseShow, isShowLabel, isVisible, onFormItemValueChanged, onHotKeyEventHandler, onShow, redraw, removeParam, resetState, runAfterDrawOnAddon, runOnHideOnAddon, runOnShowOnAddon, setCalculateValue, setDataType, setDataType, setDescription, setFocus, setFormItemSize, setLabel, setLabelPosition, setLabelSize, setLabelSize, setMargin, setModified, setObjectValue, setOriginalObjectValue, setOriginalValue, setPadding, setParam, setParams, setRequired, setShowLabel, setState, setTabIndex, setValue, setVisible, triggerFormChange, writeHTML
Methods inherited from class com.jbstrap.ui.Component
_hide, _setAttribute, addAllowedRole, addComponent, addComponents, addDeniedRole, addHandler, addStyle, addStyleClass, addStyleClasses, clearfix, closeTag, combinateAccess, containsStyle, containsStyleClass, draw, drawSubComponents, error, flattendComponentTree, getAccess, getAccessMode, getAllowedRoles, getAttribute, getAttributes, getBackgroundColor, getBorderColor, getClient, getComponentById, getComponents, getComponentsByClass, getData, getDeniedRoles, getHandlers, getId, getLanguageCode, getParent, getParent, getRegisteredEvents, getStyle, getStyleClasses, getTextAlign, getTextColor, getToolTip, getToolTipPosition, getTypeName, getUI, insertComponentAfter, insertComponentBefore, isAccess, isDrawn, isEventBubbling, onHide, openTag, removeAllComponents, removeAllowedRole, removeAllStyleClasses, removeAttribute, removeComponent, removeComponent, removeComponents, removeDeniedRole, removeHandler, removeStyle, removeStyle, removeStyleClass, removeStyleClasses, replaceComponent, replaceStyleClass, runAfterDraw, runJavaScript, runJavaScript, runJavaScript, runOnHide, runOnShow, say, setAttribute, setBackgroundColor, setBorder, setBorderColor, setData, setDisplayType, setEventBubbling, setFlex, setFloating, setHeight100, setHeight25, setHeight50, setHeight75, setHeightAuto, setLanguage, setName, setOverflow, setParent, setScrollable, setSelectionType, setShadow, setStyle, setTextAlign, setTextColor, setToolTip, setToolTipPosition, setWidth100, setWidth25, setWidth50, setWidth75, setWidthAuto, showNotification, showNotification, showProcessIndicator, toggleStyleClass
Methods inherited from class com.jbstrap.core.messagebus.MessageBus
closeMessageBus, messageBusOpened, openMessageBus, renewSubscription, sendMessageToMessageBus, subscribeMessageBus, unsubscribeAllListeners, unsubscribeMessageBus
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.jbstrap.ui.Animatable
addAnimationEndHandler, addAnimationStartHandler, getAnimation, removeAnimation, setAnimation
Methods inherited from interface com.jbstrap.ui.CanDrop
addDropEventHandler
Methods inherited from interface com.jbstrap.ui.Draggable
addDragEndEventHandler, addDragStartEventHandler, setDraggable
Methods inherited from interface com.jbstrap.ui.Editable
addCopyHandler, addCutHandler, addEnterPressedHandler, addInputHandler, addPasteHandler
Methods inherited from interface com.jbstrap.ui.Focusable
addFocusHandler, addFocusInHandler, addFocusOutHandler, addLosesFocusHandler, setFocus
Methods inherited from interface com.jbstrap.ui.HandleHotKey
addHotKey, addHotKey, removeHotKey, removeHotKeys
Methods inherited from interface com.jbstrap.ui.HandleKeyboardEvents
addKeyDownHandler, addKeyPressHandler, addKeyUpHandler
Methods inherited from interface com.jbstrap.ui.components.form.SupportHelpIcon
getHelpIcon, getHelpText, setHelpIcon, setHelpText
-
Constructor Details
-
ColorPicker
Creates a color picker component with the specified name and label.- Parameters:
name
- The color picker name, must be unique within the formlabel
- The color picker label. Ifnull
, no label will be used- Throws:
NullPointerException
- If the name is null
-
ColorPicker
Creates a color picker component with the specified name label and language.- Parameters:
name
- The color picker name, must be unique within the formlabel
- The color picker label. Ifnull
, no label will be usedlanguage
- The language code to be used by the color picker. If not specified, ornull
the default language will be used. The framework's default language can be set by theJBStrapParamType.DEFAULT_LANGUAGE
JBStrap parameter- Throws:
NullPointerException
- If the name is null
-
ColorPicker
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 anull
value, the field will be marked as not mandatory. If it cannot have anull
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)"
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
- Iftrue
, the field will be read only. Otherwise, the field can have its contents modified by the user.MetaParamName.ENABLED
- Iffalse
, 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 theIcon
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 asnull
-
ColorPicker
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 anull
value, the field will be marked as not mandatory. If it cannot have anull
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)"
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
- Iftrue
, the field will be read only. Otherwise, the field can have its contents modified by the user.MetaParamName.ENABLED
- Iffalse
, 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 theIcon
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 pickerlanguage
- The language code to be used by the color picker. If not specified, ornull
the default language will be used. The framework's default language can be set by theJBStrapParamType.DEFAULT_LANGUAGE
JBStrap parameter- Throws:
NullPointerException
- If the column was specified asnull
-
-
Method Details
-
init
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 classFormItem<String,
ColorPicker> - Throws:
JavaScriptLoadError
- If there was a JavaScript error during the initialization.
-
addColor
Adds the specified color to the predefined colors- Parameters:
name
- The name of the colorcolor
- The color code, in CSS3- Returns:
- The color picker component
- Throws:
NullPointerException
- If the name or color isnull
-
addColors
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). Ifnull
, the method won't do anything- Returns:
- The color picker component
- Throws:
NullPointerException
- If any of the names or colors arenull
-
removeColor
Removes the specified color from the predefined colors- Parameters:
name
- The name of the color- Returns:
- The color picker component
-
removeColors
Removes the specified colors from the predefined colors- Parameters:
names
- The names of the colors- Returns:
- The color picker component
-
removeColors
Removes the specified colors from the predefined colors- Parameters:
names
- A list of color names to be removed- Returns:
- The color picker component
-
removeAllColors
Removes every predefined colors- Returns:
- The color picker component
-
setFormat
Sets the displayed color's format. The default format is hexadecimal- Parameters:
format
- The displayed color format. The usable formats can be found in theColorFormat
enum- Returns:
- The color picker component
-
getFormat
Gets the color format- Returns:
- The color format used by the component
-
setLargePalette
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
- Iftrue
, 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
Opens the palette on the interface. If the component is not drawn, the method will not work- Returns:
- The color picker component
-
closePalette
Closes the palette on the interface. If the component is not drawn, the method will not work- Returns:
- The color picker component
-
setEnabled
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 classFormItem<String,
ColorPicker> - Parameters:
enabled
- Iftrue
, 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 classComponent<ColorPicker>
- Returns:
- If
true
, it is enabled, otherwisefalse
-
isReadOnly
public boolean isReadOnly()Determines if the component is read only for the user- Overrides:
isReadOnly
in classFormItem<String,
ColorPicker> - Returns:
- If
true
, it is read only, otherwisefalse
-
setReadOnly
Sets the component to be read only. By default, it is not read only.- Overrides:
setReadOnly
in classFormItem<String,
ColorPicker> - Parameters:
readOnly
- Iftrue
, the component is read only, the user won't be able to modify it. Iffalse
, the user can modify the color picker.- Returns:
- The color picker component
-
drawEditor
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 classFormItem<String,
ColorPicker> - Parameters:
writer
- The HTML string writer class instance; write here the HTML code for the input field
-
setDefaultValue
Sets the default value of the field- Specified by:
setDefaultValue
in classFormItem<String,
ColorPicker> - Parameters:
defaultValue
- The default value of the field- Returns:
- Form item component
-