1 /**********************************************************************
2 * Copyright (c) 2005, 2014 IBM Corporation, Ericsson
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.core
;
15 import java
.util
.ArrayList
;
16 import java
.util
.Arrays
;
17 import java
.util
.Comparator
;
18 import java
.util
.HashMap
;
19 import java
.util
.Iterator
;
20 import java
.util
.List
;
23 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.TmfUiTracer
;
24 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.drawings
.IGC
;
25 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.preferences
.ISDPreferences
;
26 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.preferences
.SDViewPref
;
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 private int fStartEventOccurrence
= 0;
44 * The event event occurrence.
46 private int fEndEventOccurrence
= 0;
48 * Preference ColorId to use to draw font
50 private String fPrefId
= ISDPreferences
.PREF_SYNC_MESS
;
52 * The selection state of the graph node.
54 private boolean fSelected
= false;
56 * The focus state of the graph node.
58 private boolean fFocused
= false;
60 * Flag to indicate whether node has children or not.
62 private boolean fHasChilden
= false;
64 * The graph node name used to label the graph node in the View.
66 private String fName
= ""; //$NON-NLS-1$
68 * A map from node name to graph node.
70 private Map
<String
, List
<GraphNode
>> fNodes
;
72 * A map from node name to graph node for forward sorting
74 private Map
<String
, List
<GraphNode
>> fForwardNodes
;
76 * A map from node name to graph node for backwards sorting.
78 private Map
<String
, List
<GraphNode
>> fBackwardNodes
;
80 * A map from node name to index.
82 private Map
<String
, Integer
> fIndexes
;
84 * A map from node name to flag for forwards sorting.
86 private Map
<String
, Boolean
> fForwardSort
;
88 * A map from node name to flag for backwards sorting.
90 private 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
<>(2);
119 fForwardNodes
= new HashMap
<>(2);
120 fBackwardNodes
= new HashMap
<>(2);
121 fIndexes
= new HashMap
<>(2);
122 fBackwardSort
= new HashMap
<>(2);
123 fForwardSort
= new HashMap
<>(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
.FALSE
);
137 if (nodeToAdd
.getBackComparator() != null) {
138 fBackwardNodes
.put(nodeToAdd
.getArrayId(), new ArrayList
<GraphNode
>(1));
139 fBackwardSort
.put(nodeToAdd
.getArrayId(), Boolean
.FALSE
);
143 List
<GraphNode
> fNodeList
= fForwardNodes
.get(nodeToAdd
.getArrayId());
144 List
<GraphNode
> bNodeList
= null;
145 if (fBackwardNodes
!= null) {
146 bNodeList
= 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
= 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
.TRUE
);
157 if ((bcomp
!= null) && (bcomp
.compare(node
, nodeToAdd
) > 0)) {
158 fBackwardSort
.put(nodeToAdd
.getArrayId(), Boolean
.TRUE
);
162 if (fNodeList
== null) {
163 fNodeList
= new ArrayList
<>();
166 fNodeList
.add(nodeToAdd
);
167 fNodes
.put(nodeToAdd
.getArrayId(), fNodeList
);
168 fForwardNodes
.put(nodeToAdd
.getArrayId(), fNodeList
);
169 if ((bNodeList
!= null) && (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.tracecompass.tmf.ui.views.uml2sd.SDWidget#addSelection(GraphNode)
201 * @see org.eclipse.tracecompass.tmf.ui.views.uml2sd.SDWidget#removeSelection(GraphNode)
202 * @see org.eclipse.tracecompass.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.tracecompass.tmf.ui.views.uml2sd.SDWidget#addSelection(GraphNode)
215 * @see org.eclipse.tracecompass.tmf.ui.views.uml2sd.SDWidget#removeSelection(GraphNode)
216 * @see org.eclipse.tracecompass.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 focused, false otherwise
239 public boolean hasFocus() {
244 * Returns true if the graph node contains the point given in parameter,
245 * return false otherwise.
248 * the x coordinate of the point to test containment
250 * the y coordinate of the point to test containment
251 * @return true if contained, false otherwise
253 abstract public boolean contains(int x
, int y
);
256 * Returns the x coordinate of the graph node
258 * @return the x coordinate
260 abstract public int getX();
263 * Returns the y coordinate of the graph node
265 * @return the y coordinate
267 abstract public int getY();
270 * Returns the graph node height
272 * @return the graph node height
274 abstract public int getHeight();
277 * Returns the graph node width
279 * @return the graph node width
281 abstract public int getWidth();
284 * Draws the graph node in the given context
286 * @param context the graphical context to draw in
288 abstract protected void draw(IGC context
);
291 * Returns the GraphNode visibility for the given visible area. Wrong
292 * visibility calculation, may strongly impact drawing performance
299 * The width of the area
301 * The height of the area
302 * @return true if visible, false otherwise
304 public boolean isVisible(int x
, int y
, int width
, int height
) {
309 * Return a comparator to sort the GraphNode of the same type This
310 * comparator is used to order the GraphNode array of the given node type.
313 * @return the comparator
315 public Comparator
<GraphNode
> getComparator() {
320 * If needed, return a different comparator to backward scan the GraphNode
323 * @return the backward comparator or null if not needed
325 public Comparator
<GraphNode
> getBackComparator() {
330 * Compare two graphNodes
333 * the node to compare to
334 * @return true if equal false otherwise
336 public boolean isSameAs(GraphNode node
) {
341 * Return the node type for all class instances. This id is used to store the same nodes kind in the same ordered
344 * @return the node type identifier
346 abstract public String
getArrayId();
349 * Return true if the distance from the GraphNode to the given point is positive
351 * @param x the point x coordinate
352 * @param y the point y coordinate
353 * @return true if positive false otherwise
355 public boolean positiveDistanceToPoint(int x
, int y
) {
360 * Returns the graph node which contains the point given in parameter WARNING: Only graph nodes in the current
361 * visible area can be returned
363 * @param x the x coordinate of the point to test
364 * @param y the y coordinate of the point to test
365 * @return the graph node containing the point given in parameter, null otherwise
367 public GraphNode
getNodeAt(int x
, int y
) {
368 GraphNode toReturn
= null;
374 Iterator
<String
> it
= fNodes
.keySet().iterator();
375 GraphNode node
= null;
376 while (it
.hasNext()) {
377 Object nodeType
= it
.next();
378 List
<GraphNode
> list
= fNodes
.get(nodeType
);
379 int index
= fIndexes
.get(nodeType
).intValue();
380 node
= getNodeFromListAt(x
, y
, list
, index
);
381 if (toReturn
== null) {
385 GraphNode internalNode
= node
.getNodeAt(x
, y
);
386 if (internalNode
!= null) {
388 } else if (Math
.abs(node
.getWidth()) < Math
.abs(toReturn
.getWidth()) || Math
.abs(node
.getHeight()) < Math
.abs(toReturn
.getHeight())) {
397 * Gets node list from node A to node B
399 * @param from A from node
400 * @param to A to node
401 * @return the list of nodes
403 public List
<GraphNode
> getNodeList(GraphNode from
, GraphNode to
) {
404 List
<GraphNode
> result
= new ArrayList
<>();
408 } else if (to
!= null) {
412 if ((from
== null) || (to
== null)) {
420 int startX
= Math
.min(from
.getX(), Math
.min(to
.getX(), Math
.min(from
.getX() + from
.getWidth(), to
.getX() + to
.getWidth())));
421 int endX
= Math
.max(from
.getX(), Math
.max(to
.getX(), Math
.max(from
.getX() + from
.getWidth(), to
.getX() + to
.getWidth())));
422 int startY
= Math
.min(from
.getY(), Math
.min(to
.getY(), Math
.min(from
.getY() + from
.getHeight(), to
.getY() + to
.getHeight())));
423 int endY
= Math
.max(from
.getY(), Math
.max(to
.getY(), Math
.max(from
.getY() + from
.getHeight(), to
.getY() + to
.getHeight())));
429 Iterator
<String
> it
= fNodes
.keySet().iterator();
430 while (it
.hasNext()) {
431 Object nodeType
= it
.next();
432 List
<GraphNode
> nodesList
= fNodes
.get(nodeType
);
433 if (nodesList
== null || nodesList
.isEmpty()) {
436 for (int i
= 0; i
< nodesList
.size(); i
++) {
437 GraphNode node
= nodesList
.get(i
);
438 int nw
= node
.getWidth();
439 int nh
= node
.getHeight();
440 int nx
= node
.getX();
441 int ny
= node
.getY();
442 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)) {
445 result
.addAll(node
.getNodeList(from
, to
));
449 if (!result
.contains(to
)) {
456 * Returns the graph node which contains the point given in parameter for the given graph node list and starting the
457 * iteration at the given index<br>
458 * WARNING: Only graph nodes with smaller coordinates than the current visible area can be returned.<br>
460 * @param x the x coordinate of the point to test
461 * @param y the y coordinate of the point to test
462 * @param list the list to search in
463 * @param fromIndex list browsing starting point
464 * @return the graph node containing the point given in parameter, null otherwise
466 protected GraphNode
getNodeFromListAt(int x
, int y
, List
<GraphNode
> list
, int fromIndex
) {
470 for (int i
= fromIndex
; i
< list
.size(); i
++) {
471 GraphNode node
= list
.get(i
);
472 if (node
.contains(x
, y
)) {
480 * Returns the start event occurrence attached to this graphNode.
482 * @return the start event occurrence attached to the graphNode
484 public int getStartOccurrence() {
485 return fStartEventOccurrence
;
489 * Returns the end event occurrence attached to this graphNode
491 * @return the start event occurrence attached to the graphNode
493 public int getEndOccurrence() {
494 return fEndEventOccurrence
;
498 * Computes the index of the first visible GraphNode for each ordered graph node lists depending on the visible area
501 * @param x visible area top left corner x coordinate
502 * @param y visible area top left corner y coordinate
503 * @param width visible area width
504 * @param height visible area height
506 public void updateIndex(int x
, int y
, int width
, int height
) {
510 if(TmfUiTracer
.isIndexTraced()) {
511 TmfUiTracer
.traceIndex("*****************************\n"); //$NON-NLS-1$
512 TmfUiTracer
.traceIndex("Visible area position in virtual screen (x,y)= " + x
+ " " + y
+ "\n\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
515 Iterator
<String
> it
= fNodes
.keySet().iterator();
516 while (it
.hasNext()) {
517 String nodeType
= it
.next();
519 int drawIndex
= fIndexes
.get(nodeType
).intValue();
521 * if (x==0) { drawIndex = 0; indexes.put(nodeType,new Integer(drawIndex)); }
523 if ((fNodes
.get(nodeType
) != null) && (fNodes
.get(nodeType
).size() > 1)) {
524 if (fNodes
.get(nodeType
).get(drawIndex
).positiveDistanceToPoint(x
, y
)) {
528 if (drawIndex
== 0) {
532 if ((direction
== -1) && (fBackwardNodes
.get(nodeType
) != null)) {
533 GraphNode currentNode
= fNodes
.get(nodeType
).get(drawIndex
);
534 drawIndex
= Arrays
.binarySearch(fBackwardNodes
.get(nodeType
).toArray(new GraphNode
[fBackwardNodes
.get(nodeType
).size()]),
535 fNodes
.get(nodeType
).get(drawIndex
), currentNode
.getBackComparator());
536 fNodes
.put(nodeType
, fBackwardNodes
.get(nodeType
));
541 fNodes
.put(nodeType
, fBackwardNodes
.get(nodeType
));
544 GraphNode prev
= null;
546 for (int i
= drawIndex
; i
< fNodes
.get(nodeType
).size() && i
>= 0; i
= i
+ direction
) {
548 fIndexes
.put(nodeType
, Integer
.valueOf(i
));
550 GraphNode currentNode
= fNodes
.get(nodeType
).get(i
);
556 Comparator
<GraphNode
> comp
= currentNode
.getComparator();
557 Map
<String
, Boolean
> sort
= fForwardSort
;
559 if ((direction
== -1) && (currentNode
.getBackComparator() != null)) {
560 comp
= currentNode
.getBackComparator();
561 sort
= fBackwardSort
;
564 if (i
< fNodes
.get(nodeType
).size() - 1) {
565 GraphNode next
= fNodes
.get(nodeType
).get(i
+ 1);
567 if ((comp
!= null) && (comp
.compare(currentNode
, next
) > 0)) {
568 sort
.put(nodeType
, Boolean
.TRUE
);
571 if (direction
== 1) {
572 if (fNodes
.get(nodeType
).get(i
).positiveDistanceToPoint(x
, y
)) {
576 if (currentNode
.getBackComparator() == null) {
577 if // (currentNode.isVisible(x,y,width,height)
578 (!currentNode
.positiveDistanceToPoint(x
, y
)) {
582 if (currentNode
.isVisible(x
, y
, width
, height
) && !currentNode
.positiveDistanceToPoint(x
, y
)) {
583 if ((comp
!= null) && (comp
.compare(currentNode
, prev
) <= 0)) {
586 } else if ((comp
!= null) && (comp
.compare(currentNode
, prev
) <= 0)) {
593 fNodes
.put(nodeType
, fForwardNodes
.get(nodeType
));
594 if ((fBackwardNodes
.get(nodeType
) != null) && (direction
== -1)) {
595 // nodes.put(nodeType,fnodes.get(nodeType));
596 int index
= fIndexes
.get(nodeType
).intValue();
597 List
<GraphNode
> list
= fNodes
.get(nodeType
);
598 List
<GraphNode
> backList
= fBackwardNodes
.get(nodeType
);
599 GraphNode currentNode
= (backList
.get(index
));
601 index
= Arrays
.binarySearch(list
.toArray(new GraphNode
[list
.size()]), backList
.get(index
), currentNode
.getComparator());
605 fIndexes
.put(nodeType
, Integer
.valueOf(index
));
609 for (int i
= drawIndex
; i
< fNodes
.get(nodeType
).size() && i
>= 0; i
++) {
610 GraphNode toDraw
= fNodes
.get(nodeType
).get(i
);
611 toDraw
.updateIndex(x
, y
, width
, height
);
612 if (!toDraw
.isVisible(x
, y
, width
, height
)) {
617 if (TmfUiTracer
.isIndexTraced()) {
618 TmfUiTracer
.traceIndex("First drawn " + nodeType
+ " index = " + drawIndex
+ "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
619 TmfUiTracer
.traceIndex(nodeType
+ " found in " + 0 + " iterations\n"); //$NON-NLS-1$ //$NON-NLS-2$
623 if (TmfUiTracer
.isIndexTraced()) {
624 TmfUiTracer
.traceIndex("*****************************\n"); //$NON-NLS-1$
629 * Draws the children nodes on the given context.<br>
630 * This method start width GraphNodes ordering if needed.<br>
631 * After, depending on the visible area, only visible GraphNodes are drawn.<br>
633 * @param context the context to draw to
634 * @see org.eclipse.tracecompass.tmf.ui.views.uml2sd.core.GraphNode#draw(IGC)
636 protected void drawChildenNodes(IGC context
) {
641 // If the nodes have not been added ordered, the array is ordered
642 Iterator
<String
> it
= fForwardSort
.keySet().iterator();
643 while (it
.hasNext()) {
644 String nodeType
= it
.next();
645 boolean sort
= fForwardSort
.get(nodeType
).booleanValue();
647 GraphNode
[] temp
= fForwardNodes
.get(nodeType
).toArray(new GraphNode
[fForwardNodes
.get(nodeType
).size()]);
648 GraphNode node
= fNodes
.get(nodeType
).get(0);
649 Arrays
.sort(temp
, node
.getComparator());
650 fForwardSort
.put(nodeType
, Boolean
.FALSE
);
651 fNodes
.put(nodeType
, Arrays
.asList(temp
));
652 fForwardNodes
.put(nodeType
, Arrays
.asList(temp
));
653 if (TmfUiTracer
.isSortingTraced()) {
654 TmfUiTracer
.traceSorting(nodeType
+ " array sorted\n"); //$NON-NLS-1$
659 Iterator
<String
> it2
= fBackwardSort
.keySet().iterator();
660 while (it2
.hasNext()) {
661 String nodeType
= it2
.next();
662 boolean sort
= fBackwardSort
.get(nodeType
).booleanValue();
664 GraphNode
[] temp
= fBackwardNodes
.get(nodeType
).toArray(new GraphNode
[fBackwardNodes
.get(nodeType
).size()]);
665 GraphNode node
= fNodes
.get(nodeType
).get(0);
666 Arrays
.sort(temp
, node
.getBackComparator());
667 fBackwardSort
.put(nodeType
, Boolean
.FALSE
);
668 fBackwardNodes
.put(nodeType
, Arrays
.asList(temp
));
669 if (TmfUiTracer
.isSortingTraced()) {
670 TmfUiTracer
.traceSorting(nodeType
+ " back array sorted\n"); //$NON-NLS-1$
675 if (TmfUiTracer
.isDisplayTraced()) {
676 TmfUiTracer
.traceDisplay("*****************************\n"); //$NON-NLS-1$
680 if ((Metrics
.getMessageFontHeigth() + Metrics
.MESSAGES_NAME_SPACING
* 2) * context
.getZoom() < Metrics
.MESSAGE_SIGNIFICANT_VSPACING
) {
681 arrayStep
= Math
.round(Metrics
.MESSAGE_SIGNIFICANT_VSPACING
/ ((Metrics
.getMessageFontHeigth() + Metrics
.MESSAGES_NAME_SPACING
* 2) * context
.getZoom()));
685 Iterator
<String
> it3
= fForwardSort
.keySet().iterator();
686 while (it3
.hasNext()) {
688 Object nodeType
= it3
.next();
689 GraphNode node
= fNodes
.get(nodeType
).get(0);
690 context
.setFont(SDViewPref
.getInstance().getFont(node
.fPrefId
));
691 int index
= fIndexes
.get(nodeType
).intValue();
692 count
= drawNodes(context
, fNodes
.get(nodeType
), index
, arrayStep
);
693 if (TmfUiTracer
.isDisplayTraced()) {
694 TmfUiTracer
.traceDisplay(count
+ " " + nodeType
+ " drawn, starting from index " + index
+ "\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
697 if (TmfUiTracer
.isDisplayTraced()) {
698 TmfUiTracer
.traceDisplay("*****************************\n"); //$NON-NLS-1$
704 * Draw the GraphNode stored in the given list, starting at index startIndex with the given step
706 * @param context the context to draw to
707 * @param list the GraphNodes list
708 * @param startIndex the start index
709 * @param step the step to browse the list
710 * @return the number of GraphNodes drawn
712 protected int drawNodes(IGC context
, List
<GraphNode
> list
, int startIndex
, int step
) {
717 GraphNode last
= null;
719 if (list
.size() < 0) {
723 GraphNode node
= list
.get(0);
724 context
.setFont(SDViewPref
.getInstance().getFont(node
.fPrefId
));
725 Comparator
<GraphNode
> comparator
= node
.getComparator();
726 for (int i
= startIndex
; i
< list
.size(); i
= i
+ step
) {
727 GraphNode toDraw
= list
.get(i
);
728 if (i
< list
.size() - 1) {
729 GraphNode next
= list
.get(i
+ 1);
730 if ((comparator
!= null) && (comparator
.compare(toDraw
, next
) > 0)) {
731 fForwardSort
.put(next
.getArrayId(), Boolean
.TRUE
);
734 int cx
= context
.getContentsX();
735 int cy
= context
.getContentsY();
736 int cw
= context
.getVisibleWidth();
737 int ch
= context
.getVisibleHeight();
738 // The arrays should be ordered, no needs to continue for this one
739 if (!toDraw
.isVisible(cx
, cy
, cw
, ch
) && toDraw
.positiveDistanceToPoint(cx
+ cw
, cy
+ ch
)) {
742 // ***Common*** nodes visibility
743 if ((!toDraw
.isSameAs(last
) || toDraw
.isSelected()) && (toDraw
.isVisible(context
.getContentsX(), context
.getContentsY(), context
.getVisibleWidth(), context
.getVisibleHeight()))) {
746 toDraw
.draw(context
);
748 toDraw
.drawFocus(context
);
757 * Draws the focus within the graphical context.
762 public void drawFocus(IGC context
) {
763 context
.drawFocus(getX(), getY(), getWidth(), getHeight());
767 * Determine if the given point (px,py) is contained in the rectangle (x,y,width,height)
769 * @param x the rectangle x coordinate
770 * @param y the rectangle y coordinate
771 * @param width the rectangle width
772 * @param height the rectangle height
773 * @param px the x coordinate of the point to test
774 * @param py the y coordinate of the point to test
775 * @return true if contained false otherwise
777 public static boolean contains(int x
, int y
, int width
, int height
, int px
, int py
) {
780 int locWidth
= width
;
781 int locHeight
= height
;
785 locWidth
= -locWidth
;
789 locY
= locY
+ height
;
790 locHeight
= -locHeight
;
792 return (px
>= locX
) && (py
>= locY
) && ((px
- locX
) <= locWidth
) && ((py
- locY
) <= locHeight
);
796 * Sets the start event occurrence attached to this graphNode.
799 * the start event occurrence attached to the graphNode
801 protected void setStartOccurrence(int occurence
) {
802 fStartEventOccurrence
= occurence
;
806 * Sets the end event occurrence attached to this graphNode
809 * the start event occurrence attached to the graphNode
811 protected void setEndOccurrence(int occurence
) {
812 fEndEventOccurrence
= occurence
;
816 * Sets the color preference id
818 * The color preference id
820 protected void setColorPrefId(String id
) {
825 * Gets the color preference id
826 * @return the color preference id
828 protected String
getColorPrefId() {
833 * @return if node has children or not
835 protected boolean hasChildren() {
840 * Sets the flag indicating where the node has children or not.
842 * if node has children or not
844 protected void hasChildren(boolean hasChildren
) {
845 fHasChilden
= hasChildren
;
848 * Returns a map from node name to graph node.
850 * @return map with children graph bodes
852 protected Map
<String
, List
<GraphNode
>> getNodeMap() {
856 * Returns a map from node name to graph node for forward sorting
858 * @return forward sorting map
860 protected Map
<String
, List
<GraphNode
>> getForwardNodes() {
861 return fForwardNodes
;
864 * Returns a map from node name to graph node for backwards sorting.
866 * @return backwards sorting map
868 protected Map
<String
, List
<GraphNode
>> getBackwardNodes() {
869 return fBackwardNodes
;
872 * Returns a map from node name to index.
874 * @return map with node name to index
876 protected Map
<String
, Integer
> getIndexes() {
881 * Returns a map from node name to sort flag for forwards sorting.
882 * @return a map from node name to sort flag
884 protected Map
<String
, Boolean
> getForwardSortMap() {
888 * Returns a map from node name to flag for backwards sorting.
889 * @return map from node name to flag for backwards sorting.
891 protected Map
<String
, Boolean
> getBackwardSortMap() {
892 return fBackwardSort
;