Statistics
| Revision:

root / trunk / libraries / libTopology / src / com / vividsolutions / jcs / plugin / clean / coveragecleaningtoolbox / ToolboxPanel.java @ 22873

History | View | Annotate | Download (13.1 KB)

1
package com.vividsolutions.jcs.plugin.clean.coveragecleaningtoolbox;
2

    
3
import com.vividsolutions.jcs.jump.FUTURE_ValidatingTextField;
4
import com.vividsolutions.jump.workbench.WorkbenchContext;
5
import com.vividsolutions.jump.workbench.model.Layer;
6
import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
7
import com.vividsolutions.jump.workbench.ui.*;
8
import com.vividsolutions.jump.workbench.ui.images.IconLoader;
9
import com.vividsolutions.jump.workbench.ui.task.TaskMonitorManager;
10
import com.vividsolutions.jump.workbench.ui.toolbox.MainButtonPlugIn;
11

    
12
import java.awt.*;
13
import java.awt.event.*;
14

    
15
import javax.swing.*;
16
import javax.swing.event.ListDataEvent;
17
import javax.swing.event.ListDataListener;
18

    
19
public class ToolboxPanel extends JPanel {
20
        private LayerComboBox inputLayerComboBox = new LayerComboBox();
21

    
22
        private GridBagLayout gridBagLayout = new GridBagLayout();
23

    
24
        private JPanel upperPanel = new JPanel();
25

    
26
        private GridBagLayout upperPanelGridBagLayout = new GridBagLayout();
27

    
28
        private JLabel gapToleranceLabel = new JLabel();
29

    
30
        private JLabel angleToleranceLabel = new JLabel();
31

    
32
        private ValidatingTextField gapToleranceTextField = new ValidatingTextField(
33
                        "", 5, SwingConstants.RIGHT,
34
                        new ValidatingTextField.CompositeValidator(
35
                                        new ValidatingTextField.Validator[] {
36
                                                        ValidatingTextField.DOUBLE_VALIDATOR,
37
                                                        new ValidatingTextField.GreaterThanValidator(0) }),
38
                        new FUTURE_ValidatingTextField.NumberCleaner("1.0"));
39

    
40
        private JTabbedPane resultsTabbedPane = new JTabbedPane();
41

    
42
        private JButton findGapsButton = new JButton("Find Gaps", IconLoader
43
                        .icon("BlueFlag.gif"));
44

    
45
        private JButton findOverlapsButton = new JButton("Find Overlaps",
46
                        IconLoader.icon("RedFlag.gif"));
47

    
48
        private JLabel outputLayerLabel = new JLabel();
49

    
50
        private JTextField outputLayerTextField = new JTextField();
51

    
52
        private GridLayout gridLayout1 = new GridLayout();
53

    
54
        private JPanel angleTolerancePanel = new JPanel();
55

    
56
        private GridBagLayout gridBagLayout1 = new GridBagLayout();
57

    
58
        private ValidatingTextField angleToleranceTextField = new ValidatingTextField(
59
                        "", 5, SwingConstants.RIGHT,
60
                        new ValidatingTextField.CompositeValidator(
61
                                        new ValidatingTextField.Validator[] {
62
                                                        ValidatingTextField.DOUBLE_VALIDATOR,
63
                                                        new ValidatingTextField.BoundedDoubleValidator(0,
64
                                                                        false, 180, false) }),
65
                        new FUTURE_ValidatingTextField.NumberCleaner("22.5"));
66

    
67
        private JLabel degreesLabel = new JLabel();
68

    
69
        private MyTableTab gapsTab = new MyTableTab("Gaps", "LENGTH",
70
                        resultsTabbedPane, "Find Gaps");
71

    
72
        private MyTableTab autoFixedTab = new MyTableTab("Auto-Fixed", "LENGTH",
73
                        resultsTabbedPane, "Fix Gaps");
74

    
75
        private MyTableTab overlapsTab = new MyTableTab("Overlaps", null,
76
                        resultsTabbedPane, "Find Overlaps");
77

    
78
        private Tab logTab = new Tab() {
79
                public Component createDefaultChild() {
80
                        return new HTMLPanel();
81
                }
82
        };
83

    
84
        private LayerDependencyManager layerDependencyManager = new LayerDependencyManager(
85
                        new MyTableTab[] { gapsTab, overlapsTab }, inputLayerComboBox) {
86

    
87
                {
88
                        addDependencyListener(new LayerDependencyManager.DependencyListener() {
89
                                public void dependencyChanged() {
90
                                        for (int i = 0; i < getDependents().length; i++) {
91
                                                ((MyTableTab) getDependents()[i]).updateTitle();
92
                                        }
93
                                }
94
                        });
95
                }
96
        };
97

    
98
        private WorkbenchContext context;
99

    
100
        private JTabbedPane parametersTabbedPane = new JTabbedPane();
101

    
102
        private JPanel findGapsTab = new JPanel();
103

    
104
        private JPanel findOverlapsTab = new JPanel();
105

    
106
        private GridBagLayout gridBagLayout2 = new GridBagLayout();
107

    
108
        private GridBagLayout gridBagLayout3 = new GridBagLayout();
109

    
110
        private JPanel inputLayerPanel = new JPanel();
111

    
112
        private GridBagLayout gridBagLayout4 = new GridBagLayout();
113

    
114
        private JLabel inputLayerLabel = new JLabel();
115

    
116
        private JCheckBox fixAutomaticallyCheckBox = new JCheckBox();
117

    
118
        public ToolboxPanel(WorkbenchContext context) {
119
                try {
120
                        this.context = context;
121
                        jbInit();
122
                        inputLayerComboBox.getModel().addListDataListener(
123
                                        new ListDataListener() {
124
                                                public void intervalAdded(ListDataEvent e) {
125
                                                }
126

    
127
                                                public void intervalRemoved(ListDataEvent e) {
128
                                                }
129

    
130
                                                public void contentsChanged(ListDataEvent e) {
131
                                                        if ((e.getIndex0() == -1) && (e.getIndex1() == -1)) {
132
                                                                //A new item has been selected. Better than
133
                                                                // #actionPerformed,
134
                                                                //which doesn't catch calls to
135
                                                                // #setSelectedItem. [Jon Aquino]
136
                                                                outputLayerTextField
137
                                                                                .setText((inputLayerComboBox
138
                                                                                                .getSelectedLayer() == null) ? ""
139
                                                                                                : ((inputLayerComboBox
140
                                                                                                                .getSelectedLayer()
141
                                                                                                                .getBlackboard()
142
                                                                                                                .get(
143
                                                                                                                                MainButtonPlugIn.GENERATED_KEY) != null) ? inputLayerComboBox
144
                                                                                                                .getSelectedLayer()
145
                                                                                                                .getName()
146
                                                                                                                : (inputLayerComboBox
147
                                                                                                                                .getSelectedLayer()
148
                                                                                                                                .getName() + " (cleaned)")));
149
                                                        }
150
                                                }
151
                                        });
152
                        findGapsButton.addActionListener(AbstractPlugIn
153
                                        .toActionListener(new FindGapsPlugIn(this), context,
154
                                                        new TaskMonitorManager()));
155
                        findOverlapsButton.addActionListener(AbstractPlugIn
156
                                        .toActionListener(new FindOverlapsPlugIn(this), context,
157
                                                        new TaskMonitorManager()));
158
                } catch (Exception ex) {
159
                        ex.printStackTrace();
160
                }
161
        }
162

    
163
        WorkbenchContext getContext() {
164
                return context;
165
        }
166

    
167
        public MyTableTab getAutoFixedTab() {
168
                return autoFixedTab;
169
        }
170

    
171
        public MyTableTab getGapsTab() {
172
                return gapsTab;
173
        }
174

    
175
        public MyTableTab getOverlapsTab() {
176
                return overlapsTab;
177
        }
178

    
179
        public JCheckBox getFixAutomaticallyCheckBox() {
180
                return fixAutomaticallyCheckBox;
181
        }
182

    
183
        public JTextField getOutputLayerTextField() {
184
                return outputLayerTextField;
185
        }
186

    
187
        public ValidatingTextField getAngleToleranceTextField() {
188
                return angleToleranceTextField;
189
        }
190

    
191
        public ValidatingTextField getGapToleranceTextField() {
192
                return gapToleranceTextField;
193
        }
194

    
195
        public LayerComboBox getInputLayerComboBox() {
196
                return inputLayerComboBox;
197
        }
198

    
199
        void jbInit() throws Exception {
200
                this.setLayout(gridBagLayout);
201
                upperPanel.setLayout(upperPanelGridBagLayout);
202
                gapToleranceLabel.setText("Gap Tolerance: ");
203
                angleToleranceLabel.setText("Angle Tolerance: ");
204
                gapToleranceTextField.setToolTipText("");
205
                findGapsButton.setToolTipText("");
206
                outputLayerLabel.setText("Output Layer:");
207
                angleTolerancePanel.setLayout(gridBagLayout1);
208
                degreesLabel.setText(" degrees");
209
                outputLayerTextField.setOpaque(false);
210
                outputLayerTextField.setEditable(false);
211
                gridLayout1.setColumns(2);
212
                gridLayout1.setRows(2);
213
                resultsTabbedPane.setPreferredSize(new Dimension(250, 250));
214
                findGapsTab.setLayout(gridBagLayout2);
215
                findOverlapsTab.setLayout(gridBagLayout3);
216
                inputLayerPanel.setLayout(gridBagLayout4);
217
                inputLayerLabel.setText("Input Layer: ");
218
                fixAutomaticallyCheckBox.setToolTipText("");
219
                fixAutomaticallyCheckBox.setSelected(true);
220
                fixAutomaticallyCheckBox.setText("Fix Automatically");
221
                fixAutomaticallyCheckBox
222
                                .addActionListener(new java.awt.event.ActionListener() {
223
                                        public void actionPerformed(ActionEvent e) {
224
                                                fixAutomaticallyCheckBox_actionPerformed(e);
225
                                        }
226
                                });
227
                findGapsTab.add(upperPanel, new GridBagConstraints(0, 0, 1, 1, 0.0,
228
                                0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL,
229
                                new Insets(0, 0, 0, 0), 0, 0));
230
                upperPanel.add(gapToleranceLabel, new GridBagConstraints(0, 2, 1, 1,
231
                                0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
232
                                new Insets(0, 0, 0, 0), 0, 0));
233
                upperPanel.add(angleToleranceLabel, new GridBagConstraints(0, 3, 1, 1,
234
                                0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
235
                                new Insets(0, 0, 0, 0), 0, 0));
236
                upperPanel.add(gapToleranceTextField, new GridBagConstraints(1, 2, 1,
237
                                1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
238
                                new Insets(0, 0, 0, 0), 0, 0));
239
                this.add(resultsTabbedPane, new GridBagConstraints(0, 7, 1, 1, 1.0,
240
                                1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
241
                                new Insets(0, 4, 4, 4), 0, 0));
242
                findGapsTab.add(findGapsButton, new GridBagConstraints(0, 3, 1, 1, 1.0,
243
                                0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
244
                                new Insets(4, 4, 4, 4), 0, 0));
245
                findOverlapsTab.add(findOverlapsButton, new GridBagConstraints(0, 0, 1,
246
                                1, 1.0, 1.0, GridBagConstraints.SOUTH,
247
                                GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 4), 0, 0));
248
                resultsTabbedPane.add(gapsTab, gapsTab.getTitle());
249
                resultsTabbedPane.add(autoFixedTab, autoFixedTab.getTitle());
250
                resultsTabbedPane.add(overlapsTab, overlapsTab.getTitle());
251
                resultsTabbedPane.add(logTab, "<html>Log<br></html>");
252
                upperPanel.add(outputLayerLabel, new GridBagConstraints(0, 5, 1, 1,
253
                                0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
254
                                new Insets(0, 0, 0, 0), 0, 0));
255
                upperPanel.add(outputLayerTextField, new GridBagConstraints(1, 5, 1, 1,
256
                                1.0, 0.0, GridBagConstraints.WEST,
257
                                GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
258
                upperPanel.add(angleTolerancePanel, new GridBagConstraints(1, 3, 1, 1,
259
                                0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
260
                                new Insets(0, 0, 0, 0), 0, 0));
261
                angleTolerancePanel.add(angleToleranceTextField,
262
                                new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
263
                                                GridBagConstraints.CENTER, GridBagConstraints.NONE,
264
                                                new Insets(0, 0, 0, 0), 0, 0));
265
                angleTolerancePanel.add(degreesLabel, new GridBagConstraints(2, 0, 1,
266
                                1, 0.0, 0.0, GridBagConstraints.CENTER,
267
                                GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
268
                upperPanel.add(fixAutomaticallyCheckBox, new GridBagConstraints(0, 4,
269
                                2, 1, 0.0, 0.0, GridBagConstraints.WEST,
270
                                GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
271
                this.add(parametersTabbedPane, new GridBagConstraints(0, 5, 1, 1, 0.0,
272
                                0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
273
                                new Insets(4, 4, 4, 4), 0, 0));
274
                parametersTabbedPane.add(findGapsTab, "Find Gaps");
275
                parametersTabbedPane.add(findOverlapsTab, "Find Overlaps");
276
                this.add(inputLayerPanel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
277
                                GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
278
                                new Insets(0, 0, 0, 0), 0, 0));
279
                inputLayerPanel.add(inputLayerLabel, new GridBagConstraints(0, 0, 1, 1,
280
                                0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE,
281
                                new Insets(0, 0, 0, 0), 0, 0));
282
                inputLayerPanel.add(inputLayerComboBox, new GridBagConstraints(1, 0, 1,
283
                                1, 0.0, 0.0, GridBagConstraints.CENTER,
284
                                GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
285
        }
286

    
287
        public HTMLPanel getLogPanel() {
288
                return (HTMLPanel) logTab.getChild();
289
        }
290

    
291
        public JTabbedPane getResultsTabbedPane() {
292
                return resultsTabbedPane;
293
        }
294

    
295
        public LayerDependencyManager getLayerDependencyManager() {
296
                return layerDependencyManager;
297
        }
298

    
299
        void fixAutomaticallyCheckBox_actionPerformed(ActionEvent e) {
300
                outputLayerLabel.setEnabled(fixAutomaticallyCheckBox.isSelected());
301
                outputLayerTextField.setEnabled(fixAutomaticallyCheckBox.isSelected());
302
        }
303

    
304
        public class MyTableTab extends TableTab {
305
                private JTabbedPane tabbedPane;
306

    
307
                private String basicTitle;
308

    
309
                private String associatedOperation;
310

    
311
                private JLabel errorMessageLabel = new JLabel("TEST");
312

    
313
                public TableTab setLayer(Layer layer, WorkbenchContext context) {
314
                        super.setLayer(layer, context);
315
                        updateTitle();
316
                        return this;
317
                }
318

    
319
                public MyTableTab(String basicTitle, String sortAttributeName,
320
                                JTabbedPane tabbedPane, String associatedOperation) {
321
                        super(sortAttributeName);
322
                        this.basicTitle = basicTitle;
323
                        add(errorMessageLabel, BorderLayout.NORTH);
324
                        errorMessageLabel.setVisible(true);
325
                        this.tabbedPane = tabbedPane;
326
                        this.associatedOperation = associatedOperation;
327
                }
328

    
329
                public void setChild(JPanel attributeTab) {
330
                        super.setChild(attributeTab);
331
                        updateTitle();
332
                }
333

    
334
                public void updateTitle() {
335
                        if (tabbedPane.indexOfComponent(this) == -1) {
336
                                //Get here during initialization [Jon Aquino]
337
                                return;
338
                        }
339

    
340
                        tabbedPane
341
                                        .setTitleAt(tabbedPane.indexOfComponent(this), getTitle());
342

    
343
                        if (isOutOfDate()) {
344
                                String errorMessage = getChild() instanceof OneLayerAttributeTab ? "These results may be out of date. Please re-run "
345
                                                + associatedOperation + "."
346
                                                : associatedOperation + " has not yet been run.";
347
                                tabbedPane.setToolTipTextAt(tabbedPane.indexOfComponent(this),
348
                                                errorMessage);
349
                                errorMessageLabel.setText("<html><font color=#ff0000><b>"
350
                                                + errorMessage + "</b></font></html>");
351
                                errorMessageLabel.setVisible(true);
352
                        } else {
353
                                tabbedPane.setToolTipTextAt(tabbedPane.indexOfComponent(this),
354
                                                null);
355
                                errorMessageLabel.setVisible(false);
356
                        }
357

    
358
                        repaint();
359
                }
360

    
361
                private String getTitle() {
362
                        String title = "<html><center>";
363

    
364
                        if (isOutOfDate()) {
365
                                title += "<font color=#ff0000><b>";
366
                        }
367

    
368
                        title += basicTitle + "<br>";
369

    
370
                        if (getChild() instanceof OneLayerAttributeTab) {
371
                                OneLayerAttributeTab attributeTab = (OneLayerAttributeTab) getChild();
372
                                title += ((attributeTab.getLayer() != null) ? ("("
373
                                                + attributeTab.getLayer().getFeatureCollectionWrapper()
374
                                                                .size() + ")") : "(0)");
375
                        } else {
376
                                title += "";
377
                        }
378

    
379
                        if (isOutOfDate()) {
380
                                title += "</b></font>";
381
                        }
382

    
383
                        title += "</center></html>";
384

    
385
                        return title;
386
                }
387

    
388
                private boolean isOutOfDate() {
389
                        return !layerDependencyManager.isUpToDate(this,
390
                                        getInputLayerComboBox().getSelectedLayer());
391
                }
392

    
393
                public Component createDefaultChild() {
394
                        return new JPanel();
395
                }
396
        }
397
}