1 package edu.psu.geovista.app.scatterplot;
2
3 /***
4 * <p>Title: </p>
5 * <p>Description: </p>
6 * <p>Copyright: Copyright (c) 2001</p>
7 * <p>Company: </p>
8 * @author unascribed
9 * @version 1.0
10 */
11
12 import edu.psu.geovista.classification.*;
13 import edu.psu.geovista.data.geog.*;
14 import edu.psu.geovista.symbolization.*;
15 import edu.psu.geovista.ui.cursor.*;
16 import edu.psu.geovista.ui.event.*;
17
18 import java.awt.*;
19 import java.awt.event.*;
20 import java.util.Vector;
21 import java.net.*;
22
23 import javax.swing.*;
24
25 public class SingleScatterPlot extends JPanel implements DataSetListener, ActionListener,
26 ColorClassifierListener, SelectionListener{
27
28 public static final int VARIABLE_CHOOSER_MODE_ACTIVE = 0;
29 public static final int VARIABLE_CHOOSER_MODE_FIXED = 1;
30 public static final int VARIABLE_CHOOSER_MODE_HIDDEN = 2;
31 transient private ScatterPlot scatterPlot;
32 transient private int[] displayIndices = new int[2];
33 transient private VisualClassifier visClassOne;
34 transient private VisualClassifier visClassTwo;
35 transient private JToolBar mapTools;
36 transient private JPanel topContent;
37 transient private BivariateColorSchemeVisualizer biViz;
38 transient private Color backgroundColor;
39 //transient private Vector selectedObvs;
40 transient private int[] selections;
41 //transient private int[] selectedObvsInt;
42 transient private Color[] multipleSelectionColors;
43 transient private Color[] colorArrays;
44
45 public SingleScatterPlot() {
46 super();
47
48 JPanel vcPanel = new JPanel();
49 vcPanel.setLayout(new BoxLayout(vcPanel, BoxLayout.Y_AXIS));
50 visClassOne = new VisualClassifier();
51 visClassTwo = new VisualClassifier();
52 visClassOne.setAlignmentX(Component.LEFT_ALIGNMENT);
53 visClassTwo.setAlignmentX(Component.LEFT_ALIGNMENT);
54 visClassOne.setVariableChooserMode(
55 ClassifierPicker.VARIABLE_CHOOSER_MODE_ACTIVE);
56 visClassTwo.setVariableChooserMode(
57 ClassifierPicker.VARIABLE_CHOOSER_MODE_ACTIVE);
58 visClassOne.addActionListener(this);
59 visClassTwo.addActionListener(this);
60
61 vcPanel.add(visClassTwo);
62 vcPanel.add(visClassOne);
63
64 JPanel legendPanel = new JPanel();
65 legendPanel.setLayout(new BoxLayout(legendPanel, BoxLayout.X_AXIS));
66 biViz = new BivariateColorSchemeVisualizer();
67 legendPanel.add(vcPanel);
68 legendPanel.add(Box.createRigidArea(new Dimension(4, 2)));
69 legendPanel.add(biViz);
70
71 topContent = new JPanel();
72 topContent.setLayout(new BoxLayout(topContent, BoxLayout.Y_AXIS));
73 legendPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
74 //mapTools.setAlignmentX(Component.LEFT_ALIGNMENT);
75 topContent.add(legendPanel);
76 //topContent.add(mapTools);
77
78 this.setLayout(new BorderLayout());
79 this.add(topContent, BorderLayout.NORTH);
80 scatterPlot = new ScatterPlot();
81 this.scatterPlot.addActionListener(this);
82 this.add(scatterPlot, BorderLayout.CENTER);
83 //this.scatterPlot.addIndicationListener(this);
84 visClassOne.addColorClassifierListener(this);
85 visClassTwo.addColorClassifierListener(this);
86 //this.addIndicationListener(biViz);
87 // this.scatterPlot.addActionListener(new ActionListener() {
88 // /***
89 // * Get the event from a unit plot and send it to all units.
90 // * @param e
91 // */
92 // public void actionPerformed (ActionEvent e) {
93 // // This gets the source or originator of the event
94 // try {
95 // unit_actionPerformed(e);
96 // } catch (Exception exception) {}
97 // }
98 // });
99
100 visClassTwo.setHighColor(new Color(0, 255, 255));
101 }
102
103 public void setDataSet(Object[] data) {
104
105 this.visClassOne.setData(data);
106 this.visClassTwo.setData(data);
107
108 //set default data to get color from
109 DataSetForApps dataSet = new DataSetForApps();
110 dataSet.setDataObject(data);
111 this.scatterPlot.setBackground(Color.white);
112 this.scatterPlot.setDataObject(dataSet.getDataSetNumericAndSpatial());
113 int numNumeric = dataSet.getNumberNumericAttributes();
114 this.selections = new int[dataSet.getNumObservations()];
115
116 displayIndices[0] = 1;
117 displayIndices[1] = 2;
118 this.setXVariable(displayIndices[0]);
119 this.setYVariable(displayIndices[1]);
120 this.scatterPlot.setAxisOn(true);
121 this.scatterPlot.setElementPosition(displayIndices);
122 }
123
124 public void setXVariable(int var) {
125 this.visClassOne.setCurrVariableIndex(var);
126 }
127
128 public void setYVariable(int var) {
129 this.visClassTwo.setCurrVariableIndex(var);
130 }
131 public void setBivarColorClasser(BivariateColorSymbolClassification bivarColorClasser) {
132 this.scatterPlot.setBivarColorClasser(bivarColorClasser, false);
133 }
134
135 public void setBackgroundColor(Color backgroundColor){
136 this.backgroundColor = backgroundColor;
137 }
138
139 public Color getBackgroundColor (){
140 return this.backgroundColor;
141 }
142
143 public void colorClassifierChanged(ColorClassifierEvent e) {
144 if (e.getSource() == this.visClassOne) {
145 e.setOrientation(e.SOURCE_ORIENTATION_X);
146 }
147
148 if (e.getSource() == this.visClassTwo) {
149 e.setOrientation(e.SOURCE_ORIENTATION_Y);
150 }
151
152 this.biViz.colorClassifierChanged(e);
153
154 if (this.scatterPlot == null) {
155 return;
156 }
157
158 //ColorSymbolClassification colorSymbolizer = e.getColorSymbolClassification();
159 //Object src = e.getSource();
160 ColorSymbolClassification colorSymbolizerX = this.visClassOne.getColorClasser();
161 ColorSymbolClassification colorSymbolizerY = this.visClassTwo.getColorClasser();
162
163 BivariateColorSymbolClassificationSimple biColorSymbolizer =
164 new BivariateColorSymbolClassificationSimple();
165
166 biColorSymbolizer.setClasserX(colorSymbolizerX.getClasser());
167 biColorSymbolizer.setColorerX(colorSymbolizerX.getColorer());
168
169 biColorSymbolizer.setClasserY(colorSymbolizerY.getClasser());
170 biColorSymbolizer.setColorerY(colorSymbolizerY.getColorer());
171 this.scatterPlot.setBivarColorClasser(biColorSymbolizer, false);
172 //this.colorArrays = this.scatterPlot.getColors();
173 }
174
175 public void dataSetChanged(DataSetEvent e) {
176 this.setDataSet(e.getDataSet());
177 }
178
179 public void actionPerformed(ActionEvent e) {
180 Object src = e.getSource();
181 String command = e.getActionCommand();
182 String varChangedCommand = this.visClassOne.getClassPick().COMMAND_SELECTED_VARIABLE_CHANGED;
183 String colorChangedCommand = this.visClassOne.COMMAND_COLORS_CHANGED;
184
185 if ((src == this.visClassOne) && command.equals(varChangedCommand)) {
186 int index = visClassOne.getCurrVariableIndex();
187 index++;
188 this.displayIndices[0] = index;
189 this.scatterPlot.setElementPosition(displayIndices);
190 this.fireColorArrayChanged();
191 } else if ((src == this.visClassTwo) &&
192 command.equals(varChangedCommand)) {
193 int index = visClassTwo.getCurrVariableIndex();
194 index++;
195 this.displayIndices[1] = index;
196 this.scatterPlot.setElementPosition(this.displayIndices);
197 this.fireColorArrayChanged();
198 } else if ((src == this.scatterPlot) && command.compareTo(ScatterPlot.COMMAND_POINT_SELECTED) == 0){
199 //this.selectedObvs = this.scatterPlot.getSelectedObservations();
200 System.out.println("in actionformed");
201 this.selections = this.scatterPlot.getSelections();
202 this.fireSelectionChanged(this.getSelectedObvs());
203 } else if (command.equals(colorChangedCommand)){
204 this.fireColorArrayChanged();
205 }
206 }
207
208 // private void unit_actionPerformed(ActionEvent e) {
209 // Object src = e.getSource();
210 // String command = e.getActionCommand();
211 // if ((src == this.scatterPlot) && command.compareTo(ScatterPlot.COMMAND_POINT_SELECTED) == 0){
212 // //this.selectedObvs = this.scatterPlot.getSelectedObservations();
213 // this.selections = this.scatterPlot.getSelections();
214 // this.fireSelectionChanged(this.getSelectedObvs());
215 // }
216 // }
217
218 public Color[] getColors() {
219 return this.colorArrays;
220 }
221
222 /***
223 * implements ColorArrayListener
224 */
225 public void addColorArrayListener(ColorArrayListener l) {
226 listenerList.add(ColorArrayListener.class, l);
227 this.fireColorArrayChanged(); //so that if any class registers
228 }
229
230 /***
231 * removes an ColorArrayListener from the component
232 */
233 public void removeColorArrayListener(ColorArrayListener l) {
234 listenerList.remove(ColorArrayListener.class, l);
235 }
236
237 /***
238 * Notify all listeners that have registered interest for
239 * notification on this event type. The event instance
240 * is lazily created using the parameters passed into
241 * the fire method.
242 * @see EventListenerList
243 */
244 private void fireColorArrayChanged() {
245 // Guaranteed to return a non-null array
246 Object[] listeners = listenerList.getListenerList();
247 ColorArrayEvent e = null;
248
249 // Process the listeners last to first, notifying
250 // those that are interested in this event
251 for (int i = listeners.length - 2; i >= 0; i -= 2) {
252 if (listeners[i] == ColorArrayListener.class) {
253 // Lazily create the event:
254 if (e == null) {
255 e = new ColorArrayEvent(this, this.getColors());
256 }
257 ((ColorArrayListener) listeners[i + 1]).colorArrayChanged(e);
258 }
259 } //next i
260 }
261
262 public void setSelectedObvs (int[] selected) {
263
264 if(selected == null){
265 return;
266 }else{
267 for(int i = 0; i < this.selections.length; i++){
268 this.selections[i] = 0;
269 }
270 for(int i = 0; i < selected.length; i++){
271 this.selections[selected[i]] = 1;
272 }
273 }
274 this.multipleSelectionColors = null;
275 this.scatterPlot.setSelections(this.selections);
276 repaint();
277 }
278
279 /***
280 * Return index array for selected observations.
281 * @return
282 */
283 public int[] getSelectedObvs() {
284 //need to transform data length long int[] to short int[]
285 Vector selectedObvs = new Vector();
286 for(int i = 0; i < this.selections.length; i ++){
287 if (this.selections[i] == 1){
288 selectedObvs.add(new Integer(i));
289 }
290 }
291 int[] selectedShortArray = new int[selectedObvs.size()];
292 for (int i = 0; i < selectedObvs.size(); i++) {
293 selectedShortArray[i] = ( (Integer) selectedObvs.get(i)).intValue();
294 }
295 return selectedShortArray;
296 }
297
298 public void setMultipleSelectionColors(Color[] multipleSelectionColors){
299 this.multipleSelectionColors = multipleSelectionColors;
300 this.scatterPlot.setMultipleSelectionColors(this.multipleSelectionColors);
301 }
302
303 public void selectionChanged(SelectionEvent e){
304 System.out.println("sending to selectionchanged");
305 if (e.getMultipleSlectionColors() != null){
306 this.setMultipleSelectionColors(e.getMultipleSlectionColors());
307 } else {
308 this.setSelectedObvs(e.getSelection());
309 //this.scatterPlot.setSelections(e.getSelection());
310 this.scatterPlot.repaint();
311 }
312 }
313
314 /***
315 * adds an SelectionListener.
316 * @see EventListenerList
317 */
318 public void addSelectionListener (SelectionListener l) {
319 listenerList.add(SelectionListener.class, l);
320 }
321 /***
322 * removes an SelectionListener from the component.
323 * @see EventListenerList
324 */
325 public void removeSelectionListener (SelectionListener l) {
326 listenerList.remove(SelectionListener.class, l);
327
328 }
329 /***
330 * Notify all listeners that have registered interest for
331 * notification on this event type. The event instance
332 * is lazily created using the parameters passed into
333 * the fire method.
334 * @see EventListenerList
335 */
336 protected void fireSelectionChanged (int[] newSelection) {
337 // Guaranteed to return a non-null array
338 Object[] listeners = listenerList.getListenerList();
339 SelectionEvent e = null;
340 // Process the listeners last to first, notifying
341 // those that are interested in this event
342 for (int i = listeners.length - 2; i >= 0; i -= 2) {
343 if (listeners[i] == SelectionListener.class) {
344 // Lazily create the event:
345 if (e == null) {
346 e = new SelectionEvent(this, newSelection);
347 }
348 ((SelectionListener)listeners[i + 1]).selectionChanged(e);
349 }
350 }//next i
351
352 }
353
354
355 /***
356 * implements ColorClassifierListener
357 */
358 public void addColorClassifierListener(ColorClassifierListener l) {
359 this.visClassOne.addColorClassifierListener(l);
360 this.visClassTwo.addColorClassifierListener(l);
361
362 }
363
364 /***
365 * removes an ColorClassifierListener from the component
366 */
367 public void removeColorClassifierListener(ColorClassifierListener l) {
368 this.visClassOne.removeColorClassifierListener(l);
369 this.visClassTwo.removeColorClassifierListener(l);
370 }
371 }
This page was automatically generated by Maven