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: 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 /***
30 * put your documentation comment here
31 */
32 public class UniPlotMatrix extends AbstractMatrix
33 implements ListSelectionListener{
34
35 private static final int TYPE_NONE = -1;
36 private static final int TYPE_NAME = 0;
37 private static final int TYPE_NUM = 1;
38 private static final int TYPE_INTEGER = 2;
39 private static final int TYPE_BOOLEAN = 3;
40 private static final int TYPE_DOUBLE = 4;
41 private String elementClassName;
42 private transient int[] rowInitOrder;
43 private transient int[] columnInitOrder;
44 private transient int[] rowOrder;
45 private transient int[] columnOrder;
46 private double[][] doubleDataArrays;
47 private String[] attributesArray;
48 private String[] observNames;
49 private int selectedObv;
50 protected transient EventListenerList listenerList = new EventListenerList();
51 //private ImageIcon matrixIcon = new ImageIcon(this.getClass().getResource("matrix16.gif"));
52 private ImageIcon matrixIcon = new ImageIcon(this.getClass().getResource("resources/matrixicon16.gif"));
53
54 /***
55 * put your documentation comment here
56 */
57 public UniPlotMatrix () {
58 super();
59 }
60
61 /***
62 * Set up the name for element which will be displayed in matrix. Can be defined in bean proporty.
63 * @param classname
64 */
65 public void setElementClassName (String classname) {
66 this.elementClassName = classname;
67 try {
68 setElementClass((this.elementClassName != null) ? getClass().forName(this.elementClassName) :
69 null);
70 } catch (Exception e) {
71 e.printStackTrace();
72 }
73 }
74
75 /***
76 * Get the name for element which will be displayed in matrix.
77 * @return
78 */
79 public String getElementClassName () {
80 return this.elementClassName;
81 }
82
83 /***
84 * Set the element which will be displayed in matrix by connecting to an object.
85 * @param obj
86 */
87 public void setElementClass (Object obj) {
88 setElementClassName((obj != null) ? obj.getClass().getName() : null);
89 }
90
91 /***
92 * Set up the element displayed in matrix. Called by setElementClass(Oject obj).
93 * @param clazz
94 */
95 public void setElementClass (Class clazz) {
96 if (this.elementClass != clazz) {
97 this.recreate = true;
98 }
99 this.elementClass = clazz;
100 }
101
102 /***
103 * put your documentation comment here
104 * @return
105 */
106 public String[] getAttributesArray () {
107 return attributesArray;
108 }
109
110 /***
111 * The actual procedure to create the matrix, fill graphs in each matrix element.
112 */
113 protected void createMatrix () {
114
115 this.setLayout(matrixLayout);
116 Dimension size = getSize();
117 Dimension plotSize = new Dimension(size.width/plotNumber, size.height/plotNumber);
118
119 columnButton = new SPTagButton[plotNumber];
120 rowButton = new SPTagButton[this.plotNumber];
121 Dimension tagDm = new Dimension(0, 0);
122 configButton = new JButton();
123 try {
124 for (int i = 0; i < plotNumber + 1; i++) {
125 for (int j = 0; j < plotNumber + 1; j++) {
126 if ((i == 0) && (j == 0)) {
127 //The M button on left up corner. Click on that will pop up a variable selection dialog for displaying in matrix.
128 c.weightx = 0.0;
129 c.weighty = 0.0;
130 c.gridwidth = 1;
131 c.gridheight = 1;
132 configButton.setIcon(this.matrixIcon);
133 configButton.addActionListener(new java.awt.event.ActionListener() {
134
135 /***
136 * Set up the attributes for plotted in SPM.
137 * @param e
138 */
139 public void actionPerformed (ActionEvent e) {
140 try {
141
142 configButton_actionPerformed(e);
143
144 } catch (Exception exception) {}
145 }
146 });
147 c.column = j;
148 c.row = i;
149 matrixLayout.setConstraints(configButton, c);
150 add(configButton);
151 }
152 else if ((i == 0) && (j != 0)) {
153 //The first row in matrix. They are buttons which can be dragged to change the column position.
154 c.weightx = 1.0;
155 c.weighty = 0.0;
156 c.gridwidth = this.DEFAULT_BUTTON_CONSTRAINTS;
157 //c.gridheight = 1;
158 if (j == plotNumber){
159 c.gridwidth = GridBagConstraints.REMAINDER; //end row
160 }
161 varTags[j-1] = this.attributesDisplay[plottedAttributes[j - 1]];
162 columnButton[j-1] = new SPTagButton(varTags[j-1]);
163 columnButton[j-1].setMargin(this.nullInsets);
164 columnButton[j-1].addMouseListener(columnButton[j-1]);
165 columnButton[j-1].addMouseMotionListener(columnButton[j-1]);
166 c.column = j;
167 c.row = i;
168 matrixLayout.setConstraints(columnButton[j-1], c);
169 add(columnButton[j-1]);
170 }
171 else if ((i != 0) && (j == 0)) {
172 //The first column in matrix. They are buttons which can be dragged to change the row position.
173 c.weightx = 0.0;
174 c.weighty = 1.0;
175 c.gridwidth = 1;
176 c.gridheight = this.DEFAULT_BUTTON_CONSTRAINTS;
177
178 rowButton[i-1] = new SPTagButton("s");
179 rowButton[i-1].setMargin(this.nullInsets);
180 rowButton[i-1].setVerticalAlignment(SwingConstants.BOTTOM);
181 //rowButton[i-1].setVerticalTextPosition(SwingConstants.BOTTOM);
182 //rowButton[i-1].setHorizontalAlignment(SwingConstants.BOTTOM);
183 //JLabel rowLabel = new JLabel();
184 AffineTransform trans = new AffineTransform();
185 trans.rotate(-Math.PI/2, rowButton[i-1].getWidth(), rowButton[i-1].getHeight()/2);
186 Font font = new Font("", Font.BOLD, 11);
187 font = font.deriveFont(trans);
188 //rowLabel.setFont(font);
189 //BufferedImage labelImage = new BufferedImage(rowLabel.getWidth()+1,rowLabel.getHeight()+1,BufferedImage.TYPE_INT_ARGB);
190 //Graphics2D g2 = labelImage.createGraphics();
191 //rowButton[i-1].paint(g2);
192 rowButton[i-1].setFont(font);
193 rowButton[i-1].setText(varTags[i-1]);
194 rowButton[i-1].addMouseListener(rowButton[i-1]);
195 rowButton[i-1].addMouseMotionListener(rowButton[i-1]);
196 c.column = j;
197 c.row = i;
198 matrixLayout.setConstraints(rowButton[i-1], c);
199 add(rowButton[i-1]);
200 }
201 else {
202 //Actually set up the graph components in matrix.
203 c.weightx = 1.0;
204 c.weighty = 1.0;
205 c.gridwidth = this.DEFAULT_BUTTON_CONSTRAINTS;
206 c.gridheight = this.DEFAULT_BUTTON_CONSTRAINTS;
207 int indexCurrent = (i - 1)*(plotNumber) + (j - 1);
208 int[] dataIndices = new int[2];
209 dataIndices[0] = plottedAttributes[j - 1] + 1; //+1 is because in the data structure, we reserve the first element for variable names.
210 dataIndices[1] = plottedAttributes[i - 1] + 1;
211 //construct of each element
212 this.element[indexCurrent] = (MatrixElement)this.elementClass.newInstance();
213 this.element[indexCurrent].setAxisOn(false);
214 this.element[indexCurrent].setDataObject(this.dataObject);
215 this.element[indexCurrent].setBackground(background);
216 this.element[indexCurrent].setElementPosition(dataIndices);
217 this.element[indexCurrent].setSelOriginalColorMode(this.selOriginalColorMode);
218 this.element[indexCurrent].setSelectionColor(this.selectionColor);
219 if (this.bivarColorClasser != null){
220 boolean reverseColor = false;
221 if (i > j){
222 reverseColor = true;
223 }
224 this.element[indexCurrent].setBivarColorClasser(this.bivarColorClasser, reverseColor);
225 }
226 if (this.colorArrayForObs != null){
227 //System.out.println("about to set color for each obs...");
228 this.element[indexCurrent].setColorArrayForObs(this.colorArrayForObs);
229 }
230 if (j == plotNumber)
231 c.gridwidth = GridBagConstraints.REMAINDER; //end row
232 c.column = j;
233 c.row = i;
234 matrixLayout.setConstraints((Component)this.element[indexCurrent], c);
235 add((Component)this.element[indexCurrent]);
236 this.element[indexCurrent].addActionListener(new ActionListener() {
237
238 /***
239 * Get the event from a unit plot and send it to all units.
240 * @param e
241 */
242 public void actionPerformed (ActionEvent e) {
243 // This gets the source or originator of the event
244 try {
245 unit_actionPerformed(e);
246 } catch (Exception exception) {}
247 }
248 });
249 }
250 }
251 }
252 } catch (Exception e) {
253 e.printStackTrace();
254 }
255
256 for (int j = 0; j < plotNumber; j++) {
257 if (columnButton[j].getPreferredSize().getWidth() > tagDm.getWidth())
258 tagDm = columnButton[j].getPreferredSize();
259 //System.out.println("tagDm: " + tagDm.getWidth() + tagDm.getHeight());
260 }
261 for (int j = 0; j < plotNumber; j++) {
262 columnButton[j].setPreferredSize(tagDm);
263 columnButton[j].setMinimumSize(tagDm);
264 columnButton[j].setMaximumSize(tagDm);
265 }
266 Dimension rowTag = new Dimension((int)tagDm.getHeight(), (int)tagDm.getHeight());
267 configButton.setPreferredSize(rowTag);
268 configButton.setMinimumSize(rowTag);
269 configButton.setMaximumSize(rowTag);
270 }
271
272 /***
273 * put your documentation comment here
274 * @param e
275 */
276 private void unit_actionPerformed (ActionEvent e) {
277 MatrixElement source = (MatrixElement)e.getSource();
278 String command = e.getActionCommand();
279 if (command.compareTo(MatrixElement.COMMAND_POINT_SELECTED) == 0) {
280 //For selection event.
281 //selectedObvs = source.getSelectedObservations();
282 selectedObvsInt = source.getSelections();
283 for (int k = 0; k < plotNumber*plotNumber; k++) {
284 MatrixElement otherElement = element[k];
285 // Don't recall the scatterplot which generated the original event
286 if (otherElement != source) {
287 //otherElement.setSelectedObservations(selectedObvs);
288 otherElement.setSelections(this.selectedObvsInt);
289 otherElement.setMultipleSelectionColors(null);
290 }
291 }
292 this.repaint();
293 fireChangeEvent();
294 this.fireSelectionChanged(this.getSelectedObvs());
295 } else if (command.compareTo(MatrixElement.COMMAND_COLOR_CLASSFICIATION) == 0) {
296 //For classification color event.
297 this.bivarColorClasser = source.getBivarColorClasser();
298 int row, column;
299 boolean reverseColor = false;
300 for (int k = 0; k < plotNumber*plotNumber; k++) {
301 MatrixElement otherElement = element[k];
302 // Don't recall the scatterplot which generated the original event
303 if (otherElement != source) {
304 row =k/this.plotNumber;
305 column = k%this.plotNumber;
306 if (row > column){
307 reverseColor = true;
308 }else{
309 reverseColor = false;
310 }
311 otherElement.setBivarColorClasser(this.bivarColorClasser, false);
312 }
313 }
314 this.repaint();
315 fireChangeEvent();
316 } else if (command.compareTo(MatrixElement.COMMAND_DATARANGE_SET) == 0) {
317 //For set up new axis extents in each scatterplots in matrix.
318 double[] xAxisExtents = source.getXAxisExtents();
319 double[] yAxisExtents = source.getYAxisExtents();
320 int pos = 0;
321 for (int k = 0; k < plotNumber*plotNumber; k++) {
322 MatrixElement otherElement = element[k];
323 // Don't recall the scatterplot which generated the original event
324 if (otherElement == source) {
325 pos = k;
326 //System.out.println("Element: " + pos);
327 break;
328 }
329 }
330 //Find the elements which need to reset the axis extents.
331 int r = pos/plotNumber;
332 int c = pos%plotNumber;
333 //System.out.println("Position: " + r + " " + c);
334 for (int i = 0; i < plotNumber; i++) {
335 //System.out.println("xAxis: " + (i*plotNumber + c) + " " + (c * plotNumber + i));
336 element[i*plotNumber + c].setXAxisExtents(xAxisExtents);//The xAxisExtents for all of the elements in the same column have to be changed.
337 element[c * plotNumber + i].setYAxisExtents(xAxisExtents);//The yAxisExtents for the corresponding elements on the other side
338 //of diagonal need to be changed.
339 //System.out.println("yAxis: " + (r*plotNumber + i) + " " + (r + i*plotNumber));
340 element[r*plotNumber + i].setYAxisExtents(yAxisExtents); //The yAxisExtents for all of the elements in the same row have to be changed.
341 element[r + i*plotNumber].setXAxisExtents(yAxisExtents);//The xAxisExtents for the corresponding elements on the other side
342 //of diagonal need to be changed.
343 }
344 } else {
345 System.err.println("Unknown command! = " + command);
346
347 }//end if
348 }
349
350 /***
351 * Configure attributes for plotted in matrix.
352 * @param e
353 */
354 private void configButton_actionPerformed (ActionEvent e) {
355 attSelectDialog(400, 400);
356 }
357
358 JFrame dummyFrame = new JFrame();
359 JDialog dialog = null;
360 JScrollPane dialogPane = null;
361
362 /***
363 * put your documentation comment here
364 * @param x
365 * @param y
366 */
367 private void attSelectDialog (int x, int y) {
368 attList.setSelectedIndices(this.plottedAttributes);
369 if (this.dialog == null) {
370 this.dialog = new JDialog(dummyFrame, "Attributes for Plot", true);
371 JButton selectButton;
372 JButton closeButton;
373 dialog.setSize(150, 300);
374 dialog.getContentPane().setLayout(new BorderLayout());
375 attList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
376 //attList.addListSelectionListener(this);
377 //JScrollPane scrollPane = new JScrollPane(attList);
378 this.dialogPane = new JScrollPane(attList);
379 selectButton = new JButton("Apply");
380 selectButton.addActionListener(new java.awt.event.ActionListener() {
381
382 /***
383 * put your documentation comment here
384 * @param e
385 */
386 public void actionPerformed (ActionEvent e) {
387 //System.out.println("about to press button Select");
388 selectButton_actionPerformed(e);
389 //System.out.println("after pressed button Select");
390 }
391 });
392 closeButton = new JButton("Close");
393 closeButton.addActionListener(new java.awt.event.ActionListener() {
394
395 /***
396 * put your documentation comment here
397 * @param e
398 */
399 public void actionPerformed (ActionEvent e) {
400 closeButton_actionPerformed(e);
401 }
402 });
403 JPanel buttonPanel = new JPanel(new GridLayout(1, 2));
404 buttonPanel.add(selectButton);
405 buttonPanel.add(closeButton);
406
407 JPanel attSelPanel = new JPanel(new BorderLayout());
408 attSelPanel.setPreferredSize(new Dimension(150, 290));
409 attSelPanel.add(new JLabel("Attribute Names:"), BorderLayout.NORTH);
410 attSelPanel.add(this.dialogPane, BorderLayout.CENTER);
411 attSelPanel.add(buttonPanel, BorderLayout.SOUTH);
412
413 if (this.attributeDescriptions != null){
414 JPanel descPane = new JPanel(new BorderLayout());
415 descPane.add(new JLabel("Descriptions:"), BorderLayout.NORTH);
416
417 JList descriptionList = new JList(this.attributeDescriptions);
418 JScrollPane descListPane = new JScrollPane(descriptionList);
419 descPane.add(descListPane, BorderLayout.CENTER);
420 dialog.getContentPane().add(descPane, BorderLayout.CENTER);
421 }
422 dialog.getContentPane().add(attSelPanel, BorderLayout.WEST);
423
424 }
425 else {
426 this.dialogPane.setViewportView(attList);
427 }
428 this.attList.addListSelectionListener(this);
429 this.plottedAttributes = attList.getSelectedIndices();
430 this.dialog.setLocation(x, y);
431 this.dialog.show();
432 }
433
434 /***
435 * Selection button in variable selection dialog. Click on it, the variables selected in the JList will be forwarded to matrix.
436 * @param e
437 */
438 private void selectButton_actionPerformed (ActionEvent e) {
439 //System.out.println("select button pressed, in action performed");
440 plotNumber = plottedAttributes.length;
441 //System.out.println("select button pressed, plot number = " + plotNumber);
442 init();
443 }
444
445 /***
446 * Close the variable selection dialog.
447 * @param e
448 */
449 private void closeButton_actionPerformed (ActionEvent e) {
450 dialog.hide();
451 }
452
453 /***
454 * Inform that value or selection in the JList (variable selection dialog) has been changed.
455 * @param e
456 */
457 public void valueChanged (ListSelectionEvent e) {
458
459 if (e.getValueIsAdjusting())
460 return;
461 JList theList = (JList)e.getSource();
462 if (theList.isSelectionEmpty()) {
463 return;
464 }
465 else {
466 plottedAttributes = theList.getSelectedIndices();
467 }
468 }
469 }
470
471
472
This page was automatically generated by Maven