public class Tree extends Container implements PressListener, PenListener, KeyListener, Scrollable
TreeModel tmodel = new TreeModel(); Tree tree = new Tree(tmodel); add(tree,LEFT,TOP,FILL,FILL); Node root = new Node("Tree"); tmodel.setRoot(root); Node n; root.add(n = new Node("Branch1")); n.add(new Node("SubBranch1")); n.add(new Node("SubBranch2"));You can also see the FileChooserBox control and FileChooserTest (in UIGadgets sample).
Node.userObject
Control.TranslucentShape
Modifier and Type | Field and Description |
---|---|
protected int |
btnX |
boolean |
expandClickingOnText
Set to false to only expand or collapse if you click on the +- buttons.
|
protected Flick |
flick
The Flick object listens and performs flick animations on PenUp events when appropriate.
|
protected ScrollBar |
hbar |
protected int |
hsCount |
protected int |
hsOffset |
static int |
ICON_CLOSE |
static int |
ICON_FILE |
static int |
ICON_MINUS |
static int |
ICON_OPEN |
static int |
ICON_PLUS |
protected Image |
imgClose |
protected Image |
imgFile |
protected Image |
imgMinus |
protected Image |
imgOpen |
protected Image |
imgPlus |
protected int |
itemCount |
protected Vector |
items |
int |
lineH
Deprecated.
Use setLineHeight and getLineHeight
|
protected TreeModel |
model |
boolean |
multipleSelection
Set to true to allow multiple selections using a Check drawn before the nodes.
|
protected int |
offset |
static int |
SCROLLBAR_ALWAYS |
static int |
SCROLLBAR_AS_NEEDED |
static int |
SCROLLBAR_NEVER |
protected int |
selectedIndex |
boolean |
useFullWidthOnSelection
If true, all Tree will have the selection bar drawn in
the full width instead of the selected's text width
|
protected ScrollBar |
vbar |
protected int |
visibleItems |
alwaysEraseBackground, BACKGROUND_CYLINDRIC_SHADED, BACKGROUND_SHADED, BACKGROUND_SHADED_INV, BACKGROUND_SOLID, backgroundStyle, BORDER_LOWERED, BORDER_NONE, BORDER_RAISED, BORDER_ROUNDED, BORDER_SIMPLE, BORDER_TOP, borderColor, borderRadius, children, controlFound, finishedStart, ignoreOnAddAgain, ignoreOnRemove, insets, lastScreenWidth, lastW, lastX, lastY, numChildren, started, tabOrder, tail, TRANSITION_TIME
AFTER, alphaValue, appId, appObj, asContainer, asWindow, backColor, BEFORE, BOTTOM, BOTTOM_OF, BRIGHTER_BACKGROUND, callListenersOnAllTargets, CENTER, CENTER_OF, clearValueInt, clearValueStr, DARKER_BACKGROUND, DP, effect, enableUpdateScreen, esce, eventsEnabled, FILL, fillColor, FIT, floating, fm, fmH, focusHandler, focusLess, focusOnPenDown, focusTraversable, font, FONTSIZE, foreColor, height, ignoreInsets, isHighlighting, isTablet, KEEP, keepDisabled, keepEnabled, LEFT, next, nextTabControl, npParts, offscreen, offscreen0, onEventFirst, parent, PARENTSIZE, PARENTSIZEMAX, PARENTSIZEMIN, PREFERRED, prev, RANGE, repositionAllowed, RIGHT, RIGHT_OF, SAME, SCREENSIZE, SCREENSIZEMAX, SCREENSIZEMIN, setFont, setH, setRel, setW, setX, SETX_NOT_SET, setY, tempW, textShadowColor, TOP, translucentShape, transparentBackground, uiAdjustmentsBasedOnFontHeightIsSupported, uiAndroid, UICONST, uiFlat, uiHolo, uiMaterial, uiVista, visible, width, WILL_RESIZE, x, y
Constructor and Description |
---|
Tree()
Constructs a new Tree based on an empty TreeModel.
|
Tree(TreeModel model)
Constructs a new Tree based on the given parameters.
|
Tree(TreeModel model,
boolean showRoot)
Constructs a new Tree based on the given parameters.
|
Modifier and Type | Method and Description |
---|---|
void |
actionkeyPressed(KeyEvent e)
An ACTION_KEY_PRESS event was dispatched.
|
void |
add(Control control)
Do nothing.
|
boolean |
canScrollContent(int direction,
java.lang.Object target)
Checks if there is room to flick this container in the given direction.
|
void |
checkClicked(int sel) |
void |
clear()
Same as removeAll() method.
|
boolean |
collapse(Node node)
Method to collapse an expanded node.
|
void |
controlPressed(ControlEvent e)
A PRESSED event was dispatched.
|
void |
dontShowFileAndFolderIcons()
Call this method to hide the file and folder icons.
|
protected void |
drawConnector(Graphics g,
int index,
int dx,
int dy,
Node node)
Method to draw the (line connector) angled line.
|
protected void |
drawCursor(Graphics g,
int sel)
Method to draw the highlight box when user select a listbox's item.
|
protected void |
drawFileImage(Graphics g,
Node node,
int x,
int y)
Allows the draw of customized file images.
|
protected void |
drawNode(Graphics g,
int index,
int dx,
int dy)
Method to draw the icons and node text
|
boolean |
expand(Node node)
Method to expand a collapsed node.
|
void |
expandTo(java.lang.String filePath)
Expands all nodes until the given path is reached
|
protected void |
find(char c)
Method to search this Tree for an item with the first letter matching the given char.
|
void |
flickEnded(boolean atPenDown)
Called when the flick animation is ended.
|
boolean |
flickStarted()
Called when the flick animation is started.
|
Flick |
getFlick()
Returns the current flick object.
|
void |
getFocusableControls(Vector v)
Get a list of child controls of this container which are focus candidates
|
java.lang.Object |
getItemAt(int i)
Method to get the Object at the given Index.
|
java.lang.Object[] |
getItems()
Method to return all items in the items vector as an array of object.
|
protected int |
getItemWidth(int index)
Method to return the width of the given item index with the current fontmetrics.
|
int |
getLineHeight() |
int |
getPreferredHeight()
Method to return the number of items multiplied by the font metrics height
|
int |
getPreferredWidth()
Method to return the preferred width, ie, size of the largest item plus 20.
|
int |
getScrollPosition(int direction)
Returns the current position given the direction.
|
int |
getSelectedIndex()
Method to return the position of the selected item of the Tree or -1 if the Tree has no selected index yet.
|
Node |
getSelectedItem()
Method to return the selected item of the Tree or an empty String if no selection has been made.
|
Control |
handleGeographicalFocusChangeKeys(KeyEvent ke)
Used by the main event loop to give the currently focused control an opportunity to act directly on
the KeyEvent.
|
int |
indexOf(java.lang.Object name)
Method to return the index of the item specified by the name, or -1 if not found.
|
protected void |
initImage()
Method to load icons use for the tree.
|
protected void |
initScrollBars()
Method to initialize the vertical and horizontal scrollbars maximum.
|
void |
initTree(Node root)
Method to set the tree root node with the new root node.
|
void |
keyPressed(KeyEvent e)
A KEY_PRESS event was dispatched.
|
void |
nodeInserted(Node parent,
Node child,
int index)
Method to notify the tree that a node has been added to the tree model
and to repaint the tree to reflect the changes.
|
void |
nodeModified(Node node)
Method to notify the tree that a node in the tree model has been modified (currently - only changing the user
object)
|
void |
nodeRemoved(Node node)
Method to notify the tree that a node has been removed from the tree model and to repaint the tree to reflect the
changes, if necessary
|
protected void |
onBoundsChanged(boolean screenChanged)
Method to recalculate the box size for the selected item if the control is resized by the main application .
|
protected void |
onColorsChanged(boolean colorsChanged)
Called after a setEnabled, setForeColor and setBackColor and when a control has
been added to a Container.
|
void |
onFontChanged()
Called after a setFont
|
void |
onPaint(Graphics g)
Draws the border (if any).
|
void |
penDown(PenEvent pe)
A PEN_DOWN event was dispatched.
|
void |
penDrag(DragEvent de)
A PEN_DRAG event was dispatched.
|
void |
penDragEnd(DragEvent e)
A PEN_DRAG_END event was dispatched.
|
void |
penDragStart(DragEvent e)
A PEN_DRAG_START event was dispatched.
|
void |
penUp(PenEvent pe)
A PEN_UP event was dispatched.
|
void |
reload()
Method to reload the tree.
|
void |
remove(Control control)
Do nothing.
|
void |
remove(int index)
Method to remove the given index from the Tree items vector.
|
void |
remove(java.lang.Object item)
Method to remove an Object from the Tree's items vector.
|
void |
removeAll()
Method to empties this Tree, setting all elements of the array to null, so they can be garbage collected.
|
boolean |
scrollContent(int dx,
int dy,
boolean fromFlick)
Performs a relative move.
|
void |
setBackColor(int c)
Set the background color of this control.
|
void |
setCursorColor(int color)
Method to set the cursor color for this Tree.
|
void |
setEnabled(boolean enabled)
Method to enable this control if the specified enabled flag is true.
|
void |
setIcon(int iconType,
Image img)
Method to set the icon of the tree based on the icon type.
|
void |
setItemAt(int i,
java.lang.Object s)
Method to set the Object at the given Index, starting from 0.
|
void |
setLineHeight(int k)
Default line height.
|
void |
setModel(TreeModel model)
Method to set the tree model.
|
void |
setScrollBarPolicy(int horiz,
int vert)
Method to set the scrollbar appearance.
|
void |
setSelectedIndex(int i)
Method to select the given index and scroll to it if necessary.
|
void |
setSelectedItem(java.lang.Object name)
Method to select the given name.
|
int |
size()
Returns the number of items (Nodes)
|
void |
specialkeyPressed(KeyEvent e)
A SPECIAL_KEY_PRESS event was dispatched.
|
void |
unload()
Method to clear the tree and release the tree model references.
|
boolean |
wasScrolled()
Returns true if the control was scrolled since last pen down
|
add, add, add, add, broadcastEvent, fillBackground, findChild, findNearestChild, findNextFocusControl, getBorderRadius, getBorderStyle, getChildren, getChildrenCount, getClientRect, getClientRect, getFirstChild, getInsets, incLastX, incLastY, initUI, isPressed, moveFocusToNextControl, moveFocusToNextEditable, onAddAgain, onRemove, onSwapFinished, paintChildren, resize, resizeHeight, resizeWidth, setBorderRadius, setBorderStyle, setFocusTraversable, setHighlighting, setInsets, setPressColor, setPressed, swapToTopmostWindow
_onEvent, addEnabledStateListener, addFocusListener, addFontChangeHandler, addGridListener, addHandler, addHighlightListener, addKeyListener, addListContainerListener, addMouseListener, addMultiTouchListener, addPenListener, addPressListener, addPushNotificationListener, addSizeChangeHandler, addTimer, addTimer, addTimerListener, addValueChangeHandler, addWindowListener, bringToFront, changeHighlighted, contains, drawTranslucentBackground, getAbsoluteRect, getBackColor, getDoEffect, getEffectH, getEffectW, getEffectX, getEffectY, getEventListeners, getFont, getForeColor, getGap, getGraphics, getHeight, getNext, getParent, getParentWindow, getPos, getPressedEvent, getPrev, getRect, getSize, getTextShadowColor, getWidth, getX, getX2, getY, getY2, hadParentScrolled, hasFocus, internalSetEnabled, intXYWH, isActionEvent, isChildOf, isDisplayed, isEnabled, isFloating, isInsideOrNear, isObscured, isTopMost, isVisible, isVisibleAndInside, onEvent, onWindowPaintFinished, post, postEvent, postPressedEvent, releaseScreenShot, removeEnabledStateListener, removeFocusListener, removeGridListener, removeHandler, removeHighlightListener, removeKeyListener, removeListContainerListener, removeMouseListener, removeMultiTouchListener, removePenListener, removePressListener, removePushNotificationListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, reposition, reposition, repositionChildren, requestFocus, resetSetPositions, resetStyle, safeRepaintNow, safeUpdateScreen, sendToBack, setBackForeColors, setDoEffect, setFloating, setFocusLess, setFont, setForeColor, setNinePatch, setNinePatch, setRect, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary, willOpenKeyboard
public static final int SCROLLBAR_ALWAYS
public static final int SCROLLBAR_AS_NEEDED
public static final int SCROLLBAR_NEVER
public static final int ICON_PLUS
public static final int ICON_MINUS
public static final int ICON_OPEN
public static final int ICON_CLOSE
public static final int ICON_FILE
public boolean multipleSelection
public boolean expandClickingOnText
public boolean useFullWidthOnSelection
protected Flick flick
protected Image imgPlus
protected Image imgMinus
protected Image imgOpen
protected Image imgClose
protected Image imgFile
protected ScrollBar vbar
protected ScrollBar hbar
protected TreeModel model
protected Vector items
protected int offset
protected int hsOffset
protected int selectedIndex
protected int itemCount
protected int hsCount
protected int visibleItems
protected int btnX
@Deprecated public int lineH
public Tree()
public Tree(TreeModel model)
model
- the TreeModel to be usedpublic Tree(TreeModel model, boolean showRoot)
model
- the TreeModel to be usedshowRoot
- if true, the root node is shownpublic void setLineHeight(int k)
public int getLineHeight()
public boolean flickStarted()
Scrollable
flickStarted
in interface Scrollable
public void flickEnded(boolean atPenDown)
Scrollable
flickEnded
in interface Scrollable
atPenDown
- Flag indicating if the animation ended due to a pendown event.public boolean canScrollContent(int direction, java.lang.Object target)
Scrollable
canScrollContent
in interface Scrollable
direction
- The direction we want to flick given by one of the following constants:target
- The target of the series of PEN events that triggered this flick attempt.public boolean scrollContent(int dx, int dy, boolean fromFlick)
Scrollable
scrollContent
in interface Scrollable
dx
- The relative amount of pixels to move in the X axis.dy
- The relative amount of pixels to move in the Y axis.public int getScrollPosition(int direction)
Scrollable
getScrollPosition
in interface Scrollable
public Flick getFlick()
Scrollable
getFlick
in interface Scrollable
public boolean wasScrolled()
Scrollable
wasScrolled
in interface Scrollable
public void dontShowFileAndFolderIcons()
public void setModel(TreeModel model)
model
- the tree model.public void setScrollBarPolicy(int horiz, int vert)
SCROLLBAR_ALWAYS
,
SCROLLBAR_AS_NEEDED
,
SCROLLBAR_NEVER
public void initTree(Node root)
root
- the new tree root node.public void onFontChanged()
Control
onFontChanged
in class Control
protected void initScrollBars()
protected void initImage()
public void setIcon(int iconType, Image img) throws ImageException
iconType
- one of the ICON_xxx constants.img
- The image to be used.ImageException
ICON_PLUS
,
ICON_MINUS
,
ICON_OPEN
,
ICON_CLOSE
,
ICON_FILE
protected int getItemWidth(int index)
public void removeAll()
public void clear()
public void remove(int index)
index
- the item index in the items vector.public void remove(java.lang.Object item)
item
- the Node to delete from the tree's item vector.public boolean expand(Node node)
node
- the collapse node to expand.public void expandTo(java.lang.String filePath)
public boolean collapse(Node node)
node
- the expanded node to collapse.public void setItemAt(int i, java.lang.Object s)
i
- the indexs
- the object to set.public java.lang.Object getItemAt(int i)
i
- the index.public Node getSelectedItem()
public int getSelectedIndex()
public java.lang.Object[] getItems()
public int indexOf(java.lang.Object name)
name
- the object to find.public void setSelectedItem(java.lang.Object name)
name
- the object to select.public void setSelectedIndex(int i)
i
- the index of the item.public int size()
public int getPreferredWidth()
getPreferredWidth
in class Control
public int getPreferredHeight()
getPreferredHeight
in class Control
protected void find(char c)
public void setEnabled(boolean enabled)
setEnabled
in class Container
public void setBackColor(int c)
Control
setBackColor
in class Control
protected void onColorsChanged(boolean colorsChanged)
Control
onColorsChanged
in class Container
protected void onBoundsChanged(boolean screenChanged)
onBoundsChanged
in class Control
screenChanged
- If the bounds were changed due to a screen change (rotation, collapse)public void nodeRemoved(Node node)
node
- the node that has been removed from the tree modelpublic void nodeInserted(Node parent, Node child, int index)
parent
- the parent node of the new added nodechild
- the new ly added nodeindex
- the index of the new nodepublic void nodeModified(Node node)
node
- the node that has been modifiedpublic void penDrag(DragEvent de)
PenListener
penDrag
in interface PenListener
PenEvent
public void penDragEnd(DragEvent e)
PenListener
penDragEnd
in interface PenListener
PenEvent
public void penDragStart(DragEvent e)
PenListener
penDragStart
in interface PenListener
PenEvent
public void penDown(PenEvent pe)
PenListener
penDown
in interface PenListener
PenEvent
public void penUp(PenEvent pe)
PenListener
penUp
in interface PenListener
PenEvent
public void checkClicked(int sel)
public void controlPressed(ControlEvent e)
PressListener
controlPressed
in interface PressListener
ControlEvent
public void actionkeyPressed(KeyEvent e)
KeyListener
actionkeyPressed
in interface KeyListener
KeyEvent
public void keyPressed(KeyEvent e)
KeyListener
keyPressed
in interface KeyListener
KeyEvent
public void specialkeyPressed(KeyEvent e)
KeyListener
specialkeyPressed
in interface KeyListener
KeyEvent
public Control handleGeographicalFocusChangeKeys(KeyEvent ke)
Control
handleGeographicalFocusChangeKeys
in class Control
ke
- The KeyEvent to be processedSettings.geographicalFocus
public void onPaint(Graphics g)
Container
super.onPaint(g);
, or the border will not be drawn.protected void drawNode(Graphics g, int index, int dx, int dy)
protected void drawFileImage(Graphics g, Node node, int x, int y)
protected void drawConnector(Graphics g, int index, int dx, int dy, Node node)
protected void drawCursor(Graphics g, int sel)
public void setCursorColor(int color)
public void reload()
public void unload()
public void getFocusableControls(Vector v)
Container
getFocusableControls
in class Container
v
- A vector into which to add the focus candidates.