View Javadoc
1 package edu.psu.geovista.app.matrix; 2 3 /*** 4 * <p>Title: Studio applications</p> 5 * <p>Description: </p> 6 * <p>Copyright: Copyright (c) 2002</p> 7 * <p>Company: GeoVSITA Center</p> 8 * @author Xiping Dai 9 * @version 1.0 10 */ 11 12 import java.awt.*; 13 import java.lang.*; 14 import java.util.*; 15 import java.awt.event.*; 16 import java.awt.image.*; 17 import java.awt.geom.AffineTransform; 18 import javax.swing.event.*; 19 import javax.swing.*; 20 import java.io.*; 21 import edu.psu.geovista.symbolization.*; 22 import edu.psu.geovista.category.MultiClassDistributions2D; 23 import edu.psu.geovista.ui.event.*; 24 25 public class Distribution2DMatrix extends AbstractMatrix implements ListSelectionListener 26 { 27 28 private transient int[] rowInitOrder; 29 private transient int[] columnInitOrder; 30 private transient int[] rowOrder; 31 private transient int[] columnOrder; 32 private String[] variableNames; 33 private String[] observNames; 34 private int selectedObv; 35 protected transient EventListenerList listenerList = new EventListenerList(); 36 private SPTagButton[] columnButton; 37 private JComboBox attCombo; 38 private int xIdx=0; 39 private int yIdx=0; 40 //private static ImageIcon leftRightArrow; 41 //private static ImageIcon topDownArrow; 42 private static Insets nullInsets; 43 private String[] varTags; 44 private Vector[] dataVector; 45 private MultiClassDistributions2D distributions[]; 46 47 48 public Distribution2DMatrix() 49 { 50 super(); 51 this.setSize(panelWidthPixels, panelHeightPixels); 52 } 53 54 public void setDataVector(Vector[] dataVector){ 55 this.dataVector = dataVector; 56 init(); 57 } 58 59 public void setVariableNames(String[] variableNames){ 60 this.variableNames = variableNames; 61 int numLen; 62 numLen = this.variableNames.length; 63 //check if there are enough attributes to display in matrix from specified beginning. 64 if (plottedBegin >= numLen) { 65 System.err.println("There aren't enough attributes to display! Please reset the begin display attribute or reload a more attribute data file."); 66 return; 67 } 68 plotNumber = (numLen <= maxNumArrays) ? numLen : maxNumArrays; 69 if ((plottedBegin + plotNumber) > numLen) { 70 plotNumber = numLen - plottedBegin; 71 } 72 this.plottedAttributes = new int[plotNumber]; 73 for (int i = plottedBegin; i < plottedBegin + plotNumber; i++) { 74 plottedAttributes[i - plottedBegin] = i; 75 } 76 } 77 78 protected synchronized void init () { 79 //System.out.println("get in init()..."); 80 if (!this.recreate) { 81 return; // maybe display error message. 82 } 83 this.removeAll(); 84 85 attList = new JList(this.variableNames); 86 attCombo = new JComboBox(this.variableNames); 87 88 //varTags = new String[plotNumber]; 89 if (this.dataVector != null) { 90 this.distributions = new MultiClassDistributions2D[plotNumber*plotNumber]; 91 matrixLayout = new GridBagLayout(); 92 c = new SPGridBagConstraints(); 93 c.fill = GridBagConstraints.BOTH; 94 this.createMatrix(); 95 Container parent = getParent(); 96 if (parent != null) { 97 parent.validate(); 98 } 99 else { 100 validate(); 101 } 102 } 103 } 104 105 protected void createMatrix () { 106 107 this.setLayout(matrixLayout); 108 Dimension size = getSize(); 109 Dimension plotSize = new Dimension(size.width/plotNumber, size.height/plotNumber); 110 try { 111 for (int i = 0; i < plotNumber + 1; i++) { 112 for (int j = 0; j < plotNumber + 1; j++) { 113 if ((i == 0) && (j == 0)) { 114 //The M button on left up corner. Click on that will pop up a variable selection dialog for displaying in matrix. 115 c.weightx = 0.0; 116 c.weighty = 0.0; 117 c.gridwidth = 1; 118 c.gridheight = 1; 119 JButton configButton = new JButton("M"); 120 configButton.addActionListener(new java.awt.event.ActionListener() { 121 122 /*** 123 * Set up the attributes for plotted in SPM. 124 * @param e 125 */ 126 public void actionPerformed (ActionEvent e) { 127 try { 128 129 configButton_actionPerformed(e); 130 131 } catch (Exception exception) {} 132 } 133 }); 134 c.column = j; 135 c.row = i; 136 matrixLayout.setConstraints(configButton, c); 137 add(configButton); 138 } 139 else if ((i == 0) && (j != 0)) { 140 //The first row in matrix. They are buttons which can be dragged to change the column position. 141 c.weightx = 1.0; 142 c.weighty = 0.0; 143 c.gridwidth = 4; 144 //c.gridheight = 1; 145 if (j == plotNumber) 146 c.gridwidth = GridBagConstraints.REMAINDER; //end row 147 SPTagButton columnButton = new SPTagButton(leftRightArrow); 148 columnButton.addMouseListener(columnButton); 149 columnButton.addMouseMotionListener(columnButton); 150 c.column = j; 151 c.row = i; 152 matrixLayout.setConstraints(columnButton, c); 153 add(columnButton); 154 } 155 else if ((i != 0) && (j == 0)) { 156 //The first column in matrix. They are buttons which can be dragged to change the row position. 157 c.weightx = 0.0; 158 c.weighty = 1.0; 159 c.gridwidth = 1; 160 c.gridheight = 4; 161 SPTagButton rowButton = new SPTagButton(topDownArrow); 162 rowButton.addMouseListener(rowButton); 163 rowButton.addMouseMotionListener(rowButton); 164 c.column = j; 165 c.row = i; 166 matrixLayout.setConstraints(rowButton, c); 167 add(rowButton); 168 } 169 else { 170 //Actually set up the graph components in matrix. 171 c.weightx = 1.0; 172 c.weighty = 1.0; 173 c.gridwidth = 4; 174 c.gridheight = 4; 175 int indexCurrent = (i - 1)*(plotNumber) + (j - 1); 176 int[] dataIndices = new int[2]; 177 dataIndices[0] = plottedAttributes[j - 1]; //+1 is because in the data structure, we reserve the first element for variable names. 178 dataIndices[1] = plottedAttributes[i - 1]; 179 //construct of each element 180 this.distributions[indexCurrent] = new MultiClassDistributions2D(); 181 this.distributions[indexCurrent].setAxisOn(false); 182 this.distributions[indexCurrent].setDisplayXVariableIndex(dataIndices[0]); 183 this.distributions[indexCurrent].setDisplayYVariableIndex(dataIndices[1]); 184 this.distributions[indexCurrent].setBackground(background); 185 this.distributions[indexCurrent].setGaussOn(true); 186 this.distributions[indexCurrent].setVariableNames(this.variableNames); 187 this.distributions[indexCurrent].setDataVector(this.dataVector); 188 if (j == plotNumber) 189 c.gridwidth = GridBagConstraints.REMAINDER; //end row 190 c.column = j; 191 c.row = i; 192 matrixLayout.setConstraints((Component)this.distributions[indexCurrent], c); 193 add((Component)this.distributions[indexCurrent]); 194 //this.distributions[indexCurrent].addActionListener(new ActionListener() { 195 196 /*** 197 * Get the event from a unit plot and send it to all units. 198 * @param e 199 */ 200 //public void actionPerformed (ActionEvent e) { 201 // This gets the source or originator of the event 202 //try { 203 //unit_actionPerformed(e); 204 //} catch (Exception exception) {} 205 //} 206 //}); 207 } 208 } 209 } 210 } catch (Exception e) { 211 e.printStackTrace(); 212 } 213 } 214 215 /*** 216 * Shift columns or rows in the matrix. 217 * @param lastPos 218 * @param newPos 219 */ 220 protected void moveRowAndColumn (int lastPos, int newPos) { 221 //System.out.println("move row or column..."); 222 int indicesRow; 223 int indicesCol; 224 int indicesLast1; 225 int indicesNew1; 226 int indicesLast2; 227 int indicesNew2; 228 229 for (int i = 0; i < plotNumber; i++) { 230 indicesLast1 = (distributions[i*plotNumber + lastPos - 1].getDisplayXVariableIndex()); 231 indicesLast2 = (distributions[(lastPos - 1)*plotNumber + i].getDisplayYVariableIndex()); 232 //System.out.println("Indices before move" + indicesLast1[0] + indicesLast1[1]); 233 indicesRow = indicesLast1; 234 indicesCol = indicesLast2; 235 indicesNew1 = distributions[i*plotNumber + newPos - 1].getDisplayXVariableIndex(); 236 indicesNew2 = distributions[(newPos - 1)*plotNumber + i].getDisplayYVariableIndex(); 237 //System.out.println("Indices after move" + indicesNew1[0] + indicesNew1[1]); 238 indicesLast1 = indicesNew1; 239 indicesLast2 = indicesNew2; 240 distributions[i*plotNumber + lastPos - 1].setDisplayXVariableIndex(indicesLast1); 241 distributions[(lastPos - 1)*plotNumber + i].setDisplayYVariableIndex(indicesLast2); 242 indicesNew1 = indicesRow; 243 indicesNew2 = indicesCol; 244 distributions[i*plotNumber + newPos - 1].setDisplayXVariableIndex(indicesNew1); 245 distributions[(newPos - 1)*plotNumber + i].setDisplayYVariableIndex(indicesNew2); 246 } 247 } 248 249 /*** 250 * Configure attributes for plotted in matrix. 251 * @param e 252 */ 253 private void configButton_actionPerformed (ActionEvent e) { 254 attSelectDialog(400, 400); 255 } 256 257 JFrame dummyFrame = new JFrame(); 258 JDialog dialog = null; 259 JScrollPane dialogPane = null; 260 261 /*** 262 * put your documentation comment here 263 * @param x 264 * @param y 265 */ 266 private void attSelectDialog (int x, int y) { 267 attList.setSelectedIndices(this.plottedAttributes); 268 if (this.dialog == null) { 269 this.dialog = new JDialog(dummyFrame, "Attributes for Plot", true); 270 JButton selectButton; 271 JButton closeButton; 272 dialog.setSize(150, 250); 273 dialog.getContentPane().setLayout(new BorderLayout()); 274 attList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 275 //attList.addListSelectionListener(this); 276 //JScrollPane scrollPane = new JScrollPane(attList); 277 this.dialogPane = new JScrollPane(attList); 278 279 selectButton = new JButton("Apply"); 280 selectButton.addActionListener(new java.awt.event.ActionListener() { 281 282 /*** 283 * put your documentation comment here 284 * @param e 285 */ 286 public void actionPerformed (ActionEvent e) { 287 selectButton_actionPerformed(e); 288 } 289 }); 290 closeButton = new JButton("Close"); 291 closeButton.addActionListener(new java.awt.event.ActionListener() { 292 293 /*** 294 * put your documentation comment here 295 * @param e 296 */ 297 public void actionPerformed (ActionEvent e) { 298 closeButton_actionPerformed(e); 299 } 300 }); 301 302 JPanel buttonPanel = new JPanel(new BorderLayout()); 303 buttonPanel.add(selectButton, BorderLayout.WEST); 304 buttonPanel.add(closeButton, BorderLayout.EAST); 305 JPanel namePanel = new JPanel(new GridLayout(1,1)); 306 namePanel.add(new JLabel("Column Vars:")); 307 JPanel attPanel = new JPanel(new GridLayout(1,2)); 308 attPanel.add(this.dialogPane); 309 dialog.getContentPane().add(namePanel, BorderLayout.NORTH); 310 dialog.getContentPane().add(attPanel, BorderLayout.CENTER); 311 dialog.getContentPane().add(buttonPanel, BorderLayout.SOUTH); 312 } 313 else { 314 this.dialogPane.setViewportView(attList); 315 } 316 this.attList.addListSelectionListener(this); 317 this.plottedAttributes = attList.getSelectedIndices(); 318 this.dialog.setLocation(x, y); 319 this.dialog.show(); 320 } 321 322 /*** 323 * put your documentation comment here 324 * @param e 325 */ 326 private void selectButton_actionPerformed (ActionEvent e) { 327 plotNumber = plottedAttributes.length; 328 init(); 329 } 330 331 /*** 332 * put your documentation comment here 333 * @param e 334 */ 335 private void closeButton_actionPerformed (ActionEvent e) { 336 dialog.hide(); 337 } 338 339 /*** 340 * put your documentation comment here 341 * @param e 342 */ 343 public void valueChanged (ListSelectionEvent e) { 344 if (e.getValueIsAdjusting()) 345 return; 346 JList theList = (JList)e.getSource(); 347 if (theList.isSelectionEmpty()) { 348 return; 349 } 350 else { 351 plottedAttributes = theList.getSelectedIndices(); 352 } 353 } 354 355 }

This page was automatically generated by Maven