tmf: Delete unused code in GraphNode
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / views / uml2sd / core / GraphNode.java
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
7 *
8 * Contributors:
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
12
13 package org.eclipse.tracecompass.tmf.ui.views.uml2sd.core;
14
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;
21 import java.util.Map;
22
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;
27
28 /**
29 * The base class used for all UML2 graph nodes displayed in the Sequence Diagram SDWidget.
30 *
31 * @author sveyrier
32 * @version 1.0
33 */
34 public abstract class GraphNode {
35
36 private static final String UI_DELIMITER = "*****************************\n"; //$NON-NLS-1$
37 // ------------------------------------------------------------------------
38 // Attributes
39 // ------------------------------------------------------------------------
40 /**
41 * The start event occurrence.
42 */
43 private int fStartEventOccurrence = 0;
44 /**
45 * The event event occurrence.
46 */
47 private int fEndEventOccurrence = 0;
48 /**
49 * Preference ColorId to use to draw font
50 */
51 private String fPrefId = ISDPreferences.PREF_SYNC_MESS;
52 /**
53 * The selection state of the graph node.
54 */
55 private boolean fSelected = false;
56 /**
57 * The focus state of the graph node.
58 */
59 private boolean fFocused = false;
60 /**
61 * Flag to indicate whether node has children or not.
62 */
63 private boolean fHasChilden = false;
64 /**
65 * The graph node name used to label the graph node in the View.
66 */
67 private String fName = ""; //$NON-NLS-1$
68 /**
69 * A map from node name to graph node.
70 */
71 private Map<String, List<GraphNode>> fNodes;
72 /**
73 * A map from node name to graph node for forward sorting
74 */
75 private Map<String, List<GraphNode>> fForwardNodes;
76 /**
77 * A map from node name to graph node for backwards sorting.
78 */
79 private Map<String, List<GraphNode>> fBackwardNodes;
80 /**
81 * A map from node name to index.
82 */
83 private Map<String, Integer> fIndexes;
84 /**
85 * A map from node name to flag for forwards sorting.
86 */
87 private Map<String, Boolean> fForwardSort;
88 /**
89 * A map from node name to flag for backwards sorting.
90 */
91 private Map<String, Boolean> fBackwardSort;
92
93 // ------------------------------------------------------------------------
94 // Methods
95 // ------------------------------------------------------------------------
96
97 /**
98 * Reset the internal index of the first visible GraphNode for each ordered GraphNode lists
99 */
100 public void resetIndex() {
101 if (!fHasChilden) {
102 return;
103 }
104
105 Iterator<String> it = fIndexes.keySet().iterator();
106 while (it.hasNext()) {
107 String nodeType = it.next();
108 fIndexes.put(nodeType, Integer.valueOf(0));
109 }
110 }
111
112 /**
113 * Add a GraphNode into the receiver
114 *
115 * @param nodeToAdd the node to add
116 */
117 public void addNode(GraphNode nodeToAdd) {
118 if (!fHasChilden) {
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);
125 fHasChilden = true;
126 }
127
128 // Nothing to add
129 if (nodeToAdd == null) {
130 return;
131 }
132
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);
141 }
142 }
143
144 List<GraphNode> fNodeList = fForwardNodes.get(nodeToAdd.getArrayId());
145 List<GraphNode> bNodeList = null;
146 if (fBackwardNodes != null) {
147 bNodeList = fBackwardNodes.get(nodeToAdd.getArrayId());
148 }
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);
157 }
158 if ((bcomp != null) && (bcomp.compare(node, nodeToAdd) > 0)) {
159 fBackwardSort.put(nodeToAdd.getArrayId(), Boolean.TRUE);
160 }
161 }
162
163 if (fNodeList == null) {
164 fNodeList = new ArrayList<>();
165 }
166
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);
173 }
174 }
175
176 /**
177 * Set the graph node name.<br>
178 * It is the name display in the view to label the graph node.
179 *
180 * @param nodeName the name to set
181 */
182 public void setName(String nodeName) {
183 fName = nodeName;
184 }
185
186 /**
187 * Returns the graph node name.<br>
188 * It is the name display in the view to label the graph node.
189 *
190 * @return the graph node name
191 */
192 public String getName() {
193 return fName;
194 }
195
196 /**
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
200 *
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
205 */
206 public void setSelected(boolean selection) {
207 fSelected = selection;
208 }
209
210 /**
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
214 *
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
219 */
220 public void setFocused(boolean focus) {
221 fFocused = focus;
222 }
223
224 /**
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.
227 *
228 * @return true if selected, false otherwise
229 */
230 public boolean isSelected() {
231 return fSelected;
232 }
233
234 /**
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.
237 *
238 * @return true if focused, false otherwise
239 */
240 public boolean hasFocus() {
241 return fFocused;
242 }
243
244 /**
245 * Returns true if the graph node contains the point given in parameter,
246 * return false otherwise.
247 *
248 * @param x
249 * the x coordinate of the point to test containment
250 * @param y
251 * the y coordinate of the point to test containment
252 * @return true if contained, false otherwise
253 */
254 public abstract boolean contains(int x, int y);
255
256 /**
257 * Returns the x coordinate of the graph node
258 *
259 * @return the x coordinate
260 */
261 public abstract int getX();
262
263 /**
264 * Returns the y coordinate of the graph node
265 *
266 * @return the y coordinate
267 */
268 public abstract int getY();
269
270 /**
271 * Returns the graph node height
272 *
273 * @return the graph node height
274 */
275 public abstract int getHeight();
276
277 /**
278 * Returns the graph node width
279 *
280 * @return the graph node width
281 */
282 public abstract int getWidth();
283
284 /**
285 * Draws the graph node in the given context
286 *
287 * @param context the graphical context to draw in
288 */
289 protected abstract void draw(IGC context);
290
291 /**
292 * Returns the GraphNode visibility for the given visible area. Wrong
293 * visibility calculation, may strongly impact drawing performance
294 *
295 * @param x
296 * The X coordinate
297 * @param y
298 * The Y coordinate
299 * @param width
300 * The width of the area
301 * @param height
302 * The height of the area
303 * @return true if visible, false otherwise
304 */
305 public boolean isVisible(int x, int y, int width, int height) {
306 return true;
307 }
308
309 /**
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.
312 * (see getArrayId).
313 *
314 * @return the comparator
315 */
316 public Comparator<GraphNode> getComparator() {
317 return null;
318 }
319
320 /**
321 * If needed, return a different comparator to backward scan the GraphNode
322 * array
323 *
324 * @return the backward comparator or null if not needed
325 */
326 public Comparator<GraphNode> getBackComparator() {
327 return null;
328 }
329
330 /**
331 * Compare two graphNodes
332 *
333 * @param node
334 * the node to compare to
335 * @return true if equal false otherwise
336 */
337 public boolean isSameAs(GraphNode node) {
338 return false;
339 }
340
341 /**
342 * Return the node type for all class instances. This id is used to store the same nodes kind in the same ordered
343 * array.
344 *
345 * @return the node type identifier
346 */
347 public abstract String getArrayId();
348
349 /**
350 * Return true if the distance from the GraphNode to the given point is positive
351 *
352 * @param x the point x coordinate
353 * @param y the point y coordinate
354 * @return true if positive false otherwise
355 */
356 public boolean positiveDistanceToPoint(int x, int y) {
357 return false;
358 }
359
360 /**
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
363 *
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
367 */
368 public GraphNode getNodeAt(int x, int y) {
369 GraphNode toReturn = null;
370
371 if (!fHasChilden) {
372 return null;
373 }
374
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) {
381 toReturn = node;
382 }
383 if (node != null) {
384 GraphNode internalNode = node.getNodeAt(x, y);
385 if (internalNode != null) {
386 return internalNode;
387 } else if (Math.abs(node.getWidth()) < Math.abs(toReturn.getWidth()) || Math.abs(node.getHeight()) < Math.abs(toReturn.getHeight())) {
388 toReturn = node;
389 }
390 }
391 }
392 return toReturn;
393 }
394
395 /**
396 * Gets node list from node A to node B
397
398 * @param from A from node
399 * @param to A to node
400 * @return the list of nodes
401 */
402 public List<GraphNode> getNodeList(GraphNode from, GraphNode to) {
403 List<GraphNode> result = new ArrayList<>();
404
405 if (from != null) {
406 result.add(from);
407 } else if (to != null) {
408 result.add(to);
409 }
410
411 if ((from == null) || (to == null)) {
412 return result;
413 }
414
415 if (from == to) {
416 return result;
417 }
418
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())));
423
424 if (!fHasChilden) {
425 return result;
426 }
427
428 for (Map.Entry<String, List<GraphNode>> entry : fNodes.entrySet()) {
429 List<GraphNode> nodesList = entry.getValue();
430 if (nodesList == null || nodesList.isEmpty()) {
431 return null;
432 }
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)) {
440 result.add(node);
441 }
442 result.addAll(node.getNodeList(from, to));
443 }
444 }
445
446 if (!result.contains(to)) {
447 result.add(to);
448 }
449 return result;
450 }
451
452 /**
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>
456 *
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
462 */
463 protected GraphNode getNodeFromListAt(int x, int y, List<GraphNode> list, int fromIndex) {
464 if (list == null) {
465 return null;
466 }
467 for (int i = fromIndex; i < list.size(); i++) {
468 GraphNode node = list.get(i);
469 if (node.contains(x, y)) {
470 return node;
471 }
472 }
473 return null;
474 }
475
476 /**
477 * Returns the start event occurrence attached to this graphNode.
478 *
479 * @return the start event occurrence attached to the graphNode
480 */
481 public int getStartOccurrence() {
482 return fStartEventOccurrence;
483 }
484
485 /**
486 * Returns the end event occurrence attached to this graphNode
487 *
488 * @return the start event occurrence attached to the graphNode
489 */
490 public int getEndOccurrence() {
491 return fEndEventOccurrence;
492 }
493
494 /**
495 * Computes the index of the first visible GraphNode for each ordered graph node lists depending on the visible area
496 * given in parameter
497 *
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
502 */
503 public void updateIndex(int x, int y, int width, int height) {
504 if (!fHasChilden) {
505 return;
506 }
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$
510 }
511
512 for (Map.Entry<String, List<GraphNode>> entry : fNodes.entrySet()) {
513 String nodeType = entry.getKey();
514 int direction = 1;
515 int drawIndex = fIndexes.get(nodeType).intValue();
516
517 if ((entry.getValue() != null) && (entry.getValue().size() > 1)) {
518 if (entry.getValue().get(drawIndex).positiveDistanceToPoint(x, y)) {
519 direction = -1;
520 }
521
522 if (drawIndex == 0) {
523 direction = 1;
524 }
525
526 if ((direction == -1) && (fBackwardNodes.get(nodeType) != null)) {
527 GraphNode currentNode = entry.getValue().get(drawIndex);
528 drawIndex = Arrays.binarySearch(fBackwardNodes.get(nodeType).toArray(new GraphNode[fBackwardNodes.get(nodeType).size()]),
529 entry.getValue().get(drawIndex), currentNode.getBackComparator());
530 entry.setValue(fBackwardNodes.get(nodeType));
531 if (drawIndex < 0) {
532 drawIndex = 0;
533 direction = 1;
534 } else {
535 entry.setValue(fBackwardNodes.get(nodeType));
536 }
537 }
538 GraphNode prev = null;
539
540 for (int i = drawIndex; i < entry.getValue().size() && i >= 0; i = i + direction) {
541 drawIndex = i;
542 fIndexes.put(nodeType, Integer.valueOf(i));
543
544 GraphNode currentNode = entry.getValue().get(i);
545
546 if (prev == null) {
547 prev = currentNode;
548 }
549
550 Comparator<GraphNode> comp = currentNode.getComparator();
551 Map<String, Boolean> sort = fForwardSort;
552
553 if ((direction == -1) && (currentNode.getBackComparator() != null)) {
554 comp = currentNode.getBackComparator();
555 sort = fBackwardSort;
556 }
557
558 if (i < entry.getValue().size() - 1) {
559 GraphNode next = entry.getValue().get(i + 1);
560
561 if ((comp != null) && (comp.compare(currentNode, next) > 0)) {
562 sort.put(nodeType, Boolean.TRUE);
563 }
564 }
565 if (direction == 1) {
566 if (entry.getValue().get(i).positiveDistanceToPoint(x, y)) {
567 break;
568 }
569 } else {
570 if (currentNode.getBackComparator() == null) {
571 if (!currentNode.positiveDistanceToPoint(x, y)) {
572 break;
573 }
574 } else {
575 if (currentNode.isVisible(x, y, width, height) && !currentNode.positiveDistanceToPoint(x, y)) {
576 if ((comp != null) && (comp.compare(currentNode, prev) <= 0)) {
577 break;
578 }
579 } else if ((comp != null) && (comp.compare(currentNode, prev) <= 0)) {
580 prev = currentNode;
581 }
582 }
583 }
584 }
585
586 entry.setValue(fForwardNodes.get(nodeType));
587 if ((fBackwardNodes.get(nodeType) != null) && (direction == -1)) {
588 int index = fIndexes.get(nodeType).intValue();
589 List<GraphNode> list = entry.getValue();
590 List<GraphNode> backList = fBackwardNodes.get(nodeType);
591 GraphNode currentNode = (backList.get(index));
592 if (index > 0) {
593 index = Arrays.binarySearch(list.toArray(new GraphNode[list.size()]), backList.get(index), currentNode.getComparator());
594 if (index < 0) {
595 index = 0;
596 }
597 fIndexes.put(nodeType, Integer.valueOf(index));
598 }
599 }
600
601 for (int i = drawIndex; i < entry.getValue().size() && i >= 0; i++) {
602 GraphNode toDraw = entry.getValue().get(i);
603 toDraw.updateIndex(x, y, width, height);
604 if (!toDraw.isVisible(x, y, width, height)) {
605 break;
606 }
607 }
608 }
609 if (TmfUiTracer.isIndexTraced()) {
610 TmfUiTracer.traceIndex("First drawn " + nodeType + " index = " + drawIndex + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
611 TmfUiTracer.traceIndex(nodeType + " found in " + 0 + " iterations\n"); //$NON-NLS-1$ //$NON-NLS-2$
612 }
613 }
614
615 if (TmfUiTracer.isIndexTraced()) {
616 TmfUiTracer.traceIndex(UI_DELIMITER);
617 }
618 }
619
620 /**
621 * Draws the children nodes on the given context.<br>
622 * This method start width GraphNodes ordering if needed.<br>
623 * After, depending on the visible area, only visible GraphNodes are drawn.<br>
624 *
625 * @param context the context to draw to
626 * @see org.eclipse.tracecompass.tmf.ui.views.uml2sd.core.GraphNode#draw(IGC)
627 */
628 protected void drawChildenNodes(IGC context) {
629
630 if (!fHasChilden) {
631 return;
632 }
633 // If the nodes have not been added ordered, the array is ordered
634 for (Map.Entry<String, Boolean> entry : fForwardSort.entrySet()) {
635 String nodeType = entry.getKey();
636 boolean sort = entry.getValue().booleanValue();
637 if (sort) {
638 GraphNode[] temp = fForwardNodes.get(nodeType).toArray(new GraphNode[fForwardNodes.get(nodeType).size()]);
639 GraphNode node = fNodes.get(nodeType).get(0);
640 Arrays.sort(temp, node.getComparator());
641 entry.setValue(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$
646 }
647 }
648 }
649
650 for (Map.Entry<String, Boolean> entry : fBackwardSort.entrySet()) {
651 String nodeType = entry.getKey();
652 boolean sort = entry.getValue().booleanValue();
653 if (sort) {
654 GraphNode[] temp = fBackwardNodes.get(nodeType).toArray(new GraphNode[fBackwardNodes.get(nodeType).size()]);
655 GraphNode node = fNodes.get(nodeType).get(0);
656 Arrays.sort(temp, node.getBackComparator());
657 entry.setValue(Boolean.FALSE);
658 fBackwardNodes.put(nodeType, Arrays.asList(temp));
659 if (TmfUiTracer.isSortingTraced()) {
660 TmfUiTracer.traceSorting(nodeType + " back array sorted\n"); //$NON-NLS-1$
661 }
662 }
663 }
664
665 if (TmfUiTracer.isDisplayTraced()) {
666 TmfUiTracer.traceDisplay(UI_DELIMITER);
667 }
668
669 int arrayStep = 1;
670 if ((Metrics.getMessageFontHeigth() + Metrics.MESSAGES_NAME_SPACING * 2) * context.getZoom() < Metrics.MESSAGE_SIGNIFICANT_VSPACING) {
671 arrayStep = Math.round(Metrics.MESSAGE_SIGNIFICANT_VSPACING / ((Metrics.getMessageFontHeigth() + Metrics.MESSAGES_NAME_SPACING * 2) * context.getZoom()));
672 }
673
674 int count = 0;
675 Iterator<String> it3 = fForwardSort.keySet().iterator();
676 while (it3.hasNext()) {
677 count = 0;
678 Object nodeType = it3.next();
679 GraphNode node = fNodes.get(nodeType).get(0);
680 context.setFont(SDViewPref.getInstance().getFont(node.fPrefId));
681 int index = fIndexes.get(nodeType).intValue();
682 count = drawNodes(context, fNodes.get(nodeType), index, arrayStep);
683 if (TmfUiTracer.isDisplayTraced()) {
684 TmfUiTracer.traceDisplay(count + " " + nodeType + " drawn, starting from index " + index + "\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
685 }
686 }
687 if (TmfUiTracer.isDisplayTraced()) {
688 TmfUiTracer.traceDisplay(UI_DELIMITER);
689 }
690
691 }
692
693 /**
694 * Draw the GraphNode stored in the given list, starting at index startIndex with the given step
695 *
696 * @param context the context to draw to
697 * @param list the GraphNodes list
698 * @param startIndex the start index
699 * @param step the step to browse the list
700 * @return the number of GraphNodes drawn
701 */
702 protected int drawNodes(IGC context, List<GraphNode> list, int startIndex, int step) {
703 if (!fHasChilden) {
704 return 0;
705 }
706
707 GraphNode last = null;
708 int nodesCount = 0;
709 if (list.isEmpty()) {
710 return 0;
711 }
712
713 GraphNode node = list.get(0);
714 context.setFont(SDViewPref.getInstance().getFont(node.fPrefId));
715 Comparator<GraphNode> comparator = node.getComparator();
716 for (int i = startIndex; i < list.size(); i = i + step) {
717 GraphNode toDraw = list.get(i);
718 if (i < list.size() - 1) {
719 GraphNode next = list.get(i + 1);
720 if ((comparator != null) && (comparator.compare(toDraw, next) > 0)) {
721 fForwardSort.put(next.getArrayId(), Boolean.TRUE);
722 }
723 }
724 int cx = context.getContentsX();
725 int cy = context.getContentsY();
726 int cw = context.getVisibleWidth();
727 int ch = context.getVisibleHeight();
728 // The arrays should be ordered, no needs to continue for this one
729 if (!toDraw.isVisible(cx, cy, cw, ch) && toDraw.positiveDistanceToPoint(cx + cw, cy + ch)) {
730 break;
731 }
732 // ***Common*** nodes visibility
733 if ((!toDraw.isSameAs(last) || toDraw.isSelected()) && (toDraw.isVisible(context.getContentsX(), context.getContentsY(), context.getVisibleWidth(), context.getVisibleHeight()))) {
734 nodesCount++;
735
736 toDraw.draw(context);
737 if (hasFocus()) {
738 toDraw.drawFocus(context);
739 }
740 }
741 last = toDraw;
742 }
743 return nodesCount;
744 }
745
746 /**
747 * Draws the focus within the graphical context.
748 *
749 * @param context
750 * The context
751 */
752 public void drawFocus(IGC context) {
753 context.drawFocus(getX(), getY(), getWidth(), getHeight());
754 }
755
756 /**
757 * Determine if the given point (px,py) is contained in the rectangle (x,y,width,height)
758 *
759 * @param x the rectangle x coordinate
760 * @param y the rectangle y coordinate
761 * @param width the rectangle width
762 * @param height the rectangle height
763 * @param px the x coordinate of the point to test
764 * @param py the y coordinate of the point to test
765 * @return true if contained false otherwise
766 */
767 public static boolean contains(int x, int y, int width, int height, int px, int py) {
768 int locX = x;
769 int locY = y;
770 int locWidth = width;
771 int locHeight = height;
772
773 if (width < 0) {
774 locX = locX + width;
775 locWidth = -locWidth;
776 }
777
778 if (height < 0) {
779 locY = locY + height;
780 locHeight = -locHeight;
781 }
782 return (px >= locX) && (py >= locY) && ((px - locX) <= locWidth) && ((py - locY) <= locHeight);
783 }
784
785 /**
786 * Sets the start event occurrence attached to this graphNode.
787 *
788 * @param occurence
789 * the start event occurrence attached to the graphNode
790 */
791 protected void setStartOccurrence(int occurence) {
792 fStartEventOccurrence = occurence;
793 }
794
795 /**
796 * Sets the end event occurrence attached to this graphNode
797 *
798 * @param occurence
799 * the start event occurrence attached to the graphNode
800 */
801 protected void setEndOccurrence(int occurence) {
802 fEndEventOccurrence = occurence;
803 }
804
805 /**
806 * Sets the color preference id
807 * @param id
808 * The color preference id
809 */
810 protected void setColorPrefId(String id) {
811 fPrefId = id;
812 }
813
814 /**
815 * Gets the color preference id
816 * @return the color preference id
817 */
818 protected String getColorPrefId() {
819 return fPrefId;
820 }
821
822 /**
823 * @return if node has children or not
824 */
825 protected boolean hasChildren() {
826 return fHasChilden;
827 }
828
829 /**
830 * Sets the flag indicating where the node has children or not.
831 * @param hasChildren
832 * if node has children or not
833 */
834 protected void hasChildren(boolean hasChildren) {
835 fHasChilden = hasChildren;
836 }
837 /**
838 * Returns a map from node name to graph node.
839 *
840 * @return map with children graph bodes
841 */
842 protected Map<String, List<GraphNode>> getNodeMap() {
843 return fNodes;
844 }
845 /**
846 * Returns a map from node name to graph node for forward sorting
847 *
848 * @return forward sorting map
849 */
850 protected Map<String, List<GraphNode>> getForwardNodes() {
851 return fForwardNodes;
852 }
853 /**
854 * Returns a map from node name to graph node for backwards sorting.
855 *
856 * @return backwards sorting map
857 */
858 protected Map<String, List<GraphNode>> getBackwardNodes() {
859 return fBackwardNodes;
860 }
861 /**
862 * Returns a map from node name to index.
863 *
864 * @return map with node name to index
865 */
866 protected Map<String, Integer> getIndexes() {
867 return fIndexes;
868 }
869
870 /**
871 * Returns a map from node name to sort flag for forwards sorting.
872 * @return a map from node name to sort flag
873 */
874 protected Map<String, Boolean> getForwardSortMap() {
875 return fForwardSort;
876 }
877 /**
878 * Returns a map from node name to flag for backwards sorting.
879 * @return map from node name to flag for backwards sorting.
880 */
881 protected Map<String, Boolean> getBackwardSortMap() {
882 return fBackwardSort;
883 }
884 }
This page took 0.050873 seconds and 5 git commands to generate.