gvsig-derived-geometries / org.gvsig.derivedgeometries / trunk / org.gvsig.derivedgeometries / org.gvsig.derivedgeometries.swing / org.gvsig.derivedgeometries.swing.impl / src / main / java / org / gvsig / derivedgeometries / swing / impl / views / FeaturesControlPanelView.java @ 45
History | View | Annotate | Download (16.6 KB)
1 |
/*
|
---|---|
2 |
* Copyright 2014 DiSiD Technologies S.L.L. All rights reserved.
|
3 |
*
|
4 |
* Project : DiSiD org.gvsig.derivedgeometries.swing.impl
|
5 |
* SVN Id : $Id$
|
6 |
*/
|
7 |
package org.gvsig.derivedgeometries.swing.impl.views; |
8 |
|
9 |
import java.awt.BorderLayout; |
10 |
import java.awt.Dimension; |
11 |
import java.awt.GridBagConstraints; |
12 |
import java.awt.GridBagLayout; |
13 |
import java.awt.Insets; |
14 |
|
15 |
import javax.swing.BorderFactory; |
16 |
import javax.swing.ImageIcon; |
17 |
import javax.swing.JButton; |
18 |
import javax.swing.JLabel; |
19 |
import javax.swing.JPanel; |
20 |
import javax.swing.JScrollPane; |
21 |
import javax.swing.JSplitPane; |
22 |
import javax.swing.JTable; |
23 |
import javax.swing.JTextField; |
24 |
import javax.swing.ListSelectionModel; |
25 |
import javax.swing.table.TableModel; |
26 |
|
27 |
import org.gvsig.derivedgeometries.swing.api.exceptions.FetaureTableModelException; |
28 |
import org.gvsig.fmap.dal.exception.DataException; |
29 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
30 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
31 |
import org.gvsig.fmap.mapcontrol.dal.feature.swing.FeatureTable; |
32 |
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.ConfigurableFeatureTableModel; |
33 |
import org.gvsig.tools.ToolsLocator; |
34 |
import org.gvsig.tools.exception.BaseException; |
35 |
import org.gvsig.tools.i18n.I18nManager; |
36 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
37 |
|
38 |
public class FeaturesControlPanelView extends JPanel { |
39 |
|
40 |
private static final long serialVersionUID = -3899738999699332396L; |
41 |
|
42 |
private I18nManager i18nManager = ToolsLocator.getI18nManager();
|
43 |
|
44 |
private JPanel summaryPanel; |
45 |
|
46 |
private JLabel sourceLayerNameLabel; |
47 |
|
48 |
private JTextField sourceLayerNameTextField; |
49 |
|
50 |
private JLabel destLayerNameLabel; |
51 |
|
52 |
private JTextField destLayerNameTextField; |
53 |
|
54 |
private JPanel centerPanel; |
55 |
|
56 |
private JSplitPane horizontalSplitPane; |
57 |
|
58 |
private JPanel featuresPanel; |
59 |
|
60 |
private JScrollPane allFeaturesScrollPane; |
61 |
|
62 |
private FeatureTable allFeaturesTable;
|
63 |
|
64 |
private ConfigurableFeatureTableModel allFeaturesTableModel;
|
65 |
|
66 |
private JPanel newFeatureSelectionPanel; |
67 |
|
68 |
private JPanel motionButtonsPanel; |
69 |
|
70 |
private JScrollPane selectedFeaturesScrollPane; |
71 |
|
72 |
private JTable selectedFeaturesTable; |
73 |
|
74 |
private JButton addAllIconButton; |
75 |
|
76 |
private JButton removeAllIconButton; |
77 |
|
78 |
private JButton addIconButton; |
79 |
|
80 |
private JButton removeIconButton; |
81 |
|
82 |
private JButton moveUpButton; |
83 |
|
84 |
private JButton moveDownButton; |
85 |
|
86 |
public FeaturesControlPanelView() {
|
87 |
initialize(); |
88 |
} |
89 |
|
90 |
private void initialize() { |
91 |
setLayout(new BorderLayout()); |
92 |
add(getSummaryPanel(), BorderLayout.PAGE_START);
|
93 |
add(getCenterPanel(), BorderLayout.CENTER);
|
94 |
} |
95 |
|
96 |
@Override
|
97 |
public Dimension getPreferredSize() { |
98 |
return new Dimension(500, 550); |
99 |
} |
100 |
|
101 |
protected JScrollPane getAllFeaturesScrollPane() { |
102 |
if (allFeaturesScrollPane == null) { |
103 |
allFeaturesScrollPane = new JScrollPane(); |
104 |
allFeaturesScrollPane |
105 |
.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
106 |
} |
107 |
|
108 |
return allFeaturesScrollPane;
|
109 |
} |
110 |
|
111 |
@SuppressWarnings("serial") |
112 |
protected FeatureTable getAllFeaturesTable(FeatureStore featureStore)
|
113 |
throws FetaureTableModelException {
|
114 |
if (allFeaturesTable == null) { |
115 |
try {
|
116 |
allFeaturesTable = |
117 |
new FeatureTable(getAllFeaturesTableModel(featureStore)) {
|
118 |
|
119 |
public boolean isCellEditable(int row, int column) { |
120 |
return false; |
121 |
} |
122 |
}; |
123 |
allFeaturesTable |
124 |
.setSelectionModel(new DefaultDerivedGeometriesSelectionModel(allFeaturesTableModel));
|
125 |
} catch (DataException e) {
|
126 |
throw new FetaureTableModelException(e.getMessage(), e); |
127 |
} |
128 |
|
129 |
allFeaturesTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
130 |
} |
131 |
return allFeaturesTable;
|
132 |
} |
133 |
|
134 |
protected ConfigurableFeatureTableModel getAllFeaturesTableModel(
|
135 |
FeatureStore featureStore) throws FetaureTableModelException {
|
136 |
if (allFeaturesTableModel == null) { |
137 |
try {
|
138 |
FeatureQuery query = featureStore.createFeatureQuery(); |
139 |
allFeaturesTableModel = |
140 |
new ConfigurableFeatureTableModel(featureStore, query);
|
141 |
} catch (BaseException e) {
|
142 |
throw new FetaureTableModelException(e.getMessage(), e); |
143 |
} |
144 |
} |
145 |
|
146 |
return allFeaturesTableModel;
|
147 |
} |
148 |
|
149 |
private JPanel getCenterPanel() { |
150 |
if (centerPanel == null) { |
151 |
centerPanel = new JPanel(); |
152 |
centerPanel.setLayout(new BorderLayout()); |
153 |
centerPanel.add(getHorizontalSplitPane(), BorderLayout.CENTER);
|
154 |
} |
155 |
|
156 |
return centerPanel;
|
157 |
} |
158 |
|
159 |
private JPanel getFeaturesPanel() { |
160 |
if (featuresPanel == null) { |
161 |
featuresPanel = new JPanel(); |
162 |
featuresPanel.setBorder(BorderFactory
|
163 |
.createTitledBorder(i18nManager.getTranslation("features")));
|
164 |
featuresPanel.setLayout(new BorderLayout()); |
165 |
featuresPanel.add(getAllFeaturesScrollPane(), BorderLayout.CENTER);
|
166 |
} |
167 |
|
168 |
return featuresPanel;
|
169 |
} |
170 |
|
171 |
private JSplitPane getHorizontalSplitPane() { |
172 |
if (horizontalSplitPane == null) { |
173 |
horizontalSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
174 |
horizontalSplitPane.setPreferredSize(this.getPreferredSize());
|
175 |
horizontalSplitPane.setOneTouchExpandable(true);
|
176 |
|
177 |
horizontalSplitPane.setTopComponent(getFeaturesPanel()); |
178 |
horizontalSplitPane.setBottomComponent(getNewFeaturePanel()); |
179 |
|
180 |
// Sets the split pane's divider to the 40 %
|
181 |
horizontalSplitPane.setDividerLocation((int) (horizontalSplitPane
|
182 |
.getPreferredSize().getHeight() * 0.40));
|
183 |
} |
184 |
|
185 |
return horizontalSplitPane;
|
186 |
} |
187 |
|
188 |
private JPanel getNewFeaturePanel() { |
189 |
if (newFeatureSelectionPanel == null) { |
190 |
newFeatureSelectionPanel = new JPanel(); |
191 |
newFeatureSelectionPanel |
192 |
.setBorder(BorderFactory.createTitledBorder(i18nManager
|
193 |
.getTranslation("new_features")));
|
194 |
newFeatureSelectionPanel.setLayout(new BorderLayout()); |
195 |
|
196 |
// Add all button
|
197 |
addAllIconButton = getAddAllButton(); |
198 |
// Remove all button
|
199 |
removeAllIconButton = getRemoveAllButton(); |
200 |
// Add button
|
201 |
addIconButton = getAddButton(); |
202 |
// Remove button
|
203 |
removeIconButton = getRemoveButton(); |
204 |
|
205 |
// Right panel
|
206 |
JPanel rightPanel = new JPanel(); |
207 |
rightPanel.add(addIconButton); |
208 |
rightPanel.add(removeIconButton); |
209 |
|
210 |
// Left panel
|
211 |
JPanel leftPanel = new JPanel(); |
212 |
leftPanel.add(addAllIconButton); |
213 |
leftPanel.add(removeAllIconButton); |
214 |
|
215 |
// North panel
|
216 |
JPanel northPanel = new JPanel(); |
217 |
northPanel.setLayout(new BorderLayout()); |
218 |
northPanel.add(leftPanel, BorderLayout.LINE_START);
|
219 |
northPanel.add(rightPanel, BorderLayout.LINE_END);
|
220 |
newFeatureSelectionPanel.add(northPanel, BorderLayout.PAGE_START);
|
221 |
|
222 |
// South panel
|
223 |
JPanel southPanel = new JPanel(); |
224 |
southPanel.setLayout(new GridBagLayout()); |
225 |
|
226 |
GridBagConstraints constraints = new GridBagConstraints(); |
227 |
constraints.gridx = GridBagConstraints.RELATIVE;
|
228 |
constraints.gridy = 0;
|
229 |
constraints.weightx = 1;
|
230 |
constraints.weighty = 1;
|
231 |
constraints.fill = GridBagConstraints.BOTH;
|
232 |
constraints.anchor = GridBagConstraints.WEST;
|
233 |
|
234 |
southPanel.add(getSelectedFeaturesScrollPane(), constraints); |
235 |
|
236 |
constraints = new GridBagConstraints(); |
237 |
constraints.gridx = GridBagConstraints.RELATIVE;
|
238 |
constraints.gridy = 0;
|
239 |
constraints.weightx = 0;
|
240 |
constraints.weighty = 0;
|
241 |
constraints.fill = GridBagConstraints.BOTH;
|
242 |
constraints.anchor = GridBagConstraints.EAST;
|
243 |
|
244 |
southPanel.add(getMotionButtonsPanel(), constraints); |
245 |
|
246 |
newFeatureSelectionPanel.add(southPanel, BorderLayout.CENTER);
|
247 |
} |
248 |
return newFeatureSelectionPanel;
|
249 |
} |
250 |
|
251 |
protected JButton getAddAllButton() { |
252 |
if (addAllIconButton == null) { |
253 |
ImageIcon addAllIcon =
|
254 |
ToolsSwingLocator.getIconThemeManager().getCurrent() |
255 |
.get("add-all-icon");
|
256 |
addAllIconButton = new JButton(addAllIcon); |
257 |
addAllIconButton.setToolTipText(i18nManager |
258 |
.getTranslation("_add_all_button_tooltip"));
|
259 |
} |
260 |
return addAllIconButton;
|
261 |
} |
262 |
|
263 |
protected JButton getAddButton() { |
264 |
if (addIconButton == null) { |
265 |
ImageIcon addIcon =
|
266 |
ToolsSwingLocator.getIconThemeManager().getCurrent() |
267 |
.get("add-selected-icon");
|
268 |
addIconButton = new JButton(addIcon); |
269 |
addIconButton.setToolTipText(i18nManager |
270 |
.getTranslation("_add_selected_button_tooltip"));
|
271 |
} |
272 |
return addIconButton;
|
273 |
} |
274 |
|
275 |
protected JButton getRemoveAllButton() { |
276 |
if (removeAllIconButton == null) { |
277 |
ImageIcon removeAllIcon =
|
278 |
ToolsSwingLocator.getIconThemeManager().getCurrent() |
279 |
.get("remove-all-icon");
|
280 |
removeAllIconButton = new JButton(removeAllIcon); |
281 |
removeAllIconButton.setToolTipText(i18nManager |
282 |
.getTranslation("_remove_all_button_tooltip"));
|
283 |
} |
284 |
return removeAllIconButton;
|
285 |
} |
286 |
|
287 |
protected JButton getRemoveButton() { |
288 |
if (removeIconButton == null) { |
289 |
ImageIcon removeIcon =
|
290 |
ToolsSwingLocator.getIconThemeManager().getCurrent() |
291 |
.get("remove-selected-icon");
|
292 |
removeIconButton = new JButton(removeIcon); |
293 |
removeIconButton.setToolTipText(i18nManager |
294 |
.getTranslation("_remove_selected_button_tooltip"));
|
295 |
} |
296 |
return removeIconButton;
|
297 |
} |
298 |
|
299 |
protected JScrollPane getSelectedFeaturesScrollPane() { |
300 |
if (selectedFeaturesScrollPane == null) { |
301 |
selectedFeaturesScrollPane = new JScrollPane(); |
302 |
selectedFeaturesScrollPane |
303 |
.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
304 |
} |
305 |
|
306 |
return selectedFeaturesScrollPane;
|
307 |
} |
308 |
|
309 |
@SuppressWarnings("serial") |
310 |
protected JTable getSelectedFeaturesTable() { |
311 |
if (selectedFeaturesTable == null) { |
312 |
selectedFeaturesTable = new JTable() { |
313 |
|
314 |
public boolean isCellEditable(int row, int column) { |
315 |
return false; |
316 |
} |
317 |
}; |
318 |
|
319 |
selectedFeaturesTable |
320 |
.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
321 |
selectedFeaturesTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
322 |
} |
323 |
return selectedFeaturesTable;
|
324 |
} |
325 |
|
326 |
protected SelectedFeaturesTableModel getSelectedFeaturesTableModel() {
|
327 |
TableModel model = getSelectedFeaturesTable().getModel();
|
328 |
if (model instanceof SelectedFeaturesTableModel) { |
329 |
return (SelectedFeaturesTableModel) model;
|
330 |
} |
331 |
return null; |
332 |
} |
333 |
|
334 |
private JPanel getMotionButtonsPanel() { |
335 |
if (motionButtonsPanel == null) { |
336 |
motionButtonsPanel = new JPanel(); |
337 |
motionButtonsPanel.setLayout(new GridBagLayout()); |
338 |
|
339 |
// Move up button
|
340 |
moveUpButton = getMoveUpButton(); |
341 |
|
342 |
JPanel upPanel = new JPanel(); |
343 |
upPanel.add(moveUpButton); |
344 |
|
345 |
GridBagConstraints constraints = new GridBagConstraints(); |
346 |
constraints.gridx = 0;
|
347 |
constraints.gridy = GridBagConstraints.RELATIVE;
|
348 |
constraints.gridheight = 0;
|
349 |
constraints.gridwidth = 0;
|
350 |
constraints.weightx = 0;
|
351 |
constraints.weighty = 0;
|
352 |
constraints.anchor = GridBagConstraints.CENTER;
|
353 |
constraints.fill = GridBagConstraints.NONE;
|
354 |
constraints.insets = new Insets(4, 4, 4, 0); |
355 |
|
356 |
motionButtonsPanel.add(upPanel, constraints); |
357 |
|
358 |
// Move down button
|
359 |
moveDownButton = getMoveDownButton(); |
360 |
|
361 |
JPanel downPanel = new JPanel(); |
362 |
downPanel.add(moveDownButton); |
363 |
motionButtonsPanel.add(downPanel, constraints); |
364 |
} |
365 |
|
366 |
return motionButtonsPanel;
|
367 |
} |
368 |
|
369 |
protected JButton getMoveUpButton() { |
370 |
if (moveUpButton == null) { |
371 |
ImageIcon moveUpIcon =
|
372 |
ToolsSwingLocator.getIconThemeManager().getCurrent() |
373 |
.get("up-arrow-icon");
|
374 |
moveUpButton = new JButton(moveUpIcon); |
375 |
moveUpButton.setToolTipText(i18nManager |
376 |
.getTranslation("_move_up_button_tooltip"));
|
377 |
|
378 |
} |
379 |
|
380 |
return moveUpButton;
|
381 |
} |
382 |
|
383 |
protected JButton getMoveDownButton() { |
384 |
if (moveDownButton == null) { |
385 |
ImageIcon moveDownIcon =
|
386 |
ToolsSwingLocator.getIconThemeManager().getCurrent() |
387 |
.get("down-arrow-icon");
|
388 |
moveDownButton = new JButton(moveDownIcon); |
389 |
moveDownButton.setToolTipText(i18nManager |
390 |
.getTranslation("_move_down_button_tooltip"));
|
391 |
} |
392 |
return moveDownButton;
|
393 |
} |
394 |
|
395 |
private JLabel getOutputLayerNameLabel() { |
396 |
if (destLayerNameLabel == null) { |
397 |
destLayerNameLabel = |
398 |
new JLabel(i18nManager.getTranslation("_output_layer")); |
399 |
destLayerNameLabel.setToolTipText(i18nManager |
400 |
.getTranslation("_output_layer"));
|
401 |
} |
402 |
|
403 |
return destLayerNameLabel;
|
404 |
} |
405 |
|
406 |
protected JTextField getOutputLayerNameTextField() { |
407 |
if (destLayerNameTextField == null) { |
408 |
destLayerNameTextField = new JTextField(); |
409 |
destLayerNameTextField.setEnabled(false);
|
410 |
} |
411 |
|
412 |
return destLayerNameTextField;
|
413 |
} |
414 |
|
415 |
private JLabel getSourceLayerNameLabel() { |
416 |
if (sourceLayerNameLabel == null) { |
417 |
sourceLayerNameLabel = |
418 |
new JLabel(i18nManager.getTranslation("_source_layer")); |
419 |
sourceLayerNameLabel.setToolTipText(i18nManager |
420 |
.getTranslation("_source_layer"));
|
421 |
} |
422 |
|
423 |
return sourceLayerNameLabel;
|
424 |
} |
425 |
|
426 |
protected JTextField getSourceLayerNameTextField() { |
427 |
if (sourceLayerNameTextField == null) { |
428 |
sourceLayerNameTextField = new JTextField(); |
429 |
sourceLayerNameTextField.setEnabled(false);
|
430 |
} |
431 |
|
432 |
return sourceLayerNameTextField;
|
433 |
} |
434 |
|
435 |
private JPanel getSummaryPanel() { |
436 |
if (summaryPanel == null) { |
437 |
summaryPanel = new JPanel(); |
438 |
summaryPanel.setLayout(new BorderLayout()); |
439 |
summaryPanel.setBorder(BorderFactory.createTitledBorder(i18nManager
|
440 |
.getTranslation("_layers")));
|
441 |
|
442 |
JPanel pageStartPanel = new JPanel(); |
443 |
pageStartPanel.setLayout(new GridBagLayout()); |
444 |
|
445 |
GridBagConstraints constraints = getConstraintsForLabel();
|
446 |
pageStartPanel.add(getSourceLayerNameLabel(), constraints); |
447 |
|
448 |
constraints = getContraintsForTextField(); |
449 |
pageStartPanel.add(getSourceLayerNameTextField(), constraints); |
450 |
|
451 |
summaryPanel.add(pageStartPanel, BorderLayout.PAGE_START);
|
452 |
|
453 |
JPanel pageEndPanel = new JPanel(); |
454 |
pageEndPanel.setLayout(new GridBagLayout()); |
455 |
constraints = getConstraintsForLabel(); |
456 |
pageEndPanel.add(getOutputLayerNameLabel(), constraints); |
457 |
|
458 |
constraints = getContraintsForTextField(); |
459 |
pageEndPanel.add(getOutputLayerNameTextField(), constraints); |
460 |
|
461 |
summaryPanel.add(pageEndPanel, BorderLayout.PAGE_END);
|
462 |
} |
463 |
|
464 |
return summaryPanel;
|
465 |
} |
466 |
|
467 |
private GridBagConstraints getConstraintsForLabel() { |
468 |
GridBagConstraints constraints = new GridBagConstraints(); |
469 |
constraints.gridx = GridBagConstraints.RELATIVE;
|
470 |
constraints.gridy = 0;
|
471 |
constraints.gridwidth = 1;
|
472 |
constraints.gridheight = 1;
|
473 |
constraints.anchor = GridBagConstraints.WEST;
|
474 |
constraints.fill = GridBagConstraints.NONE;
|
475 |
constraints.insets = new Insets(4, 4, 4, 4); |
476 |
return constraints;
|
477 |
} |
478 |
|
479 |
private GridBagConstraints getContraintsForTextField() { |
480 |
GridBagConstraints constraints = new GridBagConstraints(); |
481 |
constraints.gridx = GridBagConstraints.RELATIVE;
|
482 |
constraints.gridy = 0;
|
483 |
constraints.gridwidth = 2;
|
484 |
constraints.gridheight = 1;
|
485 |
constraints.weightx = 1;
|
486 |
constraints.anchor = GridBagConstraints.CENTER;
|
487 |
constraints.fill = GridBagConstraints.HORIZONTAL;
|
488 |
constraints.insets = new Insets(4, 4, 4, 4); |
489 |
return constraints;
|
490 |
} |
491 |
} |