001 /**
002 * Created by IntelliJ IDEA.
003 * User: Wei Wang
004 * Date: Nov 27, 2002
005 * Time: 5:00:08 PM
006 */
007
008 package EVolve.visualization.XYViz.ValRefViz.HotSpotViz;
009
010 import EVolve.visualization.XYViz.ValRefViz.ValueReferenceVisualization;
011 import EVolve.visualization.*;
012 import EVolve.Scene;
013 import EVolve.data.Element;
014 import javax.swing.*;
015 import java.util.*;
016 import java.awt.*;
017 import java.awt.event.*;
018
019 public class HotSpotVisualization extends ValueReferenceVisualization {
020 protected JTextField textInterval; // input for interval
021 protected JPanel configurationPanel;
022 private JMenuItem itemSelectTimeFrame, itemSelectOccurredEntities, itemSelectAllEntities;
023 protected static JMenuItem selectionMenu[] = null;
024 protected static int SELECT_OPTION = 0x0101;
025
026 public HotSpotVisualization() {
027 interval = 1000;
028 }
029
030 protected JPanel createConfigurationPanel() {
031 JPanel panelBottom = new JPanel(new FlowLayout());
032 panelBottom.add(new JLabel("Interval: "));
033
034 textInterval = new JTextField(String.valueOf(interval), 10);
035 panelBottom.add(textInterval);
036 if (configurationPanel == null)
037 configurationPanel = new JPanel(new FlowLayout());
038 configurationPanel.add(panelBottom);
039
040 return configurationPanel;
041 }
042
043 public void preVisualize() {
044 xMax = 0;
045 eventCounter = new ArrayList();
046 imageMap.clear();
047 threadFilter.preVisualize();
048 currentThread = -1;
049 image = new AutoImage();
050 xOffset = -1;
051 installPainter();
052 }
053
054 public void receiveElement(Element element) {
055 if (element.getField()[element.getField().length-1] == Integer.MAX_VALUE)
056 return;
057 int x = xAxis.getField(element);
058 int y = yAxis.getField(element);
059 int z = 0;
060 paint(x,y,z);
061 }
062
063 public void visualize() {
064 sort();
065 }
066
067 public void makeSelection() {
068 if (SELECT_OPTION == 0) {
069 Scene.showErrorMessage("No data is to be selected.");
070 return;
071 }
072
073 int x1 = ((AxesPanel)panel).getStartX();
074 int x2 = ((AxesPanel)panel).getEndX();
075 int y1 = ((AxesPanel)panel).getEndY();
076 int y2 = ((AxesPanel)panel).getStartY();
077
078 if (!normalOrientation) {
079 int temp;
080 temp = x1;
081 x1 = y1;
082 y1 = temp;
083 temp = x2;
084 x2 = y2;
085 y2 = temp;
086 }
087
088 if (x1 < 0) {
089 x1 = 0;
090 }
091
092 if (x2 > (eventCounter.size() - 1)) {
093 x2 = eventCounter.size() - 1;
094 }
095
096 if (y1 < 0) {
097 y1 = 0;
098 }
099
100 if (y2 > (yAxis.getEntityNumber() - 1)) {
101 y2 = yAxis.getEntityNumber() - 1;
102 }
103
104 int start = ((Integer)eventCounter.get(x1)).intValue();
105 int end = ((Integer)eventCounter.get(x2)).intValue();
106 if ((SELECT_OPTION & 0x000f) == 0) { // do not select time frame
107 start = 0;
108 end = Integer.MAX_VALUE;
109 }
110
111 int[] selection = null;
112 switch (SELECT_OPTION & 0x0ff0) {
113 case 0x0100: // select all entities in the draw box
114 selection = new int[y2 - y1 + 1];
115 for (int i = y1; i <= y2; i++) {
116 selection[i - y1] = i;
117 }
118 break;
119 case 0x0010: // select occurred entities
120 ArrayList idList = new ArrayList();
121 for (int i=y1; i<=y2; i++) {
122 for (int j=x1; j<=x2; j++) {
123 Color color;
124 if (normalOrientation)
125 color = image.getSortedColor(null,yAxis,j,i);
126 else
127 color = image.getSortedColor(yAxis,null,i,j);
128 if (color != null) {
129 idList.add(new Integer(i));
130 break;
131 }
132 }
133 }
134
135 selection = new int[idList.size()];
136 for (int i=0; i<idList.size(); i++) {
137 selection[i] = ((Integer)idList.get(i)).intValue();
138 }
139 break;
140 case 0x0000: // no selection on entities
141 y1 = 0;
142 y2 = yAxis.getEntityNumber() - 1;
143 selection = new int[y2 - y1 + 1];
144 for (int i = y1; i <= y2; i++) {
145 selection[i - y1] = i;
146 }
147 break;
148 }
149
150
151 yAxis.makeSelection(selection, start, end);
152 }
153
154 public void paint(int x, int y, int z) {
155 if (x > xMax) {
156 xMax = x;
157 }
158
159 if (xOffset == -1) xOffset = x/interval;
160
161 x = x/interval;
162
163 painter.paint(image,x-xOffset,y,z);
164
165 while (x >= eventCounter.size()) {
166 eventCounter.add(new Integer(Scene.getEventCounter()));
167 }
168 }
169
170 protected void updateConfiguration() {
171 try {
172 if (autoInterval == -1)
173 interval = Integer.parseInt(textInterval.getText());
174 else {
175 interval = autoInterval;
176 autoInterval = -1;
177 textInterval.setText(String.valueOf(interval));
178 }
179 super.updateConfiguration();
180
181 } catch (Exception e) {
182 Scene.showErrorMessage("Interval must be an integer");
183 configure();
184 }
185 }
186
187 public JMenuItem[] createSelectionMenuItem() {
188 if (selectionMenu != null) return selectionMenu;
189
190 itemSelectTimeFrame = new JCheckBoxMenuItem("Time Frame");
191 itemSelectTimeFrame.setMnemonic(KeyEvent.VK_T);
192 itemSelectTimeFrame.addActionListener(new ActionListener() {
193 public void actionPerformed(ActionEvent e) {
194 boolean selected = itemSelectTimeFrame.isSelected();
195 SELECT_OPTION = switchOption(selected, SELECT_OPTION, SELECT_TIME_FRAME);
196 }
197 });
198 itemSelectTimeFrame.setSelected(true);
199
200 itemSelectOccurredEntities = new JCheckBoxMenuItem("Occurred Entities");
201 itemSelectOccurredEntities.setMnemonic(KeyEvent.VK_O);
202 itemSelectOccurredEntities.addActionListener(new ActionListener() {
203 public void actionPerformed(ActionEvent e) {
204 boolean selected = itemSelectOccurredEntities.isSelected();
205 SELECT_OPTION = switchOption(selected,SELECT_OPTION, SELECT_OCCURRED_ENTITIES);
206
207 if (itemSelectAllEntities.isSelected() && selected) {
208 SELECT_OPTION = switchOption(false,SELECT_OPTION, SELECT_ALL_ENTITIES);
209 itemSelectAllEntities.setSelected(false);
210 }
211 }
212 });
213 itemSelectOccurredEntities.setSelected(false);
214
215 itemSelectAllEntities = new JCheckBoxMenuItem("All Entities");
216 itemSelectAllEntities.setMnemonic(KeyEvent.VK_A);
217 itemSelectAllEntities.addActionListener(new ActionListener() {
218 public void actionPerformed(ActionEvent e) {
219 boolean selected = itemSelectAllEntities.isSelected();
220 SELECT_OPTION = switchOption(selected, SELECT_OPTION, SELECT_ALL_ENTITIES);
221
222 if (itemSelectOccurredEntities.isSelected() && selected) {
223 SELECT_OPTION = switchOption(false,SELECT_OPTION, SELECT_OCCURRED_ENTITIES);
224 itemSelectOccurredEntities.setSelected(false);
225 }
226 }
227 });
228 itemSelectAllEntities.setSelected(true);
229
230 selectionMenu = new JMenuItem[3];
231 selectionMenu[0] = itemSelectTimeFrame;
232 selectionMenu[1] = itemSelectOccurredEntities;
233 selectionMenu[2] = itemSelectAllEntities;
234
235 return selectionMenu;
236 }
237 }