View Javadoc
1 /* ------------------------------------------------------------------- 2 GeoVISTA Center (Penn State, Dept. of Geography) 3 Java source file for the class Map 4 Copyright (c), 2002, GeoVISTA Center 5 All Rights Reserved. 6 Original Author: Frank Hardisty 7 $Author: dxg231 $ 8 $Id: GeoMap.java,v 1.5 2003/09/04 21:11:59 dxg231 Exp $ 9 $Date: 2003/09/04 21:11:59 $ 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.ui.Fisheyes; 22 23 import java.awt.*; 24 import java.awt.event.*; 25 import java.awt.geom.*; 26 27 import java.net.*; 28 29 import javax.swing.*; 30 31 /*** 32 * This class handles the user state, like selection, pan, zoom, plus 33 * symbolization options. 34 * 35 * MapCanvas does most of the work. 36 */ 37 public class GeoMap 38 extends JPanel 39 implements 40 //MouseListener, MouseMotionListener, 41 ActionListener, SelectionListener, IndicationListener, DataSetListener, 42 ColorClassifierListener, ColorArrayListener, 43 SpatialExtentListener, ComponentListener, 44 ConditioningListener { 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 transient private BivariateColorSchemeVisualizer biViz; 56 transient private Dimension currSize; 57 transient private Fisheyes fisheyes; 58 59 public GeoMap() { 60 super(); 61 62 JPanel vcPanel = new JPanel(); 63 vcPanel.setLayout(new BoxLayout(vcPanel, BoxLayout.Y_AXIS)); 64 visClassOne = new VisualClassifier(); 65 visClassTwo = new VisualClassifier(); 66 visClassOne.setAlignmentX(Component.LEFT_ALIGNMENT); 67 visClassTwo.setAlignmentX(Component.LEFT_ALIGNMENT); 68 visClassOne.setVariableChooserMode( 69 ClassifierPicker.VARIABLE_CHOOSER_MODE_ACTIVE); 70 visClassTwo.setVariableChooserMode( 71 ClassifierPicker.VARIABLE_CHOOSER_MODE_ACTIVE); 72 visClassOne.addActionListener(this); 73 visClassOne.setOrientationInParentIsX(true); 74 visClassTwo.addActionListener(this); 75 visClassTwo.setOrientationInParentIsX(false); 76 vcPanel.add(visClassTwo); 77 vcPanel.add(visClassOne); 78 79 JPanel legendPanel = new JPanel(); 80 legendPanel.setLayout(new BoxLayout(legendPanel, BoxLayout.X_AXIS)); 81 biViz = new BivariateColorSchemeVisualizer(); 82 legendPanel.add(vcPanel); 83 legendPanel.add(Box.createRigidArea(new Dimension(4, 2))); 84 legendPanel.add(biViz); 85 86 topContent = new JPanel(); 87 topContent.setLayout(new BoxLayout(topContent, BoxLayout.Y_AXIS)); 88 makeToolbar(); 89 legendPanel.setAlignmentX(Component.LEFT_ALIGNMENT); 90 mapTools.setAlignmentX(Component.LEFT_ALIGNMENT); 91 topContent.add(legendPanel); 92 topContent.add(mapTools); 93 94 //note: uncomment the line below for animation panel stuff 95 //vcPanel.add(this.makeAnimationPanel()); 96 cursors = new GeoCursors(); 97 this.setCursor(cursors.getCursor(GeoCursors.CURSOR_ARROW_SELECT)); 98 99 this.setLayout(new BorderLayout()); 100 this.add(topContent, BorderLayout.NORTH); 101 mapCan = new MapCanvas(); 102 this.add(mapCan, BorderLayout.CENTER); 103 this.mapCan.addIndicationListener(this); 104 visClassOne.addColorClassifierListener(this); 105 visClassTwo.addColorClassifierListener(this); 106 this.addIndicationListener(biViz); 107 108 visClassTwo.setHighColor(new Color(0, 150, 0)); //green 109 this.currSize = new Dimension(this.getSize()); 110 this.fisheyes = new Fisheyes(); 111 this.fisheyes.setLensType(Fisheyes.LENS_HEMISPHERE); 112 113 //this.colorClassifierChanged(new ColorClassifierEvent(visClassTwo,visClassTwo.getColorSymbolClassification())); 114 } 115 116 public JPanel makeAnimationPanel() { 117 JPanel animationPanel = new JPanel(); 118 Dimension prefSize = new Dimension(100, 50); 119 animationPanel.setSize(prefSize); 120 animationPanel.setPreferredSize(prefSize); 121 122 //animationPanel.setBorder(BorderFactory.createLineBorder(Color.blue)); 123 JLabel timeLabel = new JLabel("Time Step:"); 124 animationPanel.add(timeLabel); 125 126 JSlider timeSlider = new JSlider(0, 10, 3); 127 timeSlider.setPaintLabels(true); 128 timeSlider.setPaintTicks(true); 129 timeSlider.setPaintTrack(true); 130 timeSlider.setMajorTickSpacing(1); 131 timeSlider.createStandardLabels(2); 132 133 animationPanel.add(timeSlider); 134 135 return animationPanel; 136 } 137 138 public void makeToolbar() { 139 mapTools = new JToolBar(); 140 141 //Dimension prefSize = new Dimension(100,10); 142 //mapTools.setMinimumSize(prefSize); 143 //mapTools.setPreferredSize(prefSize); 144 JButton button = null; 145 Class cl = this.getClass(); 146 URL urlGif = null; 147 Dimension buttDim = new Dimension(20, 20); 148 149 //first button 150 try { 151 urlGif = cl.getResource("resources/select16.gif"); 152 button = new JButton(new ImageIcon(urlGif)); 153 button.setPreferredSize(buttDim); 154 } 155 catch (Exception ex) { 156 ex.printStackTrace(); 157 } 158 159 button.setToolTipText("Enter selection mode"); 160 button.addActionListener(new ActionListener() { 161 public void actionPerformed(ActionEvent e) { 162 GeoMap.this.setCursor(cursors.getCursor( 163 GeoCursors.CURSOR_ARROW_SELECT)); 164 GeoMap.this.mapCan.setMode(MapCanvas.MODE_SELECT); 165 } 166 }); 167 mapTools.add(button); 168 169 mapTools.addSeparator(); 170 171 //second button 172 try { 173 urlGif = cl.getResource("resources/ZoomIn16.gif"); 174 button = new JButton(new ImageIcon(urlGif)); 175 button.setPreferredSize(buttDim); 176 } 177 catch (Exception ex) { 178 ex.printStackTrace(); 179 } 180 181 button.setToolTipText("Enter zoom in mode"); 182 button.addActionListener(new ActionListener() { 183 public void actionPerformed(ActionEvent e) { 184 GeoMap.this.setCursor(cursors.getCursor( 185 GeoCursors.CURSOR_ARROW_ZOOM_IN)); 186 GeoMap.this.mapCan.setMode(MapCanvas.MODE_ZOOM_IN); 187 188 //GeoMap.this.setCursor(new Cursor(Cursor.HAND_CURSOR)); 189 } 190 }); 191 mapTools.add(button); 192 193 //third button 194 try { 195 urlGif = cl.getResource("resources/ZoomOut16.gif"); 196 button = new JButton(new ImageIcon(urlGif)); 197 button.setPreferredSize(buttDim); 198 } 199 catch (Exception ex) { 200 ex.printStackTrace(); 201 } 202 203 button.setToolTipText("Enter zoom out mode"); 204 button.addActionListener(new ActionListener() { 205 public void actionPerformed(ActionEvent e) { 206 GeoMap.this.mapCan.setMode(MapCanvas.MODE_ZOOM_OUT); 207 GeoMap.this.setCursor(cursors.getCursor( 208 GeoCursors.CURSOR_ARROW_ZOOM_OUT)); 209 } 210 }); 211 mapTools.add(button); 212 213 //fourth button 214 try { 215 urlGif = cl.getResource("resources/Home16.gif"); 216 button = new JButton(new ImageIcon(urlGif)); 217 button.setPreferredSize(buttDim); 218 } 219 catch (Exception ex) { 220 ex.printStackTrace(); 221 } 222 223 button.setToolTipText("Zoom to full extent"); 224 button.addActionListener(new ActionListener() { 225 public void actionPerformed(ActionEvent e) { 226 GeoMap.this.mapCan.zoomFullExtent(); 227 } 228 }); 229 mapTools.add(button); 230 231 //fifth button 232 try { 233 urlGif = cl.getResource("resources/pan16.gif"); 234 button = new JButton(new ImageIcon(urlGif)); 235 button.setPreferredSize(buttDim); 236 } 237 catch (Exception ex) { 238 ex.printStackTrace(); 239 } 240 241 button.setToolTipText("Enter pan mode"); 242 button.addActionListener(new ActionListener() { 243 public void actionPerformed(ActionEvent e) { 244 GeoMap.this.setCursor(cursors.getCursor( 245 GeoCursors.CURSOR_ARROW_PAN)); 246 GeoMap.this.mapCan.setMode(MapCanvas.MODE_PAN); 247 } 248 }); 249 mapTools.add(button); 250 //sixth button 251 try { 252 urlGif = cl.getResource("resources/excentric16.gif"); 253 button = new JButton(new ImageIcon(urlGif)); 254 button.setPreferredSize(buttDim); 255 } 256 catch (Exception ex) { 257 ex.printStackTrace(); 258 } 259 260 button.setToolTipText("Excentric Labels"); 261 button.addActionListener(new ActionListener() { 262 public void actionPerformed(ActionEvent e) { 263 GeoMap.this.setCursor(cursors.getCursor( 264 GeoCursors.CURSOR_ARROW_PAN)); 265 GeoMap.this.mapCan.setMode(MapCanvas.MODE_EXCENTRIC); 266 } 267 }); 268 mapTools.add(button); 269 270 //seventh button 271 try { 272 urlGif = cl.getResource("resources/fisheye16.gif"); 273 button = new JButton(new ImageIcon(urlGif)); 274 button.setPreferredSize(buttDim); 275 } 276 catch (Exception ex) { 277 ex.printStackTrace(); 278 } 279 280 button.setToolTipText("Fisheye Lens"); 281 button.addActionListener(new ActionListener() { 282 public void actionPerformed(ActionEvent e) { 283 GeoMap.this.setCursor(cursors.getCursor( 284 GeoCursors.CURSOR_ARROW_PAN)); 285 GeoMap.this.mapCan.setMode(MapCanvas.MODE_FISHEYE); 286 } 287 }); 288 mapTools.add(button); 289 //eighth button 290 try { 291 urlGif = cl.getResource("resources/magnifying16.gif"); 292 button = new JButton(new ImageIcon(urlGif)); 293 button.setPreferredSize(buttDim); 294 } 295 catch (Exception ex) { 296 ex.printStackTrace(); 297 } 298 299 button.setToolTipText("Magnifiying Lens"); 300 button.addActionListener(new ActionListener() { 301 public void actionPerformed(ActionEvent e) { 302 GeoMap.this.setCursor(cursors.getCursor( 303 GeoCursors.CURSOR_ARROW_PAN)); 304 GeoMap.this.mapCan.setMode(MapCanvas.MODE_PAN); 305 } 306 }); 307 308 mapTools.add(button); 309 310 } 311 312 public void actionPerformed(ActionEvent e) { 313 Object src = e.getSource(); 314 String command = e.getActionCommand(); 315 String varChangedCommand = this.visClassOne.getClassPick(). 316 COMMAND_SELECTED_VARIABLE_CHANGED; 317 318 if ( (src == this.visClassOne) && command.equals(varChangedCommand)) { 319 int index = visClassOne.getCurrVariableIndex(); 320 index++; 321 this.mapCan.setCurrColorColumnX(index); 322 } 323 else if ( (src == this.visClassTwo) && 324 command.equals(varChangedCommand)) { 325 int index = visClassTwo.getCurrVariableIndex(); 326 index++; 327 this.mapCan.setCurrColorColumnY(index); 328 } 329 330 } 331 332 public void selectionChanged(SelectionEvent e) { 333 mapCan.selectionChanged(e); 334 } 335 336 public void conditioningChanged(ConditioningEvent e) { 337 mapCan.setConditionArray(e.getConditioning()); 338 } 339 340 public void indicationChanged(IndicationEvent e) { 341 Object source = e.getSource(); 342 343 if ( (source == this.mapCan) && (e.getIndication() >= 0)) { 344 this.visClassOne.setIndicatedClass(e.getXClass()); 345 this.visClassTwo.setIndicatedClass(e.getYClass()); 346 347 //this.fireIndicationChanged(e.getIndication()); 348 } 349 else if ( (source == this.mapCan) && (e.getIndication() < 0)) { 350 this.visClassOne.setIndicatedClass( -1); 351 this.visClassTwo.setIndicatedClass( -1); 352 this.biViz.indicationChanged(new IndicationEvent(this, -1)); 353 354 //this.fireIndicationChanged(e.getIndication()); 355 } 356 else { 357 mapCan.indicationChanged(e); 358 } 359 } 360 361 public void spatialExtentChanged(SpatialExtentEvent e) { 362 mapCan.spatialExtentChanged(e); 363 } 364 365 public void dataSetChanged(DataSetEvent e) { 366 //mapCan.dataSetChanged(e); 367 this.setDataSet(e.getDataSet()); 368 } 369 370 public void colorArrayChanged(ColorArrayEvent e) { 371 if (this.mapCan == null || e.getColors() == null) { 372 return; 373 } 374 this.mapCan.setObservationColors(e.getColors()); 375 } 376 377 public void colorClassifierChanged(ColorClassifierEvent e) { 378 if (e.getSource() == this.visClassOne) { 379 e.setOrientation(e.SOURCE_ORIENTATION_X); 380 } 381 382 if (e.getSource() == this.visClassTwo) { 383 e.setOrientation(e.SOURCE_ORIENTATION_Y); 384 } 385 386 this.biViz.colorClassifierChanged(e); 387 388 if (this.mapCan == null) { 389 return; 390 } 391 392 //ColorSymbolClassification colorSymbolizer = e.getColorSymbolClassification(); 393 //Object src = e.getSource(); 394 ColorSymbolClassification colorSymbolizerX = this.visClassOne. 395 getColorClasser(); 396 ColorSymbolClassification colorSymbolizerY = this.visClassTwo. 397 getColorClasser(); 398 399 BivariateColorSymbolClassificationSimple biColorSymbolizer = 400 new BivariateColorSymbolClassificationSimple(); 401 //turn these around to match what happens in the 402 //scatterplot 403 biColorSymbolizer.setClasserX(colorSymbolizerX.getClasser()); 404 biColorSymbolizer.setColorerX(colorSymbolizerX.getColorer()); 405 406 biColorSymbolizer.setClasserY(colorSymbolizerY.getClasser()); 407 biColorSymbolizer.setColorerY(colorSymbolizerY.getColorer()); 408 this.mapCan.setBivarColorClasser(biColorSymbolizer); 409 } 410 411 public void setXVariable(int var) { 412 this.visClassOne.setCurrVariableIndex(var); 413 } 414 415 public void setYVariable(int var) { 416 this.visClassTwo.setCurrVariableIndex(var); 417 } 418 419 public void setXChooserMode(int chooserMode) { 420 this.visClassOne.setVariableChooserMode(chooserMode); 421 } 422 423 public void setYChooserMode(int chooserMode) { 424 this.visClassTwo.setVariableChooserMode(chooserMode); 425 } 426 427 public void setBivarColorClasser(BivariateColorSymbolClassification 428 bivarColorClasser) { 429 this.mapCan.setBivarColorClasser(bivarColorClasser); 430 } 431 432 public void setSelectedObservations(int[] selObs) { 433 this.mapCan.setSelectedObservationsInt(selObs); 434 } 435 436 public int[] getSelectedObservations() { 437 return this.mapCan.getSelectedObservationsInt(); 438 } 439 440 public Color[] getColors() { 441 return this.mapCan.getColors(); 442 } 443 444 public BivariateColorSymbolClassification 445 getBivariateColorSymbolClassification() { 446 return this.biViz.getBivariateColorClassification(); 447 } 448 449 public void setDataSet(Object[] data) { 450 451 this.mapCan.setDataSet(data); 452 this.visClassOne.setData(data); 453 this.visClassTwo.setData(data); 454 455 //set default data to get color from 456 DataSetForApps dataSet = new DataSetForApps(); 457 dataSet.setDataObject(data); 458 459 int numNumeric = dataSet.getNumberNumericAttributes(); 460 461 int currColorColumnX = this.mapCan.getCurrColorColumnX(); 462 int currColorColumnY = this.mapCan.getCurrColorColumnY(); 463 464 if (currColorColumnX < 0) { 465 if (numNumeric > 0) { 466 this.setXVariable(1); 467 this.mapCan.setCurrColorColumnX(1); 468 } 469 } 470 else if (currColorColumnX < numNumeric) { 471 this.setXVariable(currColorColumnX); 472 this.mapCan.setCurrColorColumnX(currColorColumnX); 473 } 474 475 if (currColorColumnY < 0) { 476 if (numNumeric > 1) { 477 this.setYVariable(2); 478 this.mapCan.setCurrColorColumnY(2); 479 } 480 else if (numNumeric == 1) { 481 this.setYVariable(1); 482 this.mapCan.setCurrColorColumnY(1); 483 } 484 } 485 else if (currColorColumnY < numNumeric) { 486 setYVariable(currColorColumnY); 487 this.mapCan.setCurrColorColumnY(currColorColumnY); 488 } 489 490 //this.colorClassifierChanged(null); 491 } 492 493 public void setAuxiliarySpatialData(Object[] data) { 494 mapCan.setAuxiliarySpatialData(data); 495 } 496 497 public void setBackground(Color bg) { 498 if ( (mapCan != null) && (bg != null)) { 499 this.mapCan.setBackground(bg); 500 } 501 } 502 503 //start component listener stuff 504 public void componentHidden(ComponentEvent e) { 505 } 506 507 public void componentMoved(ComponentEvent e) { 508 } 509 510 public void componentResized(ComponentEvent e) { 511 //todo: zoom in or out a bit 512 513 } 514 515 public void componentShown(ComponentEvent e) { 516 } 517 518 //end component listener stuff 519 520 /*** 521 * adds an IndicationListener 522 */ 523 public void addIndicationListener(IndicationListener l) { 524 this.mapCan.addIndicationListener(l); 525 } 526 527 /*** 528 * removes an IndicationListener from the component 529 */ 530 public void removeIndicationListener(IndicationListener l) { 531 this.mapCan.removeIndicationListener(l); 532 } 533 534 /*** 535 * adds an SelectionListener 536 */ 537 public void addSelectionListener(SelectionListener l) { 538 this.mapCan.addSelectionListener(l); 539 } 540 541 /*** 542 * removes an SelectionListener from the component 543 */ 544 public void removeSelectionListener(SelectionListener l) { 545 this.mapCan.removeSelectionListener(l); 546 } 547 548 /*** 549 * adds an SpatialExtentListener 550 */ 551 public void addSpatialExtentListener(SpatialExtentListener l) { 552 this.mapCan.addSpatialExtentListener(l); 553 } 554 555 /*** 556 * removes an SpatialExtentListener from the component 557 */ 558 public void removeSpatialExtentListener(SpatialExtentListener l) { 559 listenerList.remove(SpatialExtentListener.class, l); 560 this.mapCan.removeSpatialExtentListener(l); 561 } 562 563 /*** 564 * implements ColorClassifierListener 565 */ 566 public void addColorClassifierListener(ColorClassifierListener l) { 567 this.visClassOne.addColorClassifierListener(l); 568 this.visClassTwo.addColorClassifierListener(l); 569 570 } 571 572 /*** 573 * removes an ColorClassifierListener from the component 574 */ 575 public void removeColorClassifierListener(ColorClassifierListener l) { 576 this.visClassOne.removeColorClassifierListener(l); 577 this.visClassTwo.removeColorClassifierListener(l); 578 } 579 580 }

This page was automatically generated by Maven