1 /*
2 * MainPanel.java
3 *
4 * Created on 18. November 2001, 20:27
5 *
6 * Copyright 2001 by Flo Ledermann flo@subnet.at
7 *
8 * Licensed under GNU General Public License (GPL).
9 * See http://www.gnu.org/copyleft/gpl.html
10 */
11 package edu.psu.geovista.app.parvis.gui;
12
13 import edu.psu.geovista.app.parvis.file.*;
14 import edu.psu.geovista.app.parvis.model.*;
15 import edu.psu.geovista.classification.ClassifierPicker;
16 import edu.psu.geovista.data.DescriptiveStatistics;
17 import edu.psu.geovista.data.geog.DataSetForApps;
18 import edu.psu.geovista.io.*;
19 import edu.psu.geovista.symbolization.*;
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
27 import java.net.*;
28
29 import java.util.Vector;
30
31 import javax.swing.*;
32
33
34 /***
35 * A Panel containing a ParallelDisplay and the most important control features.
36 * To be used in applets and applications.
37 *
38 * @author Flo Ledermann flo@subnet.at
39 */
40 public class MainPanel extends javax.swing.JPanel implements ProgressListener,
41 DataSetListener, IndicationListener, SelectionListener, ColorArrayListener,
42 SubspaceListener, PalletListener, ConditioningListener {
43 JToggleButton lastButton = null;
44 VisualClassifier vc = null;
45 int[] activeVariables = null;
46 DataSetForApps dataSet = null;//contains original data set
47 private int maxAxes = 6;
48 private long progressstart = 0;
49
50 // Variables declaration - do not modify//GEN-BEGIN:variables
51 private javax.swing.JMenuItem openLocationItem;
52 private javax.swing.JPanel renderPanel;
53 private javax.swing.JToggleButton reorderButton;
54 private javax.swing.JButton minMaxButton;
55 private javax.swing.JRadioButton qualityButton;
56 private javax.swing.JRadioButton progressiveButton;
57 private javax.swing.JMenuItem openFileItem;
58 private javax.swing.JMenuBar mainMenuBar;
59 private javax.swing.JLabel renderLabel;
60 private javax.swing.JRadioButton previewButton;
61 private javax.swing.JButton minMaxAbsButton;
62 private javax.swing.JButton varMinMaxButton;
63 private javax.swing.JProgressBar renderProgressBar;
64 private javax.swing.JPanel optionsPanel;
65 private javax.swing.JToggleButton brushButton;
66 private javax.swing.JButton jButton1;
67 private edu.psu.geovista.app.parvis.gui.ParallelDisplay parallelDisplay;
68 private javax.swing.JCheckBox numberBox;
69 private javax.swing.JMenu editMenu;
70 private javax.swing.JToggleButton scaleButton;
71 private javax.swing.JLabel label;
72 private javax.swing.JToggleButton translateButton;
73 private javax.swing.JPanel dragModePanel;
74 private javax.swing.ButtonGroup renderButtons;
75 private javax.swing.JTextField urlField;
76 private javax.swing.JButton load;
77 private javax.swing.JLabel timeLabel;
78 private javax.swing.JPanel dummyPanel;
79 private javax.swing.JPanel openPanel;
80 private javax.swing.JMenu fileMenu;
81 private javax.swing.JButton zeroMaxButton;
82
83 // End of variables declaration//GEN-END:variables
84 //other variables
85 private double nullSeperator = 0.1d;
86
87 /***
88 * Default Constructor. Creates a new MainPanel.
89 */
90 public MainPanel() {
91 this.vc = new VisualClassifier();
92 initComponents();
93
94 lastButton = reorderButton;
95
96 reorderButton.setCursor(Cursor.getPredefinedCursor(
97 Cursor.E_RESIZE_CURSOR));
98 scaleButton.setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));
99 translateButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
100
101 parallelDisplay.addProgressListener(this);
102 parallelDisplay.addIndicationListener(this);
103 }
104
105 /*** This method is called from within the constructor to
106 * initialize the form.
107 * WARNING: Do NOT modify this code. The content of this method is
108 * always regenerated by the Form Editor.
109 */
110 private void initComponents() { //GEN-BEGIN:initComponents
111
112 java.awt.GridBagConstraints gridBagConstraints;
113
114 mainMenuBar = new javax.swing.JMenuBar();
115
116 //fileMenu = new javax.swing.JMenu();
117 //openFileItem = new javax.swing.JMenuItem();
118 openLocationItem = new javax.swing.JMenuItem();
119 editMenu = new javax.swing.JMenu();
120 renderButtons = new javax.swing.ButtonGroup();
121 openPanel = new javax.swing.JPanel();
122 label = new javax.swing.JLabel();
123 urlField = new javax.swing.JTextField();
124 load = new javax.swing.JButton();
125 parallelDisplay = new edu.psu.geovista.app.parvis.gui.ParallelDisplay();
126 dragModePanel = new javax.swing.JPanel();
127 reorderButton = new javax.swing.JToggleButton();
128 scaleButton = new javax.swing.JToggleButton();
129 translateButton = new javax.swing.JToggleButton();
130 brushButton = new javax.swing.JToggleButton();
131 jButton1 = new javax.swing.JButton();
132 optionsPanel = new javax.swing.JPanel();
133 numberBox = new javax.swing.JCheckBox();
134 zeroMaxButton = new javax.swing.JButton();
135 minMaxButton = new javax.swing.JButton();
136 minMaxAbsButton = new javax.swing.JButton();
137 varMinMaxButton = new javax.swing.JButton();
138 dummyPanel = new javax.swing.JPanel();
139 renderPanel = new javax.swing.JPanel();
140 renderLabel = new javax.swing.JLabel();
141 renderProgressBar = new javax.swing.JProgressBar();
142 timeLabel = new javax.swing.JLabel();
143 previewButton = new javax.swing.JRadioButton();
144 qualityButton = new javax.swing.JRadioButton();
145 progressiveButton = new javax.swing.JRadioButton();
146
147 //fileMenu.setText("File");
148 //openFileItem.setText("Open File...");
149 //fileMenu.add(openFileItem);
150 //openLocationItem.setText("Open URL...");
151 //fileMenu.add(openLocationItem);
152 //mainMenuBar.add(fileMenu);
153 //editMenu.setText("Menu");
154 //mainMenuBar.add(editMenu);
155 setLayout(new java.awt.GridBagLayout());
156
157 //openPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
158 /*
159 openPanel.setBorder(new javax.swing.border.TitledBorder(new javax.swing.border.EtchedBorder(), "Datasource", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.TOP));
160 label.setText("url:");
161 openPanel.add(label);
162
163 urlField.setToolTipText("Type in URL to load. Press enter.");
164 urlField.setText("file:///D:/Uni/visualisierung/datasets/cameras.stf");
165 urlField.setPreferredSize(new java.awt.Dimension(300, 21));
166 urlField.addActionListener(new java.awt.event.ActionListener() {
167 public void actionPerformed(java.awt.event.ActionEvent evt) {
168 urlFieldActionPerformed(evt);
169 }
170 });
171
172 openPanel.add(urlField);
173
174 load.setToolTipText("Press to choose a file from your local HD.");
175 load.setText("open File...");
176 load.setBorder(new javax.swing.border.EtchedBorder());
177 load.addActionListener(new java.awt.event.ActionListener() {
178 public void actionPerformed(java.awt.event.ActionEvent evt) {
179 loadActionPerformed(evt);
180 }
181 });
182
183 openPanel.add(load);
184 */
185 gridBagConstraints = new java.awt.GridBagConstraints();
186 gridBagConstraints.gridx = 0;
187 gridBagConstraints.gridy = 1;
188 gridBagConstraints.weightx = 1.0;
189 add(openPanel, gridBagConstraints);
190
191 gridBagConstraints = new java.awt.GridBagConstraints();
192 gridBagConstraints.gridx = 0;
193 gridBagConstraints.gridy = 0;
194 gridBagConstraints.gridwidth = 2;
195 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
196 gridBagConstraints.weightx = 1.0;
197 gridBagConstraints.weighty = 1.0;
198 add(parallelDisplay, gridBagConstraints);
199
200 dragModePanel.setLayout(new java.awt.FlowLayout(
201 java.awt.FlowLayout.LEFT));
202
203 dragModePanel.setBorder(new javax.swing.border.TitledBorder(
204 new javax.swing.border.EtchedBorder(), "Drag Mode"));
205 reorderButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/psu/geovista/app/parvis/gui/reorder.gif")));
206 reorderButton.setToolTipText(
207 "Reorder axes by dragging them across the display.");
208 reorderButton.setSelected(true);
209 reorderButton.setFont(new java.awt.Font("Dialog", 0, 10));
210 reorderButton.setText("order");
211 reorderButton.setPreferredSize(new java.awt.Dimension(65, 27));
212 reorderButton.setMaximumSize(new java.awt.Dimension(65, 27));
213 reorderButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
214 reorderButton.setMinimumSize(new java.awt.Dimension(65, 27));
215 reorderButton.addActionListener(new java.awt.event.ActionListener() {
216 public void actionPerformed(java.awt.event.ActionEvent evt) {
217 reorderPressed(evt);
218 }
219 });
220
221 dragModePanel.add(reorderButton);
222
223 scaleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/psu/geovista/app/parvis/gui/scale.gif")));
224 scaleButton.setToolTipText(
225 "Scale axes by dragging up (zoom out) or down (zoom in).");
226 scaleButton.setFont(new java.awt.Font("Dialog", 0, 10));
227 scaleButton.setText("scale");
228 scaleButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
229 scaleButton.addActionListener(new java.awt.event.ActionListener() {
230 public void actionPerformed(java.awt.event.ActionEvent evt) {
231 scaleButtonActionPerformed(evt);
232 }
233 });
234
235 dragModePanel.add(scaleButton);
236
237 translateButton.setIcon(new javax.swing.ImageIcon(
238 getClass().getResource("/edu/psu/geovista/app/parvis/gui/move.gif")));
239 translateButton.setToolTipText("Translate axes by dragging up or down.");
240 translateButton.setFont(new java.awt.Font("Dialog", 0, 10));
241 translateButton.setText("translate");
242 translateButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
243 translateButton.addActionListener(new java.awt.event.ActionListener() {
244 public void actionPerformed(java.awt.event.ActionEvent evt) {
245 translateButtonActionPerformed(evt);
246 }
247 });
248
249 dragModePanel.add(translateButton);
250
251 brushButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/edu/psu/geovista/app/parvis/gui/brush.gif")));
252 brushButton.setToolTipText("Translate axes by dragging up or down.");
253 brushButton.setFont(new java.awt.Font("Dialog", 0, 10));
254 brushButton.setText("brush");
255 brushButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
256 brushButton.addActionListener(new java.awt.event.ActionListener() {
257 public void actionPerformed(java.awt.event.ActionEvent evt) {
258 brushButtonActionPerformed(evt);
259 }
260 });
261
262 dragModePanel.add(brushButton);
263
264 jButton1.setText("gc()");
265 jButton1.addActionListener(new java.awt.event.ActionListener() {
266 public void actionPerformed(java.awt.event.ActionEvent evt) {
267 jButton1ActionPerformed(evt);
268 }
269 });
270
271 //dragModePanel.add(jButton1); only use garbage collection in debug mode
272 gridBagConstraints = new java.awt.GridBagConstraints();
273 gridBagConstraints.gridx = 0;
274 gridBagConstraints.gridy = 2;
275 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
276 add(dragModePanel, gridBagConstraints);
277
278 optionsPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
279
280 optionsPanel.setBorder(new javax.swing.border.TitledBorder(
281 new javax.swing.border.EtchedBorder(), "Options"));
282 numberBox.setToolTipText(
283 "Display numeric tooltips when hovering over a record.");
284 numberBox.setSelected(true);
285 numberBox.setText("show Numbers");
286 numberBox.addActionListener(new java.awt.event.ActionListener() {
287 public void actionPerformed(java.awt.event.ActionEvent evt) {
288 numberBoxActionPerformed(evt);
289 }
290 });
291
292 optionsPanel.add(numberBox);
293
294 zeroMaxButton.setText("0-max scale");
295 zeroMaxButton.addActionListener(new java.awt.event.ActionListener() {
296 public void actionPerformed(java.awt.event.ActionEvent evt) {
297 zeroMaxButtonActionPerformed(evt);
298 }
299 });
300
301 optionsPanel.add(zeroMaxButton);
302
303 minMaxButton.setText("min-max scale");
304 minMaxButton.addActionListener(new java.awt.event.ActionListener() {
305 public void actionPerformed(java.awt.event.ActionEvent evt) {
306 minMaxButtonActionPerformed(evt);
307 }
308 });
309
310 optionsPanel.add(minMaxButton);
311
312 minMaxAbsButton.setText("min-max(abs) scale");
313
314 minMaxAbsButton.addActionListener(new java.awt.event.ActionListener() {
315 public void actionPerformed(java.awt.event.ActionEvent evt) {
316 minMaxAbsButtonActionPerformed(evt);
317 }
318 });
319 optionsPanel.add(minMaxAbsButton);
320
321 varMinMaxButton.setText("min-max variable");
322
323 varMinMaxButton.addActionListener(new java.awt.event.ActionListener() {
324 public void actionPerformed(java.awt.event.ActionEvent evt) {
325 varMinMaxButtonActionPerformed(evt);
326 }
327 });
328 optionsPanel.add(varMinMaxButton);
329
330 gridBagConstraints = new java.awt.GridBagConstraints();
331 gridBagConstraints.gridx = 0;
332 gridBagConstraints.gridy = 3;
333 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
334 add(optionsPanel, gridBagConstraints);
335
336 gridBagConstraints = new java.awt.GridBagConstraints();
337 gridBagConstraints.gridx = 1;
338 gridBagConstraints.gridy = 1;
339 add(dummyPanel, gridBagConstraints);
340
341 renderPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
342 renderPanel.setBorder(new javax.swing.border.TitledBorder(
343 new javax.swing.border.EtchedBorder(), "Visual Classifier"));
344 renderPanel.add(vc);
345 vc.setPreferredSize(new Dimension(600, 20));
346 vc.getSymbolizationPanel().setLowColor(Color.black);
347
348 vc.addColorArrayListener(this);
349 vc.setVariableChooserMode(ClassifierPicker.VARIABLE_CHOOSER_MODE_ACTIVE);
350
351 // renderLabel.setText("progress:");
352 // renderLabel.setFont(new java.awt.Font("Dialog", 0, 12));
353 // renderPanel.add(renderLabel);
354 //
355 // renderProgressBar.setFont(new java.awt.Font("Dialog", 0, 10));
356 // renderProgressBar.setPreferredSize(new java.awt.Dimension(100, 20));
357 // renderProgressBar.setStringPainted(true);
358 // renderPanel.add(renderProgressBar);
359 //
360 // timeLabel.setText("0.0 s");
361 // renderPanel.add(timeLabel);
362 //
363 // previewButton.setText("preview");
364 // renderPanel.add(previewButton);
365 //
366 // qualityButton.setText("quality");
367 // renderPanel.add(qualityButton);
368 //
369 // progressiveButton.setSelected(true);
370 // progressiveButton.setText("progressive");
371 // renderPanel.add(progressiveButton);
372 //
373 gridBagConstraints = new java.awt.GridBagConstraints();
374 gridBagConstraints.gridx = 0;
375 gridBagConstraints.gridy = 4;
376 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
377 add(renderPanel, gridBagConstraints);
378 }
379 //GEN-END:initComponents
380
381 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_jButton1ActionPerformed
382 System.gc();
383 }
384 //GEN-LAST:event_jButton1ActionPerformed
385
386 private void brushButtonActionPerformed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_brushButtonActionPerformed
387
388 if (lastButton != null) {
389 lastButton.setSelected(false);
390 }
391
392 lastButton = (JToggleButton) evt.getSource();
393 lastButton.setSelected(true);
394
395 parallelDisplay.setEditMode(ParallelDisplay.BRUSH);
396 }
397 //GEN-LAST:event_brushButtonActionPerformed
398
399 private void minMaxAbsButtonActionPerformed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_minMaxAbsButtonActionPerformed
400 parallelDisplay.minMaxAbsScale();
401 }
402 //GEN-LAST:event_minMaxAbsButtonActionPerformed
403
404 private void varMinMaxButtonActionPerformed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_minMaxAbsButtonActionPerformed
405
406 int var = this.vc.getCurrVariableIndex();
407 parallelDisplay.varMinMaxScale(var);
408 }
409 //GEN-LAST:event_minMaxAbsButtonActionPerformed
410
411 private void minMaxButtonActionPerformed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_minMaxButtonActionPerformed
412 parallelDisplay.minMaxScale();
413 }
414 //GEN-LAST:event_minMaxButtonActionPerformed
415
416 private void zeroMaxButtonActionPerformed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_zeroMaxButtonActionPerformed
417 parallelDisplay.zeroMaxScale();
418 }
419 //GEN-LAST:event_zeroMaxButtonActionPerformed
420
421 private void numberBoxActionPerformed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_numberBoxActionPerformed
422 parallelDisplay.setBoolPreference("hoverText", numberBox.isSelected());
423 }
424 //GEN-LAST:event_numberBoxActionPerformed
425
426 private void translateButtonActionPerformed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_translateButtonActionPerformed
427
428 if (lastButton != null) {
429 lastButton.setSelected(false);
430 }
431
432 lastButton = (JToggleButton) evt.getSource();
433 lastButton.setSelected(true);
434
435 parallelDisplay.setEditMode(ParallelDisplay.TRANSLATE);
436 }
437 //GEN-LAST:event_translateButtonActionPerformed
438
439 private void scaleButtonActionPerformed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_scaleButtonActionPerformed
440
441 if (lastButton != null) {
442 lastButton.setSelected(false);
443 }
444
445 lastButton = (JToggleButton) evt.getSource();
446 lastButton.setSelected(true);
447
448 parallelDisplay.setEditMode(ParallelDisplay.SCALE);
449 }
450 //GEN-LAST:event_scaleButtonActionPerformed
451
452 private void reorderPressed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_reorderPressed
453
454 if (lastButton != null) {
455 lastButton.setSelected(false);
456 }
457
458 lastButton = (JToggleButton) evt.getSource();
459 lastButton.setSelected(true);
460
461 parallelDisplay.setEditMode(ParallelDisplay.REORDER);
462 }
463 //GEN-LAST:event_reorderPressed
464
465 private void urlFieldActionPerformed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_urlFieldActionPerformed
466
467 try {
468 STFFile f = new STFFile(new URL(urlField.getText()));
469 f.addProgressListener(this);
470
471 f.readContents();
472
473 parallelDisplay.setModel(f);
474 } catch (Exception e) {
475 System.out.println(e.toString() + e.getMessage());
476 }
477 }
478 //GEN-LAST:event_urlFieldActionPerformed
479
480 public void setDataSet(Object[] dataSet) {
481 this.vc.setData(dataSet);
482
483 STFDataSet ds = new STFDataSet(dataSet);
484
485 parallelDisplay.setModel(ds);
486
487 //Color[] colors = this.vc.getColorForObservations();
488 this.setColors(this.vc.getColorForObservations());
489 }
490
491 /*
492 * Added Frank Hardisty 19 July 2002
493 */
494 public void indicationChanged(IndicationEvent e) {
495 Object source = e.getSource();
496
497 if (source == this.parallelDisplay) {
498 this.fireIndicationChanged(e.getIndication());
499 } else {
500 parallelDisplay.indicationChanged(e);
501 }
502 }
503
504 /*
505 * Added Frank Hardisty 19 July 2002
506 */
507 public void selectionChanged(SelectionEvent e) {
508 // if (this.isVisible() == false){
509 // return;
510 // }
511 // if (this.getWidth() * this.getHeight() <= 0){
512 // return;
513 // }
514 this.parallelDisplay.selectionChanged(e);
515 parallelDisplay.setEditMode(ParallelDisplay.BRUSH);
516
517 //this.brushButtonActionPerformed(new ActionEvent(this,ActionEvent.ACTION_PERFORMED,"hi"));
518 }
519 public void conditioningChanged(ConditioningEvent e){
520 int[] conditioning = e.getConditioning();
521 BasicParallelDisplayUI ui = (BasicParallelDisplayUI) this.parallelDisplay.getUI();
522 ui.setConditioning(conditioning);
523 this.parallelDisplay.deepRepaint = true;
524 this.repaint();
525 }
526 public void colorArrayChanged(ColorArrayEvent e) {
527 Color[] colors = e.getColors();
528
529 if ((colors == null) || (colors.length == 0)) {
530 return;
531 }
532
533 this.setColors(colors);
534
535 //System.out.println("pcp mainPanel, got colors!");
536 }
537
538 public void setColors(Color[] colors) {
539 BasicParallelDisplayUI ui = (BasicParallelDisplayUI) this.parallelDisplay.getUI();
540 ui.setColors(colors);
541 this.parallelDisplay.deepRepaint = true;
542 this.repaint();
543 }
544
545
546 public void palletChanged(PalletEvent e){
547 this.vc.palletChanged(e);
548 }
549
550 /*
551 * Added Frank Hardisty 19 July 2002
552 */
553 public void dataSetChanged(DataSetEvent e) {
554 //no more hacks!!! x2!!!!
555 this.dataSet = new DataSetForApps();
556 dataSet.setDataObject(e.getDataSet());
557 int nVars = dataSet.getNumberNumericAttributes();
558 int min = this.maxAxes;
559 if (nVars < min){
560 min = nVars;
561 }
562 int[] vars = new int[min];
563 for (int i = 0; i < min; i++){
564 vars[i] = i;
565 }
566 this.setSubspace(vars);
567 }
568
569 public void subspaceChanged(SubspaceEvent e) {
570 int[] selectedVars = e.getSubspace();
571 this.setSubspace(selectedVars);
572 }
573
574 private void setSubspace(int[] vars) {
575
576
577 int nVars = this.maxAxes; //the number of variables to show
578 String[] obsNames = dataSet.getObservationNames(); //gotta have these
579
580 int nNumeric = dataSet.getNumberNumericAttributes();
581
582 if (nNumeric < nVars) {
583 nVars = nNumeric;
584 }
585 if (vars.length < nVars){
586 nVars = vars.length;
587 }
588
589 String[] varNames = (String[]) dataSet.getDataObjectOriginal()[0];
590 String[] varNamesNew = new String[nVars + 1];
591 Object[] newDataSet = new Object[nVars + 2]; //+1 for varNames,+1 for obsNames
592 varNamesNew[0] = "name";
593
594 for (int i = 1; i < (nVars + 1); i++) {
595 int var = vars[i-1];
596 if (var < nNumeric){
597 varNamesNew[i] = dataSet.getNumericArrayName(var); //this is an atrocity
598 }
599 }
600
601 newDataSet[0] = varNamesNew;
602 newDataSet[1] = obsNames;
603
604 for (int i = 0; i < nVars; i++) {
605 int var = vars[i];
606 if (var < nNumeric){
607 newDataSet[i + 2] = (double[]) dataSet.getNumericDataAsDouble(var);
608 }
609 }
610
611 this.setDataSet(newDataSet);
612 }
613
614 private void loadActionPerformed(java.awt.event.ActionEvent evt) { //GEN-FIRST:event_loadActionPerformed
615
616 JFileChooser chooser = new JFileChooser();
617 int option = chooser.showOpenDialog(this);
618
619 if (option == JFileChooser.APPROVE_OPTION) {
620 if (chooser.getSelectedFile() != null) {
621 String urltext = "file:///" +
622 chooser.getSelectedFile().getAbsolutePath();
623 urltext = urltext.replace('//', '/');
624 urlField.setText(urltext);
625
626 try {
627 STFFile f = new STFFile(new URL(urltext));
628 f.readContents();
629
630 parallelDisplay.setModel(f);
631 } catch (Exception e) {
632 System.out.println(e.toString() + e.getMessage());
633 }
634 }
635 }
636 }
637 //GEN-LAST:event_loadActionPerformed
638
639 public void processProgressEvent(ProgressEvent e) {
640 switch (e.getType()) {
641 case ProgressEvent.PROGRESS_START:
642 progressstart = e.getTimestamp();
643 timeLabel.setText("0 s");
644
645 break;
646
647 case ProgressEvent.PROGRESS_UPDATE:
648 renderProgressBar.setValue((int) (e.getProgress() * 100));
649 timeLabel.setText(((e.getTimestamp() - progressstart) / 1000) +
650 " s");
651
652 break;
653
654 case ProgressEvent.PROGRESS_FINISH:
655 renderProgressBar.setValue(100);
656 timeLabel.setText(((e.getTimestamp() - progressstart) / 1000) +
657 " s");
658
659 break;
660 }
661
662 renderLabel.setText(e.getMessage());
663
664 //System.out.println(e.getMessage() + ": " + ((int)(e.getProgress() * 100))+"%");
665 }
666
667 /***
668 * Main method for testing purposes.
669 */
670 public static void main(String[] args) {
671 String fileName = "C://geovista_old//data//test6.csv";
672
673 Object[] dataSet = new Object[4];
674 String[] labels = new String[] { "0", "1", "Name" };
675 dataSet[0] = labels;
676
677 try {
678 FileIO fio = new FileIO(fileName, "r");
679
680 for (int col = 0; col < 2; col++) {
681 double[] doubleData = new double[7];
682
683 for (int row = 0; row < 7; row++) {
684 doubleData[row] = fio.readDouble();
685 }
686
687 dataSet[col + 1] = doubleData;
688 }
689 } catch (Exception ex) {
690 ex.printStackTrace();
691 }
692
693 String[] names = new String[7];
694
695 for (int row = 0; row < 7; row++) {
696 names[row] = "Obs " + row;
697 }
698
699 dataSet[3] = names;
700
701 STFDataSet f = new STFDataSet(dataSet);
702 System.out.println("min = " + f.getMinValue(0));
703 System.out.println("max = " + f.getMaxValue(0));
704
705 MainPanel mp = new MainPanel();
706 JFrame app = new JFrame();
707 app.getContentPane().add(mp);
708 mp.setDataSet(dataSet);
709 app.pack();
710 app.show();
711
712 app.addWindowListener(new WindowAdapter() {
713 public void windowClosing(WindowEvent e) {
714 System.exit(0);
715 }
716 });
717 }
718
719 /***
720 * adds an IndicationListener
721 */
722 public void addIndicationListener(IndicationListener l) {
723 //System.out.println("MainPanel, adding indication listener");
724 listenerList.add(IndicationListener.class, l);
725 }
726
727 /***
728 * removes an IndicationListener from the component
729 */
730 public void removeIndicationListener(IndicationListener l) {
731 //System.out.println("PCP, removing indication listener");
732 listenerList.remove(IndicationListener.class, l);
733 }
734
735 /***
736 * Notify all listeners that have registered interest for
737 * notification on this event type. The event instance
738 * is lazily created using the parameters passed into
739 * the fire method.
740 * @see EventListenerList
741 */
742 private void fireIndicationChanged(int newIndication) {
743 // Guaranteed to return a non-null array
744 Object[] listeners = listenerList.getListenerList();
745 IndicationEvent e = null;
746
747 // Process the listeners last to first, notifying
748 // those that are interested in this event
749 for (int i = listeners.length - 2; i >= 0; i -= 2) {
750 if (listeners[i] == IndicationListener.class) {
751 // Lazily create the event:
752 if (e == null) {
753 e = new IndicationEvent(this, newIndication);
754 }
755
756 ((IndicationListener) listeners[i + 1]).indicationChanged(e);
757 }
758 }
759 //next i
760 }
761
762 /***
763 * adds an SelectionListener
764 */
765 public void addSelectionListener(SelectionListener l) {
766 this.parallelDisplay.addSelectionListener(l);
767 }
768
769 /***
770 * removes an SelectionListener from the component
771 */
772 public void removeSelectionListener(SelectionListener l) {
773 this.parallelDisplay.removeSelectionListener(l);
774 }
775 }
This page was automatically generated by Maven