1 /**********************************************************************
2 * Copyright (c) 2005, 2008 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
11 * IBM - Initial API and implementation
12 * Bernd Hufmann - Updated for TMF
13 **********************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
;
16 import java
.util
.ArrayList
;
17 import java
.util
.Arrays
;
18 import java
.util
.Comparator
;
19 import java
.util
.HashMap
;
20 import java
.util
.Iterator
;
21 import java
.util
.List
;
24 import org
.eclipse
.linuxtools
.internal
.tmf
.ui
.TmfUiTracer
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.IGC
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.preferences
.ISDPreferences
;
29 * The base class used for all UML2 graph nodes displayed in the Sequence Diagram SDWidget.
34 public abstract class GraphNode
{
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
40 * The start event occurrence.
42 protected int fStartEventOccurrence
= 0;
44 * The event event occurrence.
46 protected int fEndEventOccurrence
= 0;
48 * Preference ColorId to use to draw font
50 public String fPrefId
= ISDPreferences
.PREF_SYNC_MESS
;
52 * The selection state of the graph node.
54 protected boolean fSelected
= false;
56 * The focus state of the graph node.
58 protected boolean fFocused
= false;
60 * Flag to indicate whether node has children or not.
62 protected boolean fHasChilden
= false;
64 * The graph node name used to label the graph node in the View.
66 protected String fName
= ""; //$NON-NLS-1$
68 * A map from node name to graph node.
70 protected Map
<String
, List
<GraphNode
>> fNodes
;
72 * A map from node name to graph node for forward sorting
74 protected Map
<String
, List
<GraphNode
>> fForwardNodes
;
76 * A map from node name to graph node for backwards sorting.
78 protected Map
<String
, List
<GraphNode
>> fBackwardNodes
;
80 * A map from node name to index.
82 protected Map
<String
, Integer
> fIndexes
;
84 * A map from node name to index for forwards sorting.
86 protected Map
<String
, Boolean
> fForwardSort
;
88 * A map from node name to index for forwards sorting.
90 protected Map
<String
, Boolean
> fBackwardSort
;
92 // ------------------------------------------------------------------------
94 // ------------------------------------------------------------------------
97 * Reset the internal index of the first visible GraphNode for each ordered GraphNode lists
99 public void resetIndex() {
104 Iterator
<String
> it
= fIndexes
.keySet().iterator();
105 while (it
.hasNext()) {
106 String nodeType
= it
.next();
107 fIndexes
.put(nodeType
, Integer
.valueOf(0));
112 * Add a GraphNode into the receiver
114 * @param nodeToAdd the node to add
116 public void addNode(GraphNode nodeToAdd
) {
118 fNodes
= new HashMap
<String
, List
<GraphNode
>>(2);
119 fForwardNodes
= new HashMap
<String
, List
<GraphNode
>>(2);
120 fBackwardNodes
= new HashMap
<String
, List
<GraphNode
>>(2);
121 fIndexes
= new HashMap
<String
, Integer
>(2);
122 fBackwardSort
= new HashMap
<String
, Boolean
>(2);
123 fForwardSort
= new HashMap
<String
, Boolean
>(2);
128 if (nodeToAdd
== null) {
132 if (fNodes
.get(nodeToAdd
.getArrayId()) == null) {
133 fNodes
.put(nodeToAdd
.getArrayId(), new ArrayList
<GraphNode
>(1));
134 fIndexes
.put(nodeToAdd
.getArrayId(), Integer
.valueOf(0));
135 fForwardNodes
.put(nodeToAdd
.getArrayId(), new ArrayList
<GraphNode
>(1));
136 fForwardSort
.put(nodeToAdd
.getArrayId(), Boolean
.valueOf(false));
137 if (nodeToAdd
.getBackComparator() != null) {
138 fBackwardNodes
.put(nodeToAdd
.getArrayId(), new ArrayList
<GraphNode
>(1));
139 fBackwardSort
.put(nodeToAdd
.getArrayId(), Boolean
.valueOf(false));
143 List
<GraphNode
> fNodeList
= (List
<GraphNode
>) fForwardNodes
.get(nodeToAdd
.getArrayId());
144 List
<GraphNode
> bNodeList
= null;
145 if (fBackwardNodes
!= null) {
146 bNodeList
= (List
<GraphNode
>) fBackwardNodes
.get(nodeToAdd
.getArrayId());
148 if (fNodeList
!= null && fNodeList
.size() > 0) {
149 // check if the nodes are added y ordered
150 // if not, tag the list to sort it later (during draw)
151 GraphNode node
= (GraphNode
) fNodeList
.get(fNodeList
.size() - 1);
152 Comparator
<GraphNode
> fcomp
= nodeToAdd
.getComparator();
153 Comparator
<GraphNode
> bcomp
= nodeToAdd
.getBackComparator();
154 if ((fcomp
!= null) && (fcomp
.compare(node
, nodeToAdd
) > 0)) {
155 fForwardSort
.put(nodeToAdd
.getArrayId(), Boolean
.valueOf(true));
157 if ((bcomp
!= null) && (bcomp
.compare(node
, nodeToAdd
) > 0)) {
158 fBackwardSort
.put(nodeToAdd
.getArrayId(), Boolean
.valueOf(true));
162 if (fNodeList
== null) {
163 fNodeList
= new ArrayList
<GraphNode
>();
166 fNodeList
.add(nodeToAdd
);
167 fNodes
.put(nodeToAdd
.getArrayId(), fNodeList
);
168 fForwardNodes
.put(nodeToAdd
.getArrayId(), fNodeList
);
169 if (nodeToAdd
.getBackComparator() != null) {
170 bNodeList
.add(nodeToAdd
);
171 fBackwardNodes
.put(nodeToAdd
.getArrayId(), bNodeList
);
176 * Set the graph node name.<br>
177 * It is the name display in the view to label the graph node.
179 * @param nodeName the name to set
181 public void setName(String nodeName
) {
186 * Returns the graph node name.<br>
187 * It is the name display in the view to label the graph node.
189 * @return the graph node name
191 public String
getName() {
196 * Tags the the graph node has selected.<br>
197 * WARNING: This method is only used to draw the graph node using the system selection colors. <br>
198 * To use the complete SDViewer selection mechanism (selection management, notification, etc..) see SDWidget class
200 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget#addSelection(GraphNode)
201 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget#removeSelection(GraphNode)
202 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget#clearSelection()
203 * @param selection - true to set selected, false to set unselected
205 public void setSelected(boolean selection
) {
206 fSelected
= selection
;
210 * Tags the the graph node as focused.<br>
211 * WARNING: This method is only used to draw the graph node using the system focus style. <br>
212 * To use the complete SDViewer focus mechanism see SDWidget class
214 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget#addSelection(GraphNode)
215 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget#removeSelection(GraphNode)
216 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget#clearSelection()
217 * @param focus - true to set focued, false otherwise
219 public void setFocused(boolean focus
) {
224 * Returns true if the graph node is selected, false otherwise.<br>
225 * The returned value is used to highlight the graph node in the View.
227 * @return true if selected, false otherwise
229 public boolean isSelected() {
234 * Returns true if the graph node is focused, false otherwise.<br>
235 * The returned value is used to highlight the graph node in the View.
237 * @return true if focued, false otherwise
239 public boolean hasFocus() {
244 * Returns true if the graph node contains the point given in parameter, return false otherwise.
246 * @param x the x coordinate of the point to test containment <br>
247 * y the y coordinate of the point to test containment
248 * @return true if contained, false otherwise
250 abstract public boolean contains(int x
, int y
);
253 * Returns the x coordinate of the graph node
255 * @return the x coordinate
257 abstract public int getX();
260 * Returns the y coordinate of the graph node
262 * @return the y coordinate
264 abstract public int getY();
267 * Returns the graph node height
269 * @return the graph node height
271 abstract public int getHeight();
274 * Returns the graph node width
276 * @return the graph node width
278 abstract public int getWidth();
281 * Draws the graph node in the given context
283 * @param context the graphical context to draw in
285 abstract protected void draw(IGC context
);
288 * Returns the GraphNode visibility for the given visible area. Wrong visibility calculation, may strongly impact
289 * drawing performance
295 * @return true if visible false otherwise
297 public boolean isVisible(int x
, int y
, int width
, int height
) {
302 * Return a comparator to sort the GraphNode of the same type This comparator is used to order the GraphNode array
303 * of the given node type. (see getArrayId).
305 * @return the comparator
307 public Comparator
<GraphNode
> getComparator() {
312 * If needed, return a different comparator to backward scan the GraphNode array
314 * @return the backward comparator or null if not needed
316 public Comparator
<GraphNode
> getBackComparator() {
321 * Compare two graphNodes
323 * @param node the node to compare to
324 * @return true if equal false otherwise
326 public boolean isSameAs(GraphNode node
) {
331 * Return the node type for all class instances. This id is used to store the same nodes kind in the same ordered
334 * @return the node type identifier
336 abstract public String
getArrayId();
339 * Return true if the distance from the GraphNode to the given point is positive
341 * @param x the point x coordinate
342 * @param y the point y coordinate
343 * @return true if positive false otherwise
345 public boolean positiveDistanceToPoint(int x
, int y
) {
350 * Returns the graph node which contains the point given in parameter WARNING: Only graph nodes in the current
351 * visible area can be returned
353 * @param x the x coordinate of the point to test
354 * @param y the y coordinate of the point to test
355 * @return the graph node containing the point given in parameter, null otherwise
357 public GraphNode
getNodeAt(int x
, int y
) {
358 GraphNode toReturn
= null;
364 Iterator
<String
> it
= fNodes
.keySet().iterator();
365 GraphNode node
= null;
366 while (it
.hasNext()) {
367 Object nodeType
= it
.next();
368 List
<GraphNode
> list
= (List
<GraphNode
>) fNodes
.get(nodeType
);
369 int index
= ((Integer
) fIndexes
.get(nodeType
)).intValue();
370 node
= getNodeFromListAt(x
, y
, list
, index
);
371 if (toReturn
== null) {
375 GraphNode internalNode
= node
.getNodeAt(x
, y
);
376 if (internalNode
!= null) {
378 } else if (Math
.abs(node
.getWidth()) < Math
.abs(toReturn
.getWidth()) || Math
.abs(node
.getHeight()) < Math
.abs(toReturn
.getHeight())) {
387 * Gets node list from node A to node B
389 * @param from A from node
390 * @param to A to node
391 * @return the list of nodes
393 public List
<GraphNode
> getNodeList(GraphNode from
, GraphNode to
) {
394 List
<GraphNode
> result
= new ArrayList
<GraphNode
>();
398 } else if (to
!= null) {
402 if ((from
== null) || (to
== null)) {
410 int startX
= Math
.min(from
.getX(), Math
.min(to
.getX(), Math
.min(from
.getX() + from
.getWidth(), to
.getX() + to
.getWidth())));
411 int endX
= Math
.max(from
.getX(), Math
.max(to
.getX(), Math
.max(from
.getX() + from
.getWidth(), to
.getX() + to
.getWidth())));
412 int startY
= Math
.min(from
.getY(), Math
.min(to
.getY(), Math
.min(from
.getY() + from
.getHeight(), to
.getY() + to
.getHeight())));
413 int endY
= Math
.max(from
.getY(), Math
.max(to
.getY(), Math
.max(from
.getY() + from
.getHeight(), to
.getY() + to
.getHeight())));
419 Iterator
<String
> it
= fNodes
.keySet().iterator();
420 while (it
.hasNext()) {
421 Object nodeType
= it
.next();
422 List
<GraphNode
> nodesList
= (List
<GraphNode
>) fNodes
.get(nodeType
);
423 if (nodesList
== null || nodesList
.isEmpty()) {
426 for (int i
= 0; i
< nodesList
.size(); i
++) {
427 GraphNode node
= (GraphNode
) nodesList
.get(i
);
428 int nw
= node
.getWidth();
429 int nh
= node
.getHeight();
430 int nx
= node
.getX();
431 int ny
= node
.getY();
432 if (contains(startX
, startY
, endX
- startX
, endY
- startY
, nx
+ 1, ny
+ 1) && contains(startX
, startY
, endX
- startX
, endY
- startY
, nx
+ nw
- 2, ny
+ nh
- 2)) {
435 result
.addAll(node
.getNodeList(from
, to
));
439 if (!result
.contains(to
)) {
446 * Returns the graph node which contains the point given in parameter for the given graph node list and starting the
447 * iteration at the given index<br>
448 * WARNING: Only graph nodes with smaller coordinates than the current visible area can be returned.<br>
450 * @param x the x coordinate of the point to test
451 * @param y the y coordinate of the point to test
452 * @param list the list to search in
453 * @param fromIndex list browsing starting point
454 * @return the graph node containing the point given in parameter, null otherwise
456 protected GraphNode
getNodeFromListAt(int x
, int y
, List
<GraphNode
> list
, int fromIndex
) {
460 for (int i
= fromIndex
; i
< list
.size(); i
++) {
461 GraphNode node
= (GraphNode
) list
.get(i
);
462 if (node
.contains(x
, y
)) {
470 * Returns the start event occurrence attached to this graphNode.
472 * @return the start event occurrence attached to the graphNode
474 public int getStartOccurrence() {
475 return fStartEventOccurrence
;
479 * Returns the end event occurrence attached to this graphNode
481 * @return the start event occurrence attached to the graphNode
483 public int getEndOccurrence() {
484 return fEndEventOccurrence
;
488 * Computes the index of the first visible GraphNode for each ordered graph node lists depending on the visible area
491 * @param x visible area top left corner x coordinate
492 * @param y visible area top left corner y coordinate
493 * @param width visible area width
494 * @param height visible area height
496 public void updateIndex(int x
, int y
, int width
, int height
) {
500 if(TmfUiTracer
.isIndexTraced()) {
501 TmfUiTracer
.traceIndex("*****************************\n"); //$NON-NLS-1$
502 TmfUiTracer
.traceIndex("Visible area position in virtual screen (x,y)= " + x
+ " " + y
+ "\n\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
505 Iterator
<String
> it
= fNodes
.keySet().iterator();
506 while (it
.hasNext()) {
507 String nodeType
= it
.next();
509 int drawIndex
= ((Integer
) fIndexes
.get(nodeType
)).intValue();
511 * if (x==0) { drawIndex = 0; indexes.put(nodeType,new Integer(drawIndex)); }
513 if ((fNodes
.get(nodeType
) != null) && (((List
<GraphNode
>) fNodes
.get(nodeType
)).size() > 1)) {
514 if (((GraphNode
) ((List
<GraphNode
>) fNodes
.get(nodeType
)).get(drawIndex
)).positiveDistanceToPoint(x
, y
)) {
518 if (drawIndex
== 0) {
522 if ((direction
== -1) && (fBackwardNodes
.get(nodeType
) != null)) {
523 GraphNode currentNode
= (GraphNode
) ((List
<GraphNode
>) fNodes
.get(nodeType
)).get(drawIndex
);
524 drawIndex
= Arrays
.binarySearch(((List
<GraphNode
>) fBackwardNodes
.get(nodeType
)).toArray(new GraphNode
[0]), ((List
<GraphNode
>) fNodes
.get(nodeType
)).get(drawIndex
), currentNode
.getBackComparator());
525 fNodes
.put(nodeType
, (List
<GraphNode
>) fBackwardNodes
.get(nodeType
));
530 fNodes
.put(nodeType
, (List
<GraphNode
>) fBackwardNodes
.get(nodeType
));
533 GraphNode prev
= null;
535 for (int i
= drawIndex
; i
< ((List
<GraphNode
>) fNodes
.get(nodeType
)).size() && i
>= 0; i
= i
+ direction
) {
537 fIndexes
.put(nodeType
, Integer
.valueOf(i
));
539 GraphNode currentNode
= (GraphNode
) ((List
<GraphNode
>) fNodes
.get(nodeType
)).get(i
);
545 Comparator
<GraphNode
> comp
= currentNode
.getComparator();
546 Map
<String
, Boolean
> sort
= fForwardSort
;
548 if ((direction
== -1) && (currentNode
.getBackComparator() != null)) {
549 comp
= currentNode
.getBackComparator();
550 sort
= fBackwardSort
;
553 if (i
< ((List
<GraphNode
>) fNodes
.get(nodeType
)).size() - 1) {
554 GraphNode next
= (GraphNode
) ((List
<GraphNode
>) fNodes
.get(nodeType
)).get(i
+ 1);
556 if ((comp
!= null) && (comp
.compare(currentNode
, next
) > 0)) {
557 sort
.put(nodeType
, Boolean
.valueOf(true));
560 if (direction
== 1) {
561 if (((GraphNode
) ((List
<GraphNode
>) fNodes
.get(nodeType
)).get(i
)).positiveDistanceToPoint(x
, y
)) {
565 if (currentNode
.getBackComparator() == null) {
566 if // (currentNode.isVisible(x,y,width,height)
567 (!currentNode
.positiveDistanceToPoint(x
, y
)) {
571 if (currentNode
.isVisible(x
, y
, width
, height
) && !currentNode
.positiveDistanceToPoint(x
, y
)) {
572 if ((comp
!= null) && (comp
.compare(currentNode
, prev
) <= 0)) {
575 } else if ((comp
!= null) && (comp
.compare(currentNode
, prev
) <= 0)) {
582 fNodes
.put(nodeType
, fForwardNodes
.get(nodeType
));
583 if ((fBackwardNodes
.get(nodeType
) != null) && (direction
== -1)) {
584 // nodes.put(nodeType,fnodes.get(nodeType));
585 int index
= ((Integer
) fIndexes
.get(nodeType
)).intValue();
586 List
<GraphNode
> list
= (List
<GraphNode
>) fNodes
.get(nodeType
);
587 List
<GraphNode
> backList
= (List
<GraphNode
>) fBackwardNodes
.get(nodeType
);
588 GraphNode currentNode
= (GraphNode
) (backList
.get(index
));
590 index
= Arrays
.binarySearch(list
.toArray(new GraphNode
[list
.size()]), backList
.get(index
), currentNode
.getComparator());
594 fIndexes
.put(nodeType
, Integer
.valueOf(index
));
598 for (int i
= drawIndex
; i
< ((List
<GraphNode
>) fNodes
.get(nodeType
)).size() && i
>= 0; i
++) {
599 GraphNode toDraw
= (GraphNode
) ((List
<GraphNode
>) fNodes
.get(nodeType
)).get(i
);
600 toDraw
.updateIndex(x
, y
, width
, height
);
601 if (!toDraw
.isVisible(x
, y
, width
, height
)) {
606 if (TmfUiTracer
.isIndexTraced()) {
607 TmfUiTracer
.traceIndex("First drawn " + nodeType
+ " index = " + drawIndex
+ "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
608 TmfUiTracer
.traceIndex(nodeType
+ " found in " + 0 + " iterations\n"); //$NON-NLS-1$ //$NON-NLS-2$
612 if (TmfUiTracer
.isIndexTraced()) {
613 TmfUiTracer
.traceIndex("*****************************\n"); //$NON-NLS-1$
618 * Draws the children nodes on the given context.<br>
619 * This method start width GraphNodes ordering if needed.<br>
620 * After, depending on the visible area, only visible GraphNodes are drawn.<br>
622 * @param context the context to draw to
623 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#draw(IGC)
625 protected void drawChildenNodes(IGC context
) {
630 // If the nodes have not been added ordered, the array is ordered
631 Iterator
<String
> it
= fForwardSort
.keySet().iterator();
632 while (it
.hasNext()) {
633 String nodeType
= it
.next();
634 boolean sort
= ((Boolean
) fForwardSort
.get(nodeType
)).booleanValue();
636 GraphNode
[] temp
= ((List
<GraphNode
>) fForwardNodes
.get(nodeType
)).toArray(new GraphNode
[((List
<GraphNode
>)fForwardNodes
.get(nodeType
)).size()]);
637 GraphNode node
= (GraphNode
) ((List
<GraphNode
>) fNodes
.get(nodeType
)).get(0);
638 Arrays
.sort(temp
, node
.getComparator());
639 fForwardSort
.put(nodeType
, Boolean
.valueOf(false));
640 fNodes
.put(nodeType
, Arrays
.asList(temp
));
641 fForwardNodes
.put(nodeType
, Arrays
.asList(temp
));
642 if (TmfUiTracer
.isSortingTraced()) {
643 TmfUiTracer
.traceSorting(nodeType
+ " array sorted\n"); //$NON-NLS-1$
648 Iterator
<String
> it2
= fBackwardSort
.keySet().iterator();
649 while (it2
.hasNext()) {
650 String nodeType
= it2
.next();
651 boolean sort
= ((Boolean
) fBackwardSort
.get(nodeType
)).booleanValue();
653 GraphNode
[] temp
= ((List
<GraphNode
>) fBackwardNodes
.get(nodeType
)).toArray(new GraphNode
[((List
<GraphNode
>) fBackwardNodes
.get(nodeType
)).size()]);
654 GraphNode node
= (GraphNode
) ((List
<GraphNode
>) fNodes
.get(nodeType
)).get(0);
655 Arrays
.sort(temp
, node
.getBackComparator());
656 fBackwardSort
.put(nodeType
, Boolean
.valueOf(false));
657 fBackwardNodes
.put(nodeType
, Arrays
.asList(temp
));
658 if (TmfUiTracer
.isSortingTraced()) {
659 TmfUiTracer
.traceSorting(nodeType
+ " back array sorted\n"); //$NON-NLS-1$
664 if (TmfUiTracer
.isDisplayTraced()) {
665 TmfUiTracer
.traceDisplay("*****************************\n"); //$NON-NLS-1$
669 if ((Metrics
.getMessageFontHeigth() + Metrics
.MESSAGES_NAME_SPACING
* 2) * context
.getZoom() < Metrics
.MESSAGE_SIGNIFICANT_VSPACING
) {
670 arrayStep
= Math
.round(Metrics
.MESSAGE_SIGNIFICANT_VSPACING
/ ((Metrics
.getMessageFontHeigth() + Metrics
.MESSAGES_NAME_SPACING
* 2) * context
.getZoom()));
674 Iterator
<String
> it3
= fForwardSort
.keySet().iterator();
675 while (it3
.hasNext()) {
677 Object nodeType
= it3
.next();
678 GraphNode node
= (GraphNode
) ((List
<GraphNode
>) fNodes
.get(nodeType
)).get(0);
679 context
.setFont(Frame
.getUserPref().getFont(node
.fPrefId
));
680 int index
= ((Integer
) fIndexes
.get(nodeType
)).intValue();
681 count
= drawNodes(context
, (List
<GraphNode
>) fNodes
.get(nodeType
), index
, arrayStep
);
682 if (TmfUiTracer
.isDisplayTraced()) {
683 TmfUiTracer
.traceDisplay(count
+ " " + nodeType
+ " drawn, starting from index " + index
+ "\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
686 if (TmfUiTracer
.isDisplayTraced()) {
687 TmfUiTracer
.traceDisplay("*****************************\n"); //$NON-NLS-1$
693 * Draw the GraphNode stored in the given list, starting at index startIndex with the given step
695 * @param context the context to draw to
696 * @param list the GraphNodes list
697 * @param startIndex the start index
698 * @param step the step to browse the list
699 * @return the number of GraphNodes drawn
701 protected int drawNodes(IGC context
, List
<GraphNode
> list
, int startIndex
, int step
) {
706 GraphNode last
= null;
708 if (list
.size() < 0) {
712 GraphNode node
= (GraphNode
) list
.get(0);
713 context
.setFont(Frame
.getUserPref().getFont(node
.fPrefId
));
714 Comparator
<GraphNode
> comparator
= node
.getComparator();
715 for (int i
= startIndex
; i
< list
.size(); i
= i
+ step
) {
716 GraphNode toDraw
= (GraphNode
) list
.get(i
);
717 if (i
< list
.size() - 1) {
718 GraphNode next
= (GraphNode
) list
.get(i
+ 1);
719 if ((comparator
!= null) && (comparator
.compare(toDraw
, next
) > 0)) {
720 fForwardSort
.put(next
.getArrayId(), Boolean
.valueOf(true));
723 int cx
= context
.getContentsX();
724 int cy
= context
.getContentsY();
725 int cw
= context
.getVisibleWidth();
726 int ch
= context
.getVisibleHeight();
727 // The arrays should be ordered, no needs to continue for this one
728 if (!toDraw
.isVisible(cx
, cy
, cw
, ch
) && toDraw
.positiveDistanceToPoint(cx
+ cw
, cy
+ ch
)) {
731 // ***Common*** nodes visibility
732 if ((!toDraw
.isSameAs(last
) || toDraw
.isSelected()) && (toDraw
.isVisible(context
.getContentsX(), context
.getContentsY(), context
.getVisibleWidth(), context
.getVisibleHeight()))) {
735 toDraw
.draw(context
);
737 toDraw
.drawFocus(context
);
746 * Draws the focus within the graphical context.
749 public void drawFocus(IGC context
) {
750 context
.drawFocus(getX(), getY(), getWidth(), getHeight());
754 * Determine if the given point (px,py) is contained in the rectangle (x,y,width,height)
756 * @param x the rectangle x coordinate
757 * @param y the rectangle y coordinate
758 * @param width the rectangle width
759 * @param height the rectangle height
760 * @param px the x coordinate of the point to test
761 * @param py the y coordinate of the point to test
762 * @return true if contained false otherwise
764 public static boolean contains(int x
, int y
, int width
, int height
, int px
, int py
) {
767 int locWidth
= width
;
768 int locHeight
= height
;
772 locWidth
= -locWidth
;
776 locY
= locY
+ height
;
777 locHeight
= -locHeight
;
779 return (px
>= locX
) && (py
>= locY
) && ((px
- locX
) <= locWidth
) && ((py
- locY
) <= locHeight
);