public class TreeView extends GadgetContainer implements CollapsibleGadget, Command, ElementView, ElementViewPart
GadgetContainer.Side
Modifier and Type | Field and Description |
---|---|
protected boolean |
collapsed |
Element |
element |
protected TreeViewSettings |
settings |
children, NO_GADGETS
Modifier | Constructor and Description |
---|---|
protected |
TreeView(Element element) |
|
TreeView(Element element,
TreeViewSettings settings) |
Modifier and Type | Method and Description |
---|---|
Gadget |
addChildViewGadgets(NodeView childView,
int viewIndex)
Attaches to the gadget tree the gadgets used to render specified child
view.
|
void |
detachingFromModel(Document document,
int viewIndex)
Invoked by DocumentView to notify this view just before it is no longer
used to graphically represent its node.
|
CommandResult |
executeCommand(Gadget gadget,
String parameter,
int x,
int y)
Actually executes this command with specified parameter and in
specified context.
|
Element |
getElement()
Returns the element which is represented graphically by this view.
|
ElementView |
getElementView()
Returns the view which is (at least partly) rendered by this gadget.
|
void |
getGadgets(GadgetList gadgets,
int viewIndex)
Returns all gadgets that are used to render the view.
|
Node |
getModel()
Returns the node which is represented graphically by this view.
|
int[] |
getNonBreakableVerticalRanges()
Called by
GadgetPrinter to know where page boundaries
cannot occur. |
TreeViewSettings |
getSettings() |
void |
getSizeConstraints(Gadget child,
Dimension constraints)
Invoked by a child gadget before layouting itself to know what are the
constraints for its width and height.
|
NodeView |
getView()
Returns the view which is (at least partly) rendered by this gadget.
|
boolean |
grabsMouseButton(MouseEvent e)
Invoked by EventDispatcher to know if this gadget has an action
triggered by mouse button+modifiers of specified mouse event.
|
void |
handleMouseEvent(MouseEvent e)
Invoked by EventDispatcher to request this gadget to handle specified
mouse event.
|
boolean |
isCollapsed()
Returns
true if this gadget is collapsed; returns
false otherwise. |
boolean |
isCollapsible()
Returns
true if this gadget can be collapsed; returns
false otherwise. |
boolean |
isTreeView()
Returns
true if this view is rendered as a tree;
false otherwise;
This method is needed to implement
styled view factories. |
boolean |
isTreeViewContainer()
Returns
true if this view can only contain child
tree views; false otherwise;
This method is needed to implement
styled view factories. |
void |
layout(int constrainedWidth,
int constrainedHeight,
boolean recursive)
Requests this gadget to relayout itself.
|
void |
paint(Graphics g)
Paint this gadget using specified Graphics object.
|
protected void |
paint(Graphics g,
Color backgroundColor) |
void |
paintRelayout(Gadget child,
int prevWidth,
int prevHeight,
GadgetContainer.Side damagedSide,
int damagedLength)
Invoked by a child gadget when its geometry (width, height, but also
for some gadgets baseline, reference point, etc) has changed.
|
boolean |
prepareCommand(Gadget gadget,
String parameter,
int x,
int y)
Tests whether this command can be executed with specified parameter
and in specified context.
|
void |
print(Graphics g)
Print this gadget using specified Graphics object.
|
Gadget |
removeChildViewGadgets(NodeView childView,
int viewIndex)
Detaches from the gadget tree the gadgets used to render specified
child view.
|
void |
setCollapsed(boolean collapsed)
Collapses/expands this gadget according to specified flag (if this
gadget is in a state different from the one specified by the flag).
|
addChild, findGadgetAt, getChild, getChildCount, getChildren, indexOfChild, indexOfChildAt, insertChild, isAncestorOf, paintRelayout, removeAllChildren, removeChild, removeChild, replaceChild, replaceChild
focusGained, focusLost, gadgetToPanel, gadgetToRoot, getAncestors, getBounds, getBounds, getCursor, getEventDispatcher, getFontMetrics, getGadgetPanel, getGraphics, getLocation, getLocation, getRoot, getSize, getSize, getToolkit, getToolTip, handleAppEvent, handleKeyEvent, hasFocus, isAppEventHandler, layout, makeRectangleVisible, makeRectangleVisible, panelToGadget, refresh, relayout, relayout, repaint, repaint, requestFocus
public final Element element
protected TreeViewSettings settings
protected boolean collapsed
public TreeView(Element element, TreeViewSettings settings)
protected TreeView(Element element)
public Node getModel()
NodeView
public void getGadgets(GadgetList gadgets, int viewIndex)
NodeView
For example, for elements displayed inline, it returns the gadgets that render the generated content for this inline (if any) plus all the gadgets that render the child views.
Only topmost gadgets needs to be returned by this method, that is, descendant gadgets of gadgets used to render this view need not be returned.
getGadgets
in interface NodeView
gadgets
- this method appends gadgets to this list to return its
resultviewIndex
- view index of the DocumentView ancestor of this viewpublic void detachingFromModel(Document document, int viewIndex)
NodeView
Implemented by views that need to perform some sort of cleanup.
detachingFromModel
in interface NodeView
document
- document being represented by the DocumentView invoking
this methodviewIndex
- view index of the DocumentView invoking this methodpublic Element getElement()
ElementView
getElement
in interface ElementView
public Gadget addChildViewGadgets(NodeView childView, int viewIndex)
ElementView
addChildViewGadgets
in interface ElementView
childView
- child view for which gadgets are to be addedviewIndex
- view index of the DocumentView ancestor of this viewpublic Gadget removeChildViewGadgets(NodeView childView, int viewIndex)
ElementView
removeChildViewGadgets
in interface ElementView
childView
- child view for which gadgets are to be addedviewIndex
- view index of the DocumentView ancestor of this viewpublic boolean isTreeView()
ElementView
true
if this view is rendered as a tree;
false
otherwise;
This method is needed to implement styled view factories.
isTreeView
in interface ElementView
ElementView.isTreeViewContainer()
public boolean isTreeViewContainer()
ElementView
true
if this view can only contain child
tree views; false
otherwise;
This method is needed to implement styled view factories.
isTreeViewContainer
in interface ElementView
ElementView.isTreeView()
public NodeView getView()
NodeViewPart
getView
in interface NodeViewPart
public ElementView getElementView()
ElementViewPart
getElementView
in interface ElementViewPart
NodeViewPart.getView()
public TreeViewSettings getSettings()
public boolean isCollapsible()
CollapsibleGadget
true
if this gadget can be collapsed; returns
false
otherwise.isCollapsible
in interface CollapsibleGadget
public void setCollapsed(boolean collapsed)
CollapsibleGadget
setCollapsed
in interface CollapsibleGadget
Gadget.refresh()
public boolean isCollapsed()
CollapsibleGadget
true
if this gadget is collapsed; returns
false
otherwise.isCollapsed
in interface CollapsibleGadget
public void getSizeConstraints(Gadget child, Dimension constraints)
GadgetContainer
getSizeConstraints
in class GadgetContainer
child
- the child that invoked this methodconstraints
- this Dimension object is updated to reflect the
contraints on the child size. A negative or null width or height means
not constrained.public void layout(int constrainedWidth, int constrainedHeight, boolean recursive)
Gadget
This gadget responds by recomputing and updating its width and height.
layout
in class Gadget
constrainedWidth
- A stretchable gadget might be able to adapt its
size to this constrained width. A negative or null value means not
constrained.constrainedHeight
- A stretchable gadget might be able to adapt
its size to this constrained height. A negative or null value means not
constrained.recursive
- If true, recursively layout children too.public void paintRelayout(Gadget child, int prevWidth, int prevHeight, GadgetContainer.Side damagedSide, int damagedLength)
GadgetContainer
This parent gadget must at least respond by repainting its child but generally this parent gadget has to ``refresh'' itself.
This default implementation is a kind of light-weight Gadget.refresh()
where the relayout is not recursive. It should be redefined
by a faster, more container specific, version.
This default implementation assumes that if, after the relayout, this container has not changed its width and height, a repaint is sufficient and its own parent doesn't need to be notified.
paintRelayout
in class GadgetContainer
child
- the child that invoked this methodprevWidth
- child width before the relayoutprevHeight
- child height before the relayoutdamagedSide
- the side, if any, that was expanded or shrinkeddamagedLength
- If damagedSide is GadgetContainer.Side.TOP
, it is
sufficient to repaint (0, 0, width, damagedLength).
If damagedSide is GadgetContainer.Side.BOTTOM
, it is sufficient to repaint
(0, height-damagedLength, width, damagedLength).
If damagedSide is GadgetContainer.Side.LEFT
, it is sufficient to repaint
(0, 0, damagedLength, height).
If damagedSide is GadgetContainer.Side.RIGHT
, it is sufficient to repaint
(width-damagedLength, 0, damagedLength, height).
If damagedSide is GadgetContainer.Side.NONE
, (damagedLength is meaningless)
repaint the whole child.
public void paint(Graphics g)
Gadget
One cannot assume that any of the attributes of the Graphics object (background, foreground, font, etc) is properly set.
paint
in class GadgetContainer
public void print(Graphics g)
Gadget
One cannot assume that any of the attributes of the Graphics object (background, foreground, font, etc) is properly set.
print
in class GadgetContainer
public int[] getNonBreakableVerticalRanges()
GadgetContainer
GadgetPrinter
to know where page boundaries
cannot occur.
This implementation returns null
which specifies that a
page break can occur anywhere inside this container.
getNonBreakableVerticalRanges
in class GadgetContainer
null
to specify that
a page break can occur anywhere.public boolean grabsMouseButton(MouseEvent e)
Gadget
The type of mouse event (CLICKED, PRESSED, DRAGGED, etc) is not
relevant here. If a gadget ``grabs'' Shift+mouse button 1, it will
receive all the following mouse events: PRESSED, DRAGGED,
RELEASED, CLICKED, etc, through Gadget.handleMouseEvent(java.awt.event.MouseEvent)
.
grabsMouseButton
in class Gadget
public void handleMouseEvent(MouseEvent e)
Gadget
handleMouseEvent
in class Gadget
public boolean prepareCommand(Gadget gadget, String parameter, int x, int y)
Command
If the command can be executed, this method returns
true
after having configured its internal state for
consumption by method Command.executeCommand(com.xmlmind.xmledit.gadget.Gadget, java.lang.String, int, int)
which should be invoked
immediately after this one.
Returns false
if this command cannot be executed with
specified parameter and in specified context.
prepareCommand
in interface Command
gadget
- the target of this commandparameter
- parameterizes the command (that is, modifies the
behavior of the command in a command specific way)x
- X position relative to gadget of the mouse event
having triggered this command; -1 if this command was triggered by a
keyboard inputy
- Y position relative to gadget of the mouse event
having triggered this command; -1 if this command was triggered by a
keyboard inputpublic CommandResult executeCommand(Gadget gadget, String parameter, int x, int y)
Command
This method assumes that Command.prepareCommand(com.xmlmind.xmledit.gadget.Gadget, java.lang.String, int, int)
has been
successfully invoked immediately before its own invocation.
executeCommand
in interface Command
gadget
- the target of this commandparameter
- parameterizes the command (that is, modifies the
behavior of the command in a command specific way)x
- X position relative to gadget of the mouse event
having triggered this command; -1 if this command was triggered by a
keyboard inputy
- Y position relative to gadget of the mouse event
having triggered this command; -1 if this command was triggered by a
keyboard inputnull