1 /* -------------------------------------------------------------------
2 GeoVISTA Center (Penn State, Dept. of Geography)
3 Java source file for the class SpaceFill
4 Copyright (c), 2002, GeoVISTA Center
5 All Rights Reserved.
6 Original Author: Frank Hardisty
7 $Author: hardisty $
8 $Id: SpaceFill.java,v 1.2 2003/04/25 20:14:41 hardisty Exp $
9 $Date: 2003/04/25 20:14:41 $
10 Reference: Document no:
11 ___ ___
12 ------------------------------------------------------------------- *
13
14 */
15
16
17 package edu.psu.geovista.app.spacefill;
18
19
20 import javax.swing.*;
21 import java.awt.*;
22 import java.awt.event.*;
23 import java.awt.image.*;
24 import java.awt.geom.*;
25 import java.util.*;
26
27
28 import edu.psu.geovista.ui.panel.*;
29 import java.io.*;
30 import edu.psu.geovista.symbolization.*;
31 import edu.psu.geovista.data.geog.DataSetForApps;
32 import edu.psu.geovista.ui.event.*;
33
34 public class SpaceFill extends JPanel implements ActionListener, Serializable,
35 SelectionListener, IndicationListener,
36 DataSetListener, ConditioningListener{
37
38 private SpaceFillCanvas spat;
39 private VisualClassifier vc;
40
41 private String[] variableNames;
42 private DataSetForApps dataSet;
43 private Object[] dataToShow;
44 private int[] orignalToNew;
45 private JPanel topPane;
46 private FoldupPanel allTop;
47 private JComboBox colorColumnCombo;
48 private JComboBox orderColumnCombo;
49 private JComboBox fillOrderCombo;
50 private int fillOrder;
51 private boolean useDrawingShapes;
52
53
54 private ColorSymbolClassification colorClasser;
55
56 private transient String currColorName;
57 private transient String currOrderName;
58
59
60 public SpaceFill() {
61 this.useDrawingShapes = true;
62 this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
63 this.setLayout(new BorderLayout());
64 this.allTop = new FoldupPanel();
65 this.allTop.getContentPanel().setLayout(new BoxLayout(this.allTop.getContentPanel(), BoxLayout.Y_AXIS));
66 this.topPane = this.makeTopPanel();
67 this.topPane.setPreferredSize(new Dimension(200,30));
68 vc = new VisualClassifier();
69 this.allTop.getContentPanel().add(vc);
70
71 vc.addActionListener(this);
72
73 this.allTop.setPreferredSize(new Dimension(200,50));
74 this.allTop.getContentPanel().add(topPane);
75 this.add(allTop,BorderLayout.NORTH);
76 this.spat = makeSpat();
77 spat.addActionListener(this);
78 //spat.setPreferredSize(new Dimension(2000,2000));
79 spat.setMaximumSize(new Dimension(20000,20000));
80 this.add(spat,BorderLayout.CENTER);
81 Color[] colors = this.vc.getColors();
82 this.spat.setColors(colors);
83 this.colorClasser = this.vc.getColorSymbolClassification();
84 this.spat.setColorSymbolizer(this.vc.getColorSymbolClassification());
85 this.setPreferredSize(new Dimension(400,400));
86
87 //
88 //orders to implement (in order): scan, bostrophedon, spiral, Morton, Peano
89 }
90
91 public void actionPerformed(ActionEvent e) {
92 String command = e.getActionCommand();
93 if (command == VisualClassifier.COMMAND_COLORS_CHANGED){
94 Color[] colors = this.vc.getColors();
95 this.spat.setColorSymbolizer(this.vc.getColorSymbolClassification());
96 this.fireActionPerformed(SpaceFillCanvas.COMMAND_COLOR_CLASSFICIATION);
97 //this.spat.setColors(colors);
98 }
99 if (command == SpaceFillCanvas.COMMAND_SELECTION && e.getSource() == this.spat){
100 //pass it along
101 this.fireActionPerformed(SpaceFillCanvas.COMMAND_SELECTION);
102 this.fireSelectionChanged(this.spat.getSelectedObservationsInt());
103 }
104
105
106 }
107 private void findColors(Color[] colors) {
108 //int[] colorsInFill = this.spat.getC
109 }
110
111 private JPanel makeTopPanel() {
112
113 JPanel topPanel = new JPanel();
114 colorColumnCombo = new JComboBox();
115 colorColumnCombo.addActionListener(new ActionListener() {
116
117 public void actionPerformed(ActionEvent e) {
118 JComboBox cb = (JComboBox)e.getSource();
119 if (cb.getItemCount() > 0) {
120 String arrayName = (String)cb.getSelectedItem();
121
122 if (arrayName.equals(SpaceFill.this.currColorName) == false){
123 SpaceFill.this.currColorName = arrayName;
124 int index = cb.getSelectedIndex();
125 SpaceFill.this.setCurrColorColumn(index + 1); //skip header + 1
126 }//end if
127 }//end if count > 0
128 }//end inner class
129 });//end add listener
130 JLabel labelColor = new JLabel("Color by:");
131
132 topPanel.add(labelColor, BorderLayout.NORTH);
133 topPanel.add(colorColumnCombo, BorderLayout.NORTH);
134 JLabel someSpace = new JLabel(" ");
135 topPanel.add(someSpace, BorderLayout.NORTH);
136
137 orderColumnCombo = new JComboBox();
138 JLabel labelOrder = new JLabel("Order by:");
139 orderColumnCombo.addActionListener(new ActionListener() {
140 public void actionPerformed(ActionEvent e) {
141 JComboBox cb = (JComboBox)e.getSource();
142 if (cb.getItemCount() > 0) {
143 String arrayName = (String)cb.getSelectedItem();
144
145 if (arrayName.equals(SpaceFill.this.currOrderName) == false){
146 SpaceFill.this.currOrderName = arrayName;
147 int index = cb.getSelectedIndex();
148 SpaceFill.this.setCurrOrderColumn(index +1);//skip header
149 }//end if
150 }//end if count > 0
151 }//end inner class
152 });//end add listener
153 topPanel.add(labelOrder, BorderLayout.EAST);
154 topPanel.add(orderColumnCombo, BorderLayout.EAST);
155
156 fillOrderCombo = new JComboBox();
157 JLabel labelFill = new JLabel("Fill Order:");
158 String[] desc = FillOrder.findFillOrderDescriptions();
159 for (int i = 0; i < desc.length; i++) {
160 fillOrderCombo.addItem(desc[i]);
161 }
162 fillOrderCombo.addActionListener(new ActionListener() {
163 public void actionPerformed(ActionEvent e) {
164 JComboBox cb = (JComboBox)e.getSource();
165 if (cb.getItemCount() > 0) {
166 int fillOrd = cb.getSelectedIndex();
167 //if (SpaceFill.this.fillOrder != fillOrd){
168 SpaceFill.this.setFillOrder(fillOrd);
169 //}//end if
170 }//end if count > 0
171 }//end inner class
172 });//end add listener
173 topPanel.add(labelFill, BorderLayout.EAST);
174 topPanel.add(fillOrderCombo, BorderLayout.EAST);
175
176 JCheckBox useShapesCB = new JCheckBox("Use Shapes?",true);
177 useShapesCB.addItemListener(new ItemListener() {
178 public void itemStateChanged(ItemEvent e) {
179 JCheckBox cb = (JCheckBox)e.getSource();
180 if (e.getStateChange() == ItemEvent.SELECTED) {
181 SpaceFill.this.setUseDrawingShapes(true);
182 } else {
183 SpaceFill.this.setUseDrawingShapes(false);
184 }
185 }//end itemStateChanged
186
187
188 });//end add listener
189 topPanel.add(useShapesCB,BorderLayout.EAST);
190
191 topPanel.setBorder(BorderFactory.createLineBorder(Color.black));
192 return topPanel;
193 }//end method
194
195 private SpaceFillCanvas makeSpat(){
196 SpaceFillCanvas spat = new SpaceFillCanvas();
197 //spat.setPreferredSize(new Dimension(400,350));
198 return spat;
199 }
200
201 //start accessors
202 public void setData(Object[] dataIn) {
203 this.dataSet = new DataSetForApps();
204 dataSet.setDataObject(dataIn);
205 this.dataToShow = dataSet.getDataSetNumericAndSpatial();
206 this.setVariableNames(dataSet.getAttributeNamesNumeric());
207 this.spat.setData(dataToShow);
208 if (dataSet.getNumberNumericAttributes() > 2) {
209 this.colorColumnCombo.setSelectedIndex(1);
210 this.orderColumnCombo.setSelectedIndex(0);
211 }
212
213 this.spat.setObservationNames(dataSet.getObservationNames());
214 }
215
216 public Object[] getData() {
217 return this.spat.getData();
218 }
219
220 public void setCurrOrderColumn(int currOrderColumn) {
221 this.orderColumnCombo.setSelectedIndex(currOrderColumn-1);
222
223 this.spat.setCurrOrderColumn(currOrderColumn);
224 }
225 public int getCurrOrderColumn() {
226 return this.spat.getCurrOrderColumn();
227 }
228
229 public void setCurrColorColumn(int currColorColumn) {
230 this.colorColumnCombo.setSelectedIndex(currColorColumn-1);
231 this.spat.setCurrColorColumn(currColorColumn);
232 }
233 public int getCurrColorColumn() {
234 return this.spat.getCurrColorColumn();
235 }
236
237 public void setColorSelection(Color colorSelection) {
238 this.spat.setColorSelection(colorSelection);
239 }
240 public Color getColorSelection() {
241 return this.spat.getColorSelection();
242 }
243
244 public void setColorIndication(Color colorIndication) {
245 this.spat.setColorIndication(colorIndication);
246 }
247 public Color getColorIndication() {
248 return this.spat.getColorIndication();
249 }
250
251 public void setColorNull(Color colorNull) {
252 this.spat.setColorNull(colorNull);
253 }
254 public Color getColorNull() {
255 return this.spat.getColorNull();
256 }
257
258 public void setColorOutOfFocus(Color colorOutOfFocus) {
259 this.spat.setColorOutOfFocus(colorOutOfFocus);
260 }
261 public Color getColorOutOfFocus() {
262 return this.spat.getColorOutOfFocus();
263 }
264
265 public void setColorNotInStudyArea(Color colorNotInStudyArea) {
266 this.spat.setColorNotInStudyArea(colorNotInStudyArea);
267 }
268 public Color getColorNotInStudyArea() {
269 return this.spat.getColorNotInStudyArea();
270 }
271
272
273 public void setVariableNames(String[] variableNames) {
274
275 this.variableNames = variableNames;
276 this.spat.setVariableNames(variableNames);
277 this.colorColumnCombo.removeAllItems();
278 this.orderColumnCombo.removeAllItems();
279 for (int i = 0; i < variableNames.length; i++) {
280 this.colorColumnCombo.addItem(variableNames[i]);
281 this.orderColumnCombo.addItem(variableNames[i]);
282 }
283 }
284 public String[] getVariableNames() {
285 return this.variableNames;
286 }
287 public void setSelectedObservations(Vector selectedObservations) {
288 this.spat.setSelectedObservations(selectedObservations);
289 }
290 public Vector getSelectedObservations() {
291 return this.spat.getSelectedObservations();
292 }
293
294 public void setSelectedObservationsInt(int[] selectedObservations) {
295 this.spat.setSelectedObservationsInt(selectedObservations);
296 }
297 public void selectionChanged(SelectionEvent e) {
298 int[] sel = e.getSelection();
299 this.setSelectedObservationsInt(sel);
300 }
301
302 public void indicationChanged(IndicationEvent e){
303 int indic = e.getIndication();
304 if (indic < 0){
305 return;
306 }
307 this.spat.setIndication(indic);
308 }
309 public void dataSetChanged(DataSetEvent e){
310 this.setData(e.getDataSet());
311 }
312 public void conditioningChanged(ConditioningEvent e){
313 this.spat.setConditionArray(e.getConditioning());
314 }
315 public int[] getSelectedObservationsInt() {
316 return this.spat.getSelectedObservationsInt();
317 }
318
319 public void setTopPane(FoldupPanel topPane) {
320 this.topPane = topPane;
321 }
322 public JPanel getTopPane() {
323 return this.topPane;
324 }
325
326 public void setColorColumnCombo(JComboBox colorColumnCombo) {
327 this.colorColumnCombo = colorColumnCombo;
328 }
329 public JComboBox getColorColumnCombo() {
330 return this.colorColumnCombo;
331 }
332
333 public void setOrderColumnCombo(JComboBox orderColumnCombo) {
334 this.orderColumnCombo = orderColumnCombo;
335 }
336 public JComboBox getOrderColumnCombo() {
337 return this.orderColumnCombo;
338 }
339 public void setFillOrder(int fillOrder) {
340 if (this.fillOrder != fillOrder) {
341 if (fillOrder > FillOrder.FILL_ORDER_MAX || fillOrder < 0) {
342 throw new IllegalArgumentException("Fill order outside legal range defined in FillOrder");
343 } else {
344 this.fillOrder = fillOrder;
345 this.spat.setFillOrder(fillOrder);
346 }
347 }//
348 }//end method
349 public int getFillOrder() {
350 return this.fillOrder;
351 }
352
353 public void setUseDrawingShapes(boolean useDrawingShapes) {
354 this.useDrawingShapes = useDrawingShapes;
355 this.spat.setUseDrawingShapes(useDrawingShapes);
356 }
357
358 public boolean getUseDrawingShapes() {
359 return this.useDrawingShapes;
360 }
361
362 public BivariateColorSymbolClassification getBivarColorClasser(){
363 return this.spat.getBivarColorClasser();
364 }
365 //end accessors
366
367 /***
368 * adds an ActionListener to the component
369 */
370 public void addActionListener (ActionListener l) {
371 listenerList.add(ActionListener.class, l);
372 }
373
374 /***
375 * removes an ActionListener from the component
376 */
377 public void removeActionListener (ActionListener l) {
378 listenerList.remove(ActionListener.class, l);
379 }
380
381 /***
382 * Notify all listeners that have registered interest for
383 * notification on this event type. The event instance
384 * is lazily created using the parameters passed into
385 * the fire method.
386 * @see EventListenerList
387 */
388 public void fireActionPerformed (String command) {
389 // Guaranteed to return a non-null array
390 Object[] listeners = listenerList.getListenerList();
391 ActionEvent e = null;
392 // Process the listeners last to first, notifying
393 // those that are interested in this event
394 for (int i = listeners.length - 2; i >= 0; i -= 2) {
395 if (listeners[i] == ActionListener.class) {
396 // Lazily create the event:
397 if (e == null) {
398 e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, command);
399 }
400 ((ActionListener)listeners[i + 1]).actionPerformed(e);
401 }
402 }
403 }
404
405 /***
406 * adds an SelectionListener
407 */
408 public void addSelectionListener (SelectionListener l) {
409 listenerList.add(SelectionListener.class, l);
410 }
411 /***
412 * removes an SelectionListener from the component
413 */
414 public void removeSelectionListener (SelectionListener l) {
415 listenerList.remove(SelectionListener.class, l);
416 }
417 /***
418 * Notify all listeners that have registered interest for
419 * notification on this event type. The event instance
420 * is lazily created using the parameters passed into
421 * the fire method.
422 * @see EventListenerList
423 */
424 private void fireSelectionChanged (int[] newSelection) {
425
426 // Guaranteed to return a non-null array
427 Object[] listeners = listenerList.getListenerList();
428 SelectionEvent e = null;
429 // Process the listeners last to first, notifying
430 // those that are interested in this event
431 for (int i = listeners.length - 2; i >= 0; i -= 2) {
432 if (listeners[i] == SelectionListener.class) {
433 // Lazily create the event:
434 if (e == null) {
435 e = new SelectionEvent(this, newSelection);
436 }
437 ((SelectionListener)listeners[i + 1]).selectionChanged(e);
438 }
439 }//next i
440
441 }
442
443 }
This page was automatically generated by Maven