View Javadoc
1 package edu.psu.geovista.data.condition; 2 3 /*** 4 * Title: ConditionManager 5 * Description: 6 * Copyright: Copyright (c) 2001 7 * Company: GeoVISTA 8 * @author Xiping 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 javax.swing.event.*; 17 import javax.swing.*; 18 import java.io.*; 19 import javax.swing.event.EventListenerList; 20 import java.awt.event.ActionEvent; 21 import java.awt.event.ActionListener; 22 import edu.psu.geovista.ui.event.*; 23 24 public class ConditionManager extends JPanel implements ChangeListener, ListSelectionListener, 25 DataSetListener{ 26 27 private static final int TYPE_NONE = -1; 28 private static final int TYPE_NAME = 0; 29 private static final int TYPE_DOUBLE = 1; 30 private static final int TYPE_INTEGER = 2; 31 private static final int TYPE_BOOLEAN = 3; 32 33 private Object[] dataObject; 34 //private String[] observNames; 35 private int[] dataType; 36 private double[][] doubleDataArrays = null; 37 private double[] dataConditionedOn; 38 private String[] attributesArray = null; 39 private String[] attributesDisplay; 40 private int condVarIndex; 41 private double[] conditionRanges; 42 private int[] conditionResults; 43 private JList attList; 44 private JScrollPane attSelectPane; 45 private JComboBox conditionMethod; 46 private String[] method; 47 private String methodName; 48 private JLabel conditionSetLabel; 49 private static String conditionSetStr = "Set Conditions:"; 50 private JTextField[] conditionSetField; 51 private OneVarCondition oneVarCond; 52 private OneVarCondExtremes oneVarCondEx; 53 private double[] minMaxValues; 54 private Object[] rangesTitle = new Object[2]; 55 private JLabel varMin = new JLabel(); 56 private JLabel varMax = new JLabel(); 57 private EventListenerList listenerListAction = new EventListenerList(); 58 private edu.psu.geovista.data.geog.DataSetForApps dataObjTransfer; 59 public ConditionManager() { 60 super(); 61 this.setLayout(new BorderLayout()); 62 this.setSize(300, 300); 63 init(); 64 } 65 66 public void setDataObject (Object[] data) { 67 dataObjTransfer = new edu.psu.geovista.data.geog.DataSetForApps(); 68 dataObjTransfer.setDataObject(data); 69 this.dataObject = dataObjTransfer.getDataSetNumericAndSpatial(); 70 this.attributesDisplay = dataObjTransfer.getAttributeNamesNumeric(); 71 this.dataType = dataObjTransfer.getDataTypeArray(); 72 //this.observNames = dataObjTransfer.getObservationNames(); 73 initList(); 74 this.rangesTitle[0] = this.attributesDisplay[0]; 75 fireChangeEvent (); 76 } 77 78 public void setDoubleDataArrays (double[][] dataArrays) { 79 this.doubleDataArrays = (double[][])dataArrays.clone(); 80 if (this.attributesArray != null && this.doubleDataArrays.length == this.attributesArray.length) { 81 initList(); 82 } 83 } 84 85 public void setAttributesArray (String[] attributesArray) { 86 this.attributesArray = (String[])attributesArray.clone(); 87 if (this.doubleDataArrays != null && this.doubleDataArrays.length == this.attributesArray.length) { 88 initList(); 89 } 90 } 91 92 public void setConditionRanges (double[] ranges){ 93 this.conditionRanges = ranges; 94 if (methodName.equals(method[0])){ 95 oneVarCond = new OneVarCondition(); 96 oneVarCond.setDataArray(this.dataConditionedOn); 97 oneVarCond.setConditionRanges(this.conditionRanges); 98 conditionSetField[0].setText(Double.toString(conditionRanges[0])); 99 conditionSetField[1].setText(Double.toString(conditionRanges[1])); 100 this.conditionResults = (int[])(oneVarCond.getConditionResults()).clone(); 101 ActionEvent e = new ActionEvent(this,1,"condition_set"); 102 fireActionPerformed (e); 103 this.fireConditioningChanged (this.conditionResults); 104 } else if (methodName == method[1]){ 105 oneVarCondEx = new OneVarCondExtremes(); 106 oneVarCondEx.setDataArray(this.dataConditionedOn); 107 oneVarCondEx.setConditionRanges(this.conditionRanges); 108 conditionSetField[0].setText(Double.toString(conditionRanges[0])); 109 conditionSetField[1].setText(Double.toString(conditionRanges[1])); 110 this.conditionResults = (int[])(oneVarCondEx.getConditionResults()).clone(); 111 ActionEvent e = new ActionEvent(this,1,"condition_set"); 112 fireActionPerformed (e); 113 this.fireConditioningChanged (this.conditionResults); 114 115 //} else { 116 } 117 } 118 119 public double getMinimumRanges(){ 120 return this.minMaxValues[0]; 121 } 122 123 public double getMaximumRanges(){ 124 return this.minMaxValues[1]; 125 } 126 127 public double[] getSliderRanges(){ 128 //System.out.println("get ranges for slider..."); 129 return this.minMaxValues; 130 } 131 132 public String getAttributeName(){ 133 //return this.attributesArray[condVarIndex]; 134 return this.attributesDisplay[condVarIndex - 1]; 135 } 136 137 public Object[] getRangesTitle(){ 138 //System.out.println("get rangesTitle for slider..."); 139 return rangesTitle; 140 } 141 142 public int[] getConditionResults(){ 143 //System.out.println("get conditioning in conditionManager"); 144 return conditionResults; 145 } 146 147 public void setConditionResults(int[] conditionResults){ 148 this.conditionResults = conditionResults; 149 } 150 151 void init(){ 152 this.attList = new JList(); 153 this.attList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); 154 this.attList.addListSelectionListener(this); 155 156 this.attSelectPane = new JScrollPane(attList); 157 this.attSelectPane.setViewportView(attList); 158 159 this.method = new String[]{"Display Focus", "Display Extreme", "Display All", "Two Var Condtion"}; 160 this.conditionMethod = new JComboBox(method); 161 conditionMethod.addActionListener(new ActionListener() { 162 public void actionPerformed(ActionEvent e) { 163 JComboBox cb = (JComboBox)e.getSource(); 164 methodName = (String)cb.getSelectedItem(); 165 166 } 167 }); 168 conditionMethod.setSelectedIndex(0); 169 170 JButton okButton; 171 JButton cancelButton; 172 okButton = new JButton("OK"); 173 okButton.addActionListener(new java.awt.event.ActionListener() { 174 /*** 175 * put your documentation comment here 176 * @param e 177 */ 178 public void actionPerformed (ActionEvent e) { 179 okButton_actionPerformed(e); 180 } 181 }); 182 183 cancelButton = new JButton("Cancel"); 184 cancelButton.addActionListener(new java.awt.event.ActionListener() { 185 public void actionPerformed(ActionEvent e) { 186 cancelButton_actionPerformed(e); 187 } 188 }); 189 190 conditionSetLabel = new JLabel(conditionSetStr); 191 192 varMin.setText("unknown"); 193 varMax.setText("unknown"); 194 195 conditionSetField = new JTextField[2]; 196 conditionSetField[0] = new JTextField(8); 197 conditionSetField[1] = new JTextField(8); 198 //end loop 199 200 JPanel attPanel = new JPanel(new BorderLayout()); 201 attPanel.add(new JLabel("Attribute Names:"), BorderLayout.NORTH); 202 attPanel.add(attSelectPane, BorderLayout.CENTER); 203 204 JPanel comboPanel = new JPanel(new BorderLayout()); 205 comboPanel.add(new JLabel("ConditionMethods:"), BorderLayout.NORTH); 206 JPanel tmpComboPanel = new JPanel(new BorderLayout()); 207 tmpComboPanel.add(conditionMethod, BorderLayout.NORTH); 208 comboPanel.add(tmpComboPanel, BorderLayout.CENTER); 209 210 JPanel conditionPanel = new JPanel(new BorderLayout()); 211 JPanel conditionField = new JPanel(new GridLayout(1, 4)); 212 conditionField.add(varMin); //loop 213 conditionField.add(conditionSetField[0]); 214 conditionField.add(conditionSetField[1]); 215 conditionField.add(varMax); 216 217 conditionPanel.add(conditionSetLabel, BorderLayout.NORTH); 218 conditionPanel.add(conditionField, BorderLayout.CENTER); 219 conditionPanel.add(okButton, BorderLayout.SOUTH); 220 221 this.add(attPanel, BorderLayout.CENTER); 222 this.add(comboPanel, BorderLayout.EAST); 223 this.add(conditionPanel, BorderLayout.SOUTH); 224 225 this.validate(); 226 } 227 228 void initList(){ 229 int observLen = 0; 230 observLen = this.dataObjTransfer.getNumObservations(); 231 this.conditionResults = new int[observLen]; 232 233 //this.conditionResults = new int[this.attributesArray.length]; //mistake. should be observations' #. 234 if (this.attList == null) { 235 //this.attList = new JList(attributesArray); 236 this.attList = new JList(this.attributesDisplay); 237 } else { 238 //this.attList.setListData(attributesArray); 239 this.attList.setListData(this.attributesDisplay); 240 } 241 //this.condVarIndex = 0; 242 this.condVarIndex = 1; //first object in dataset is the variable names. So, data begins with 1. 243 //this.attList.setSelectedIndex(condVarIndex); 244 this.attList.setSelectedIndex(condVarIndex-1); 245 setMinMaxValues(condVarIndex); 246 this.validate(); 247 } 248 249 void setMinMaxValues(int index) { 250 boolean[] dataBoolean; 251 int[] dataInt; 252 int len; 253 if (dataObject[index] instanceof double[]) { 254 this.dataConditionedOn = (double[])(dataObject[index]); 255 } 256 else if (dataObject[index] instanceof int[]) { 257 dataInt = (int[])dataObject[index]; 258 len = dataInt.length; 259 dataConditionedOn = new double[len]; 260 for (int i = 0; i < len; i++) { 261 dataConditionedOn[i] = (double)dataInt[i]; 262 } 263 } 264 else if (dataObject[index] instanceof boolean[]) { 265 dataBoolean = (boolean[])dataObject[index]; 266 len = dataBoolean.length; 267 dataConditionedOn = new double[len]; 268 for (int i = 0; i < len; i++) { 269 if (dataBoolean[i] == true) { 270 dataConditionedOn[i] = 1; 271 } 272 else 273 dataConditionedOn[i] = 0; 274 } 275 } 276 minMaxValues = getMinMaxValues(dataConditionedOn); 277 rangesTitle[1] = minMaxValues; 278 varMin.setText(Double.toString(minMaxValues[0])); 279 varMax.setText(Double.toString(minMaxValues[1])); 280 conditionSetField[0].setText(Double.toString(minMaxValues[0])); 281 conditionSetField[1].setText(Double.toString(minMaxValues[1])); 282 } 283 284 private void okButton_actionPerformed (ActionEvent e) { 285 if (methodName.equals(method[0])){ 286 oneVarCond = new OneVarCondition(); 287 oneVarCond.setDataArray(this.dataConditionedOn); 288 289 // set conditionRanges 290 if (this.conditionRanges == null) { 291 this.conditionRanges = new double[2]; 292 } 293 this.conditionRanges[0] = Double.parseDouble(conditionSetField[0].getText()); 294 this.conditionRanges[1] = Double.parseDouble(conditionSetField[1].getText()); 295 oneVarCond.setConditionRanges(this.conditionRanges); 296 this.conditionResults = (int[])(oneVarCond.getConditionResults()).clone(); 297 this.minMaxValues = this.conditionRanges; 298 this.rangesTitle[1] = minMaxValues; 299 fireChangeEvent (); 300 this.fireConditioningChanged (this.conditionResults); 301 fireActionPerformed (e); 302 } else if (methodName == method[1]){ 303 this.oneVarCondEx = new OneVarCondExtremes(); 304 this.oneVarCondEx.setDataArray(this.dataConditionedOn); 305 // set conditionRanges 306 if (this.conditionRanges == null) { 307 this.conditionRanges = new double[2]; 308 } 309 this.conditionRanges[0] = Double.parseDouble(conditionSetField[0].getText()); 310 this.conditionRanges[1] = Double.parseDouble(conditionSetField[1].getText()); 311 oneVarCondEx.setConditionRanges(this.conditionRanges); 312 this.conditionResults = (int[])(oneVarCondEx.getConditionResults()).clone(); 313 this.minMaxValues = this.conditionRanges; 314 this.rangesTitle[1] = this.minMaxValues; 315 fireChangeEvent (); 316 this.fireConditioningChanged (this.conditionResults); 317 fireActionPerformed (e); 318 } 319 //} else { 320 } 321 322 void cancelButton_actionPerformed(ActionEvent e){ 323 //System.exit(0); 324 } 325 326 public void valueChanged (ListSelectionEvent e) { 327 if (e.getValueIsAdjusting()) 328 return; 329 JList theList = (JList)e.getSource(); 330 if (theList.isSelectionEmpty()) { 331 return; 332 } 333 else { 334 condVarIndex = theList.getSelectedIndex() + 1; //dataObject[0] is attribute name array. 335 setMinMaxValues(condVarIndex); 336 this.rangesTitle[0] = this.attributesDisplay[condVarIndex - 1]; 337 this.rangesTitle[1] = this.minMaxValues; 338 fireChangeEvent (); 339 } 340 } 341 342 private double[] getMinMaxValues(double[] dataArray){ 343 double[] minMaxValues = new double[2]; 344 minMaxValues[0] = dataArray[0]; 345 minMaxValues[1] = dataArray[0]; 346 for (int i = 1; i<dataArray.length; i++){ 347 if (minMaxValues[0] > dataArray[i]){ 348 minMaxValues[0] = dataArray[i]; 349 } 350 if (minMaxValues[1] < dataArray[i]){ 351 minMaxValues[1] = dataArray[i]; 352 } 353 } 354 return minMaxValues; 355 } 356 357 public void stateChanged (ChangeEvent e) { 358 JButton button = (JButton)e.getSource(); 359 } 360 361 public void addChangeListener (ChangeListener l) { 362 this.listenerList.add(ChangeListener.class, l); 363 } 364 365 /*** 366 * put your documentation comment here 367 * @param l 368 */ 369 public void removeChangeListener (ChangeListener l) { 370 this.listenerList.remove(ChangeListener.class, l); 371 } 372 373 /*** 374 * put your documentation comment here 375 */ 376 private void fireChangeEvent () { 377 Object[] listeners = this.listenerList.getListenerList(); 378 // Process the listeners last to first, notifying 379 // those that are interested in this event 380 for (int i = listeners.length - 2; i >= 0; i -= 2) { 381 if (listeners[i] == ChangeListener.class) { 382 ((ChangeListener)listeners[i + 1]).stateChanged(new ChangeEvent(this)); 383 } 384 } // end for 385 } 386 387 //Work with coordinator. 388 public void dataSetChanged(DataSetEvent e){ 389 this.setDataObject(e.getDataSet()); 390 } 391 392 /*** 393 * adds an SelectionListener. 394 * @see EventListenerList 395 */ 396 public void addConditioningListener (ConditioningListener l) { 397 398 listenerList.add(ConditioningListener.class, l); 399 } 400 /*** 401 * removes an SelectionListener from the component. 402 * @see EventListenerList 403 */ 404 public void removeConditioningListener (ConditioningListener l) { 405 listenerList.remove(ConditioningListener.class, l); 406 407 } 408 409 /*** 410 * Notify all listeners that have registered interest for 411 * notification on this event type. The event instance 412 * is lazily created using the parameters passed into 413 * the fire method. 414 * @see EventListenerList 415 */ 416 public void fireConditioningChanged (int[] condition) { 417 418 // Guaranteed to return a non-null array 419 Object[] listeners = listenerList.getListenerList(); 420 ConditioningEvent e = null; 421 // Process the listeners last to first, notifying 422 // those that are interested in this event 423 for (int i = listeners.length - 2; i >= 0; i -= 2) { 424 if (listeners[i] == ConditioningListener.class) { 425 // Lazily create the event: 426 if (e == null) { 427 e = new ConditioningEvent(this, condition); 428 } 429 ((ConditioningListener)listeners[i + 1]).conditioningChanged(e); 430 } 431 }//next i 432 433 } 434 /*** 435 * adds an ActionListener to the button 436 */ 437 public void addActionListener (ActionListener l) { 438 listenerListAction.add(ActionListener.class, l); 439 } 440 441 /*** 442 * removes an ActionListener from the button 443 */ 444 public void removeActionListener (ActionListener l) { 445 listenerListAction.remove(ActionListener.class, l); 446 } 447 448 /*** 449 * Notify all listeners that have registered interest for 450 * notification on this event type. The event instance 451 * is lazily created using the parameters passed into 452 * the fire method. 453 * @see EventListenerList 454 */ 455 public void fireActionPerformed (ActionEvent e) { 456 // Guaranteed to return a non-null array 457 Object[] listeners = listenerListAction.getListenerList(); 458 // Process the listeners last to first, notifying 459 // those that are interested in this event 460 ActionEvent e2 = new ActionEvent(this,ActionEvent.ACTION_PERFORMED,"OK"); 461 for (int i = listeners.length - 2; i >= 0; i -= 2) { 462 if (listeners[i] == ActionListener.class) { 463 // Lazily create the event: 464 ((ActionListener)listeners[i + 1]).actionPerformed(e2); 465 } 466 } 467 } 468 }

This page was automatically generated by Maven