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
;
27 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.preferences
.SDViewPref
;
30 * The base class used for all UML2 graph nodes displayed in the Sequence Diagram SDWidget.
35 public abstract class GraphNode
{
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
41 * The start event occurrence.
43 protected int fStartEventOccurrence
= 0;
45 * The event event occurrence.
47 protected int fEndEventOccurrence
= 0;
49 * Preference ColorId to use to draw font
51 public String fPrefId
= ISDPreferences
.PREF_SYNC_MESS
;
53 * The selection state of the graph node.
55 protected boolean fSelected
= false;
57 * The focus state of the graph node.
59 protected boolean fFocused
= false;
61 * Flag to indicate whether node has children or not.
63 protected boolean fHasChilden
= false;
65 * The graph node name used to label the graph node in the View.
67 protected String fName
= ""; //$NON-NLS-1$
69 * A map from node name to graph node.
71 protected Map
<String
, List
<GraphNode
>> fNodes
;
73 * A map from node name to graph node for forward sorting
75 protected Map
<String
, List
<GraphNode
>> fForwardNodes
;
77 * A map from node name to graph node for backwards sorting.
79 protected Map
<String
, List
<GraphNode
>> fBackwardNodes
;
81 * A map from node name to index.
83 protected Map
<String
, Integer
> fIndexes
;
85 * A map from node name to index for forwards sorting.
87 protected Map
<String
, Boolean
> fForwardSort
;
89 * A map from node name to index for forwards sorting.
91 protected Map
<String
, Boolean
> fBackwardSort
;
93 // ------------------------------------------------------------------------
95 // ------------------------------------------------------------------------
98 * Reset the internal index of the first visible GraphNode for each ordered GraphNode lists
100 public void resetIndex() {
105 Iterator
<String
> it
= fIndexes
.keySet().iterator();
106 while (it
.hasNext()) {
107 String nodeType
= it
.next();
108 fIndexes
.put(nodeType
, Integer
.valueOf(0));
113 * Add a GraphNode into the receiver
115 * @param nodeToAdd the node to add
117 public void addNode(GraphNode nodeToAdd
) {
119 fNodes
= new HashMap
<String
, List
<GraphNode
>>(2);
120 fForwardNodes
= new HashMap
<String
, List
<GraphNode
>>(2);
121 fBackwardNodes
= new HashMap
<String
, List
<GraphNode
>>(2);
122 fIndexes
= new HashMap
<String
, Integer
>(2);
123 fBackwardSort
= new HashMap
<String
, Boolean
>(2);
124 fForwardSort
= new HashMap
<String
, Boolean
>(2);
129 if (nodeToAdd
== null) {
133 if (fNodes
.get(nodeToAdd
.getArrayId()) == null) {
134 fNodes
.put(nodeToAdd
.getArrayId(), new ArrayList
<GraphNode
>(1));
135 fIndexes
.put(nodeToAdd
.getArrayId(), Integer
.valueOf(0));
136 fForwardNodes
.put(nodeToAdd
.getArrayId(), new ArrayList
<GraphNode
>(1));
137 fForwardSort
.put(nodeToAdd
.getArrayId(), Boolean
.FALSE
);
138 if (nodeToAdd
.getBackComparator() != null) {
139 fBackwardNodes
.put(nodeToAdd
.getArrayId(), new ArrayList
<GraphNode
>(1));
140 fBackwardSort
.put(nodeToAdd
.getArrayId(), Boolean
.FALSE
);
144 List
<GraphNode
> fNodeList
= (List
<GraphNode
>) fForwardNodes
.get(nodeToAdd
.getArrayId());
145 List
<GraphNode
> bNodeList
= null;
146 if (fBackwardNodes
!= null) {
147 bNodeList
= (List
<GraphNode
>) fBackwardNodes
.get(nodeToAdd
.getArrayId());
149 if (fNodeList
!= null && fNodeList
.size() > 0) {
150 // check if the nodes are added y ordered
151 // if not, tag the list to sort it later (during draw)
152 GraphNode node
= (GraphNode
) fNodeList
.get(fNodeList
.size() - 1);
153 Comparator
<GraphNode
> fcomp
= nodeToAdd
.getComparator();
154 Comparator
<GraphNode
> bcomp
= nodeToAdd
.getBackComparator();
155 if ((fcomp
!= null) && (fcomp
.compare(node
, nodeToAdd
) > 0)) {
156 fForwardSort
.put(nodeToAdd
.getArrayId(), Boolean
.TRUE
);
158 if ((bcomp
!= null) && (bcomp
.compare(node
, nodeToAdd
) > 0)) {
159 fBackwardSort
.put(nodeToAdd
.getArrayId(), Boolean
.TRUE
);
163 if (fNodeList
== null) {
164 fNodeList
= new ArrayList
<GraphNode
>();
167 fNodeList
.add(nodeToAdd
);
168 fNodes
.put(nodeToAdd
.getArrayId(), fNodeList
);
169 fForwardNodes
.put(nodeToAdd
.getArrayId(), fNodeList
);
170 if (nodeToAdd
.getBackComparator() != null) {
171 bNodeList
.add(nodeToAdd
);
172 fBackwardNodes
.put(nodeToAdd
.getArrayId(), bNodeList
);
177 * Set the graph node name.<br>
178 * It is the name display in the view to label the graph node.
180 * @param nodeName the name to set
182 public void setName(String nodeName
) {
187 * Returns the graph node name.<br>
188 * It is the name display in the view to label the graph node.
190 * @return the graph node name
192 public String
getName() {
197 * Tags the the graph node has selected.<br>
198 * WARNING: This method is only used to draw the graph node using the system selection colors. <br>
199 * To use the complete SDViewer selection mechanism (selection management, notification, etc..) see SDWidget class
201 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget#addSelection(GraphNode)
202 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget#removeSelection(GraphNode)
203 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget#clearSelection()
204 * @param selection - true to set selected, false to set unselected
206 public void setSelected(boolean selection
) {
207 fSelected
= selection
;
211 * Tags the the graph node as focused.<br>
212 * WARNING: This method is only used to draw the graph node using the system focus style. <br>
213 * To use the complete SDViewer focus mechanism see SDWidget class
215 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget#addSelection(GraphNode)
216 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget#removeSelection(GraphNode)
217 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget#clearSelection()
218 * @param focus - true to set focued, false otherwise
220 public void setFocused(boolean focus
) {
225 * Returns true if the graph node is selected, false otherwise.<br>
226 * The returned value is used to highlight the graph node in the View.
228 * @return true if selected, false otherwise
230 public boolean isSelected() {
235 * Returns true if the graph node is focused, false otherwise.<br>
236 * The returned value is used to highlight the graph node in the View.
238 * @return true if focued, false otherwise
240 public boolean hasFocus() {
245 * Returns true if the graph node contains the point given in parameter, return false otherwise.
247 * @param x the x coordinate of the point to test containment <br>
248 * y the y coordinate of the point to test containment
249 * @return true if contained, false otherwise
251 abstract public boolean contains(int x
, int y
);
254 * Returns the x coordinate of the graph node
256 * @return the x coordinate
258 abstract public int getX();
261 * Returns the y coordinate of the graph node
263 * @return the y coordinate
265 abstract public int getY();
268 * Returns the graph node height
270 * @return the graph node height
272 abstract public int getHeight();
275 * Returns the graph node width
277 * @return the graph node width
279 abstract public int getWidth();
282 * Draws the graph node in the given context
284 * @param context the graphical context to draw in
286 abstract protected void draw(IGC context
);
289 * Returns the GraphNode visibility for the given visible area. Wrong visibility calculation, may strongly impact
290 * drawing performance
296 * @return true if visible false otherwise
298 public boolean isVisible(int x
, int y
, int width
, int height
) {
303 * Return a comparator to sort the GraphNode of the same type This comparator is used to order the GraphNode array
304 * of the given node type. (see getArrayId).
306 * @return the comparator
308 public Comparator
<GraphNode
> getComparator() {
313 * If needed, return a different comparator to backward scan the GraphNode array
315 * @return the backward comparator or null if not needed
317 public Comparator
<GraphNode
> getBackComparator() {
322 * Compare two graphNodes
324 * @param node the node to compare to
325 * @return true if equal false otherwise
327 public boolean isSameAs(GraphNode node
) {
332 * Return the node type for all class instances. This id is used to store the same nodes kind in the same ordered
335 * @return the node type identifier
337 abstract public String
getArrayId();
340 * Return true if the distance from the GraphNode to the given point is positive
342 * @param x the point x coordinate
343 * @param y the point y coordinate
344 * @return true if positive false otherwise
346 public boolean positiveDistanceToPoint(int x
, int y
) {
351 * Returns the graph node which contains the point given in parameter WARNING: Only graph nodes in the current
352 * visible area can be returned
354 * @param x the x coordinate of the point to test
355 * @param y the y coordinate of the point to test
356 * @return the graph node containing the point given in parameter, null otherwise
358 public GraphNode
getNodeAt(int x
, int y
) {
359 GraphNode toReturn
= null;
365 Iterator
<String
> it
= fNodes
.keySet().iterator();
366 GraphNode node
= null;
367 while (it
.hasNext()) {
368 Object nodeType
= it
.next();
369 List
<GraphNode
> list
= (List
<GraphNode
>) fNodes
.get(nodeType
);
370 int index
= ((Integer
) fIndexes
.get(nodeType
)).intValue();
371 node
= getNodeFromListAt(x
, y
, list
, index
);
372 if (toReturn
== null) {
376 GraphNode internalNode
= node
.getNodeAt(x
, y
);
377 if (internalNode
!= null) {
379 } else if (Math
.abs(node
.getWidth()) < Math
.abs(toReturn
.getWidth()) || Math
.abs(node
.getHeight()) < Math
.abs(toReturn
.getHeight())) {
388 * Gets node list from node A to node B
390 * @param from A from node
391 * @param to A to node
392 * @return the list of nodes
394 public List
<GraphNode
> getNodeList(GraphNode from
, GraphNode to
) {
395 List
<GraphNode
> result
= new ArrayList
<GraphNode
>();
399 } else if (to
!= null) {
403 if ((from
== null) || (to
== null)) {
411 int startX
= Math
.min(from
.getX(), Math
.min(to
.getX(), Math
.min(from
.getX() + from
.getWidth(), to
.getX() + to
.getWidth())));
412 int endX
= Math
.max(from
.getX(), Math
.max(to
.getX(), Math
.max(from
.getX() + from
.getWidth(), to
.getX() + to
.getWidth())));
413 int startY
= Math
.min(from
.getY(), Math
.min(to
.getY(), Math
.min(from
.getY() + from
.getHeight(), to
.getY() + to
.getHeight())));
414 int endY
= Math
.max(from
.getY(), Math
.max(to
.getY(), Math
.max(from
.getY() + from
.getHeight(), to
.getY() + to
.getHeight())));
420 Iterator
<String
> it
= fNodes
.keySet().iterator();
421 while (it
.hasNext()) {
422 Object nodeType
= it
.next();
423 List
<GraphNode
> nodesList
= (List
<GraphNode
>) fNodes
.get(nodeType
);
424 if (nodesList
== null || nodesList
.isEmpty()) {
427 for (int i
= 0; i
< nodesList
.size(); i
++) {
428 GraphNode node
= (GraphNode
) nodesList
.get(i
);
429 int nw
= node
.getWidth();
430 int nh
= node
.getHeight();
431 int nx
= node
.getX();
432 int ny
= node
.getY();
433 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)) {
436 result
.addAll(node
.getNodeList(from
, to
));
440 if (!result
.contains(to
)) {
447 * Returns the graph node which contains the point given in parameter for the given graph node list and starting the
448 * iteration at the given index<br>
449 * WARNING: Only graph nodes with smaller coordinates than the current visible area can be returned.<br>
451 * @param x the x coordinate of the point to test
452 * @param y the y coordinate of the point to test
453 * @param list the list to search in
454 * @param fromIndex list browsing starting point
455 * @return the graph node containing the point given in parameter, null otherwise
457 protected GraphNode
getNodeFromListAt(int x
, int y
, List
<GraphNode
> list
, int fromIndex
) {
461 for (int i
= fromIndex
; i
< list
.size(); i
++) {
462 GraphNode node
= (GraphNode
) list
.get(i
);
463 if (node
.contains(x
, y
)) {
471 * Returns the start event occurrence attached to this graphNode.
473 * @return the start event occurrence attached to the graphNode
475 public int getStartOccurrence() {
476 return fStartEventOccurrence
;
480 * Returns the end event occurrence attached to this graphNode
482 * @return the start event occurrence attached to the graphNode
484 public int getEndOccurrence() {
485 return fEndEventOccurrence
;
489 * Computes the index of the first visible GraphNode for each ordered graph node lists depending on the visible area
492 * @param x visible area top left corner x coordinate
493 * @param y visible area top left corner y coordinate
494 * @param width visible area width
495 * @param height visible area height
497 public void updateIndex(int x
, int y
, int width
, int height
) {
501 if(TmfUiTracer
.isIndexTraced()) {
502 TmfUiTracer
.traceIndex("*****************************\n"); //$NON-NLS-1$
503 TmfUiTracer
.traceIndex("Visible area position in virtual screen (x,y)= " + x
+ " " + y
+ "\n\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
506 Iterator
<String
> it
= fNodes
.keySet().iterator();
507 while (it
.hasNext()) {
508 String nodeType
= it
.next();
510 int drawIndex
= ((Integer
) fIndexes
.get(nodeType
)).intValue();
512 * if (x==0) { drawIndex = 0; indexes.put(nodeType,new Integer(drawIndex)); }
514 if ((fNodes
.get(nodeType
) != null) && (((List
<GraphNode
>) fNodes
.get(nodeType
)).size() > 1)) {
515 if (((GraphNode
) ((List
<GraphNode
>) fNodes
.get(nodeType
)).get(drawIndex
)).positiveDistanceToPoint(x
, y
)) {
519 if (drawIndex
== 0) {
523 if ((direction
== -1) && (fBackwardNodes
.get(nodeType
) != null)) {
524 GraphNode currentNode
= (GraphNode
) ((List
<GraphNode
>) fNodes
.get(nodeType
)).get(drawIndex
);
525 drawIndex
= Arrays
.binarySearch(((List
<GraphNode
>) fBackwardNodes
.get(nodeType
)).toArray(new GraphNode
[((List
<GraphNode
>) fBackwardNodes
.get(nodeType
)).size()]),
526 ((List
<GraphNode
>) fNodes
.get(nodeType
)).get(drawIndex
), currentNode
.getBackComparator());
527 fNodes
.put(nodeType
, (List
<GraphNode
>) fBackwardNodes
.get(nodeType
));
532 fNodes
.put(nodeType
, (List
<GraphNode
>) fBackwardNodes
.get(nodeType
));
535 GraphNode prev
= null;
537 for (int i
= drawIndex
; i
< ((List
<GraphNode
>) fNodes
.get(nodeType
)).size() && i
>= 0; i
= i
+ direction
) {
539 fIndexes
.put(nodeType
, Integer
.valueOf(i
));
541 GraphNode currentNode
= (GraphNode
) ((List
<GraphNode
>) fNodes
.get(nodeType
)).get(i
);
547 Comparator
<GraphNode
> comp
= currentNode
.getComparator();
548 Map
<String
, Boolean
> sort
= fForwardSort
;
550 if ((direction
== -1) && (currentNode
.getBackComparator() != null)) {
551 comp
= currentNode
.getBackComparator();
552 sort
= fBackwardSort
;
555 if (i
< ((List
<GraphNode
>) fNodes
.get(nodeType
)).size() - 1) {
556 GraphNode next
= (GraphNode
) ((List
<GraphNode
>) fNodes
.get(nodeType
)).get(i
+ 1);
558 if ((comp
!= null) && (comp
.compare(currentNode
, next
) > 0)) {
559 sort
.put(nodeType
, Boolean
.TRUE
);
562 if (direction
== 1) {
563 if (((GraphNode
) ((List
<GraphNode
>) fNodes
.get(nodeType
)).get(i
)).positiveDistanceToPoint(x
, y
)) {
567 if (currentNode
.getBackComparator() == null) {
568 if // (currentNode.isVisible(x,y,width,height)
569 (!currentNode
.positiveDistanceToPoint(x
, y
)) {
573 if (currentNode
.isVisible(x
, y
, width
, height
) && !currentNode
.positiveDistanceToPoint(x
, y
)) {
574 if ((comp
!= null) && (comp
.compare(currentNode
, prev
) <= 0)) {
577 } else if ((comp
!= null) && (comp
.compare(currentNode
, prev
) <= 0)) {
584 fNodes
.put(nodeType
, fForwardNodes
.get(nodeType
));
585 if ((fBackwardNodes
.get(nodeType
) != null) && (direction
== -1)) {
586 // nodes.put(nodeType,fnodes.get(nodeType));
587 int index
= ((Integer
) fIndexes
.get(nodeType
)).intValue();
588 List
<GraphNode
> list
= (List
<GraphNode
>) fNodes
.get(nodeType
);
589 List
<GraphNode
> backList
= (List
<GraphNode
>) fBackwardNodes
.get(nodeType
);
590 GraphNode currentNode
= (GraphNode
) (backList
.get(index
));
592 index
= Arrays
.binarySearch(list
.toArray(new GraphNode
[list
.size()]), backList
.get(index
), currentNode
.getComparator());
596 fIndexes
.put(nodeType
, Integer
.valueOf(index
));
600 for (int i
= drawIndex
; i
< ((List
<GraphNode
>) fNodes
.get(nodeType
)).size() && i
>= 0; i
++) {
601 GraphNode toDraw
= (GraphNode
) ((List
<GraphNode
>) fNodes
.get(nodeType
)).get(i
);
602 toDraw
.updateIndex(x
, y
, width
, height
);
603 if (!toDraw
.isVisible(x
, y
, width
, height
)) {
608 if (TmfUiTracer
.isIndexTraced()) {
609 TmfUiTracer
.traceIndex("First drawn " + nodeType
+ " index = " + drawIndex
+ "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
610 TmfUiTracer
.traceIndex(nodeType
+ " found in " + 0 + " iterations\n"); //$NON-NLS-1$ //$NON-NLS-2$
614 if (TmfUiTracer
.isIndexTraced()) {
615 TmfUiTracer
.traceIndex("*****************************\n"); //$NON-NLS-1$
620 * Draws the children nodes on the given context.<br>
621 * This method start width GraphNodes ordering if needed.<br>
622 * After, depending on the visible area, only visible GraphNodes are drawn.<br>
624 * @param context the context to draw to
625 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#draw(IGC)
627 protected void drawChildenNodes(IGC context
) {
632 // If the nodes have not been added ordered, the array is ordered
633 Iterator
<String
> it
= fForwardSort
.keySet().iterator();
634 while (it
.hasNext()) {
635 String nodeType
= it
.next();
636 boolean sort
= ((Boolean
) fForwardSort
.get(nodeType
)).booleanValue();
638 GraphNode
[] temp
= ((List
<GraphNode
>) fForwardNodes
.get(nodeType
)).toArray(new GraphNode
[((List
<GraphNode
>)fForwardNodes
.get(nodeType
)).size()]);
639 GraphNode node
= (GraphNode
) ((List
<GraphNode
>) fNodes
.get(nodeType
)).get(0);
640 Arrays
.sort(temp
, node
.getComparator());
641 fForwardSort
.put(nodeType
, Boolean
.FALSE
);
642 fNodes
.put(nodeType
, Arrays
.asList(temp
));
643 fForwardNodes
.put(nodeType
, Arrays
.asList(temp
));
644 if (TmfUiTracer
.isSortingTraced()) {
645 TmfUiTracer
.traceSorting(nodeType
+ " array sorted\n"); //$NON-NLS-1$
650 Iterator
<String
> it2
= fBackwardSort
.keySet().iterator();
651 while (it2
.hasNext()) {
652 String nodeType
= it2
.next();
653 boolean sort
= ((Boolean
) fBackwardSort
.get(nodeType
)).booleanValue();
655 GraphNode
[] temp
= ((List
<GraphNode
>) fBackwardNodes
.get(nodeType
)).toArray(new GraphNode
[((List
<GraphNode
>) fBackwardNodes
.get(nodeType
)).size()]);
656 GraphNode node
= (GraphNode
) ((List
<GraphNode
>) fNodes
.get(nodeType
)).get(0);
657 Arrays
.sort(temp
, node
.getBackComparator());
658 fBackwardSort
.put(nodeType
, Boolean
.FALSE
);
659 fBackwardNodes
.put(nodeType
, Arrays
.asList(temp
));
660 if (TmfUiTracer
.isSortingTraced()) {
661 TmfUiTracer
.traceSorting(nodeType
+ " back array sorted\n"); //$NON-NLS-1$
666 if (TmfUiTracer
.isDisplayTraced()) {
667 TmfUiTracer
.traceDisplay("*****************************\n"); //$NON-NLS-1$
671 if ((Metrics
.getMessageFontHeigth() + Metrics
.MESSAGES_NAME_SPACING
* 2) * context
.getZoom() < Metrics
.MESSAGE_SIGNIFICANT_VSPACING
) {
672 arrayStep
= Math
.round(Metrics
.MESSAGE_SIGNIFICANT_VSPACING
/ ((Metrics
.getMessageFontHeigth() + Metrics
.MESSAGES_NAME_SPACING
* 2) * context
.getZoom()));
676 Iterator
<String
> it3
= fForwardSort
.keySet().iterator();
677 while (it3
.hasNext()) {
679 Object nodeType
= it3
.next();
680 GraphNode node
= (GraphNode
) ((List
<GraphNode
>) fNodes
.get(nodeType
)).get(0);
681 context
.setFont(SDViewPref
.getInstance().getFont(node
.fPrefId
));
682 int index
= ((Integer
) fIndexes
.get(nodeType
)).intValue();
683 count
= drawNodes(context
, (List
<GraphNode
>) fNodes
.get(nodeType
), index
, arrayStep
);
684 if (TmfUiTracer
.isDisplayTraced()) {
685 TmfUiTracer
.traceDisplay(count
+ " " + nodeType
+ " drawn, starting from index " + index
+ "\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
688 if (TmfUiTracer
.isDisplayTraced()) {
689 TmfUiTracer
.traceDisplay("*****************************\n"); //$NON-NLS-1$
695 * Draw the GraphNode stored in the given list, starting at index startIndex with the given step
697 * @param context the context to draw to
698 * @param list the GraphNodes list
699 * @param startIndex the start index
700 * @param step the step to browse the list
701 * @return the number of GraphNodes drawn
703 protected int drawNodes(IGC context
, List
<GraphNode
> list
, int startIndex
, int step
) {
708 GraphNode last
= null;
710 if (list
.size() < 0) {
714 GraphNode node
= (GraphNode
) list
.get(0);
715 context
.setFont(SDViewPref
.getInstance().getFont(node
.fPrefId
));
716 Comparator
<GraphNode
> comparator
= node
.getComparator();
717 for (int i
= startIndex
; i
< list
.size(); i
= i
+ step
) {
718 GraphNode toDraw
= (GraphNode
) list
.get(i
);
719 if (i
< list
.size() - 1) {
720 GraphNode next
= (GraphNode
) list
.get(i
+ 1);
721 if ((comparator
!= null) && (comparator
.compare(toDraw
, next
) > 0)) {
722 fForwardSort
.put(next
.getArrayId(), Boolean
.TRUE
);
725 int cx
= context
.getContentsX();
726 int cy
= context
.getContentsY();
727 int cw
= context
.getVisibleWidth();
728 int ch
= context
.getVisibleHeight();
729 // The arrays should be ordered, no needs to continue for this one
730 if (!toDraw
.isVisible(cx
, cy
, cw
, ch
) && toDraw
.positiveDistanceToPoint(cx
+ cw
, cy
+ ch
)) {
733 // ***Common*** nodes visibility
734 if ((!toDraw
.isSameAs(last
) || toDraw
.isSelected()) && (toDraw
.isVisible(context
.getContentsX(), context
.getContentsY(), context
.getVisibleWidth(), context
.getVisibleHeight()))) {
737 toDraw
.draw(context
);
739 toDraw
.drawFocus(context
);
748 * Draws the focus within the graphical context.
751 public void drawFocus(IGC context
) {
752 context
.drawFocus(getX(), getY(), getWidth(), getHeight());
756 * Determine if the given point (px,py) is contained in the rectangle (x,y,width,height)
758 * @param x the rectangle x coordinate
759 * @param y the rectangle y coordinate
760 * @param width the rectangle width
761 * @param height the rectangle height
762 * @param px the x coordinate of the point to test
763 * @param py the y coordinate of the point to test
764 * @return true if contained false otherwise
766 public static boolean contains(int x
, int y
, int width
, int height
, int px
, int py
) {
769 int locWidth
= width
;
770 int locHeight
= height
;
774 locWidth
= -locWidth
;
778 locY
= locY
+ height
;
779 locHeight
= -locHeight
;
781 return (px
>= locX
) && (py
>= locY
) && ((px
- locX
) <= locWidth
) && ((py
- locY
) <= locHeight
);