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 private static final String UI_DELIMITER
= "*****************************\n"; //$NON-NLS-1$
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
41 * The start event occurrence.
43 private int fStartEventOccurrence
= 0;
45 * The event event occurrence.
47 private int fEndEventOccurrence
= 0;
49 * Preference ColorId to use to draw font
51 private String fPrefId
= ISDPreferences
.PREF_SYNC_MESS
;
53 * The selection state of the graph node.
55 private boolean fSelected
= false;
57 * The focus state of the graph node.
59 private boolean fFocused
= false;
61 * Flag to indicate whether node has children or not.
63 private boolean fHasChilden
= false;
65 * The graph node name used to label the graph node in the View.
67 private String fName
= ""; //$NON-NLS-1$
69 * A map from node name to graph node.
71 private Map
<String
, List
<GraphNode
>> fNodes
;
73 * A map from node name to graph node for forward sorting
75 private Map
<String
, List
<GraphNode
>> fForwardNodes
;
77 * A map from node name to graph node for backwards sorting.
79 private Map
<String
, List
<GraphNode
>> fBackwardNodes
;
81 * A map from node name to index.
83 private Map
<String
, Integer
> fIndexes
;
85 * A map from node name to flag for forwards sorting.
87 private Map
<String
, Boolean
> fForwardSort
;
89 * A map from node name to flag for backwards sorting.
91 private 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
<>(2);
120 fForwardNodes
= new HashMap
<>(2);
121 fBackwardNodes
= new HashMap
<>(2);
122 fIndexes
= new HashMap
<>(2);
123 fBackwardSort
= new HashMap
<>(2);
124 fForwardSort
= new HashMap
<>(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
= fForwardNodes
.get(nodeToAdd
.getArrayId());
145 List
<GraphNode
> bNodeList
= null;
146 if (fBackwardNodes
!= null) {
147 bNodeList
= 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
= 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
<>();
167 fNodeList
.add(nodeToAdd
);
168 fNodes
.put(nodeToAdd
.getArrayId(), fNodeList
);
169 fForwardNodes
.put(nodeToAdd
.getArrayId(), fNodeList
);
170 if ((bNodeList
!= null) && (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.tracecompass.tmf.ui.views.uml2sd.SDWidget#addSelection(GraphNode)
202 * @see org.eclipse.tracecompass.tmf.ui.views.uml2sd.SDWidget#removeSelection(GraphNode)
203 * @see org.eclipse.tracecompass.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.tracecompass.tmf.ui.views.uml2sd.SDWidget#addSelection(GraphNode)
216 * @see org.eclipse.tracecompass.tmf.ui.views.uml2sd.SDWidget#removeSelection(GraphNode)
217 * @see org.eclipse.tracecompass.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 focused, false otherwise
240 public boolean hasFocus() {
245 * Returns true if the graph node contains the point given in parameter,
246 * return false otherwise.
249 * the x coordinate of the point to test containment
251 * the y coordinate of the point to test containment
252 * @return true if contained, false otherwise
254 public abstract boolean contains(int x
, int y
);
257 * Returns the x coordinate of the graph node
259 * @return the x coordinate
261 public abstract int getX();
264 * Returns the y coordinate of the graph node
266 * @return the y coordinate
268 public abstract int getY();
271 * Returns the graph node height
273 * @return the graph node height
275 public abstract int getHeight();
278 * Returns the graph node width
280 * @return the graph node width
282 public abstract int getWidth();
285 * Draws the graph node in the given context
287 * @param context the graphical context to draw in
289 protected abstract void draw(IGC context
);
292 * Returns the GraphNode visibility for the given visible area. Wrong
293 * visibility calculation, may strongly impact drawing performance
300 * The width of the area
302 * The height of the area
303 * @return true if visible, false otherwise
305 public boolean isVisible(int x
, int y
, int width
, int height
) {
310 * Return a comparator to sort the GraphNode of the same type This
311 * comparator is used to order the GraphNode array of the given node type.
314 * @return the comparator
316 public Comparator
<GraphNode
> getComparator() {
321 * If needed, return a different comparator to backward scan the GraphNode
324 * @return the backward comparator or null if not needed
326 public Comparator
<GraphNode
> getBackComparator() {
331 * Compare two graphNodes
334 * the node to compare to
335 * @return true if equal false otherwise
337 public boolean isSameAs(GraphNode node
) {
342 * Return the node type for all class instances. This id is used to store the same nodes kind in the same ordered
345 * @return the node type identifier
347 public abstract String
getArrayId();
350 * Return true if the distance from the GraphNode to the given point is positive
352 * @param x the point x coordinate
353 * @param y the point y coordinate
354 * @return true if positive false otherwise
356 public boolean positiveDistanceToPoint(int x
, int y
) {
361 * Returns the graph node which contains the point given in parameter WARNING: Only graph nodes in the current
362 * visible area can be returned
364 * @param x the x coordinate of the point to test
365 * @param y the y coordinate of the point to test
366 * @return the graph node containing the point given in parameter, null otherwise
368 public GraphNode
getNodeAt(int x
, int y
) {
369 GraphNode toReturn
= null;
375 GraphNode node
= null;
376 for (Map
.Entry
<String
, List
<GraphNode
>> entry
: fNodes
.entrySet()) {
377 List
<GraphNode
> list
= entry
.getValue();
378 int index
= fIndexes
.get(entry
.getKey()).intValue();
379 node
= getNodeFromListAt(x
, y
, list
, index
);
380 if (toReturn
== null) {
384 GraphNode internalNode
= node
.getNodeAt(x
, y
);
385 if (internalNode
!= null) {
387 } else if (Math
.abs(node
.getWidth()) < Math
.abs(toReturn
.getWidth()) || Math
.abs(node
.getHeight()) < Math
.abs(toReturn
.getHeight())) {
396 * Gets node list from node A to node B
398 * @param from A from node
399 * @param to A to node
400 * @return the list of nodes
402 public List
<GraphNode
> getNodeList(GraphNode from
, GraphNode to
) {
403 List
<GraphNode
> result
= new ArrayList
<>();
407 } else if (to
!= null) {
411 if ((from
== null) || (to
== null)) {
419 int startX
= Math
.min(from
.getX(), Math
.min(to
.getX(), Math
.min(from
.getX() + from
.getWidth(), to
.getX() + to
.getWidth())));
420 int endX
= Math
.max(from
.getX(), Math
.max(to
.getX(), Math
.max(from
.getX() + from
.getWidth(), to
.getX() + to
.getWidth())));
421 int startY
= Math
.min(from
.getY(), Math
.min(to
.getY(), Math
.min(from
.getY() + from
.getHeight(), to
.getY() + to
.getHeight())));
422 int endY
= Math
.max(from
.getY(), Math
.max(to
.getY(), Math
.max(from
.getY() + from
.getHeight(), to
.getY() + to
.getHeight())));
428 for (Map
.Entry
<String
, List
<GraphNode
>> entry
: fNodes
.entrySet()) {
429 List
<GraphNode
> nodesList
= entry
.getValue();
430 if (nodesList
== null || nodesList
.isEmpty()) {
433 for (int i
= 0; i
< nodesList
.size(); i
++) {
434 GraphNode node
= nodesList
.get(i
);
435 int nw
= node
.getWidth();
436 int nh
= node
.getHeight();
437 int nx
= node
.getX();
438 int ny
= node
.getY();
439 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)) {
442 result
.addAll(node
.getNodeList(from
, to
));
446 if (!result
.contains(to
)) {
453 * Returns the graph node which contains the point given in parameter for the given graph node list and starting the
454 * iteration at the given index<br>
455 * WARNING: Only graph nodes with smaller coordinates than the current visible area can be returned.<br>
457 * @param x the x coordinate of the point to test
458 * @param y the y coordinate of the point to test
459 * @param list the list to search in
460 * @param fromIndex list browsing starting point
461 * @return the graph node containing the point given in parameter, null otherwise
463 protected GraphNode
getNodeFromListAt(int x
, int y
, List
<GraphNode
> list
, int fromIndex
) {
467 for (int i
= fromIndex
; i
< list
.size(); i
++) {
468 GraphNode node
= list
.get(i
);
469 if (node
.contains(x
, y
)) {
477 * Returns the start event occurrence attached to this graphNode.
479 * @return the start event occurrence attached to the graphNode
481 public int getStartOccurrence() {
482 return fStartEventOccurrence
;
486 * Returns the end event occurrence attached to this graphNode
488 * @return the start event occurrence attached to the graphNode
490 public int getEndOccurrence() {
491 return fEndEventOccurrence
;
495 * Computes the index of the first visible GraphNode for each ordered graph node lists depending on the visible area
498 * @param x visible area top left corner x coordinate
499 * @param y visible area top left corner y coordinate
500 * @param width visible area width
501 * @param height visible area height
503 public void updateIndex(int x
, int y
, int width
, int height
) {
507 if(TmfUiTracer
.isIndexTraced()) {
508 TmfUiTracer
.traceIndex(UI_DELIMITER
);
509 TmfUiTracer
.traceIndex("Visible area position in virtual screen (x,y)= " + x
+ " " + y
+ "\n\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
512 for (Map
.Entry
<String
, List
<GraphNode
>> entry
: fNodes
.entrySet()) {
513 String nodeType
= entry
.getKey();
515 int drawIndex
= fIndexes
.get(nodeType
).intValue();
517 * if (x==0) { drawIndex = 0; indexes.put(nodeType,new Integer(drawIndex)); }
519 if ((entry
.getValue() != null) && (entry
.getValue().size() > 1)) {
520 if (entry
.getValue().get(drawIndex
).positiveDistanceToPoint(x
, y
)) {
524 if (drawIndex
== 0) {
528 if ((direction
== -1) && (fBackwardNodes
.get(nodeType
) != null)) {
529 GraphNode currentNode
= entry
.getValue().get(drawIndex
);
530 drawIndex
= Arrays
.binarySearch(fBackwardNodes
.get(nodeType
).toArray(new GraphNode
[fBackwardNodes
.get(nodeType
).size()]),
531 entry
.getValue().get(drawIndex
), currentNode
.getBackComparator());
532 entry
.setValue(fBackwardNodes
.get(nodeType
));
537 entry
.setValue(fBackwardNodes
.get(nodeType
));
540 GraphNode prev
= null;
542 for (int i
= drawIndex
; i
< entry
.getValue().size() && i
>= 0; i
= i
+ direction
) {
544 fIndexes
.put(nodeType
, Integer
.valueOf(i
));
546 GraphNode currentNode
= entry
.getValue().get(i
);
552 Comparator
<GraphNode
> comp
= currentNode
.getComparator();
553 Map
<String
, Boolean
> sort
= fForwardSort
;
555 if ((direction
== -1) && (currentNode
.getBackComparator() != null)) {
556 comp
= currentNode
.getBackComparator();
557 sort
= fBackwardSort
;
560 if (i
< entry
.getValue().size() - 1) {
561 GraphNode next
= entry
.getValue().get(i
+ 1);
563 if ((comp
!= null) && (comp
.compare(currentNode
, next
) > 0)) {
564 sort
.put(nodeType
, Boolean
.TRUE
);
567 if (direction
== 1) {
568 if (entry
.getValue().get(i
).positiveDistanceToPoint(x
, y
)) {
572 if (currentNode
.getBackComparator() == null) {
573 if // (currentNode.isVisible(x,y,width,height)
574 (!currentNode
.positiveDistanceToPoint(x
, y
)) {
578 if (currentNode
.isVisible(x
, y
, width
, height
) && !currentNode
.positiveDistanceToPoint(x
, y
)) {
579 if ((comp
!= null) && (comp
.compare(currentNode
, prev
) <= 0)) {
582 } else if ((comp
!= null) && (comp
.compare(currentNode
, prev
) <= 0)) {
589 entry
.setValue(fForwardNodes
.get(nodeType
));
590 if ((fBackwardNodes
.get(nodeType
) != null) && (direction
== -1)) {
591 // nodes.put(nodeType,fnodes.get(nodeType));
592 int index
= fIndexes
.get(nodeType
).intValue();
593 List
<GraphNode
> list
= entry
.getValue();
594 List
<GraphNode
> backList
= fBackwardNodes
.get(nodeType
);
595 GraphNode currentNode
= (backList
.get(index
));
597 index
= Arrays
.binarySearch(list
.toArray(new GraphNode
[list
.size()]), backList
.get(index
), currentNode
.getComparator());
601 fIndexes
.put(nodeType
, Integer
.valueOf(index
));
605 for (int i
= drawIndex
; i
< entry
.getValue().size() && i
>= 0; i
++) {
606 GraphNode toDraw
= entry
.getValue().get(i
);
607 toDraw
.updateIndex(x
, y
, width
, height
);
608 if (!toDraw
.isVisible(x
, y
, width
, height
)) {
613 if (TmfUiTracer
.isIndexTraced()) {
614 TmfUiTracer
.traceIndex("First drawn " + nodeType
+ " index = " + drawIndex
+ "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
615 TmfUiTracer
.traceIndex(nodeType
+ " found in " + 0 + " iterations\n"); //$NON-NLS-1$ //$NON-NLS-2$
619 if (TmfUiTracer
.isIndexTraced()) {
620 TmfUiTracer
.traceIndex(UI_DELIMITER
);
625 * Draws the children nodes on the given context.<br>
626 * This method start width GraphNodes ordering if needed.<br>
627 * After, depending on the visible area, only visible GraphNodes are drawn.<br>
629 * @param context the context to draw to
630 * @see org.eclipse.tracecompass.tmf.ui.views.uml2sd.core.GraphNode#draw(IGC)
632 protected void drawChildenNodes(IGC context
) {
637 // If the nodes have not been added ordered, the array is ordered
638 for (Map
.Entry
<String
, Boolean
> entry
: fForwardSort
.entrySet()) {
639 String nodeType
= entry
.getKey();
640 boolean sort
= entry
.getValue().booleanValue();
642 GraphNode
[] temp
= fForwardNodes
.get(nodeType
).toArray(new GraphNode
[fForwardNodes
.get(nodeType
).size()]);
643 GraphNode node
= fNodes
.get(nodeType
).get(0);
644 Arrays
.sort(temp
, node
.getComparator());
645 entry
.setValue(Boolean
.FALSE
);
646 fNodes
.put(nodeType
, Arrays
.asList(temp
));
647 fForwardNodes
.put(nodeType
, Arrays
.asList(temp
));
648 if (TmfUiTracer
.isSortingTraced()) {
649 TmfUiTracer
.traceSorting(nodeType
+ " array sorted\n"); //$NON-NLS-1$
654 for (Map
.Entry
<String
, Boolean
> entry
: fBackwardSort
.entrySet()) {
655 String nodeType
= entry
.getKey();
656 boolean sort
= entry
.getValue().booleanValue();
658 GraphNode
[] temp
= fBackwardNodes
.get(nodeType
).toArray(new GraphNode
[fBackwardNodes
.get(nodeType
).size()]);
659 GraphNode node
= fNodes
.get(nodeType
).get(0);
660 Arrays
.sort(temp
, node
.getBackComparator());
661 entry
.setValue(Boolean
.FALSE
);
662 fBackwardNodes
.put(nodeType
, Arrays
.asList(temp
));
663 if (TmfUiTracer
.isSortingTraced()) {
664 TmfUiTracer
.traceSorting(nodeType
+ " back array sorted\n"); //$NON-NLS-1$
669 if (TmfUiTracer
.isDisplayTraced()) {
670 TmfUiTracer
.traceDisplay(UI_DELIMITER
);
674 if ((Metrics
.getMessageFontHeigth() + Metrics
.MESSAGES_NAME_SPACING
* 2) * context
.getZoom() < Metrics
.MESSAGE_SIGNIFICANT_VSPACING
) {
675 arrayStep
= Math
.round(Metrics
.MESSAGE_SIGNIFICANT_VSPACING
/ ((Metrics
.getMessageFontHeigth() + Metrics
.MESSAGES_NAME_SPACING
* 2) * context
.getZoom()));
679 Iterator
<String
> it3
= fForwardSort
.keySet().iterator();
680 while (it3
.hasNext()) {
682 Object nodeType
= it3
.next();
683 GraphNode node
= fNodes
.get(nodeType
).get(0);
684 context
.setFont(SDViewPref
.getInstance().getFont(node
.fPrefId
));
685 int index
= fIndexes
.get(nodeType
).intValue();
686 count
= drawNodes(context
, fNodes
.get(nodeType
), index
, arrayStep
);
687 if (TmfUiTracer
.isDisplayTraced()) {
688 TmfUiTracer
.traceDisplay(count
+ " " + nodeType
+ " drawn, starting from index " + index
+ "\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
691 if (TmfUiTracer
.isDisplayTraced()) {
692 TmfUiTracer
.traceDisplay(UI_DELIMITER
);
698 * Draw the GraphNode stored in the given list, starting at index startIndex with the given step
700 * @param context the context to draw to
701 * @param list the GraphNodes list
702 * @param startIndex the start index
703 * @param step the step to browse the list
704 * @return the number of GraphNodes drawn
706 protected int drawNodes(IGC context
, List
<GraphNode
> list
, int startIndex
, int step
) {
711 GraphNode last
= null;
713 if (list
.isEmpty()) {
717 GraphNode node
= list
.get(0);
718 context
.setFont(SDViewPref
.getInstance().getFont(node
.fPrefId
));
719 Comparator
<GraphNode
> comparator
= node
.getComparator();
720 for (int i
= startIndex
; i
< list
.size(); i
= i
+ step
) {
721 GraphNode toDraw
= list
.get(i
);
722 if (i
< list
.size() - 1) {
723 GraphNode next
= list
.get(i
+ 1);
724 if ((comparator
!= null) && (comparator
.compare(toDraw
, next
) > 0)) {
725 fForwardSort
.put(next
.getArrayId(), Boolean
.TRUE
);
728 int cx
= context
.getContentsX();
729 int cy
= context
.getContentsY();
730 int cw
= context
.getVisibleWidth();
731 int ch
= context
.getVisibleHeight();
732 // The arrays should be ordered, no needs to continue for this one
733 if (!toDraw
.isVisible(cx
, cy
, cw
, ch
) && toDraw
.positiveDistanceToPoint(cx
+ cw
, cy
+ ch
)) {
736 // ***Common*** nodes visibility
737 if ((!toDraw
.isSameAs(last
) || toDraw
.isSelected()) && (toDraw
.isVisible(context
.getContentsX(), context
.getContentsY(), context
.getVisibleWidth(), context
.getVisibleHeight()))) {
740 toDraw
.draw(context
);
742 toDraw
.drawFocus(context
);
751 * Draws the focus within the graphical context.
756 public void drawFocus(IGC context
) {
757 context
.drawFocus(getX(), getY(), getWidth(), getHeight());
761 * Determine if the given point (px,py) is contained in the rectangle (x,y,width,height)
763 * @param x the rectangle x coordinate
764 * @param y the rectangle y coordinate
765 * @param width the rectangle width
766 * @param height the rectangle height
767 * @param px the x coordinate of the point to test
768 * @param py the y coordinate of the point to test
769 * @return true if contained false otherwise
771 public static boolean contains(int x
, int y
, int width
, int height
, int px
, int py
) {
774 int locWidth
= width
;
775 int locHeight
= height
;
779 locWidth
= -locWidth
;
783 locY
= locY
+ height
;
784 locHeight
= -locHeight
;
786 return (px
>= locX
) && (py
>= locY
) && ((px
- locX
) <= locWidth
) && ((py
- locY
) <= locHeight
);
790 * Sets the start event occurrence attached to this graphNode.
793 * the start event occurrence attached to the graphNode
795 protected void setStartOccurrence(int occurence
) {
796 fStartEventOccurrence
= occurence
;
800 * Sets the end event occurrence attached to this graphNode
803 * the start event occurrence attached to the graphNode
805 protected void setEndOccurrence(int occurence
) {
806 fEndEventOccurrence
= occurence
;
810 * Sets the color preference id
812 * The color preference id
814 protected void setColorPrefId(String id
) {
819 * Gets the color preference id
820 * @return the color preference id
822 protected String
getColorPrefId() {
827 * @return if node has children or not
829 protected boolean hasChildren() {
834 * Sets the flag indicating where the node has children or not.
836 * if node has children or not
838 protected void hasChildren(boolean hasChildren
) {
839 fHasChilden
= hasChildren
;
842 * Returns a map from node name to graph node.
844 * @return map with children graph bodes
846 protected Map
<String
, List
<GraphNode
>> getNodeMap() {
850 * Returns a map from node name to graph node for forward sorting
852 * @return forward sorting map
854 protected Map
<String
, List
<GraphNode
>> getForwardNodes() {
855 return fForwardNodes
;
858 * Returns a map from node name to graph node for backwards sorting.
860 * @return backwards sorting map
862 protected Map
<String
, List
<GraphNode
>> getBackwardNodes() {
863 return fBackwardNodes
;
866 * Returns a map from node name to index.
868 * @return map with node name to index
870 protected Map
<String
, Integer
> getIndexes() {
875 * Returns a map from node name to sort flag for forwards sorting.
876 * @return a map from node name to sort flag
878 protected Map
<String
, Boolean
> getForwardSortMap() {
882 * Returns a map from node name to flag for backwards sorting.
883 * @return map from node name to flag for backwards sorting.
885 protected Map
<String
, Boolean
> getBackwardSortMap() {
886 return fBackwardSort
;