01: package org.enhydra.jawe.components.graph;
02:
03: import java.util.Comparator;
04:
05: /**
06: * Used to properly sort visual objects that represents Participant's contained within graph.
07: */
08: public class GraphParticipantComparator implements Comparator {
09:
10: GraphManager graphManager;
11:
12: public GraphParticipantComparator(GraphManager graphManager) {
13: this .graphManager = graphManager;
14: }
15:
16: public int compare(Object o1, Object o2) {
17: GraphParticipantInterface p1 = (GraphParticipantInterface) o1;
18: GraphParticipantInterface p2 = (GraphParticipantInterface) o2;
19: int pos1;
20: int pos2;
21: if (!graphManager.isGraphRotated()) {
22: pos1 = graphManager.getBounds(p1, null).y;
23: pos2 = graphManager.getBounds(p2, null).y;
24: } else {
25: pos1 = graphManager.getBounds(p1, null).x;
26: pos2 = graphManager.getBounds(p2, null).x;
27: }
28:
29: return (pos1 < pos2 ? -1 : (pos1 == pos2 ? 0 : 1)); //sort that highest is the first
30: }
31:
32: }
|