View Javadoc
1 /* 2 * put your module comment here 3 * formatted with JxBeauty (c) johann.langhofer@nextra.at 4 */ 5 6 7 package edu.psu.geovista.app.matrix; 8 9 /*** 10 * Title: Mixed Matrix 11 * Description: Manipulable Matrix 12 * Copyright: Copyright (c) 2001 13 * Company: GeoVISTA Center 14 * @author Xiping Dai 15 * @version 1.0 16 */ 17 import java.awt.*; 18 import java.lang.*; 19 import java.util.*; 20 import java.awt.event.*; 21 import javax.swing.event.*; 22 import javax.swing.*; 23 import java.io.*; 24 import java.net.URL; 25 import java.awt.geom.AffineTransform; 26 import edu.psu.geovista.symbolization.*; 27 import edu.psu.geovista.ui.event.*; 28 29 public class BiPlotMatrix extends AbstractMatrix 30 implements ListSelectionListener{ 31 private transient String elementClassName; 32 private transient int[] rowInitOrder; 33 private transient int[] columnInitOrder; 34 private transient int[] rowOrder; 35 private transient int[] columnOrder; 36 private transient String[] attributesArray; 37 private transient String[] observNames; 38 private transient int selectedObv; 39 private transient Color foreground = Color.white; 40 protected transient EventListenerList listenerList = new EventListenerList(); 41 private transient Class[] elementClasses = new Class[2]; 42 private transient String[] elementClassNames = new String[2]; 43 private transient BivariateColorSymbolClassificationOneColor bivarOneColor; 44 protected ImageIcon matrixIcon = new ImageIcon(this.getClass().getResource("resources/matrixicon16.gif")); 45 46 public BiPlotMatrix() { 47 super(); 48 //configButton = new JButton(); 49 //configButton.setIcon(this.matrixIcon); 50 } 51 52 /*** 53 * put your documentation comment here 54 * @param classname 55 */ 56 public void setElementClassName1 (String classname) { 57 this.elementClassNames[0] = classname; 58 try { 59 setElementClass1((this.elementClassNames[0] != null) ? getClass().forName(this.elementClassNames[0]) : 60 null); 61 } catch (Exception e) { 62 e.printStackTrace(); 63 } 64 } 65 66 public void setElementClassName2 (String classname) { 67 this.elementClassNames[1] = classname; 68 try { 69 setElementClass2((this.elementClassNames[1] != null) ? getClass().forName(this.elementClassNames[1]) : 70 null); 71 } catch (Exception e) { 72 e.printStackTrace(); 73 } 74 } 75 /*** 76 * put your documentation comment here 77 * @return 78 */ 79 public String getElementClassName1 () { 80 return this.elementClassNames[0]; 81 } 82 83 public String getElementClassName2 () { 84 return this.elementClassNames[1]; 85 } 86 /*** 87 * put your documentation comment here 88 * @param obj 89 */ 90 public void setElementClass1 (Object obj) { 91 setElementClassName1((obj != null) ? obj.getClass().getName() : null); 92 } 93 public void setElementClass2 (Object obj) { 94 setElementClassName2((obj != null) ? obj.getClass().getName() : null); 95 } 96 /*** 97 * put your documentation comment here 98 * @param clazz 99 */ 100 public void setElementClass1 (Class clazz) { 101 this.elementClasses[0] = clazz; 102 } 103 public void setElementClass2 (Class clazz) { 104 this.elementClasses[1] = clazz; 105 } 106 /*** 107 * put your documentation comment here 108 */ 109 protected synchronized void init () { 110 111 //System.out.println("get in init()..."); 112 if (!this.recreate) { 113 return; // maybe display error message. 114 } 115 this.removeAll(); 116 panelWidthPixels = DEFAULT_PANEL_WIDTH_PIXELS; 117 panelHeightPixels = DEFAULT_PANEL_HEIGHT_PIXELS; 118 setPanelSize(panelWidthPixels, panelHeightPixels); 119 120 this.bivarOneColor = new BivariateColorSymbolClassificationOneColor(); 121 int colorTotal = this.background.getRed() + this.background.getGreen() + this.background.getBlue(); 122 int greyColor = 128 * 3; 123 if (colorTotal < greyColor) 124 foreground = Color.white; 125 else 126 foreground = Color.black; 127 this.bivarOneColor.setOneColor(foreground); 128 129 if (this.dataObject != null) { 130 131 attList = new JList(this.attributesDisplay); 132 if (this.attributeDescriptions != null){ 133 descriptionList = new JList(this.attributeDescriptions); 134 } 135 this.element = new MatrixElement[plotNumber*plotNumber]; 136 matrixLayout = new GridBagLayout(); 137 c = new SPGridBagConstraints(); 138 //this.setLayout(matrixLayout); 139 c.fill = GridBagConstraints.BOTH; 140 varTags = new String[plotNumber]; 141 createMatrix(); 142 Container parent = getParent(); 143 if (parent != null) { 144 parent.validate(); 145 } 146 else { 147 validate(); 148 } 149 } 150 //for indication 151 super.registerIndicationListeners(); 152 } 153 /*** 154 * put your documentation comment here 155 */ 156 protected void createMatrix () { 157 //System.out.println("create SP:"); 158 this.setLayout(matrixLayout); 159 Dimension size = getSize(); 160 Dimension plotSize = new Dimension(size.width/plotNumber, size.height/plotNumber); 161 columnButton = new SPTagButton[plotNumber]; 162 rowButton = new SPTagButton[this.plotNumber]; 163 Dimension tagDm = new Dimension(0, 0); 164 configButton = new JButton(); 165 try { 166 for (int i = 0; i < plotNumber + 1; i++) { 167 for (int j = 0; j < plotNumber + 1; j++) { 168 if ((i == 0) && (j == 0)) { 169 c.weightx = 0.0; 170 c.weighty = 0.0; 171 c.gridwidth = 1; 172 c.gridheight = 1; 173 174 configButton.setIcon(this.matrixIcon); 175 configButton.addActionListener(new java.awt.event.ActionListener() { 176 177 /*** 178 * Set up the attributes for plotted in SPM. 179 * @param e 180 */ 181 public void actionPerformed (ActionEvent e) { 182 try { 183 configButton_actionPerformed(e); 184 } catch (Exception exception) {} 185 } 186 }); 187 c.column = j; 188 c.row = i; 189 matrixLayout.setConstraints(configButton, c); 190 add(configButton); 191 } 192 else if ((i == 0) && (j != 0)) { 193 c.weightx = 1.0; 194 c.weighty = 0.0; 195 c.gridwidth = this.DEFAULT_BUTTON_CONSTRAINTS; 196 c.gridheight = 1; 197 if (j == plotNumber){ 198 c.gridwidth = GridBagConstraints.REMAINDER; 199 } //end row 200 varTags[j-1] = this.attributesDisplay[plottedAttributes[j - 1]]; 201 columnButton[j-1] = new SPTagButton(varTags[j-1]); 202 columnButton[j-1].setMargin(this.nullInsets); 203 columnButton[j-1].addMouseListener(columnButton[j-1]); 204 columnButton[j-1].addMouseMotionListener(columnButton[j-1]); 205 c.column = j; 206 c.row = i; 207 matrixLayout.setConstraints(columnButton[j-1], c); 208 add(columnButton[j-1]); 209 } 210 else if ((i != 0) && (j == 0)) { 211 c.weightx = 0.0; 212 c.weighty = 1.0; 213 c.gridwidth = 1; 214 c.gridheight = this.DEFAULT_BUTTON_CONSTRAINTS; 215 rowButton[i-1] = new SPTagButton("s"); 216 rowButton[i-1].setMargin(this.nullInsets); 217 rowButton[i-1].setVerticalAlignment(SwingConstants.BOTTOM); 218 rowButton[i-1].setHorizontalAlignment(SwingConstants.CENTER); 219 //JLabel rowLabel = new JLabel(); 220 AffineTransform trans = new AffineTransform(); 221 trans.rotate(-Math.PI/2, rowButton[i-1].getWidth(), rowButton[i-1].getHeight()/2); 222 Font font = new Font("", Font.BOLD, 11); 223 font = font.deriveFont(trans); 224 //rowLabel.setFont(font); 225 //BufferedImage labelImage = new BufferedImage(rowLabel.getWidth()+1,rowLabel.getHeight()+1,BufferedImage.TYPE_INT_ARGB); 226 //Graphics2D g2 = labelImage.createGraphics(); 227 //rowButton[i-1].paint(g2); 228 rowButton[i-1].setFont(font); 229 rowButton[i-1].setText(varTags[i-1]); 230 rowButton[i-1].addMouseListener(rowButton[i-1]); 231 rowButton[i-1].addMouseMotionListener(rowButton[i-1]); 232 c.column = j; 233 c.row = i; 234 matrixLayout.setConstraints(rowButton[i-1], c); 235 add(rowButton[i-1]); 236 } 237 else { 238 c.weightx = 1.0; 239 c.weighty = 1.0; 240 c.gridwidth = this.DEFAULT_BUTTON_CONSTRAINTS; 241 c.gridheight = this.DEFAULT_BUTTON_CONSTRAINTS; 242 int indexCurrent = (i - 1)*(plotNumber) + (j - 1); 243 int[] dataIndices = new int[2]; 244 dataIndices[0] = plottedAttributes[j - 1] + 1; 245 dataIndices[1] = plottedAttributes[i - 1] + 1; 246 //construct of each element 247 if (this.elementClasses[0] != null &&this.elementClasses[1] == null){ 248 this.element[indexCurrent] = (MatrixElement)this.elementClasses[0].newInstance(); 249 } else if (this.elementClasses[0] == null &&this.elementClasses[1] != null){ 250 this.element[indexCurrent] = (MatrixElement)this.elementClasses[1].newInstance(); 251 } else if (this.elementClasses[0] != null &&this.elementClasses[1] != null){ 252 if (i <= j) { 253 this.element[indexCurrent] = (MatrixElement)this.elementClasses[0].newInstance(); 254 }else{ 255 this.element[indexCurrent] = (MatrixElement)this.elementClasses[1].newInstance(); 256 } 257 } 258 this.element[indexCurrent].setAxisOn(false); 259 this.element[indexCurrent].setDataObject(this.dataObject); 260 261 this.element[indexCurrent].setBackground(background); 262 this.element[indexCurrent].setElementPosition(dataIndices); 263 this.element[indexCurrent].setSelOriginalColorMode(this.selOriginalColorMode); 264 this.element[indexCurrent].setSelectionColor(this.selectionColor); 265 if ((this.bivarColorClasser != null) && (this.element[indexCurrent].getClass().getName()!="edu.psu.geovista.app.scatterplot.ScatterPlot")){ 266 boolean reverseColor = false; 267 if (i > j){ 268 reverseColor = true; 269 } 270 this.element[indexCurrent].setBivarColorClasser(this.bivarColorClasser, reverseColor); 271 } 272 if (this.colorArrayForObs != null){ 273 this.element[indexCurrent].setColorArrayForObs(this.colorArrayForObs); 274 } 275 if (j == plotNumber) 276 c.gridwidth = GridBagConstraints.REMAINDER; //end row 277 c.column = j; 278 c.row = i; 279 matrixLayout.setConstraints((Component)this.element[indexCurrent], c); 280 add((Component)this.element[indexCurrent]); 281 this.element[indexCurrent].addActionListener(new ActionListener() { 282 283 /*** 284 * Get the event from a unit plot and send it to all units. 285 * @param e 286 */ 287 public void actionPerformed (ActionEvent e) { 288 // This gets the source or originator of the event 289 try { 290 unit_actionPerformed(e); 291 } catch (Exception exception) {} 292 } 293 }); 294 } 295 } 296 } 297 } catch (Exception e) { 298 e.printStackTrace(); 299 } 300 for (int j = 0; j < plotNumber; j++) { 301 if (columnButton[j].getPreferredSize().getWidth() > tagDm.getWidth()) 302 tagDm = columnButton[j].getPreferredSize(); 303 //System.out.println("tagDm: " + tagDm.getWidth() + tagDm.getHeight()); 304 } 305 for (int j = 0; j < plotNumber; j++) { 306 columnButton[j].setPreferredSize(tagDm); 307 columnButton[j].setMinimumSize(tagDm); 308 columnButton[j].setMaximumSize(tagDm); 309 } 310 Dimension rowTag = new Dimension((int)tagDm.getHeight(), (int)tagDm.getHeight()); 311 configButton.setPreferredSize(rowTag); 312 configButton.setMinimumSize(rowTag); 313 configButton.setMaximumSize(rowTag); 314 } 315 316 /*** 317 * put your documentation comment here 318 * @param e 319 */ 320 private void unit_actionPerformed (ActionEvent e) { 321 //ScatterPlot source = (ScatterPlot)e.getSource(); 322 MatrixElement source = (MatrixElement)e.getSource(); 323 String command = e.getActionCommand(); 324 if (command.compareTo(MatrixElement.COMMAND_POINT_SELECTED) == 0) { 325 //System.out.println("SPMC.plotUnitPanel.actionPerformed(), point selected"); 326 //selectedObvs = source.getSelectedObservations(); 327 this.selectedObvsInt = source.getSelections(); 328 for (int k = 0; k < this.plotNumber*this.plotNumber; k++) { 329 MatrixElement otherElement = element[k]; 330 // Don't recall the scatterplot which generated the original event 331 if (otherElement != source) { 332 //otherElement.setSelectedObservations(selectedObvs); 333 otherElement.setSelections(this.selectedObvsInt); 334 } 335 } 336 this.repaint(); 337 fireChangeEvent(); 338 this.fireSelectionChanged(this.getSelectedObvs()); 339 }else if (command.compareTo(MatrixElement.COMMAND_COLOR_CLASSFICIATION) == 0) { 340 this.bivarColorClasser = source.getBivarColorClasser(); 341 boolean reverseColor = false; 342 int row, column; 343 for (int k = 0; k < this.plotNumber*this.plotNumber; k++) { 344 MatrixElement otherElement = element[k]; 345 // Don't recall the scatterplot which generated the original event 346 if (otherElement != source) { 347 row =k/this.plotNumber; 348 column = k%this.plotNumber; 349 if (row > column){ 350 reverseColor = true; 351 }else{ 352 reverseColor = false; 353 } 354 otherElement.setBivarColorClasser(this.bivarColorClasser, reverseColor); 355 } 356 } 357 this.repaint(); 358 fireChangeEvent(); 359 } else { 360 if (command.compareTo(MatrixElement.COMMAND_DATARANGE_SET) == 0) { 361 //System.out.println("SPMC.plotUnitPanel.actionPerformed(), data range"); 362 double[] xAxisExtents = source.getXAxisExtents(); 363 double[] yAxisExtents = source.getYAxisExtents(); 364 int pos = 0; 365 for (int k = 0; k < this.plotNumber*this.plotNumber; k++) { 366 MatrixElement otherElement = element[k]; 367 // Don't recall the scatterplot which generated the original event 368 if (otherElement == source) { 369 pos = k; 370 break; 371 } 372 } 373 int r = pos/plotNumber; 374 int c = pos%plotNumber; 375 //System.out.println("pos: " + pos); 376 for (int i = 0; i < plotNumber; i++) { 377 element[i*plotNumber + c].setXAxisExtents(xAxisExtents);//The xAxisExtents for all of the elements in the same column have to be changed. 378 element[c * plotNumber + i].setYAxisExtents(xAxisExtents);//The yAxisExtents for the corresponding elements on the other side 379 //of diagonal need to be changed. 380 //System.out.println("yAxis: " + (r*plotNumber + i) + " " + (r + i*plotNumber)); 381 element[r*plotNumber + i].setYAxisExtents(yAxisExtents); //The yAxisExtents for all of the elements in the same row have to be changed. 382 element[r + i*plotNumber].setXAxisExtents(yAxisExtents);//The xAxisExtents for the corresponding elements on the other side 383 //of diagonal need to be changed. 384 } 385 } 386 else 387 System.err.println("Unknown command! = " + command); 388 } 389 } 390 391 /*** 392 * Configure attributes for plotted in matrix. 393 * @param e 394 */ 395 private void configButton_actionPerformed (ActionEvent e) { 396 attSelectDialog(400, 400); 397 } 398 399 JFrame dummyFrame = new JFrame(); 400 JDialog dialog = null; 401 JScrollPane dialogPane = null; 402 403 /*** 404 * Construct the variable selection for displaying in the matrix. 405 * @param x 406 * @param y 407 */ 408 private void attSelectDialog (int x, int y) { 409 attList.setSelectedIndices(this.plottedAttributes); 410 if (this.dialog == null) { 411 this.dialog = new JDialog(dummyFrame, "Attributes for Plot", true); 412 JButton selectButton; 413 JButton closeButton; 414 dialog.setSize(150, 300); 415 dialog.getContentPane().setLayout(new BorderLayout()); 416 attList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 417 //attList.addListSelectionListener(this); 418 //JScrollPane scrollPane = new JScrollPane(attList); 419 this.dialogPane = new JScrollPane(attList); 420 selectButton = new JButton("Apply"); 421 selectButton.addActionListener(new java.awt.event.ActionListener() { 422 423 /*** 424 * put your documentation comment here 425 * @param e 426 */ 427 public void actionPerformed (ActionEvent e) { 428 selectButton_actionPerformed(e); 429 } 430 }); 431 closeButton = new JButton("Close"); 432 closeButton.addActionListener(new java.awt.event.ActionListener() { 433 434 /*** 435 * put your documentation comment here 436 * @param e 437 */ 438 public void actionPerformed (ActionEvent e) { 439 closeButton_actionPerformed(e); 440 } 441 }); 442 JPanel buttonPanel = new JPanel(new GridLayout(1, 2)); 443 buttonPanel.add(selectButton); 444 buttonPanel.add(closeButton); 445 446 JPanel attSelPanel = new JPanel(new BorderLayout()); 447 attSelPanel.setPreferredSize(new Dimension(150, 290)); 448 attSelPanel.add(new JLabel("Attribute Names:"), BorderLayout.NORTH); 449 attSelPanel.add(this.dialogPane, BorderLayout.CENTER); 450 attSelPanel.add(buttonPanel, BorderLayout.SOUTH); 451 452 if (this.attributeDescriptions != null){ 453 //System.out.println("attributeDescription not null.."); 454 JPanel descPane = new JPanel(new BorderLayout()); 455 descPane.add(new JLabel("Descriptions:"), BorderLayout.NORTH); 456 JScrollPane descListPane = new JScrollPane(descriptionList); 457 descPane.add(descListPane, BorderLayout.CENTER); 458 dialog.getContentPane().add(descPane, BorderLayout.CENTER); 459 } 460 dialog.getContentPane().add(attSelPanel, BorderLayout.WEST); 461 } 462 else { 463 this.dialogPane.setViewportView(attList); 464 } 465 this.attList.addListSelectionListener(this); 466 this.plottedAttributes = attList.getSelectedIndices(); 467 this.dialog.setLocation(x, y); 468 this.dialog.show(); 469 } 470 471 /*** 472 * put your documentation comment here 473 * @param e 474 */ 475 private void selectButton_actionPerformed (ActionEvent e) { 476 plotNumber = plottedAttributes.length; 477 init(); 478 super.fireSubspaceChanged(plottedAttributes); 479 } 480 481 /*** 482 * put your documentation comment here 483 * @param e 484 */ 485 private void closeButton_actionPerformed (ActionEvent e) { 486 dialog.hide(); 487 } 488 489 /*** 490 * put your documentation comment here 491 * @see ListSelectionListener 492 */ 493 public void valueChanged (ListSelectionEvent e) { 494 if (e.getValueIsAdjusting()) 495 return; 496 JList theList = (JList)e.getSource(); 497 if (theList.isSelectionEmpty()) { 498 return; 499 } 500 else { 501 plottedAttributes = theList.getSelectedIndices(); 502 503 } 504 } 505 }

This page was automatically generated by Maven