-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNeighborhoodPreservationParamView.java
397 lines (356 loc) · 19.2 KB
/
NeighborhoodPreservationParamView.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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
package dataanalysis;
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 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 NeighborhoodPreservationParamView extends AbstractParametersView {
/** Creates new form NJConnectionParamView */
public NeighborhoodPreservationParamView(NeighborhoodPreservationComp comp) {
initComponents();
this.comp = comp;
for (DissimilarityType disstype : DissimilarityType.values()) {
this.distanceComboBox.addItem(disstype);
}
reset();
distanceCalcTypeComboBox.setVisible(false);
}
/** 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();
nrNeighborsLabel = new javax.swing.JLabel();
nrNeighborsTextField = new javax.swing.JTextField();
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();
treePanel = new javax.swing.JPanel();
useWeightCheckBox = new javax.swing.JCheckBox();
useVisEuclideanDistanceCheckBox = new javax.swing.JCheckBox();
useEuclideanAsWeightsCheckBox = new javax.swing.JCheckBox();
distanceCalcTypeComboBox = new javax.swing.JComboBox();
setBorder(javax.swing.BorderFactory.createTitledBorder("Neighborhood Preservation Parameters"));
setLayout(new java.awt.GridBagLayout());
nrNeighborsPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
nrNeighborsLabel.setText("Number of neighbors");
nrNeighborsPanel.add(nrNeighborsLabel);
nrNeighborsTextField.setColumns(10);
nrNeighborsTextField.setText("30");
nrNeighborsPanel.add(nrNeighborsTextField);
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);
treePanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Trees"));
treePanel.setLayout(new java.awt.GridBagLayout());
useWeightCheckBox.setText("Use Edges Weights");
useWeightCheckBox.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
useWeightCheckBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
useWeightCheckBoxActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
treePanel.add(useWeightCheckBox, gridBagConstraints);
useVisEuclideanDistanceCheckBox.setText("Use Euclidean Distance (Visualization Plane)");
useVisEuclideanDistanceCheckBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
useVisEuclideanDistanceCheckBoxActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
treePanel.add(useVisEuclideanDistanceCheckBox, gridBagConstraints);
useEuclideanAsWeightsCheckBox.setText("Use Plane Euclidean Distances as Weights");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
treePanel.add(useEuclideanAsWeightsCheckBox, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 3;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
add(treePanel, gridBagConstraints);
distanceCalcTypeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Floyd", "Tree" }));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 4;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
add(distanceCalcTypeComboBox, 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(NeighborhoodPreservationParamView.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(NeighborhoodPreservationParamView.class.getName()).log(Level.SEVERE, null, ex);
}
}//GEN-LAST:event_distanceMatrixButtonActionPerformed
private void useVisEuclideanDistanceCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_useVisEuclideanDistanceCheckBoxActionPerformed
if (useVisEuclideanDistanceCheckBox.isSelected()) {
useWeightCheckBox.setSelected(false);
useWeightCheckBox.setEnabled(false);
useEuclideanAsWeightsCheckBox.setSelected(false);
useEuclideanAsWeightsCheckBox.setEnabled(false);
}else {
useWeightCheckBox.setEnabled(true);
}
}//GEN-LAST:event_useVisEuclideanDistanceCheckBoxActionPerformed
private void useWeightCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_useWeightCheckBoxActionPerformed
if (useWeightCheckBox.isSelected()) {
useEuclideanAsWeightsCheckBox.setEnabled(true);
}else {
useEuclideanAsWeightsCheckBox.setSelected(false);
useEuclideanAsWeightsCheckBox.setEnabled(false);
}
}//GEN-LAST:event_useWeightCheckBoxActionPerformed
@Override
public void reset() {
if (comp.getNrNeighbors() == 0)
nrNeighborsTextField.setText("30");
else
nrNeighborsTextField.setText(Integer.toString(comp.getNrNeighbors()));
if (comp.isDistanceMatrixProvided()) {
distanceComboBox.setSelectedItem(comp.getDissimilarityType());
distanceComboBox.setEnabled(false);
} else {
distanceComboBox.setEnabled(true);
distanceComboBox.setSelectedItem(comp.getDissimilarityType());
}
switch (comp.getDataFileType()) {
case 0: //.data
pointsRadioButton.setSelected(true);
distanceMatrixRadioButton.setSelected(false);
pointsTextField.setText(comp.getDataFileName());
break;
case 1: //.dmat
distanceMatrixTextField.setEnabled(true);
distanceComboBox.setEnabled(false);
pointsRadioButton.setSelected(false);
distanceMatrixRadioButton.setSelected(true);
distanceMatrixTextField.setText(comp.getDataFileName());
}
useVisEuclideanDistanceCheckBox.setSelected(comp.getUseVisEuclidianDistance());
useWeightCheckBox.setSelected(comp.isUseWeight());
useEuclideanAsWeightsCheckBox.setSelected(comp.getUseEuclideanAsWeights());
useWeightCheckBoxActionPerformed(null);
useVisEuclideanDistanceCheckBoxActionPerformed(null);
this.distanceCalcTypeComboBox.setSelectedIndex(comp.getDistanceCalcType());
}
@Override
public void finished() throws IOException {
comp.setNrNeighbors(Integer.parseInt(nrNeighborsTextField.getText()));
comp.setDissimilarityType((DissimilarityType) distanceComboBox.getSelectedItem());
if (this.pointsRadioButton.isSelected()) {
if (this.pointsTextField.getText().trim().length() > 0) {
comp.setDataFileType(0);
comp.setDataFileName(this.pointsTextField.getText());
// 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(NeighborhoodPreservationParamView.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) {
comp.setDataFileType(1);
comp.setDataFileName(this.distanceMatrixTextField.getText());
// try {
// DistanceMatrix dmat = new DistanceMatrix(this.distanceMatrixTextField.getText());
// comp.setDmat(dmat);
// } catch (IOException ex) {
// Logger.getLogger(NeighborhoodPreservationParamView.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());
//}
}
// if (!comp.isDistanceMatrixProvided()) {
// comp.setDissimilarityType((DissimilarityType) distanceComboBox.getSelectedItem());
// }
comp.setUseWeight(useWeightCheckBox.isSelected());
comp.setUseVisEuclidianDistance(this.useVisEuclideanDistanceCheckBox.isSelected());
comp.setUseEuclideanAsWeights(this.useEuclideanAsWeightsCheckBox.isSelected());
comp.setDistanceCalcType(this.distanceCalcTypeComboBox.getSelectedIndex());
}
private NeighborhoodPreservationComp comp;
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JPanel chooseDistanceTypePanel2;
private javax.swing.JComboBox distanceCalcTypeComboBox;
private javax.swing.JComboBox distanceComboBox;
private javax.swing.JButton distanceMatrixButton;
private javax.swing.JRadioButton distanceMatrixRadioButton;
private javax.swing.JTextField distanceMatrixTextField;
private javax.swing.JLabel nrNeighborsLabel;
private javax.swing.JPanel nrNeighborsPanel;
private javax.swing.JTextField nrNeighborsTextField;
private javax.swing.JButton pointsButton;
private javax.swing.JRadioButton pointsRadioButton;
private javax.swing.JTextField pointsTextField;
private javax.swing.JPanel sourcePanel;
private javax.swing.JPanel treePanel;
private javax.swing.JCheckBox useEuclideanAsWeightsCheckBox;
private javax.swing.JCheckBox useVisEuclideanDistanceCheckBox;
private javax.swing.JCheckBox useWeightCheckBox;
// End of variables declaration//GEN-END:variables
}