|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--adavid.awt.TNode
TNode : Tree Node I create my own tree component because Java copies the nodes without telling me when, and it copies the content of the nodes as well, so when my other components refer to these nodes, well, they are not valid because they have been replaced by new ones! Imagine the time I've lost to understand where the problem came from, and then to implement my own tree!!! This is my second version of tree: it is 100% swing free, only pure java awt, which is much much faster than swing. A node listens to its own events to expand/collapse or send an event to a listener ; to use the serialization the user has to be sure that the content object, the TListener objects and the TNodeRenderer objects are serializable as well!!!!!
Field Summary | |
static java.awt.Color |
DEFAULT_COLOR
|
static java.awt.Color |
DEFAULT_SELECTED_COLOR
default color settings: the background when selected and the default color for the renderer |
static int |
step
step used to enlarge the array of leaves/children when adding a node useful when dealing with big trees to reduce memory allocation |
Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT,
CENTER_ALIGNMENT,
LEFT_ALIGNMENT,
RIGHT_ALIGNMENT,
TOP_ALIGNMENT |
Constructor Summary | |
TNode(java.lang.Object object)
contructor : take the content ; if it is a component, it will display itself, otherwise a label will be created with its toString() the DefaultTNodeRenderer is used |
|
TNode(java.lang.Object object,
java.awt.Component item)
another constructor |
|
TNode(java.lang.Object object,
TNodeRenderer renderer)
constructor : same as previously with a customized renderer |
|
TNode(java.lang.Object object,
TNodeRenderer renderer,
java.awt.Component item)
real constructor : takes the content (object), the renderer and a component to display the content ; the component should be able to update itself when its background changes. |
Method Summary | |
void |
add(java.awt.PopupMenu pmenu)
add/set the popup menu |
void |
addNode(TNode node)
add a new node to this tree ; bad things may happen if one adds twice the same node |
void |
addTListener(TListener listener)
add a TNode listener |
void |
collapse()
collapse this node |
void |
delete()
delete this node ; works only if this is not the root ; delegate the call to its parent |
void |
expand()
expand this node ; and all the path to this node to make it visible |
void |
expandAll()
expand all children and invalidate |
java.awt.Color |
getColor()
returns the color used for the renderer ; the Graphics object has a g.setColor(..) just before the call to the renderer |
java.awt.Color |
getColorSelected()
returns the color used for background selection |
java.awt.Component |
getComponent()
returns the component of the TNode |
java.lang.Object |
getContent()
returns the content of the node ; the content is immutable |
boolean |
getOpenOnDoubleClick()
|
TNode |
getParentNode()
returns the parent node |
java.awt.Dimension |
getPreferredSize()
returns the preferred size of this node ; this does the computation of the size when not valid and does the layout as well |
TNode |
getRootNode()
returns the root node of this node |
java.lang.String |
getStringLabel()
return the string of the ?label |
java.lang.Object[] |
getSubContents()
returns the content of all sub nodes |
TNode |
getSubNode(int index)
returns one sub node null if invalid |
TNode[] |
getSubNodes()
returns all the sub nodes |
void |
invalidateNode()
invalidates itself and revalidates itself ; should be called after some addNode in order to update the layout |
static void |
invalidateNode(TNode node)
invalidate the node given in arguments if one node is not valid, then all its parents are not valid, so we do not need to propagate when we find one !valid, thus the test in the loop |
boolean |
isExpanded()
returns the expansion state |
boolean |
isMutable()
returns true if the node is mutable |
void |
keyPressed(java.awt.event.KeyEvent e)
|
void |
keyReleased(java.awt.event.KeyEvent e)
|
void |
keyTyped(java.awt.event.KeyEvent e)
same as before ; we call the nodeClicked method as if it were a click when one presses the space bar ; the return key just toggles the node |
void |
mouseClicked(java.awt.event.MouseEvent e)
mouse listener ; delegate the call to the listeners after processing (expand/collapse) |
void |
mouseEntered(java.awt.event.MouseEvent e)
|
void |
mouseExited(java.awt.event.MouseEvent e)
|
void |
mousePressed(java.awt.event.MouseEvent e)
|
void |
mouseReleased(java.awt.event.MouseEvent e)
unused methods of listeners I prefer to use this method instead of using the "empty" listener provided by Sun, which we should extend, imagine, you download two classes just for a simple listener, and you have to pass arguments to have access to what you want. |
void |
paint(java.awt.Graphics g)
the paint method: delegate the call to the renderer the component is called by the super method |
void |
remove(java.awt.MenuComponent mc)
remove the popup menu |
void |
removeAllNodes()
remove all nodes |
void |
removeNode(TNode node)
removes a node ; local management of memory as in Vector |
void |
removeTListener(TListener listener)
remove a TNode listener |
void |
repaint(long tm,
int x,
int y,
int width,
int height)
this is to clean the component before repainting it |
void |
select()
selects this node ; unselect the selected one and selects itself see unselect for the repaint |
void |
setColor(java.awt.Color color)
change the color for the renderer |
void |
setColorSelected(java.awt.Color color)
change the color for the background selection |
void |
setFont(java.awt.Font font)
change the font : resend this to the component which represents the content of this node |
void |
setMutable(boolean flag)
sets the mutable flag: mutable is inherited |
void |
setOpenOnDoubleClick(boolean flag)
customize the double click->open/close |
void |
setRenderer(TNodeRenderer renderer)
change the renderer ; test if it is not null |
void |
setScrollPane(java.awt.ScrollPane pane)
set the scroll pane (useful for the root only) |
void |
toggle()
toggle between collapse/expand and repaint |
java.lang.String |
toString()
string representation of this node |
void |
unselect()
unselects itself : repaints itself ; the component which represents this node should be able to repaint itself on its own after the setBackground call |
Methods inherited from class java.awt.Container |
add,
add,
add,
add,
add,
addContainerListener,
addImpl,
addNotify,
countComponents,
deliverEvent,
doLayout,
findComponentAt,
findComponentAt,
getAlignmentX,
getAlignmentY,
getComponent,
getComponentAt,
getComponentAt,
getComponentCount,
getComponents,
getInsets,
getLayout,
getMaximumSize,
getMinimumSize,
insets,
invalidate,
isAncestorOf,
layout,
list,
list,
locate,
minimumSize,
paintComponents,
paramString,
preferredSize,
print,
printComponents,
processContainerEvent,
processEvent,
remove,
remove,
removeAll,
removeContainerListener,
removeNotify,
setCursor,
setLayout,
update,
validate,
validateTree |
Methods inherited from class java.awt.Component |
action,
addComponentListener,
addFocusListener,
addInputMethodListener,
addKeyListener,
addMouseListener,
addMouseMotionListener,
addPropertyChangeListener,
addPropertyChangeListener,
bounds,
checkImage,
checkImage,
coalesceEvents,
contains,
contains,
createImage,
createImage,
disable,
disableEvents,
dispatchEvent,
enable,
enable,
enableEvents,
enableInputMethods,
firePropertyChange,
getBackground,
getBounds,
getBounds,
getColorModel,
getComponentOrientation,
getCursor,
getDropTarget,
getFont,
getFontMetrics,
getForeground,
getGraphics,
getHeight,
getInputContext,
getInputMethodRequests,
getLocale,
getLocation,
getLocation,
getLocationOnScreen,
getName,
getParent,
getPeer,
getSize,
getSize,
getToolkit,
getTreeLock,
getWidth,
getX,
getY,
gotFocus,
handleEvent,
hasFocus,
hide,
imageUpdate,
inside,
isDisplayable,
isDoubleBuffered,
isEnabled,
isFocusTraversable,
isLightweight,
isOpaque,
isShowing,
isValid,
isVisible,
keyDown,
keyUp,
list,
list,
list,
location,
lostFocus,
mouseDown,
mouseDrag,
mouseEnter,
mouseExit,
mouseMove,
mouseUp,
move,
nextFocus,
paintAll,
postEvent,
prepareImage,
prepareImage,
printAll,
processComponentEvent,
processFocusEvent,
processInputMethodEvent,
processKeyEvent,
processMouseEvent,
processMouseMotionEvent,
removeComponentListener,
removeFocusListener,
removeInputMethodListener,
removeKeyListener,
removeMouseListener,
removeMouseMotionListener,
removePropertyChangeListener,
removePropertyChangeListener,
repaint,
repaint,
repaint,
requestFocus,
reshape,
resize,
resize,
setBackground,
setBounds,
setBounds,
setComponentOrientation,
setDropTarget,
setEnabled,
setForeground,
setLocale,
setLocation,
setLocation,
setName,
setSize,
setSize,
setVisible,
show,
show,
size,
transferFocus |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
public static final java.awt.Color DEFAULT_SELECTED_COLOR
public static final java.awt.Color DEFAULT_COLOR
public static int step
Constructor Detail |
public TNode(java.lang.Object object)
public TNode(java.lang.Object object, TNodeRenderer renderer)
public TNode(java.lang.Object object, java.awt.Component item)
public TNode(java.lang.Object object, TNodeRenderer renderer, java.awt.Component item)
Method Detail |
public java.lang.Object getContent()
public void setMutable(boolean flag)
public boolean isMutable()
public java.awt.Component getComponent()
public void setOpenOnDoubleClick(boolean flag)
public boolean getOpenOnDoubleClick()
public void add(java.awt.PopupMenu pmenu)
public void remove(java.awt.MenuComponent mc)
public void setFont(java.awt.Font font)
public void setRenderer(TNodeRenderer renderer)
public java.awt.Color getColorSelected()
public java.awt.Color getColor()
public void setColor(java.awt.Color color)
public void setColorSelected(java.awt.Color color)
public void setScrollPane(java.awt.ScrollPane pane)
public void delete()
public TNode getParentNode()
public boolean isExpanded()
public TNode[] getSubNodes()
public TNode getSubNode(int index)
public java.lang.String getStringLabel()
public java.lang.Object[] getSubContents()
public void addNode(TNode node)
public static void invalidateNode(TNode node)
public void invalidateNode()
public void removeNode(TNode node)
public void removeAllNodes()
public void expand()
public void expandAll()
public void collapse()
public java.lang.String toString()
public java.awt.Dimension getPreferredSize()
public void paint(java.awt.Graphics g)
public void repaint(long tm, int x, int y, int width, int height)
public void addTListener(TListener listener)
public void removeTListener(TListener listener)
public void unselect()
public TNode getRootNode()
public void select()
public void toggle()
public void mouseClicked(java.awt.event.MouseEvent e)
public void mousePressed(java.awt.event.MouseEvent e)
public void keyTyped(java.awt.event.KeyEvent e)
public void mouseReleased(java.awt.event.MouseEvent e)
public void mouseEntered(java.awt.event.MouseEvent e)
public void mouseExited(java.awt.event.MouseEvent e)
public void keyPressed(java.awt.event.KeyEvent e)
public void keyReleased(java.awt.event.KeyEvent e)
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |