Mercurial > hg > truffle
comparison visualizer/SelectionCoordinator/src/com/sun/hotspot/igv/selectioncoordinator/SelectionCoordinator.java @ 4512:015fb895586b
Moved visualizer to new directory.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Tue, 07 Feb 2012 22:41:09 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4511:6cb549627941 | 4512:015fb895586b |
---|---|
1 /* | |
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 * | |
23 */ | |
24 | |
25 package com.sun.hotspot.igv.selectioncoordinator; | |
26 | |
27 import com.sun.hotspot.igv.data.ChangedEvent; | |
28 import java.util.Collections; | |
29 import java.util.HashSet; | |
30 import java.util.Set; | |
31 | |
32 /** | |
33 * | |
34 * @author Thomas | |
35 */ | |
36 public class SelectionCoordinator { | |
37 | |
38 private static SelectionCoordinator singleInstance = new SelectionCoordinator(); | |
39 private Set<Object> selectedObjects; | |
40 private Set<Object> highlightedObjects; | |
41 private ChangedEvent<SelectionCoordinator> selectedChangedEvent; | |
42 private ChangedEvent<SelectionCoordinator> highlightedChangedEvent; | |
43 | |
44 public static SelectionCoordinator getInstance() { | |
45 return singleInstance; | |
46 } | |
47 | |
48 private SelectionCoordinator() { | |
49 selectedChangedEvent = new ChangedEvent<>(this); | |
50 highlightedChangedEvent = new ChangedEvent<>(this); | |
51 selectedObjects = new HashSet<>(); | |
52 highlightedObjects = new HashSet<>(); | |
53 } | |
54 | |
55 public Set<Object> getSelectedObjects() { | |
56 return Collections.unmodifiableSet(selectedObjects); | |
57 } | |
58 | |
59 public Set<Object> getHighlightedObjects() { | |
60 return Collections.unmodifiableSet(highlightedObjects); | |
61 } | |
62 | |
63 public ChangedEvent<SelectionCoordinator> getHighlightedChangedEvent() { | |
64 return highlightedChangedEvent; | |
65 } | |
66 | |
67 public ChangedEvent<SelectionCoordinator> getSelectedChangedEvent() { | |
68 return selectedChangedEvent; | |
69 } | |
70 | |
71 public void addHighlighted(Object o) { | |
72 if (!highlightedObjects.contains(o)) { | |
73 highlightedObjects.add(o); | |
74 highlightedObjectsChanged(); | |
75 } | |
76 } | |
77 | |
78 public void removeHighlighted(Object o) { | |
79 if (highlightedObjects.contains(o)) { | |
80 highlightedObjects.remove(o); | |
81 highlightedObjectsChanged(); | |
82 } | |
83 } | |
84 | |
85 public void addAllHighlighted(Set<? extends Object> s) { | |
86 int oldSize = highlightedObjects.size(); | |
87 highlightedObjects.addAll(s); | |
88 if (oldSize != highlightedObjects.size()) { | |
89 highlightedObjectsChanged(); | |
90 } | |
91 } | |
92 | |
93 public void removeAllHighlighted(Set<? extends Object> s) { | |
94 int oldSize = highlightedObjects.size(); | |
95 highlightedObjects.removeAll(s); | |
96 if (oldSize != highlightedObjects.size()) { | |
97 highlightedObjectsChanged(); | |
98 } | |
99 } | |
100 | |
101 private void highlightedObjectsChanged() { | |
102 highlightedChangedEvent.fire(); | |
103 } | |
104 | |
105 public void addAllSelected(Set<? extends Object> s) { | |
106 int oldSize = selectedObjects.size(); | |
107 selectedObjects.addAll(s); | |
108 if (oldSize != selectedObjects.size()) { | |
109 selectedObjectsChanged(); | |
110 } | |
111 } | |
112 | |
113 public void removeAllSelected(Set<? extends Object> s) { | |
114 int oldSize = selectedObjects.size(); | |
115 selectedObjects.removeAll(s); | |
116 if (oldSize != selectedObjects.size()) { | |
117 selectedObjectsChanged(); | |
118 } | |
119 } | |
120 | |
121 public void setSelectedObjects(Set<? extends Object> s) { | |
122 assert s != null; | |
123 selectedObjects.clear(); | |
124 selectedObjects.addAll(s); | |
125 selectedObjectsChanged(); | |
126 } | |
127 | |
128 private void selectedObjectsChanged() { | |
129 selectedChangedEvent.fire(); | |
130 } | |
131 | |
132 public void setHighlightedObjects(Set<? extends Object> s) { | |
133 assert s != null; | |
134 this.highlightedObjects.clear(); | |
135 this.highlightedObjects.addAll(s); | |
136 highlightedObjectsChanged(); | |
137 } | |
138 } |