org.zaval.lw
Class LwSpin
java.lang.Object
|
+--org.zaval.lw.LwCanvas
|
+--org.zaval.lw.LwPanel
|
+--org.zaval.lw.LwSpin
- All Implemented Interfaces:
- java.util.EventListener, Layoutable, LayoutContainer, LwActionListener, LwComponent, LwContainer, LwLayout, TextListener, Validationable
- public class LwSpin
- extends LwPanel
- implements LwLayout, LwActionListener, TextListener
This is spin light weight component that can be used to input a bound integer value.
The bound is determined by the BasicMaskValidator. To control current value
use the setValue and getValue methods. The component performs
action event whenever the spin value has been changed. Use the addActionListener
and removeActionListener methods to register the listener.
The spin implements a layout manager to place its child components. It is possible to
replace buttons components with an own, taking in account the following remarks:
- Remove the old button before adding new one.
- Use INC_BUTTON or DEC_BUTTON as the layout constraint.
- The new button should be LwStButton or inherits it.
|
Field Summary |
static java.lang.Integer |
DEC_BUTTON
This is decrement button layout constraint. |
static java.lang.Integer |
EDITOR_EL
This is decrement button layout constraint. |
static java.lang.Integer |
INC_BUTTON
This is increment button layout constraint. |
| Fields inherited from class org.zaval.lw.LwCanvas |
bits, bottom, height, isValidValue, left, parent, psHeight, psWidth, right, skins, temporary, top, width, x, y |
|
Constructor Summary |
LwSpin()
Constructs the component. |
| Methods inherited from class org.zaval.lw.LwPanel |
add, add, calcPreferredSize, count, get, getLayoutOffset, getLwComponentAt, getLwLayout, getPreferredSize, indexOf, insert, insert, invalidate, isInvalidatedByChild, laidout, paintOnTop, remove, remove, removeAll, setBackground, setLwLayout, setOpaque, setSize, toFront, updateCashedPs, validate |
| Methods inherited from class org.zaval.lw.LwCanvas |
calcInsets, canHaveFocus, customize, cvp, getBackground, getBottom, getBounds, getHeight, getInsets, getLeft, getLocation, getLwParent, getOrigin, getPSImpl, getRight, getSize, getTop, getViewMan, getVisiblePart, getWidth, getX, getY, hasFocus, isEnabled, isOpaque, isValid, isVisible, paint, recalc, repaint, repaint, repaint, requestFocus, setEnabled, setInsets, setLocation, setLwParent, setPSSize, setViewMan, setVisible, update, viewManChanged, vrp |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.zaval.lw.LwComponent |
canHaveFocus, getBackground, getLwParent, getOrigin, getViewMan, getVisiblePart, isEnabled, isOpaque, paint, repaint, repaint, repaint, setEnabled, setInsets, setLwParent, setViewMan, setVisible, update |
INC_BUTTON
public static final java.lang.Integer INC_BUTTON
- This is increment button layout constraint.
DEC_BUTTON
public static final java.lang.Integer DEC_BUTTON
- This is decrement button layout constraint.
EDITOR_EL
public static final java.lang.Integer EDITOR_EL
- This is decrement button layout constraint.
LwSpin
public LwSpin()
- Constructs the component. In this case the bound is [-10 .. +10].
getElement
public LwComponent getElement(java.lang.Integer type)
- Gets the increment, decrement button or editor component depending on the specified layout
constraint.
- Parameters:
type - the specified layout constraint. Use one of the following
constant:
- INC_BUTTON - to get increment button component.
- DEC_BUTTON - to get decrement button component.
- EDITOR_EL - to get editor component.
- Returns:
- a component.
getTextModel
public TextModel getTextModel()
- Gets the text model.
- Returns:
- a text model.
enableLoop
public void enableLoop(boolean b)
- Enables or disables the loop mode. If the loop mode is enabled than a spin value
will grow from minimal to maximal or from maximal to minimum values.
- Parameters:
b - true to enable the loop mode.
isLoopEnabled
public boolean isLoopEnabled()
- Returns the loop mode.
- Returns:
- a loop mode
setStep
public void setStep(int s)
- Sets the specified step. The step is used as the spin value increment or decrement
whenever a spin button is pressed.
- Parameters:
s - the specified step.
getStep
public int getStep()
- Gets the current step.
- Returns:
- a current step
addActionListener
public void addActionListener(LwActionListener l)
- Adds the action events listener. The action event is performed when a spin value has
been changed.
- Parameters:
l - the action events listener.
removeActionListener
public void removeActionListener(LwActionListener l)
- Removes the action events listener so it no longer get action events from the component.
- Parameters:
l - the action events listener.
componentAdded
public void componentAdded(java.lang.Object id,
Layoutable lw,
int index)
- Description copied from interface:
LwLayout
- Invoked when the specified layoutable component was added to the layout container
(that uses the layout manager). The specified constraints, layoutable component
and child index are passed as arguments into the method.
- Specified by:
componentAdded in interface LwLayout
- Following copied from interface:
org.zaval.lw.LwLayout
- Parameters:
id - the layoutable component constraints.lw - the layoutable component that has been added.index - the child index.
componentRemoved
public void componentRemoved(Layoutable lw,
int index)
- Description copied from interface:
LwLayout
- Invoked when the specified layoutable component was removed from the layout
container, that uses the layout manager.
- Specified by:
componentRemoved in interface LwLayout
- Following copied from interface:
org.zaval.lw.LwLayout
- Parameters:
lw - the layoutable component that has been removed.index - the child component index.
calcPreferredSize
public java.awt.Dimension calcPreferredSize(LayoutContainer target)
- Description copied from interface:
LwLayout
- Calculates the preferred size dimension for the layout container.
The method has to calculate "pure" preferred size, it means that container insets
should not be taken into account.
- Specified by:
calcPreferredSize in interface LwLayout
- Following copied from interface:
org.zaval.lw.LwLayout
- Parameters:
target - the layout container.- Returns:
- a "pure" preferred size.
layout
public void layout(LayoutContainer target)
- Description copied from interface:
LwLayout
- Lays out the child layoutable components inside the layout container.
- Specified by:
layout in interface LwLayout
- Following copied from interface:
org.zaval.lw.LwLayout
- Parameters:
target - the layout container.
actionPerformed
public void actionPerformed(java.lang.Object src,
java.lang.Object data)
- Description copied from interface:
LwActionListener
- Invoked when an action event occurred.
- Specified by:
actionPerformed in interface LwActionListener
- Following copied from interface:
org.zaval.lw.event.LwActionListener
- Parameters:
src - the specified source where the event has been originated.data - the event data.
getValue
public int getValue()
- Gets the current value.
- Returns:
- a current value.
setValue
public void setValue(int v)
- Sets the specified value.
If the loop mode is enabled than a case when the new value is less than minimum the
method sets maximum value as the current or if the new value is greater than
maximum the method sets minimum value as the current.
- Parameters:
v - the new current value.
getMinValue
public int getMinValue()
- Gets the minimum value. The current value cannot be less the minimum value.
- Returns:
- a minimum value.
getMaxValue
public int getMaxValue()
- Gets the maximum value. The current value cannot be greater the maximum value.
- Returns:
- a maxim um value.
getSpinValidator
public BasicMaskValidator getSpinValidator()
- Gets the spin validator. The current validator is a mask handler that defines
a spin value representation and validation algorithm.
- Returns:
- a spin validator.
setSpinValidator
public void setSpinValidator(BasicMaskValidator v)
- Sets the specified spin validator. The validator is a mask handler that defines
a spin value representation and validation algorithm.
- Parameters:
v - the specified spin validator.
textRemoved
public void textRemoved(TextEvent e)
- Description copied from interface:
TextListener
- Invoked when a part of the text has been removed.
- Specified by:
textRemoved in interface TextListener
- Following copied from interface:
org.zaval.data.event.TextListener
- Parameters:
e - the text event.
textInserted
public void textInserted(TextEvent e)
- Description copied from interface:
TextListener
- Invoked when a new text has been inserted in the text.
- Specified by:
textInserted in interface TextListener
- Following copied from interface:
org.zaval.data.event.TextListener
- Parameters:
e - the text event.
textUpdated
public void textUpdated(TextEvent e)
- Description copied from interface:
TextListener
- Invoked when the text has been updated.
- Specified by:
textUpdated in interface TextListener
- Following copied from interface:
org.zaval.data.event.TextListener
- Parameters:
e - the text event.
getDefaultLayout
protected LwLayout getDefaultLayout()
- Description copied from class:
LwPanel
- Gets the default layout manager that is set with the container during initialization.
This implementation of the method returns LwRastLayout as the default layout manager, the
layout manager is got as a static object by "def.lay" key.
- Overrides:
getDefaultLayout in class LwPanel
- Following copied from class:
org.zaval.lw.LwPanel
- Returns:
- a layout manager.
valueChanged
protected void valueChanged()
- The method is called whenever the spin value has been changed.
createMask
protected java.lang.String createMask()
- Creates the mask that should be set for the mask validator.
- Returns:
- a mask.
createValue
protected java.lang.String createValue(int value)
- Creates the value by the specified integer value. The created value is acceptable
for the given mask.
- Parameters:
value - the specified integer value.- Returns:
- a value is acceptable for the mask.
|