-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDistanceScatterPlotParamView.java
289 lines (255 loc) · 13.4 KB
/
DistanceScatterPlotParamView.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
package dataanalysis;
import distance.DistanceMatrix;
import distance.dissimilarity.AbstractDissimilarity;
import distance.dissimilarity.DissimilarityFactory;
import distance.dissimilarity.DissimilarityFactory.DissimilarityType;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import matrix.AbstractMatrix;
import matrix.MatrixFactory;
import projection.util.ProjectionConstants;
import vispipelinebasics.interfaces.AbstractParametersView;
import visualizationbasics.util.OpenDialog;
import visualizationbasics.util.PropertiesManager;
import visualizationbasics.util.filter.DATAFilter;
import visualizationbasics.util.filter.DMATFilter;
/**
*
* @author Jose Gustavo de Souza Paiva
*/
public class DistanceScatterPlotParamView extends AbstractParametersView {
/** Creates new form NJConnectionParamView */
public DistanceScatterPlotParamView(DistanceScatterPlotComp comp) {
initComponents();
this.comp = comp;
for (DissimilarityType disstype : DissimilarityType.values()) {
this.distanceComboBox.addItem(disstype);
}
reset();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
buttonGroup1 = new javax.swing.ButtonGroup();
nrNeighborsPanel = new javax.swing.JPanel();
useWeightCheckBox = new javax.swing.JCheckBox();
sourcePanel = new javax.swing.JPanel();
pointsRadioButton = new javax.swing.JRadioButton();
distanceMatrixRadioButton = new javax.swing.JRadioButton();
distanceMatrixTextField = new javax.swing.JTextField();
pointsTextField = new javax.swing.JTextField();
pointsButton = new javax.swing.JButton();
distanceMatrixButton = new javax.swing.JButton();
chooseDistanceTypePanel2 = new javax.swing.JPanel();
distanceComboBox = new javax.swing.JComboBox();
setBorder(javax.swing.BorderFactory.createTitledBorder("Distance ScatterPlot Parameters"));
setLayout(new java.awt.GridBagLayout());
nrNeighborsPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
useWeightCheckBox.setText("Use Edges Weights");
useWeightCheckBox.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
nrNeighborsPanel.add(useWeightCheckBox);
add(nrNeighborsPanel, new java.awt.GridBagConstraints());
sourcePanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Source File"));
sourcePanel.setLayout(new java.awt.GridBagLayout());
buttonGroup1.add(pointsRadioButton);
pointsRadioButton.setSelected(true);
pointsRadioButton.setText("Points File");
pointsRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
pointsRadioButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
pointsRadioButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
pointsRadioButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
sourcePanel.add(pointsRadioButton, gridBagConstraints);
buttonGroup1.add(distanceMatrixRadioButton);
distanceMatrixRadioButton.setText("Distance File");
distanceMatrixRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
distanceMatrixRadioButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
distanceMatrixRadioButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
distanceMatrixRadioButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 4;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
sourcePanel.add(distanceMatrixRadioButton, gridBagConstraints);
distanceMatrixTextField.setColumns(35);
distanceMatrixTextField.setEnabled(false);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 4;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
sourcePanel.add(distanceMatrixTextField, gridBagConstraints);
pointsTextField.setColumns(35);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
sourcePanel.add(pointsTextField, gridBagConstraints);
pointsButton.setText("Search...");
pointsButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
pointsButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 3;
gridBagConstraints.gridy = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
sourcePanel.add(pointsButton, gridBagConstraints);
distanceMatrixButton.setText("Search...");
distanceMatrixButton.setEnabled(false);
distanceMatrixButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
distanceMatrixButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 3;
gridBagConstraints.gridy = 4;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
sourcePanel.add(distanceMatrixButton, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
add(sourcePanel, gridBagConstraints);
chooseDistanceTypePanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Choose the Distance Type"));
chooseDistanceTypePanel2.setLayout(new java.awt.GridBagLayout());
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(3, 0, 3, 3);
chooseDistanceTypePanel2.add(distanceComboBox, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
add(chooseDistanceTypePanel2, gridBagConstraints);
}// </editor-fold>//GEN-END:initComponents
private void pointsRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pointsRadioButtonActionPerformed
this.distanceMatrixButton.setEnabled(false);
this.distanceMatrixTextField.setEnabled(false);
this.pointsButton.setEnabled(true);
this.pointsTextField.setEnabled(true);
this.distanceMatrixTextField.setText("");
this.distanceComboBox.setEnabled(true);
}//GEN-LAST:event_pointsRadioButtonActionPerformed
private void distanceMatrixRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_distanceMatrixRadioButtonActionPerformed
this.distanceMatrixButton.setEnabled(true);
this.distanceMatrixTextField.setEnabled(true);
this.pointsButton.setEnabled(false);
this.pointsTextField.setEnabled(false);
this.pointsTextField.setText("");
this.distanceComboBox.setEnabled(false);
}//GEN-LAST:event_distanceMatrixRadioButtonActionPerformed
private void pointsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pointsButtonActionPerformed
try {
PropertiesManager spm = PropertiesManager.getInstance(ProjectionConstants.PROPFILENAME);
int result = OpenDialog.showOpenDialog(spm, new DATAFilter(), this);
if (result == JFileChooser.APPROVE_OPTION) {
String filename = OpenDialog.getFilename();
this.pointsTextField.setText(filename);
}
} catch (IOException ex) {
Logger.getLogger(DistanceScatterPlotParamView.class.getName()).log(Level.SEVERE, null, ex);
}
}//GEN-LAST:event_pointsButtonActionPerformed
private void distanceMatrixButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_distanceMatrixButtonActionPerformed
try {
PropertiesManager spm = PropertiesManager.getInstance(ProjectionConstants.PROPFILENAME);
int result = OpenDialog.showOpenDialog(spm, new DMATFilter(), this);
if (result == JFileChooser.APPROVE_OPTION) {
String filename = OpenDialog.getFilename();
this.distanceMatrixTextField.setText(filename);
}
} catch (IOException ex) {
Logger.getLogger(DistanceScatterPlotParamView.class.getName()).log(Level.SEVERE, null, ex);
}
}//GEN-LAST:event_distanceMatrixButtonActionPerformed
@Override
public void reset() {
useWeightCheckBox.setSelected(comp.isUseWeight());
if (comp.isDistanceMatrixProvided()) {
distanceComboBox.setSelectedItem(comp.getDissimilarityType());
distanceComboBox.setEnabled(false);
} else {
distanceComboBox.setEnabled(true);
distanceComboBox.setSelectedItem(comp.getDissimilarityType());
}
}
@Override
public void finished() throws IOException {
comp.setUseWeight(useWeightCheckBox.isSelected());
if (this.pointsRadioButton.isSelected()) {
if (this.pointsTextField.getText().trim().length() > 0) {
try {
AbstractMatrix matrix = MatrixFactory.getInstance(this.pointsTextField.getText());
DissimilarityType mtype = (DissimilarityType) this.distanceComboBox.getSelectedItem();
AbstractDissimilarity diss = DissimilarityFactory.getInstance(mtype);
DistanceMatrix dmat = new DistanceMatrix(matrix, diss);
comp.setDmat(dmat);
} catch (IOException ex) {
Logger.getLogger(DistanceScatterPlotParamView.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
JOptionPane.showMessageDialog(this, "A points file must be selected.","Error",JOptionPane.ERROR_MESSAGE);
}
} else if (this.distanceMatrixRadioButton.isSelected()) {
if (this.distanceMatrixTextField.getText().trim().length() > 0) {
try {
DistanceMatrix dmat = new DistanceMatrix(this.distanceMatrixTextField.getText());
comp.setDmat(dmat);
} catch (IOException ex) {
Logger.getLogger(DistanceScatterPlotParamView.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
JOptionPane.showMessageDialog(this, "A distance matrix file must be selected.",
"Error", JOptionPane.ERROR_MESSAGE);
}
}
if (!comp.isDistanceMatrixProvided()) {
comp.setDissimilarityType((DissimilarityType) distanceComboBox.getSelectedItem());
}
}
private DistanceScatterPlotComp comp;
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JPanel chooseDistanceTypePanel2;
private javax.swing.JComboBox distanceComboBox;
private javax.swing.JButton distanceMatrixButton;
private javax.swing.JRadioButton distanceMatrixRadioButton;
private javax.swing.JTextField distanceMatrixTextField;
private javax.swing.JPanel nrNeighborsPanel;
private javax.swing.JButton pointsButton;
private javax.swing.JRadioButton pointsRadioButton;
private javax.swing.JTextField pointsTextField;
private javax.swing.JPanel sourcePanel;
private javax.swing.JCheckBox useWeightCheckBox;
// End of variables declaration//GEN-END:variables
}