org.zaval.lw.tree
Class LwTree
java.lang.Object
|
+--org.zaval.lw.LwCanvas
|
+--org.zaval.lw.LwPanel
|
+--org.zaval.lw.tree.LwTree
- All Implemented Interfaces:
- java.util.EventListener, Layoutable, LayoutContainer, LwChildrenListener, LwComponent, LwContainer, LwKeyListener, LwMouseListener, LwViewProvider, ScrollObj, TreeListener, Validationable
- public class LwTree
- extends LwPanel
- implements TreeListener, LwViewProvider, LwMouseListener, LwKeyListener, ScrollObj, LwChildrenListener
This is tree view component. The component renders the specified TreeModel
and organizes navigation through the tree. The sample below illustrates
the component usage:
...
Item root = new Item("root");
TreeModel data = new Tree(root);
data.add(data.getRoot(), new Item("First Child root"));
data.add(data.getRoot(), new Item("Second Child root"));
LwTree tree = new LwTree(data);
...
The class provides ability to customize the tree node rendering by defining the
LwViewProvider provider. It allows you to specify the view for the tree item.
The default tree item view is LwTextRender.
The class provides ability to edit and customize editing process for the tree view items.
Use the setEditorProvider method to customize items editing.
Use the addSelectionListener and removeSelectionListener methods to
handle selection events. The events are performed by the component whenever the tree node
has been selected, deselected.
Use the addActionListener and removeActionListener methods to
be notified whenever the node has been expanded or collapsed. The data argument of the event contains
the tree expanded or collapsed item.
It is possible to disable node selection by the enableSelection method.
It is possible to customize views for some elements of the tree by the setView
method. The default views of the elements are read as static objects by the following keys:
- The toggle off view is fetched by "tr.off" key.
- The toggle on view is fetched by "tr.on" key.
- The list node view is fetched by the "tr.least" key.
- The opened node view is fetched by the "tr.open" key.
- The closed node view is fetched by the "tr.close" key.
The tree nodes height and width can be extended by the setGaps method that
defines horizontal and vertical gaps between the nodes.
Use the setColor method to customize the selection marker and tree lines color.
It is possible disables tree view line rendering by the setColor method.
Set the tree lines color to null value to disable the lines rendering.
|
Field Summary |
static int |
CLOSED_VIEW
Defines closed view element type. |
static int |
LEAST_VIEW
Defines list view element type. |
static int |
LN_COLOR
Defines the lines color type. |
static int |
OPENED_VIEW
Defines opened view element type. |
static int |
SEL1_COLOR
Defines the selection marker color type for the tree component that has the focus. |
static int |
SEL2_COLOR
Defines the selection marker color type for the tree component that doesn't have the focus. |
static int |
TOGGLE_OFF_VIEW
Defines toggle off view element type. |
static int |
TOGGLE_ON_VIEW
Defines toggle on view element type. |
| 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 |
LwTree(TreeModel d)
Constructs a tree view component with the specified tree model. |
LwTree(TreeModel d,
boolean b)
Constructs a tree view component with the specified tree model and tree node state.
|
|
Method Summary |
void |
addActionListener(LwActionListener l)
Adds the specified action listener to receive action events from this tree.
|
void |
addSelectionListener(LwActionListener l)
Adds the specified selection listener to be notified whenever the tree item has been
selected, deselected. |
protected java.awt.Dimension |
calcPreferredSize()
Gets the "pure" preferred size for this component. |
boolean |
canHaveFocus()
Specifies if the component can have focus. |
void |
childPerformed(LwVCLEvent e)
Invoked whenever the child event has been performed. |
void |
enableSelection(boolean b)
Enables the tree node selecting. |
java.awt.Color |
getColor(int type)
Gets the color for the specified element. |
LwEditorProvider |
getEditorProvider()
Gets the items editors provider. |
Item |
getItemAt(int x,
int y)
Looks up and returns an item that is placed at the specified location.
|
ItemMetrics |
getItemMetrics(Item i)
Gets the item metric for the specified item. |
TreeModel |
getModel()
Gets the tree model that is rendered with the tree view component. |
java.awt.Point |
getOrigin()
Returns an origin of the component. |
Item |
getSelectedItem()
Gets the item that is selected at the moment. |
java.awt.Point |
getSOLocation()
Gets the scroll object location. |
java.awt.Dimension |
getSOSize()
Gets the scroll object size. |
LwView |
getView(LwComponent d,
java.lang.Object obj)
Gets the view for the specified object of the specified component. |
LwViewProvider |
getViewProvider()
Gets the view provider. |
void |
iItem(Item item)
Invalidates a metric of the specified tree item. |
void |
iItems()
Invalidates a metric for all tree items. |
void |
invalidate()
Invalidates this object. |
boolean |
isInvalidatedByChild(LwComponent c)
Invoked by a child component whenever the child invalidates itself. |
boolean |
isOpen(Item i)
Checks if the tree item is expanded. |
boolean |
isSelectionEnabled()
Tests if the tree items selection is enabled. |
void |
itemInserted(java.lang.Object target,
Item item)
Invoked when the item has been inserted as a member of the source tree. |
void |
itemModified(java.lang.Object target,
Item item)
Invoked when source tree item has been modified. |
void |
itemRemoved(java.lang.Object target,
Item item)
Invoked when the item has been removed from the source tree. |
void |
keyPressed(LwKeyEvent e)
Invoked when a key has been pressed. |
void |
keyReleased(LwKeyEvent e)
Invoked when a key has been released. |
void |
keyTyped(LwKeyEvent e)
Invoked when a key has been typed. |
protected void |
laidout()
Invoked whenever the container layouting procedure has been finished. |
void |
mouseClicked(LwMouseEvent e)
Invoked when the mouse button has been clicked on a light weight component. |
void |
mouseEntered(LwMouseEvent e)
Invoked when the mouse enters a light weight component. |
void |
mouseExited(LwMouseEvent e)
Invoked when the mouse exits a light weight component. |
void |
mousePressed(LwMouseEvent e)
Invoked when the mouse button has been pressed on a light weight component. |
void |
mouseReleased(LwMouseEvent e)
Invoked when the mouse button has been released on a light weight component. |
boolean |
moveContent()
Tests if the scrolled component performs scrolling by changing its location or moving view. |
void |
paint(java.awt.Graphics g)
Paints this component. |
protected void |
recalc()
Invoked with validate method only if the component is not valid.
|
void |
removeActionListener(LwActionListener l)
Removes the specified action listener. |
void |
removeSelectionListener(LwActionListener l)
Removes the specified selection listener. |
void |
repaint(boolean b)
Invoked whenever the component got or lost the focus. |
void |
select(Item item)
Selects the specified node of the tree. |
void |
setColor(int type,
java.awt.Color c)
Sets the specified color to render the given element. |
void |
setEditorProvider(LwEditorProvider p)
Sets the items editors provider. |
void |
setGaps(int gx,
int gy)
Sets the specified vertical and horizontal gaps. |
void |
setModel(TreeModel d)
Sets the specified tree model to be rendered with the component. |
void |
setScrollMan(ScrollMan m)
Sets the specified scroll manager for the scroll object. |
void |
setSOLocation(int x,
int y)
Sets the specified scroll object location. |
void |
setView(int id,
LwView v)
Sets the specified view for the specified tree view element. |
void |
setViewProvider(LwViewProvider p)
Sets the specified view provider. |
void |
startEditing(Item item)
Starts editing of the specified tree item. |
void |
stopEditing(boolean applyData)
Stops the item editing. |
void |
toggle(Item item)
Switches a toggle state for the specified tree item. |
protected void |
vVisibility()
Validates the tree component visibility. |
| Methods inherited from class org.zaval.lw.LwPanel |
add, add, count, get, getDefaultLayout, getLayoutOffset, getLwComponentAt, getLwLayout, getPreferredSize, indexOf, insert, insert, paintOnTop, remove, remove, removeAll, setBackground, setLwLayout, setOpaque, setSize, toFront, updateCashedPs, validate |
| Methods inherited from class org.zaval.lw.LwCanvas |
calcInsets, customize, cvp, getBackground, getBottom, getBounds, getHeight, getInsets, getLeft, getLocation, getLwParent, getPSImpl, getRight, getSize, getTop, getViewMan, getVisiblePart, getWidth, getX, getY, hasFocus, isEnabled, isOpaque, isValid, isVisible, 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 |
getBackground, getLwParent, getViewMan, getVisiblePart, isEnabled, isOpaque, repaint, repaint, setEnabled, setInsets, setLwParent, setViewMan, setVisible, update |
LEAST_VIEW
public static final int LEAST_VIEW
- Defines list view element type.
OPENED_VIEW
public static final int OPENED_VIEW
- Defines opened view element type.
CLOSED_VIEW
public static final int CLOSED_VIEW
- Defines closed view element type.
TOGGLE_OFF_VIEW
public static final int TOGGLE_OFF_VIEW
- Defines toggle off view element type.
TOGGLE_ON_VIEW
public static final int TOGGLE_ON_VIEW
- Defines toggle on view element type.
SEL1_COLOR
public static final int SEL1_COLOR
- Defines the selection marker color type for the tree component that has the focus.
SEL2_COLOR
public static final int SEL2_COLOR
- Defines the selection marker color type for the tree component that doesn't have the focus.
LN_COLOR
public static final int LN_COLOR
- Defines the lines color type.
LwTree
public LwTree(TreeModel d)
- Constructs a tree view component with the specified tree model.
- Parameters:
d - the specified tree model.
LwTree
public LwTree(TreeModel d,
boolean b)
- Constructs a tree view component with the specified tree model and tree node state.
The state defines if all nodes that have children should be opened or closed.
- Parameters:
d - the specified tree model.b - the specified tree node state.
setEditorProvider
public void setEditorProvider(LwEditorProvider p)
- Sets the items editors provider.
- Parameters:
p - the items editors provider.
getEditorProvider
public LwEditorProvider getEditorProvider()
- Gets the items editors provider.
- Returns:
- an items editors provider.
startEditing
public void startEditing(Item item)
- Starts editing of the specified tree item. The method initiates editing process if
the editor provider has been defined for the component and the editor component
exists.
- Parameters:
item - the specified iten to be edited.
stopEditing
public void stopEditing(boolean applyData)
- Stops the item editing. The method has effect if the editing process has been initiated
before.
- Parameters:
applyData - use true value if the edited data should be
applied to data model, use false otherwise.
canHaveFocus
public boolean canHaveFocus()
- Description copied from interface:
LwComponent
- Specifies if the component can have focus.
- Overrides:
canHaveFocus in class LwCanvas
- Following copied from interface:
org.zaval.lw.LwComponent
- Returns:
true if the component can have the focus.
enableSelection
public void enableSelection(boolean b)
- Enables the tree node selecting.
- Parameters:
b - use true to enable the tree node selecting;
false otherwise.
isSelectionEnabled
public boolean isSelectionEnabled()
- Tests if the tree items selection is enabled.
- Returns:
true if the tree items selection is enabled;
false otherwise.
getColor
public java.awt.Color getColor(int type)
- Gets the color for the specified element.
- Parameters:
type - the specified element type.- Returns:
- a color.
setColor
public void setColor(int type,
java.awt.Color c)
- Sets the specified color to render the given element. Use the SEL1_COLOR, SEL2_COLOR
or LN_COLOR constant as the type value. To disable the tree lines rendering, set the LN_COLOR
to the
null value.
- Parameters:
type - the specified element type.c - the specified color.
setGaps
public void setGaps(int gx,
int gy)
- Sets the specified vertical and horizontal gaps. The method doesn't touch
a gap in case if it is less zero, so it is possible to use the method to
set only vertical or only horizontal gap.
- Parameters:
gx - the specified horizontal gap.gy - the specified vertical gap.
getModel
public TreeModel getModel()
- Gets the tree model that is rendered with the tree view component.
- Returns:
- a tree model.
setViewProvider
public void setViewProvider(LwViewProvider p)
- Sets the specified view provider. The provider is used to define a view that
will be used to paint the node. It is possible to use
null value
as the input argument, in this case the LwTextRender view is used (the method
sets itself as the view provider) to paint the node.
- Parameters:
p - the specified view provider.
getViewProvider
public LwViewProvider getViewProvider()
- Gets the view provider.
- Returns:
- a view provider.
setView
public void setView(int id,
LwView v)
- Sets the specified view for the specified tree view element. Use one of the following
constants as the view element id:
-
LEAST_VIEW - to define least node element.
-
OPENED_VIEW - to define opened node element.
-
CLOSED_VIEW - to define closed node element.
-
TOGGLE_OFF_VIEW - to define toggle off node element.
-
TOGGLE_ON_VIEW - to define toggle on node element.
- Parameters:
id - the specified element id.v - the specified view.
setModel
public void setModel(TreeModel d)
- Sets the specified tree model to be rendered with the component.
- Parameters:
d - the specified tree model.
paint
public void paint(java.awt.Graphics g)
- Paints this component.
- Overrides:
paint in class LwCanvas
- Parameters:
g - the graphics context to be used for painting.
addSelectionListener
public void addSelectionListener(LwActionListener l)
- Adds the specified selection listener to be notified whenever the tree item has been
selected, deselected.
- Parameters:
l - the specified selection listener.
removeSelectionListener
public void removeSelectionListener(LwActionListener l)
- Removes the specified selection listener.
- Parameters:
l - the specified selection listener.
getView
public LwView getView(LwComponent d,
java.lang.Object obj)
- Description copied from interface:
LwViewProvider
- Gets the view for the specified object of the specified component.
- Specified by:
getView in interface LwViewProvider
- Following copied from interface:
org.zaval.lw.LwViewProvider
- Parameters:
d - the specified component.obj - the specified object.- Returns:
- a view.
mouseClicked
public void mouseClicked(LwMouseEvent e)
- Description copied from interface:
LwMouseListener
- Invoked when the mouse button has been clicked on a light weight component.
- Specified by:
mouseClicked in interface LwMouseListener
- Following copied from interface:
org.zaval.lw.event.LwMouseListener
- Parameters:
e - the specified mouse event.
mouseReleased
public void mouseReleased(LwMouseEvent e)
- Description copied from interface:
LwMouseListener
- Invoked when the mouse button has been released on a light weight component.
- Specified by:
mouseReleased in interface LwMouseListener
- Following copied from interface:
org.zaval.lw.event.LwMouseListener
- Parameters:
e - the specified mouse event.
mouseEntered
public void mouseEntered(LwMouseEvent e)
- Description copied from interface:
LwMouseListener
- Invoked when the mouse enters a light weight component.
- Specified by:
mouseEntered in interface LwMouseListener
- Following copied from interface:
org.zaval.lw.event.LwMouseListener
- Parameters:
e - the specified mouse event.
mouseExited
public void mouseExited(LwMouseEvent e)
- Description copied from interface:
LwMouseListener
- Invoked when the mouse exits a light weight component.
- Specified by:
mouseExited in interface LwMouseListener
- Following copied from interface:
org.zaval.lw.event.LwMouseListener
- Parameters:
e - the specified mouse event.
keyReleased
public void keyReleased(LwKeyEvent e)
- Description copied from interface:
LwKeyListener
- Invoked when a key has been released.
- Specified by:
keyReleased in interface LwKeyListener
- Following copied from interface:
org.zaval.lw.event.LwKeyListener
- Parameters:
e - the specified key event.
keyTyped
public void keyTyped(LwKeyEvent e)
- Description copied from interface:
LwKeyListener
- Invoked when a key has been typed.
- Specified by:
keyTyped in interface LwKeyListener
- Following copied from interface:
org.zaval.lw.event.LwKeyListener
- Parameters:
e - the specified key event.
keyPressed
public void keyPressed(LwKeyEvent e)
- Description copied from interface:
LwKeyListener
- Invoked when a key has been pressed.
- Specified by:
keyPressed in interface LwKeyListener
- Following copied from interface:
org.zaval.lw.event.LwKeyListener
- Parameters:
e - the specified key event.
childPerformed
public void childPerformed(LwVCLEvent e)
- Description copied from interface:
LwChildrenListener
- Invoked whenever the child event has been performed.
- Specified by:
childPerformed in interface LwChildrenListener
- Following copied from interface:
org.zaval.lw.event.LwChildrenListener
- Parameters:
e - the child event.
mousePressed
public void mousePressed(LwMouseEvent e)
- Description copied from interface:
LwMouseListener
- Invoked when the mouse button has been pressed on a light weight component.
- Specified by:
mousePressed in interface LwMouseListener
- Following copied from interface:
org.zaval.lw.event.LwMouseListener
- Parameters:
e - the specified mouse event.
toggle
public void toggle(Item item)
- Switches a toggle state for the specified tree item. If the toggle state
is "on" than the method switches it to "off" and the "off" state will be
switched to "on" state.
- Parameters:
item - the specified tree item.
select
public void select(Item item)
- Selects the specified node of the tree.
- Parameters:
item - the specified node.
getSelectedItem
public Item getSelectedItem()
- Gets the item that is selected at the moment.
- Returns:
- a selected item.
addActionListener
public void addActionListener(LwActionListener l)
- Adds the specified action listener to receive action events from this tree.
The event is generated whenever the tree node has been expanded or collapsed.
The tree item that has been expanded or collapsed can be got as the event data
argument.
- Parameters:
l - the specified action listener.
removeActionListener
public void removeActionListener(LwActionListener l)
- Removes the specified action listener.
- Parameters:
l - the specified action listener.
itemInserted
public void itemInserted(java.lang.Object target,
Item item)
- Description copied from interface:
TreeListener
- Invoked when the item has been inserted as a member of the source tree.
- Specified by:
itemInserted in interface TreeListener
- Following copied from interface:
org.zaval.data.event.TreeListener
- Parameters:
target - the specified tree model.item - the specified item that has been inserted into the tree model.
itemRemoved
public void itemRemoved(java.lang.Object target,
Item item)
- Description copied from interface:
TreeListener
- Invoked when the item has been removed from the source tree.
- Specified by:
itemRemoved in interface TreeListener
- Following copied from interface:
org.zaval.data.event.TreeListener
- Parameters:
target - the specified tree model.item - the specified item that has been removed from the tree model.
itemModified
public void itemModified(java.lang.Object target,
Item item)
- Description copied from interface:
TreeListener
- Invoked when source tree item has been modified.
- Specified by:
itemModified in interface TreeListener
- Following copied from interface:
org.zaval.data.event.TreeListener
- Parameters:
target - the specified tree model.item - the specified item that has been modified.
getItemAt
public Item getItemAt(int x,
int y)
- Looks up and returns an item that is placed at the specified location.
The method searches the item only inside the visible component area.
- Parameters:
x - the x coordinate.y - the y coordinate.- Returns:
- an item that is placed at the specified location of the visible area.
invalidate
public void invalidate()
- Description copied from interface:
Validationable
- Invalidates this object.
- Overrides:
invalidate in class LwPanel
isInvalidatedByChild
public boolean isInvalidatedByChild(LwComponent c)
- Description copied from interface:
LwContainer
- Invoked by a child component whenever the child invalidates itself. Usually a child component
invalidate its parent. The method provides ability to control container invalidation by the
specified child component. The child asks the container if it should be invalidated by the
calling the method.
- Overrides:
isInvalidatedByChild in class LwPanel
- Following copied from interface:
org.zaval.lw.LwContainer
- Parameters:
c - the child component that wants to invalidate the container.- Returns:
true if the container should be invalidated by the child component;
false otherwise.
getOrigin
public java.awt.Point getOrigin()
- Description copied from interface:
LwComponent
- Returns an origin of the component. The origin defines an offset of the component view
relatively the component point of origin. The method can be implemented to organize
scrolling of the component view.
- Overrides:
getOrigin in class LwCanvas
- Following copied from interface:
org.zaval.lw.LwComponent
- Returns:
- an origin of the component.
getSOLocation
public java.awt.Point getSOLocation()
- Description copied from interface:
ScrollObj
- Gets the scroll object location.
- Specified by:
getSOLocation in interface ScrollObj
- Following copied from interface:
org.zaval.misc.ScrollObj
- Returns:
- a scroll object location.
setSOLocation
public void setSOLocation(int x,
int y)
- Description copied from interface:
ScrollObj
- Sets the specified scroll object location. The method defines a mechanism that will be used to
scrool the object.
- Specified by:
setSOLocation in interface ScrollObj
- Following copied from interface:
org.zaval.misc.ScrollObj
- Parameters:
x - the specified x coordinate.y - the specified y coordinate.
repaint
public void repaint(boolean b)
- Description copied from interface:
LwComponent
- Invoked whenever the component got or lost the focus. The method is supposed to optimize
the performance of the focus marker, since in most cases it is not necessary to repaint
all component area. By default the method repaint all component area.
- Overrides:
repaint in class LwCanvas
- Following copied from interface:
org.zaval.lw.LwComponent
- Parameters:
b - true if the component has got the focus, and false
if the component lost the focus.
getSOSize
public java.awt.Dimension getSOSize()
- Description copied from interface:
ScrollObj
- Gets the scroll object size. The size is a size that the scroll object wants to have.
- Specified by:
getSOSize in interface ScrollObj
- Following copied from interface:
org.zaval.misc.ScrollObj
- Returns:
- a scroll object size.
setScrollMan
public void setScrollMan(ScrollMan m)
- Description copied from interface:
ScrollObj
- Sets the specified scroll manager for the scroll object. The manager reference should
be stored and used by the scrolled object to move itself inside the scrolled area.
- Specified by:
setScrollMan in interface ScrollObj
- Following copied from interface:
org.zaval.misc.ScrollObj
- Parameters:
m - the specified scroll manager.
moveContent
public boolean moveContent()
- Description copied from interface:
ScrollObj
- Tests if the scrolled component performs scrolling by changing its location or moving view.
- Specified by:
moveContent in interface ScrollObj
- Following copied from interface:
org.zaval.misc.ScrollObj
- Returns:
true if the scroll component organizes scrolling by moving
its view; otherwise false.
iItem
public void iItem(Item item)
- Invalidates a metric of the specified tree item.
- Parameters:
item - the specified tree item.
iItems
public void iItems()
- Invalidates a metric for all tree items.
isOpen
public boolean isOpen(Item i)
- Checks if the tree item is expanded. The item is expanded if it is expanded and
all parent items are expanded too.
- Parameters:
i - the specified tree item.- Returns:
true if the item and its parent item is expanded too;
false otherwise.
getItemMetrics
public ItemMetrics getItemMetrics(Item i)
- Gets the item metric for the specified item.
- Parameters:
i - the specified item.- Returns:
- an item metric.
calcPreferredSize
protected java.awt.Dimension calcPreferredSize()
- Description copied from class:
LwPanel
- Gets the "pure" preferred size for this component. The method has not be overridden,
because it determines the preferred size by the layout manager.
- Overrides:
calcPreferredSize in class LwPanel
- Following copied from class:
org.zaval.lw.LwPanel
- Returns:
- a "pure" preferred size.
laidout
protected void laidout()
- Description copied from class:
LwPanel
- Invoked whenever the container layouting procedure has been finished.
- Overrides:
laidout in class LwPanel
vVisibility
protected void vVisibility()
- Validates the tree component visibility.
recalc
protected void recalc()
- Description copied from class:
LwCanvas
- Invoked with
validate method only if the component is not valid.
The method should be overridden to calculate metrical characteristics of the component to
minimize computation time of the preferred size for the component. For example, you can
calculate a preferred size inside the method and just return it by
calcPreferredSize method.
- Overrides:
recalc in class LwCanvas
|