View Javadoc
1 /* ------------------------------------------------------------------- 2 GeoVISTA Center (Penn State, Dept. of Geography) 3 Java source file for the class GeoMapUni 4 Copyright (c), 2002, GeoVISTA Center 5 All Rights Reserved. 6 Original Author: Frank Hardisty 7 $Author: hardisty $ 8 $Id: GeoMapUni.java,v 1.5 2003/07/10 00:30:07 hardisty Exp $ 9 $Date: 2003/07/10 00:30:07 $ 10 Reference: Document no: 11 ___ ___ 12 ------------------------------------------------------------------- * 13 */ 14 package edu.psu.geovista.app.map; 15 16 import edu.psu.geovista.classification.*; 17 import edu.psu.geovista.data.geog.*; 18 import edu.psu.geovista.symbolization.*; 19 import edu.psu.geovista.ui.cursor.*; 20 import edu.psu.geovista.ui.event.*; 21 import edu.psu.geovista.common.event.*; 22 import edu.psu.geovista.common.color.Pallet; 23 24 import java.awt.*; 25 import java.awt.event.*; 26 import java.awt.geom.*; 27 28 import java.net.*; 29 30 import javax.swing.*; 31 32 33 /*** 34 * This class handles the user state, like selection, pan, zoom, plus 35 * symbolization options. 36 * 37 * MapCanvas does most of the work. 38 */ 39 public class GeoMapUni extends JPanel implements 40 //MouseListener, MouseMotionListener, 41 ActionListener, SelectionListener, IndicationListener, DataSetListener, 42 ColorClassifierListener, 43 SpatialExtentListener, 44 PalletListener{ 45 public static final int VARIABLE_CHOOSER_MODE_ACTIVE = 0; 46 public static final int VARIABLE_CHOOSER_MODE_FIXED = 1; 47 public static final int VARIABLE_CHOOSER_MODE_HIDDEN = 2; 48 transient private MapCanvas mapCan; 49 transient private VisualClassifier visClassOne; 50 //transient private VisualClassifier visClassTwo; 51 transient private JToolBar mapTools; 52 transient private JPanel topContent; 53 transient private Cursor[] customCursors; 54 transient private GeoCursors cursors; 55 56 57 public GeoMapUni() { 58 super(); 59 60 JPanel vcPanel = new JPanel(); 61 vcPanel.setPreferredSize(new Dimension(600,40)); 62 vcPanel.setLayout(new BoxLayout(vcPanel, BoxLayout.Y_AXIS)); 63 visClassOne = new VisualClassifier(); 64 // visClassTwo = new VisualClassifier(); 65 visClassOne.setAlignmentX(Component.LEFT_ALIGNMENT); 66 // visClassTwo.setAlignmentX(Component.LEFT_ALIGNMENT); 67 visClassOne.setVariableChooserMode( 68 ClassifierPicker.VARIABLE_CHOOSER_MODE_ACTIVE); 69 // visClassTwo.setVariableChooserMode( 70 // ClassifierPicker.VARIABLE_CHOOSER_MODE_ACTIVE); 71 visClassOne.addActionListener(this); 72 // visClassTwo.addActionListener(this); 73 vcPanel.add(visClassOne); 74 // vcPanel.add(visClassTwo); 75 76 JPanel legendPanel = new JPanel(); 77 legendPanel.setLayout(new BoxLayout(legendPanel, BoxLayout.X_AXIS)); 78 legendPanel.add(vcPanel); 79 legendPanel.add(Box.createRigidArea(new Dimension(4, 2))); 80 81 topContent = new JPanel(); 82 topContent.setLayout(new BoxLayout(topContent, BoxLayout.Y_AXIS)); 83 makeToolbar(); 84 legendPanel.setAlignmentX(Component.LEFT_ALIGNMENT); 85 mapTools.setAlignmentX(Component.LEFT_ALIGNMENT); 86 topContent.add(legendPanel); 87 topContent.add(mapTools); 88 89 90 //note: uncomment the line below for animation panel stuff 91 //vcPanel.add(this.makeAnimationPanel()); 92 cursors = new GeoCursors(); 93 this.setCursor(cursors.getCursor(GeoCursors.CURSOR_ARROW_SELECT)); 94 95 this.setLayout(new BorderLayout()); 96 this.add(topContent, BorderLayout.NORTH); 97 mapCan = new MapCanvas(); 98 this.add(mapCan, BorderLayout.CENTER); 99 this.mapCan.addIndicationListener(this); 100 visClassOne.addColorClassifierListener(this); 101 // visClassTwo.addColorClassifierListener(this); 102 103 104 105 //this.colorClassifierChanged(new ColorClassifierEvent(visClassTwo,visClassTwo.getColorSymbolClassification())); 106 } 107 108 public JPanel makeAnimationPanel() { 109 JPanel animationPanel = new JPanel(); 110 Dimension prefSize = new Dimension(100, 50); 111 animationPanel.setSize(prefSize); 112 animationPanel.setPreferredSize(prefSize); 113 114 //animationPanel.setBorder(BorderFactory.createLineBorder(Color.blue)); 115 JLabel timeLabel = new JLabel("Time Step:"); 116 animationPanel.add(timeLabel); 117 118 JSlider timeSlider = new JSlider(0, 10, 3); 119 timeSlider.setPaintLabels(true); 120 timeSlider.setPaintTicks(true); 121 timeSlider.setPaintTrack(true); 122 timeSlider.setMajorTickSpacing(1); 123 timeSlider.createStandardLabels(2); 124 125 animationPanel.add(timeSlider); 126 127 return animationPanel; 128 } 129 130 public void makeToolbar() { 131 mapTools = new JToolBar(); 132 133 //Dimension prefSize = new Dimension(100,10); 134 //mapTools.setMinimumSize(prefSize); 135 //mapTools.setPreferredSize(prefSize); 136 JButton button = null; 137 Class cl = this.getClass(); 138 URL urlGif = null; 139 Dimension buttDim = new Dimension(20, 20); 140 141 //first button 142 try { 143 urlGif = cl.getResource("resources/select16.gif"); 144 button = new JButton(new ImageIcon(urlGif)); 145 button.setPreferredSize(buttDim); 146 } catch (Exception ex) { 147 ex.printStackTrace(); 148 } 149 150 button.setToolTipText("Enter selection mode"); 151 button.addActionListener(new ActionListener() { 152 public void actionPerformed(ActionEvent e) { 153 GeoMapUni.this.setCursor(cursors.getCursor( 154 GeoCursors.CURSOR_ARROW_SELECT)); 155 GeoMapUni.this.mapCan.setMode(MapCanvas.MODE_SELECT); 156 } 157 }); 158 mapTools.add(button); 159 160 mapTools.addSeparator(); 161 162 //second button 163 try { 164 urlGif = cl.getResource("resources/ZoomIn16.gif"); 165 button = new JButton(new ImageIcon(urlGif)); 166 button.setPreferredSize(buttDim); 167 } catch (Exception ex) { 168 ex.printStackTrace(); 169 } 170 171 button.setToolTipText("Enter zoom in mode"); 172 button.addActionListener(new ActionListener() { 173 public void actionPerformed(ActionEvent e) { 174 GeoMapUni.this.setCursor(cursors.getCursor( 175 GeoCursors.CURSOR_ARROW_ZOOM_IN)); 176 GeoMapUni.this.mapCan.setMode(MapCanvas.MODE_ZOOM_IN); 177 178 //GeoMapUni.this.setCursor(new Cursor(Cursor.HAND_CURSOR)); 179 } 180 }); 181 mapTools.add(button); 182 183 //third button 184 try { 185 urlGif = cl.getResource("resources/ZoomOut16.gif"); 186 button = new JButton(new ImageIcon(urlGif)); 187 button.setPreferredSize(buttDim); 188 } catch (Exception ex) { 189 ex.printStackTrace(); 190 } 191 192 button.setToolTipText("Enter zoom out mode"); 193 button.addActionListener(new ActionListener() { 194 public void actionPerformed(ActionEvent e) { 195 GeoMapUni.this.mapCan.setMode(MapCanvas.MODE_ZOOM_OUT); 196 GeoMapUni.this.setCursor(cursors.getCursor( 197 GeoCursors.CURSOR_ARROW_ZOOM_OUT)); 198 } 199 }); 200 mapTools.add(button); 201 202 //fourth button 203 try { 204 urlGif = cl.getResource("resources/Home16.gif"); 205 button = new JButton(new ImageIcon(urlGif)); 206 button.setPreferredSize(buttDim); 207 } catch (Exception ex) { 208 ex.printStackTrace(); 209 } 210 211 button.setToolTipText("Zoom to full extent"); 212 button.addActionListener(new ActionListener() { 213 public void actionPerformed(ActionEvent e) { 214 GeoMapUni.this.mapCan.zoomFullExtent(); 215 } 216 }); 217 mapTools.add(button); 218 219 //fifth button 220 try { 221 urlGif = cl.getResource("resources/pan16.gif"); 222 button = new JButton(new ImageIcon(urlGif)); 223 button.setPreferredSize(buttDim); 224 } catch (Exception ex) { 225 ex.printStackTrace(); 226 } 227 228 button.setToolTipText("Enter pan mode"); 229 button.addActionListener(new ActionListener() { 230 public void actionPerformed(ActionEvent e) { 231 GeoMapUni.this.setCursor(cursors.getCursor( 232 GeoCursors.CURSOR_ARROW_PAN)); 233 GeoMapUni.this.mapCan.setMode(MapCanvas.MODE_PAN); 234 } 235 }); 236 mapTools.add(button); 237 } 238 239 public void actionPerformed(ActionEvent e) { 240 Object src = e.getSource(); 241 String command = e.getActionCommand(); 242 String varChangedCommand = this.visClassOne.getClassPick().COMMAND_SELECTED_VARIABLE_CHANGED; 243 244 if ((src == this.visClassOne) && command.equals(varChangedCommand)) { 245 int index = visClassOne.getCurrVariableIndex(); 246 index++; 247 this.mapCan.setCurrColorColumnX(index); 248 this.mapCan.setCurrColorColumnY(index); 249 // } else if ((src == this.visClassTwo) && 250 // command.equals(varChangedCommand)) { 251 // int index = visClassTwo.getCurrVariableIndex(); 252 // index++; 253 // this.mapCan.setCurrColorColumnY(index); 254 } 255 256 } 257 258 public void selectionChanged(SelectionEvent e) { 259 mapCan.selectionChanged(e); 260 } 261 262 public void indicationChanged(IndicationEvent e) { 263 Object source = e.getSource(); 264 265 if ((source == this.mapCan) && (e.getIndication() >= 0)) { 266 this.visClassOne.setIndicatedClass(e.getXClass()); 267 // this.visClass.setIndicatedClass(e.getYClass()); 268 269 //this.fireIndicationChanged(e.getIndication()); 270 } else if ((source == this.mapCan) && (e.getIndication() < 0)) { 271 this.visClassOne.setIndicatedClass(-1); 272 // this.visClassTwo.setIndicatedClass(-1); 273 274 //this.fireIndicationChanged(e.getIndication()); 275 } else { 276 mapCan.indicationChanged(e); 277 } 278 } 279 280 public void spatialExtentChanged(SpatialExtentEvent e) { 281 mapCan.spatialExtentChanged(e); 282 } 283 284 public void dataSetChanged(DataSetEvent e) { 285 //mapCan.dataSetChanged(e); 286 this.setDataSet(e.getDataSet()); 287 } 288 289 public void palletChanged(PalletEvent e){ 290 this.visClassOne.palletChanged(e); 291 } 292 293 public void colorClassifierChanged(ColorClassifierEvent e) { 294 if (e.getSource() == this.visClassOne) { 295 e.setOrientation(e.SOURCE_ORIENTATION_X); 296 } 297 if (this.mapCan == null) { 298 return; 299 } 300 ColorSymbolClassification colorSymbolizerX = this.visClassOne.getColorClasser(); 301 ColorSymbolClassification colorSymbolizerY = this.visClassOne.getColorClasser(); 302 303 BivariateColorSymbolClassificationSimple biColorSymbolizer = 304 new BivariateColorSymbolClassificationSimple(); 305 306 biColorSymbolizer.setClasserX(colorSymbolizerX.getClasser()); 307 biColorSymbolizer.setColorerX(colorSymbolizerX.getColorer()); 308 309 biColorSymbolizer.setClasserY(colorSymbolizerY.getClasser()); 310 biColorSymbolizer.setColorerY(colorSymbolizerY.getColorer()); 311 this.mapCan.setBivarColorClasser(biColorSymbolizer); 312 } 313 314 public void setXVariable(int var) { 315 this.visClassOne.setCurrVariableIndex(var); 316 } 317 318 public void setYVariable(int var) { 319 this.visClassOne.setCurrVariableIndex(var); 320 } 321 322 public void setXChooserMode(int chooserMode) { 323 this.visClassOne.setVariableChooserMode(chooserMode); 324 } 325 326 public void setYChooserMode(int chooserMode) { 327 this.visClassOne.setVariableChooserMode(chooserMode); 328 } 329 330 public void setBivarColorClasser(BivariateColorSymbolClassification bivarColorClasser) { 331 this.mapCan.setBivarColorClasser(bivarColorClasser); 332 } 333 334 public void setSelectedObservations(int[] selObs) { 335 this.mapCan.setSelectedObservationsInt(selObs); 336 } 337 338 public int[] getSelectedObservations() { 339 return this.mapCan.getSelectedObservationsInt(); 340 } 341 342 public Color[] getColors() { 343 return this.mapCan.getColors(); 344 } 345 346 public void setDataSet(Object[] data) { 347 this.mapCan.setDataSet(data); 348 this.visClassOne.setData(data); 349 //this.visClassTwo.setData(data); 350 351 //set default data to get color from 352 DataSetForApps dataSet = new DataSetForApps(); 353 dataSet.setDataObject(data); 354 355 int numNumeric = dataSet.getNumberNumericAttributes(); 356 357 int currColorColumnX = this.mapCan.getCurrColorColumnX(); 358 int currColorColumnY = this.mapCan.getCurrColorColumnY(); 359 360 if (currColorColumnX < 0) { 361 if (numNumeric > 0) { 362 this.setXVariable(1); 363 this.setYVariable(1); 364 this.mapCan.setCurrColorColumnX(1); 365 this.mapCan.setCurrColorColumnY(1); 366 } 367 } else if (currColorColumnX < numNumeric) { 368 this.setXVariable(currColorColumnX); 369 this.setYVariable(currColorColumnX); 370 this.mapCan.setCurrColorColumnX(currColorColumnX); 371 this.mapCan.setCurrColorColumnY(currColorColumnX); 372 } 373 374 375 } 376 377 public void setAuxiliarySpatialData(Object[] data) { 378 379 mapCan.setAuxiliarySpatialData(data); 380 } 381 382 public void setBackground(Color bg) { 383 if ((mapCan != null) && (bg != null)) { 384 this.mapCan.setBackground(bg); 385 } 386 } 387 388 /*** 389 * adds an IndicationListener 390 */ 391 public void addIndicationListener(IndicationListener l) { 392 this.mapCan.addIndicationListener(l); 393 } 394 395 /*** 396 * removes an IndicationListener from the component 397 */ 398 public void removeIndicationListener(IndicationListener l) { 399 this.mapCan.removeIndicationListener(l); 400 } 401 402 /*** 403 * adds an SelectionListener 404 */ 405 public void addSelectionListener(SelectionListener l) { 406 this.mapCan.addSelectionListener(l); 407 } 408 409 /*** 410 * removes an SelectionListener from the component 411 */ 412 public void removeSelectionListener(SelectionListener l) { 413 this.mapCan.removeSelectionListener(l); 414 } 415 416 /*** 417 * adds an SpatialExtentListener 418 */ 419 public void addSpatialExtentListener(SpatialExtentListener l) { 420 this.mapCan.addSpatialExtentListener(l); 421 } 422 423 /*** 424 * removes an SpatialExtentListener from the component 425 */ 426 public void removeSpatialExtentListener(SpatialExtentListener l) { 427 listenerList.remove(SpatialExtentListener.class, l); 428 this.mapCan.removeSpatialExtentListener(l); 429 } 430 431 432 433 }

This page was automatically generated by Maven