Revision 801
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.102/org.gvsig.educa.portableview.swing/org.gvsig.educa.portableview.swing.impl/src/main/java/org/gvsig/educa/portableview/swing/impl/editor/layers/DefaultPortableViewLayersEditor.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.educa.portableview.swing.impl.editor.layers; |
|
23 |
|
|
24 |
import java.awt.BorderLayout; |
|
25 |
import java.util.ArrayList; |
|
26 |
import java.util.Collections; |
|
27 |
import java.util.List; |
|
28 |
|
|
29 |
import javax.swing.JComponent; |
|
30 |
import javax.swing.JPanel; |
|
31 |
import javax.swing.JScrollPane; |
|
32 |
import javax.swing.JTree; |
|
33 |
import javax.swing.tree.DefaultMutableTreeNode; |
|
34 |
import javax.swing.tree.DefaultTreeModel; |
|
35 |
import javax.swing.tree.TreePath; |
|
36 |
import javax.swing.tree.TreeSelectionModel; |
|
37 |
|
|
38 |
import org.gvsig.educa.portableview.swing.editor.PortableViewCompilationEditor; |
|
39 |
import org.gvsig.educa.portableview.swing.editor.PortableViewLayersEditor; |
|
40 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
|
41 |
import org.gvsig.fmap.mapcontext.layers.CancelationException; |
|
42 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
43 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
44 |
import org.gvsig.fmap.mapcontext.layers.LayerCollectionEvent; |
|
45 |
import org.gvsig.fmap.mapcontext.layers.LayerCollectionListener; |
|
46 |
import org.gvsig.fmap.mapcontext.layers.LayerEvent; |
|
47 |
import org.gvsig.fmap.mapcontext.layers.LayerListener; |
|
48 |
import org.gvsig.fmap.mapcontext.layers.LayerPositionEvent; |
|
49 |
import org.gvsig.fmap.mapcontext.layers.operations.LayerCollection; |
|
50 |
|
|
51 |
/** |
|
52 |
* <p> |
|
53 |
* Default implementation of {@link PortableViewLayersEditor} |
|
54 |
* </p> |
|
55 |
* <p> |
|
56 |
* Creates a JTree to represent MapContext structure. |
|
57 |
* </p> |
|
58 |
* <p> |
|
59 |
* Uses {@link LayerCollection} and {@link LayerListener} notifications to |
|
60 |
* update JTree contents. |
|
61 |
* </p> |
|
62 |
* |
|
63 |
* @author gvSIG Team |
|
64 |
* @version $Id$ |
|
65 |
* |
|
66 |
*/ |
|
67 |
public class DefaultPortableViewLayersEditor extends JPanel implements |
|
68 |
PortableViewLayersEditor, LayerCollectionListener, LayerListener { |
|
69 |
|
|
70 |
/** |
|
71 |
* |
|
72 |
*/ |
|
73 |
private static final long serialVersionUID = 3659268618881281187L; |
|
74 |
|
|
75 |
private PortableViewCompilationEditor editor; |
|
76 |
|
|
77 |
private boolean initialized = false; |
|
78 |
|
|
79 |
private JTree tree; |
|
80 |
|
|
81 |
private DefaultMutableTreeNode rootNode; |
|
82 |
|
|
83 |
private DefaultTreeModel treeModel; |
|
84 |
|
|
85 |
private FLayers rootLayer; |
|
86 |
|
|
87 |
/** |
|
88 |
* |
|
89 |
*/ |
|
90 |
public DefaultPortableViewLayersEditor() { |
|
91 |
|
|
92 |
} |
|
93 |
|
|
94 |
/** |
|
95 |
* Initialize UI components |
|
96 |
*/ |
|
97 |
private void initializeUI() { |
|
98 |
if (initialized) { |
|
99 |
return; |
|
100 |
} |
|
101 |
setLayout(new BorderLayout()); |
|
102 |
|
|
103 |
tree = new JTree(); |
|
104 |
|
|
105 |
tree.setCellRenderer(new LayerTreeCellRenderer()); |
|
106 |
|
|
107 |
tree.setRootVisible(false); |
|
108 |
|
|
109 |
tree.getSelectionModel().setSelectionMode( |
|
110 |
TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); |
|
111 |
|
|
112 |
add(new JScrollPane(tree), BorderLayout.CENTER); |
|
113 |
|
|
114 |
initialized = true; |
|
115 |
} |
|
116 |
|
|
117 |
/** {@inheridDoc} */ |
|
118 |
public JComponent getSwingComponent() { |
|
119 |
return this; |
|
120 |
} |
|
121 |
|
|
122 |
/** {@inheridDoc} */ |
|
123 |
public void setCompilationEditor( |
|
124 |
PortableViewCompilationEditor compilationEditor) { |
|
125 |
initializeUI(); |
|
126 |
editor = compilationEditor; |
|
127 |
loadTreeModel(); |
|
128 |
} |
|
129 |
|
|
130 |
/** |
|
131 |
* Load tree model from mapContext |
|
132 |
*/ |
|
133 |
private void loadTreeModel() { |
|
134 |
rootLayer = editor.getCompilation().getMapContext().getLayers(); |
|
135 |
// rootNode = new LayerTreeNode(rootLayer); |
|
136 |
// rootLayer.addLayerCollectionListener(this); |
|
137 |
loadLayerNode(rootLayer, null); |
|
138 |
treeModel = new DefaultTreeModel(rootNode); |
|
139 |
tree.setModel(treeModel); |
|
140 |
tree.invalidate(); |
|
141 |
|
|
142 |
} |
|
143 |
|
|
144 |
/** |
|
145 |
* Load a layer Node |
|
146 |
* |
|
147 |
* @param layer |
|
148 |
* @param parent |
|
149 |
*/ |
|
150 |
private void loadLayerNode(FLayer layer, LayerTreeNode parent) { |
|
151 |
layer.addLayerListener(this); |
|
152 |
LayerTreeNode node = new LayerTreeNode(layer); |
|
153 |
if (parent == null) { |
|
154 |
rootNode = node; |
|
155 |
} else { |
|
156 |
parent.add(node); |
|
157 |
} |
|
158 |
if (layer instanceof LayerCollection) { |
|
159 |
LayerCollection collection = (LayerCollection) layer; |
|
160 |
collection.addLayerCollectionListener(this); |
|
161 |
for (int i = 0; i < collection.getLayersCount(); i++) { |
|
162 |
loadLayerNode(collection.getLayer(i), node); |
|
163 |
} |
|
164 |
} |
|
165 |
} |
|
166 |
|
|
167 |
/** {@inheridDoc} */ |
|
168 |
public PortableViewCompilationEditor getCompilationEditor() { |
|
169 |
return editor; |
|
170 |
} |
|
171 |
|
|
172 |
/** {@inheridDoc} */ |
|
173 |
public List<FLayer> getSelectedLayers() { |
|
174 |
List<FLayer> selectedLayers = new ArrayList<FLayer>(); |
|
175 |
LayerTreeNode node; |
|
176 |
TreePath[] paths = tree.getSelectionPaths(); |
|
177 |
if (paths != null && paths.length > 0) { |
|
178 |
for (TreePath path : paths) { |
|
179 |
node = (LayerTreeNode) (path.getLastPathComponent()); |
|
180 |
selectedLayers.add(node.getLayer()); |
|
181 |
} |
|
182 |
} |
|
183 |
return Collections.unmodifiableList(selectedLayers); |
|
184 |
} |
|
185 |
|
|
186 |
/** {@inheridDoc} */ |
|
187 |
public void removeSelectedLayers() { |
|
188 |
List<FLayer> selected = getSelectedLayers(); |
|
189 |
LayerCollection parent; |
|
190 |
for (FLayer fLayer : selected) { |
|
191 |
parent = fLayer.getParentLayer(); |
|
192 |
parent.removeLayer(fLayer); |
|
193 |
} |
|
194 |
} |
|
195 |
|
|
196 |
/** {@inheridDoc} */ |
|
197 |
public void addLayersToGroup(List<FLayer> layers) |
|
198 |
throws LoadLayerException, CancelationException { |
|
199 |
List<FLayer> selecteds = getSelectedLayers(); |
|
200 |
if (selecteds.size() > 1) { |
|
201 |
throw new IllegalStateException("Too much selected layers"); |
|
202 |
} |
|
203 |
FLayer selected = selecteds.get(0); |
|
204 |
LayerCollection parent; |
|
205 |
if (selected instanceof LayerCollection) { |
|
206 |
parent = (LayerCollection) selected; |
|
207 |
} else { |
|
208 |
parent = selected.getParentLayer(); |
|
209 |
} |
|
210 |
|
|
211 |
for (FLayer fLayer : layers) { |
|
212 |
parent.addLayer(fLayer); |
|
213 |
} |
|
214 |
} |
|
215 |
|
|
216 |
/** |
|
217 |
* Locates the layer node in all tree structure from root |
|
218 |
* |
|
219 |
* @param layer |
|
220 |
* @return |
|
221 |
*/ |
|
222 |
private LayerTreeNode findLayerNode(FLayer layer) { |
|
223 |
if (rootNode == null) { |
|
224 |
return null; |
|
225 |
} |
|
226 |
return findLayerNode((LayerTreeNode) rootNode, layer); |
|
227 |
} |
|
228 |
|
|
229 |
/** |
|
230 |
* Locates the layer node in all tree structure from root |
|
231 |
* |
|
232 |
* @param node |
|
233 |
* @param layer |
|
234 |
* @return |
|
235 |
*/ |
|
236 |
private LayerTreeNode findLayerNode(LayerTreeNode node, FLayer layer) { |
|
237 |
if (node.getLayer() == layer) { |
|
238 |
return node; |
|
239 |
} |
|
240 |
if (node.isLeaf()) { |
|
241 |
return null; |
|
242 |
} |
|
243 |
LayerTreeNode aNode; |
|
244 |
LayerTreeNode result; |
|
245 |
for (int i = 0; i < node.getChildCount(); i++) { |
|
246 |
aNode = (LayerTreeNode) node.getChildAt(i); |
|
247 |
result = findLayerNode(aNode, layer); |
|
248 |
if (result != null) { |
|
249 |
return result; |
|
250 |
} |
|
251 |
} |
|
252 |
return null; |
|
253 |
} |
|
254 |
|
|
255 |
public void layerAdded(LayerCollectionEvent e) { |
|
256 |
FLayer afectedLayer = e.getAffectedLayer(); |
|
257 |
if (afectedLayer instanceof LayerCollection) { |
|
258 |
((LayerCollection) afectedLayer).addLayerCollectionListener(this); |
|
259 |
} |
|
260 |
afectedLayer.addLayerListener(this); |
|
261 |
FLayer parentLayer = afectedLayer.getParentLayer(); |
|
262 |
LayerTreeNode parentNode = findLayerNode(parentLayer); |
|
263 |
LayerTreeNode afectedNode = new LayerTreeNode(afectedLayer); |
|
264 |
treeModel.insertNodeInto(afectedNode, parentNode, |
|
265 |
parentNode.getChildCount()); |
|
266 |
tree.scrollPathToVisible(new TreePath(afectedNode.getPath())); |
|
267 |
} |
|
268 |
|
|
269 |
public void layerMoved(LayerPositionEvent e) { |
|
270 |
FLayer afectedLayer = e.getAffectedLayer(); |
|
271 |
FLayer parentLayer = afectedLayer.getParentLayer(); |
|
272 |
LayerTreeNode parentNode = findLayerNode(parentLayer); |
|
273 |
LayerTreeNode afectedNode = |
|
274 |
(LayerTreeNode) parentNode.getChildAt(e.getOldPos()); |
|
275 |
if (afectedNode.getLayer() != afectedLayer) { |
|
276 |
// TODO |
|
277 |
} |
|
278 |
treeModel.removeNodeFromParent(afectedNode); |
|
279 |
treeModel.insertNodeInto(afectedNode, parentNode, e.getNewPos()); |
|
280 |
} |
|
281 |
|
|
282 |
public void layerRemoved(LayerCollectionEvent e) { |
|
283 |
FLayer afectedLayer = e.getAffectedLayer(); |
|
284 |
if (afectedLayer instanceof LayerCollection) { |
|
285 |
((LayerCollection) afectedLayer) |
|
286 |
.removeLayerCollectionListener(this); |
|
287 |
} |
|
288 |
afectedLayer.removeLayerListener(this); |
|
289 |
LayerTreeNode afected = findLayerNode(afectedLayer); |
|
290 |
treeModel.removeNodeFromParent(afected); |
|
291 |
} |
|
292 |
|
|
293 |
public void layerAdding(LayerCollectionEvent e) throws CancelationException { |
|
294 |
// Nothing to do |
|
295 |
} |
|
296 |
|
|
297 |
public void layerMoving(LayerPositionEvent e) throws CancelationException { |
|
298 |
// Nothing to do |
|
299 |
} |
|
300 |
|
|
301 |
public void layerRemoving(LayerCollectionEvent e) |
|
302 |
throws CancelationException { |
|
303 |
// Nothing to do |
|
304 |
} |
|
305 |
|
|
306 |
public void visibilityChanged(LayerCollectionEvent e) |
|
307 |
throws CancelationException { |
|
308 |
// Nothing to do |
|
309 |
} |
|
310 |
|
|
311 |
public void visibilityChanged(LayerEvent e) { |
|
312 |
// Nothing to do |
|
313 |
} |
|
314 |
|
|
315 |
public void activationChanged(LayerEvent e) { |
|
316 |
// Nothing to do |
|
317 |
} |
|
318 |
|
|
319 |
public void nameChanged(LayerEvent e) { |
|
320 |
FLayer layer = e.getSource(); |
|
321 |
LayerTreeNode node = findLayerNode(layer); |
|
322 |
treeModel.nodeChanged(node); |
|
323 |
tree.scrollPathToVisible(new TreePath(node.getPath())); |
|
324 |
} |
|
325 |
|
|
326 |
public void editionChanged(LayerEvent e) { |
|
327 |
// Nothing to do |
|
328 |
} |
|
329 |
|
|
330 |
public void drawValueChanged(LayerEvent e) { |
|
331 |
// Nothing to do |
|
332 |
} |
|
333 |
|
|
334 |
} |
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.102/org.gvsig.educa.portableview.swing/org.gvsig.educa.portableview.swing.impl/src/main/java/org/gvsig/educa/portableview/swing/impl/editor/layers/LayerTreeNode.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.educa.portableview.swing.impl.editor.layers; |
|
23 |
|
|
24 |
import javax.swing.tree.DefaultMutableTreeNode; |
|
25 |
|
|
26 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
27 |
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer; |
|
28 |
|
|
29 |
/** |
|
30 |
* Node representation of a layer in JTree of |
|
31 |
* {@link DefaultPortableViewLayersEditor} |
|
32 |
* |
|
33 |
* @author gvSIG Team |
|
34 |
* @version $Id$ |
|
35 |
* |
|
36 |
*/ |
|
37 |
public class LayerTreeNode extends DefaultMutableTreeNode { |
|
38 |
|
|
39 |
/** |
|
40 |
* |
|
41 |
*/ |
|
42 |
private static final long serialVersionUID = -5660745136587795464L; |
|
43 |
|
|
44 |
/** |
|
45 |
* |
|
46 |
*/ |
|
47 |
public LayerTreeNode(FLayer layer) { |
|
48 |
super(layer); |
|
49 |
} |
|
50 |
|
|
51 |
public FLayer getLayer() { |
|
52 |
return (FLayer) getUserObject(); |
|
53 |
} |
|
54 |
|
|
55 |
@Override |
|
56 |
public boolean isLeaf() { |
|
57 |
return getLayer() instanceof SingleLayer; |
|
58 |
} |
|
59 |
|
|
60 |
} |
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.102/org.gvsig.educa.portableview.swing/org.gvsig.educa.portableview.swing.impl/src/main/java/org/gvsig/educa/portableview/swing/impl/editor/layers/LayerTreeCellRenderer.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.educa.portableview.swing.impl.editor.layers; |
|
23 |
|
|
24 |
import java.awt.Component; |
|
25 |
|
|
26 |
import javax.swing.JTree; |
|
27 |
import javax.swing.tree.DefaultTreeCellRenderer; |
|
28 |
|
|
29 |
import org.apache.commons.lang3.StringUtils; |
|
30 |
|
|
31 |
/** |
|
32 |
* <p> |
|
33 |
* Tree cell renderer for {@link DefaultPortableViewLayersEditor} JTree |
|
34 |
* </p> |
|
35 |
* <p> |
|
36 |
* Nodes shows the name of layer. |
|
37 |
* </p> |
|
38 |
* |
|
39 |
* @author gvSIG Team |
|
40 |
* @version $Id$ |
|
41 |
* |
|
42 |
*/ |
|
43 |
public class LayerTreeCellRenderer extends DefaultTreeCellRenderer { |
|
44 |
|
|
45 |
/** |
|
46 |
* |
|
47 |
*/ |
|
48 |
private static final long serialVersionUID = 2372319888923346385L; |
|
49 |
|
|
50 |
@Override |
|
51 |
public Component getTreeCellRendererComponent(JTree tree, Object value, |
|
52 |
boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { |
|
53 |
|
|
54 |
if (value instanceof LayerTreeNode) { |
|
55 |
LayerTreeNode layerNode = (LayerTreeNode) value; |
|
56 |
String layerName = layerNode.getLayer().getName(); |
|
57 |
if (StringUtils.isBlank(layerName)) { |
|
58 |
layerName = "{No_Name}"; |
|
59 |
} |
|
60 |
value = layerName; |
|
61 |
} |
|
62 |
|
|
63 |
return super.getTreeCellRendererComponent(tree, value, sel, expanded, |
|
64 |
leaf, row, hasFocus); |
|
65 |
} |
|
66 |
} |
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.102/org.gvsig.educa.portableview.swing/org.gvsig.educa.portableview.swing.impl/src/main/java/org/gvsig/educa/portableview/swing/impl/editor/layers/DefaultPortableViewLayerPropertiesEditor.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.educa.portableview.swing.impl.editor.layers; |
|
23 |
|
|
24 |
import java.awt.BorderLayout; |
|
25 |
import java.awt.GridBagConstraints; |
|
26 |
import java.awt.GridBagLayout; |
|
27 |
import java.awt.Insets; |
|
28 |
import java.awt.event.ActionEvent; |
|
29 |
import java.awt.event.ActionListener; |
|
30 |
|
|
31 |
import javax.swing.Box; |
|
32 |
import javax.swing.BoxLayout; |
|
33 |
import javax.swing.JButton; |
|
34 |
import javax.swing.JCheckBox; |
|
35 |
import javax.swing.JComponent; |
|
36 |
import javax.swing.JLabel; |
|
37 |
import javax.swing.JPanel; |
|
38 |
import javax.swing.JTextField; |
|
39 |
|
|
40 |
import org.gvsig.educa.portableview.swing.PortableViewSwingLocator; |
|
41 |
import org.gvsig.educa.portableview.swing.PortableViewSwingManager; |
|
42 |
import org.gvsig.educa.portableview.swing.editor.PortableViewLayerPropertiesEditor; |
|
43 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
44 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
45 |
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager; |
|
46 |
|
|
47 |
/** |
|
48 |
* <p> |
|
49 |
* Default implementation of PortableViewLayerPropertiesEditor |
|
50 |
* </p> |
|
51 |
* <p> |
|
52 |
* Allows to modify: |
|
53 |
* <ul> |
|
54 |
* <li>name</li> |
|
55 |
* <li>visibility</li> |
|
56 |
* <li>show in TOC</li> |
|
57 |
* </ul> |
|
58 |
* </p> |
|
59 |
* |
|
60 |
* TODO complete this?? |
|
61 |
* |
|
62 |
* @author gvSIG Team |
|
63 |
* @version $Id$ |
|
64 |
* |
|
65 |
*/ |
|
66 |
public class DefaultPortableViewLayerPropertiesEditor extends JPanel implements |
|
67 |
PortableViewLayerPropertiesEditor, ActionListener { |
|
68 |
|
|
69 |
/** |
|
70 |
* |
|
71 |
*/ |
|
72 |
private static final long serialVersionUID = -8148127849062866099L; |
|
73 |
|
|
74 |
private static final GridBagConstraints LABEL_CONSTRAINT = |
|
75 |
new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0, 0, |
|
76 |
GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(4, 4, |
|
77 |
4, 10), 2, 2); |
|
78 |
|
|
79 |
private static final GridBagConstraints LARGE_LABEL_CONSTRAINT = |
|
80 |
new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 3, 0, 0, |
|
81 |
GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(4, 4, |
|
82 |
4, 10), 2, 2); |
|
83 |
|
|
84 |
private static final GridBagConstraints FIELD_CONSTRAINT = |
|
85 |
new GridBagConstraints(1, GridBagConstraints.RELATIVE, |
|
86 |
GridBagConstraints.REMAINDER, 1, 1, 0, GridBagConstraints.WEST, |
|
87 |
GridBagConstraints.HORIZONTAL, new Insets(4, 4, 4, 10), 2, 2); |
|
88 |
|
|
89 |
private static final GridBagConstraints LARGE_FIELD_CONSTRAINT = |
|
90 |
new GridBagConstraints(1, GridBagConstraints.RELATIVE, |
|
91 |
GridBagConstraints.REMAINDER, 3, 1, 1, GridBagConstraints.WEST, |
|
92 |
GridBagConstraints.BOTH, new Insets(4, 4, 4, 10), 2, 2); |
|
93 |
|
|
94 |
private final PortableViewSwingManager swingManager; |
|
95 |
|
|
96 |
private boolean initialized; |
|
97 |
|
|
98 |
private JTextField txtName; |
|
99 |
|
|
100 |
private JCheckBox chkVisible; |
|
101 |
|
|
102 |
private JCheckBox chkShowInToc; |
|
103 |
|
|
104 |
private final UsabilitySwingManager usabManager; |
|
105 |
|
|
106 |
private JButton botAccept; |
|
107 |
|
|
108 |
private JButton botCancel; |
|
109 |
|
|
110 |
private FLayer layer; |
|
111 |
|
|
112 |
/** |
|
113 |
* |
|
114 |
*/ |
|
115 |
public DefaultPortableViewLayerPropertiesEditor() { |
|
116 |
swingManager = PortableViewSwingLocator.getSwingManager(); |
|
117 |
usabManager = ToolsSwingLocator.getUsabilitySwingManager(); |
|
118 |
initialized = false; |
|
119 |
} |
|
120 |
|
|
121 |
/** |
|
122 |
* Initializes UI components |
|
123 |
*/ |
|
124 |
private void initializeUI() { |
|
125 |
if (initialized) { |
|
126 |
return; |
|
127 |
} |
|
128 |
setLayout(new BorderLayout()); |
|
129 |
JPanel dataPanel = new JPanel(); |
|
130 |
dataPanel.setLayout(new GridBagLayout()); |
|
131 |
txtName = new JTextField(); |
|
132 |
chkVisible = |
|
133 |
new JCheckBox(swingManager.getTranslation("layer_visible")); |
|
134 |
chkShowInToc = |
|
135 |
new JCheckBox(swingManager.getTranslation("layer_show_in_toc")); |
|
136 |
|
|
137 |
addField(dataPanel, "layer_name", txtName, false); |
|
138 |
addField(dataPanel, null, chkVisible, false); |
|
139 |
addField(dataPanel, null, chkShowInToc, true); |
|
140 |
add(dataPanel, BorderLayout.CENTER); |
|
141 |
|
|
142 |
JPanel commandsPanel = new JPanel(); |
|
143 |
commandsPanel.setLayout(new BoxLayout(commandsPanel, BoxLayout.X_AXIS)); |
|
144 |
commandsPanel.add(Box.createHorizontalGlue()); |
|
145 |
botAccept = |
|
146 |
usabManager.createJButton(swingManager.getTranslation("accept")); |
|
147 |
botAccept.addActionListener(this); |
|
148 |
|
|
149 |
botCancel = |
|
150 |
usabManager.createJButton(swingManager.getTranslation("cancel")); |
|
151 |
botCancel.addActionListener(this); |
|
152 |
|
|
153 |
commandsPanel.add(botAccept); |
|
154 |
commandsPanel.add(Box.createHorizontalStrut(10)); |
|
155 |
commandsPanel.add(botCancel); |
|
156 |
commandsPanel.add(Box.createHorizontalStrut(5)); |
|
157 |
add(commandsPanel, BorderLayout.SOUTH); |
|
158 |
|
|
159 |
initialized = true; |
|
160 |
} |
|
161 |
|
|
162 |
/** |
|
163 |
* Add a field to form |
|
164 |
* |
|
165 |
* @param panel |
|
166 |
* where add field |
|
167 |
* @param key |
|
168 |
* for translation of field label |
|
169 |
* @param component |
|
170 |
* input component |
|
171 |
* @param large |
|
172 |
* if is a large field (multirow size) |
|
173 |
*/ |
|
174 |
private void addField(JPanel panel, String key, JComponent component, |
|
175 |
boolean large) { |
|
176 |
GridBagConstraints gbc; |
|
177 |
if (key != null) { |
|
178 |
gbc = LABEL_CONSTRAINT; |
|
179 |
if (large) { |
|
180 |
gbc = LARGE_LABEL_CONSTRAINT; |
|
181 |
} |
|
182 |
panel |
|
183 |
.add(new JLabel(swingManager.getTranslation(key)), gbc.clone()); |
|
184 |
} |
|
185 |
gbc = FIELD_CONSTRAINT; |
|
186 |
if (large) { |
|
187 |
gbc = LARGE_FIELD_CONSTRAINT; |
|
188 |
} |
|
189 |
panel.add(component, gbc.clone()); |
|
190 |
} |
|
191 |
|
|
192 |
/** {@inheridDoc} */ |
|
193 |
public JComponent getSwingComponent() { |
|
194 |
initializeUI(); |
|
195 |
return this; |
|
196 |
} |
|
197 |
|
|
198 |
/** {@inheridDoc} */ |
|
199 |
public void setLayer(FLayer layer) { |
|
200 |
this.layer = layer; |
|
201 |
loadUI(); |
|
202 |
} |
|
203 |
|
|
204 |
/** {@inheridDoc} */ |
|
205 |
public void saveLayerData() { |
|
206 |
layer.setName(txtName.getText()); |
|
207 |
layer.setInTOC(chkShowInToc.isSelected()); |
|
208 |
layer.setVisible(chkVisible.isSelected()); |
|
209 |
} |
|
210 |
|
|
211 |
/** {@inheridDoc} */ |
|
212 |
public void discartAllChanges() { |
|
213 |
loadUI(); |
|
214 |
} |
|
215 |
|
|
216 |
/** |
|
217 |
* Load data to UI components |
|
218 |
*/ |
|
219 |
private void loadUI() { |
|
220 |
initializeUI(); |
|
221 |
txtName.setText(layer.getName()); |
|
222 |
chkShowInToc.setSelected(layer.isInTOC()); |
|
223 |
chkVisible.setSelected(layer.isVisible()); |
|
224 |
} |
|
225 |
|
|
226 |
public void actionPerformed(ActionEvent e) { |
|
227 |
Object source = e.getSource(); |
|
228 |
if (source == botAccept) { |
|
229 |
saveLayerData(); |
|
230 |
close(); |
|
231 |
} |
|
232 |
if (source == botCancel) { |
|
233 |
close(); |
|
234 |
} |
|
235 |
|
|
236 |
} |
|
237 |
|
|
238 |
/** |
|
239 |
* Close panel |
|
240 |
*/ |
|
241 |
public void close() { |
|
242 |
setVisible(false); |
|
243 |
} |
|
244 |
|
|
245 |
} |
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.102/org.gvsig.educa.portableview.swing/org.gvsig.educa.portableview.swing.impl/src/main/java/org/gvsig/educa/portableview/swing/impl/editor/StepIdentification.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.educa.portableview.swing.impl.editor; |
|
23 |
|
|
24 |
import java.awt.GridBagConstraints; |
|
25 |
import java.awt.GridBagLayout; |
|
26 |
import java.awt.Insets; |
|
27 |
|
|
28 |
import javax.swing.JComponent; |
|
29 |
import javax.swing.JLabel; |
|
30 |
import javax.swing.JPanel; |
|
31 |
import javax.swing.JScrollPane; |
|
32 |
import javax.swing.JTextArea; |
|
33 |
import javax.swing.JTextField; |
|
34 |
|
|
35 |
import org.apache.commons.lang3.StringUtils; |
|
36 |
|
|
37 |
import org.gvsig.educa.portableview.compilation.PortableViewCompilation; |
|
38 |
import org.gvsig.educa.portableview.compilation.PortableViewCompilationInformation; |
|
39 |
import org.gvsig.educa.portableview.swing.PortableViewSwingLocator; |
|
40 |
import org.gvsig.educa.portableview.swing.PortableViewSwingManager; |
|
41 |
import org.gvsig.gui.beans.wizard.panel.NotContinueWizardException; |
|
42 |
import org.gvsig.gui.beans.wizard.panel.OptionPanel; |
|
43 |
|
|
44 |
/** |
|
45 |
* |
|
46 |
* {@link DefaultPortableViewCompilationEditor} step which allows set/modify |
|
47 |
* information data of the compilation |
|
48 |
* |
|
49 |
* @author gvSIG Team |
|
50 |
* @version $Id$ |
|
51 |
* |
|
52 |
*/ |
|
53 |
public class StepIdentification extends JPanel implements OptionPanel { |
|
54 |
|
|
55 |
/** |
|
56 |
* |
|
57 |
*/ |
|
58 |
private static final long serialVersionUID = 5061121028061557890L; |
|
59 |
|
|
60 |
private static final GridBagConstraints LABEL_CONSTRAINT = |
|
61 |
new GridBagConstraints(GridBagConstraints.RELATIVE, |
|
62 |
GridBagConstraints.RELATIVE, 1, 1, 0, 0, GridBagConstraints.WEST, |
|
63 |
GridBagConstraints.NONE, new Insets(4, 4, 4, 10), 2, 2); |
|
64 |
|
|
65 |
private static final GridBagConstraints LARGE_LABEL_CONSTRAINT = |
|
66 |
new GridBagConstraints(GridBagConstraints.RELATIVE, |
|
67 |
GridBagConstraints.RELATIVE, 1, 3, 0, 0, GridBagConstraints.WEST, |
|
68 |
GridBagConstraints.NONE, new Insets(4, 4, 4, 10), 2, 2); |
|
69 |
|
|
70 |
private static final GridBagConstraints FIELD_CONSTRAINT = |
|
71 |
new GridBagConstraints(GridBagConstraints.RELATIVE, |
|
72 |
GridBagConstraints.RELATIVE, GridBagConstraints.REMAINDER, 1, 1, 0, |
|
73 |
GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets( |
|
74 |
4, 4, 4, 10), 2, 2); |
|
75 |
|
|
76 |
private static final GridBagConstraints LARGE_FIELD_CONSTRAINT = |
|
77 |
new GridBagConstraints(GridBagConstraints.RELATIVE, |
|
78 |
GridBagConstraints.RELATIVE, GridBagConstraints.REMAINDER, 3, 1, 1, |
|
79 |
GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(4, 4, |
|
80 |
4, 10), 2, 2); |
|
81 |
|
|
82 |
private final PortableViewCompilation compilation; |
|
83 |
|
|
84 |
private final PortableViewSwingManager swingManager; |
|
85 |
|
|
86 |
@SuppressWarnings("unused") |
|
87 |
private final DefaultPortableViewCompilationEditor editor; |
|
88 |
|
|
89 |
private JTextField txtId; |
|
90 |
|
|
91 |
private JTextField txtName; |
|
92 |
|
|
93 |
private JTextField txtVersion; |
|
94 |
|
|
95 |
private JTextArea txtDescription; |
|
96 |
|
|
97 |
private boolean allowChangeId; |
|
98 |
|
|
99 |
/** |
|
100 |
* @param defaultPortableViewCompilationEditor |
|
101 |
* @param allowChangeId |
|
102 |
*/ |
|
103 |
public StepIdentification( |
|
104 |
DefaultPortableViewCompilationEditor defaultPortableViewCompilationEditor, |
|
105 |
boolean allowChangeId) { |
|
106 |
swingManager = PortableViewSwingLocator.getSwingManager(); |
|
107 |
this.editor = defaultPortableViewCompilationEditor; |
|
108 |
this.compilation = defaultPortableViewCompilationEditor.getCompilation(); |
|
109 |
this.allowChangeId = allowChangeId; |
|
110 |
initializeUI(); |
|
111 |
} |
|
112 |
|
|
113 |
/** |
|
114 |
* Initialize UI components |
|
115 |
*/ |
|
116 |
private void initializeUI() { |
|
117 |
setLayout(new GridBagLayout()); |
|
118 |
|
|
119 |
// Create input widgets |
|
120 |
txtId = new JTextField(); |
|
121 |
txtId.setEditable(allowChangeId); |
|
122 |
txtName = new JTextField(); |
|
123 |
txtVersion = new JTextField(); |
|
124 |
txtDescription = new JTextArea(); |
|
125 |
JScrollPane scrDescription = new JScrollPane(txtDescription); |
|
126 |
|
|
127 |
// Add components |
|
128 |
addField("portable_view_id", txtId, false); |
|
129 |
addField("portable_view_name", txtName, false); |
|
130 |
addField("portable_view_version", txtVersion, false); |
|
131 |
addField("portable_view_description", scrDescription, true); |
|
132 |
} |
|
133 |
|
|
134 |
/** |
|
135 |
* Add field to form |
|
136 |
* |
|
137 |
* @param key |
|
138 |
* translation key for field name |
|
139 |
* @param component |
|
140 |
* file input component |
|
141 |
* @param large |
|
142 |
* if field is large |
|
143 |
*/ |
|
144 |
private void addField(String key, JComponent component, boolean large) { |
|
145 |
GridBagConstraints gbc = LABEL_CONSTRAINT; |
|
146 |
if (large) { |
|
147 |
gbc = LARGE_LABEL_CONSTRAINT; |
|
148 |
} |
|
149 |
add(new JLabel(swingManager.getTranslation(key)), gbc.clone()); |
|
150 |
gbc = FIELD_CONSTRAINT; |
|
151 |
if (large) { |
|
152 |
gbc = LARGE_FIELD_CONSTRAINT; |
|
153 |
} |
|
154 |
add(component, gbc.clone()); |
|
155 |
} |
|
156 |
|
|
157 |
/** {@inheridDoc} */ |
|
158 |
public String getPanelTitle() { |
|
159 |
return swingManager.getTranslation("portable_view_information"); |
|
160 |
} |
|
161 |
|
|
162 |
/** {@inheridDoc} */ |
|
163 |
public void nextPanel() throws NotContinueWizardException { |
|
164 |
if (StringUtils.isBlank(txtId.getText())) { |
|
165 |
throw new NotContinueWizardException( |
|
166 |
swingManager.getTranslation("missing_id_value"), txtId, true); |
|
167 |
} |
|
168 |
if (StringUtils.isBlank(txtName.getText())) { |
|
169 |
throw new NotContinueWizardException( |
|
170 |
swingManager.getTranslation("missing_name_value"), txtName, |
|
171 |
true); |
|
172 |
} |
|
173 |
if (StringUtils.isBlank(txtVersion.getText())) { |
|
174 |
txtVersion.setText("1"); |
|
175 |
} |
|
176 |
if (!StringUtils.isNumeric(txtVersion.getText())) { |
|
177 |
throw new NotContinueWizardException( |
|
178 |
swingManager.getTranslation("version_must_be_a_integer"), |
|
179 |
txtName, true); |
|
180 |
} |
|
181 |
PortableViewCompilationInformation info = compilation.getInformation(); |
|
182 |
if (allowChangeId) { |
|
183 |
info.setId(StringUtils.trim(txtId.getText())); |
|
184 |
} |
|
185 |
info.setName(StringUtils.trim(txtName.getText())); |
|
186 |
info.setVersion(Integer.parseInt(StringUtils.trim(txtVersion.getText()))); |
|
187 |
info.setDescription(StringUtils.trim(txtDescription.getText())); |
|
188 |
} |
|
189 |
|
|
190 |
/** {@inheridDoc} */ |
|
191 |
public void lastPanel() { |
|
192 |
// TODO Auto-generated method stub |
|
193 |
|
|
194 |
} |
|
195 |
|
|
196 |
/** {@inheridDoc} */ |
|
197 |
public void updatePanel() { |
|
198 |
PortableViewCompilationInformation info = compilation.getInformation(); |
|
199 |
txtId.setText(info.getId()); |
|
200 |
txtName.setText(info.getName()); |
|
201 |
txtVersion.setText(String.valueOf(info.getVersion())); |
|
202 |
txtDescription.setText(info.getDescription()); |
|
203 |
} |
|
204 |
|
|
205 |
/** {@inheridDoc} */ |
|
206 |
public JPanel getJPanel() { |
|
207 |
return this; |
|
208 |
} |
|
209 |
|
|
210 |
/** |
|
211 |
* Informs if all data of the panel is ok |
|
212 |
* |
|
213 |
* @return |
|
214 |
*/ |
|
215 |
public boolean isPanelDataOk() { |
|
216 |
try { |
|
217 |
nextPanel(); |
|
218 |
} catch (NotContinueWizardException ex) { |
|
219 |
return false; |
|
220 |
} |
|
221 |
return true; |
|
222 |
} |
|
223 |
|
|
224 |
public boolean isAllowChangeId() { |
|
225 |
return allowChangeId; |
|
226 |
} |
|
227 |
|
|
228 |
public void allowChangeId(boolean allow) { |
|
229 |
this.allowChangeId = allow; |
|
230 |
if (txtId != null) { |
|
231 |
txtId.setEnabled(allow); |
|
232 |
} |
|
233 |
|
|
234 |
} |
|
235 |
|
|
236 |
} |
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.102/org.gvsig.educa.portableview.swing/org.gvsig.educa.portableview.swing.impl/src/main/java/org/gvsig/educa/portableview/swing/impl/editor/addlayer/StoreParametersCellEditor.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.educa.portableview.swing.impl.editor.addlayer; |
|
23 |
|
|
24 |
import java.awt.Component; |
|
25 |
import java.awt.GridBagConstraints; |
|
26 |
import java.awt.GridBagLayout; |
|
27 |
import java.awt.Insets; |
|
28 |
import java.awt.event.ActionEvent; |
|
29 |
import java.awt.event.ActionListener; |
|
30 |
|
|
31 |
import javax.swing.AbstractCellEditor; |
|
32 |
import javax.swing.JButton; |
|
33 |
import javax.swing.JPanel; |
|
34 |
import javax.swing.JTable; |
|
35 |
import javax.swing.table.TableCellEditor; |
|
36 |
|
|
37 |
import org.gvsig.educa.portableview.swing.PortableViewSwingLocator; |
|
38 |
import org.gvsig.educa.portableview.swing.PortableViewSwingManager; |
|
39 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager.MODE; |
|
40 |
|
|
41 |
/** |
|
42 |
* <p> |
|
43 |
* Store Parameters Table cell editor for |
|
44 |
* {@link DefaultPortableViewAddLayerComponent} sources list |
|
45 |
* </p> |
|
46 |
* <p> |
|
47 |
* Shows store parameter description (delegates on |
|
48 |
* {@link StoreParametersCellRenderer}) and a button which shows a dialog ( |
|
49 |
* {@link StoreParametersEditor}) to modify the values. |
|
50 |
* </p> |
|
51 |
* |
|
52 |
* @author gvSIG Team |
|
53 |
* @version $Id$ |
|
54 |
* |
|
55 |
*/ |
|
56 |
public class StoreParametersCellEditor extends AbstractCellEditor implements |
|
57 |
ActionListener, TableCellEditor { |
|
58 |
|
|
59 |
/** |
|
60 |
* |
|
61 |
*/ |
|
62 |
private static final long serialVersionUID = -6112666198058347246L; |
|
63 |
|
|
64 |
private final PortableViewSwingManager swingManager; |
|
65 |
|
|
66 |
private final JPanel panel; |
|
67 |
private final StoreParametersCellRenderer renderer; |
|
68 |
private final JButton button; |
|
69 |
|
|
70 |
private final GridBagConstraints constrainLabel; |
|
71 |
private final GridBagConstraints constrainButton; |
|
72 |
|
|
73 |
/** |
|
74 |
* |
|
75 |
*/ |
|
76 |
public StoreParametersCellEditor() { |
|
77 |
swingManager = PortableViewSwingLocator.getSwingManager(); |
|
78 |
panel = new JPanel(new GridBagLayout()); |
|
79 |
renderer = new StoreParametersCellRenderer(); |
|
80 |
this.button = new JButton("..."); |
|
81 |
this.button.addActionListener(this); |
|
82 |
constrainLabel = new GridBagConstraints(); |
|
83 |
constrainLabel.gridx = 0; |
|
84 |
constrainLabel.gridy = 0; |
|
85 |
constrainLabel.fill = GridBagConstraints.BOTH; |
|
86 |
constrainLabel.weightx = 1; |
|
87 |
constrainLabel.weighty = 1; |
|
88 |
constrainLabel.ipadx = 0; |
|
89 |
constrainLabel.ipady = 0; |
|
90 |
constrainLabel.insets = new Insets(0, 0, 0, 0); |
|
91 |
|
|
92 |
constrainButton = new GridBagConstraints(); |
|
93 |
constrainButton.gridx = 1; |
|
94 |
constrainButton.gridy = 0; |
|
95 |
constrainButton.fill = GridBagConstraints.VERTICAL; |
|
96 |
constrainButton.weightx = 0; |
|
97 |
constrainButton.weighty = 1; |
|
98 |
constrainButton.insets = constrainLabel.insets; |
|
99 |
|
|
100 |
} |
|
101 |
|
|
102 |
public Object getCellEditorValue() { |
|
103 |
return renderer.getValue(); |
|
104 |
} |
|
105 |
|
|
106 |
public void actionPerformed(ActionEvent e) { |
|
107 |
Object source = e.getSource(); |
|
108 |
if (source == button) { |
|
109 |
showPropertiesPanel(renderer.getValue()); |
|
110 |
} |
|
111 |
|
|
112 |
} |
|
113 |
|
|
114 |
/** |
|
115 |
* @param value |
|
116 |
*/ |
|
117 |
private void showPropertiesPanel(Object value) { |
|
118 |
swingManager.getWindowManager().showWindow( |
|
119 |
new StoreParametersEditor(renderer.getValue()), |
|
120 |
swingManager.getTranslation("edit_source_properties"), MODE.DIALOG); |
|
121 |
|
|
122 |
} |
|
123 |
|
|
124 |
public Component getTableCellEditorComponent(JTable table, Object value, |
|
125 |
boolean isSelected, int row, int column) { |
|
126 |
panel.removeAll(); |
|
127 |
panel.add(renderer.getTableCellRendererComponent(table, value, |
|
128 |
isSelected, true, row, column), constrainLabel); |
|
129 |
panel.add(button, constrainButton); |
|
130 |
return panel; |
|
131 |
} |
|
132 |
|
|
133 |
} |
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.102/org.gvsig.educa.portableview.swing/org.gvsig.educa.portableview.swing.impl/src/main/java/org/gvsig/educa/portableview/swing/impl/editor/addlayer/StoreParametersCellRenderer.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.educa.portableview.swing.impl.editor.addlayer; |
|
23 |
|
|
24 |
import java.awt.Color; |
|
25 |
|
|
26 |
import javax.swing.table.DefaultTableCellRenderer; |
|
27 |
|
|
28 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
29 |
|
|
30 |
/** |
|
31 |
* <p> |
|
32 |
* Store Parameters Table cell renderer for |
|
33 |
* {@link DefaultPortableViewAddLayerComponent} sources list |
|
34 |
* </p> |
|
35 |
* <p> |
|
36 |
* Shows store parameter description. |
|
37 |
* </p> |
|
38 |
* |
|
39 |
* @author gvSIG Team |
|
40 |
* @version $Id$ |
|
41 |
* |
|
42 |
*/ |
|
43 |
public class StoreParametersCellRenderer extends DefaultTableCellRenderer { |
|
44 |
|
|
45 |
/** |
|
46 |
* |
|
47 |
*/ |
|
48 |
private static final long serialVersionUID = -2287544105907864898L; |
|
49 |
private DataStoreParameters value; |
|
50 |
|
|
51 |
public String format(DataStoreParameters storeParameters) { |
|
52 |
return String.format("[%1$6s] %2s", storeParameters.getDataStoreName(), |
|
53 |
storeParameters.getDescription()); |
|
54 |
} |
|
55 |
|
|
56 |
@Override |
|
57 |
protected void setValue(Object value) { |
|
58 |
this.value = (DataStoreParameters) value; |
|
59 |
if (this.value != null) { |
|
60 |
setText(format(this.value)); |
|
61 |
if (!this.value.isValid()) { |
|
62 |
setBackground(Color.red); |
|
63 |
setOpaque(true); |
|
64 |
} else { |
|
65 |
setOpaque(false); |
|
66 |
} |
|
67 |
|
|
68 |
} else { |
|
69 |
setText(""); |
|
70 |
} |
|
71 |
} |
|
72 |
|
|
73 |
/** |
|
74 |
* @return the value |
|
75 |
*/ |
|
76 |
public DataStoreParameters getValue() { |
|
77 |
return value; |
|
78 |
} |
|
79 |
|
|
80 |
} |
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.102/org.gvsig.educa.portableview.swing/org.gvsig.educa.portableview.swing.impl/src/main/java/org/gvsig/educa/portableview/swing/impl/editor/addlayer/StoreParametersEditor.java | ||
---|---|---|
1 |
/* gvSIG. Geographic Information System of the Valencian Government |
|
2 |
* |
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
|
4 |
* of the Valencian Government (CIT) |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
*/ |
|
22 |
package org.gvsig.educa.portableview.swing.impl.editor.addlayer; |
|
23 |
|
|
24 |
import java.awt.BorderLayout; |
|
25 |
import java.awt.event.ActionEvent; |
|
26 |
import java.awt.event.ActionListener; |
|
27 |
|
|
28 |
import javax.swing.Box; |
|
29 |
import javax.swing.BoxLayout; |
|
30 |
import javax.swing.JButton; |
|
31 |
import javax.swing.JPanel; |
|
32 |
|
|
33 |
import org.gvsig.educa.portableview.swing.PortableViewSwingLocator; |
|
34 |
import org.gvsig.educa.portableview.swing.PortableViewSwingManager; |
|
35 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
36 |
import org.gvsig.tools.dynform.DynFormLocator; |
|
37 |
import org.gvsig.tools.dynform.DynFormManager; |
|
38 |
import org.gvsig.tools.dynform.JDynForm; |
|
39 |
import org.gvsig.tools.exception.BaseException; |
|
40 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
41 |
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager; |
|
42 |
|
|
43 |
/** |
|
44 |
* <p> |
|
45 |
* Dialog to edit Data Store parameters (used by |
|
46 |
* {@link StoreParametersCellEditor}) |
|
47 |
* </p> |
|
48 |
* <p> |
|
49 |
* Uses {@link DynObjectSwingManager} to generate components |
|
50 |
* </p> |
|
51 |
* |
|
52 |
* @author gvSIG Team |
|
53 |
* @version $Id$ |
|
54 |
* |
|
55 |
*/ |
|
56 |
public class StoreParametersEditor extends JPanel implements ActionListener { |
|
57 |
|
|
58 |
/** |
|
59 |
* |
|
60 |
*/ |
|
61 |
private static final long serialVersionUID = -3044289357512879309L; |
|
62 |
|
|
63 |
private final PortableViewSwingManager swingManager; |
|
64 |
private final UsabilitySwingManager usabManager; |
|
65 |
|
|
66 |
private final DynFormManager dynSwingManager; |
|
67 |
private JDynForm propertyEditor; |
|
68 |
private DataStoreParameters parameters; |
|
69 |
|
|
70 |
private JButton botAccept; |
|
71 |
|
|
72 |
private JButton botCancel; |
|
73 |
|
|
74 |
/** |
|
75 |
* |
|
76 |
*/ |
|
77 |
public StoreParametersEditor(DataStoreParameters parameters) { |
|
78 |
super(); |
|
79 |
dynSwingManager = DynFormLocator.getDynFormManager(); |
|
80 |
swingManager = PortableViewSwingLocator.getSwingManager(); |
|
81 |
usabManager = ToolsSwingLocator.getUsabilitySwingManager(); |
|
82 |
|
|
83 |
// create property editor component |
|
84 |
this.parameters = parameters; |
|
85 |
propertyEditor = dynSwingManager.createJDynForm(parameters); |
|
86 |
setLayout(new BorderLayout(10, 10)); |
|
87 |
add(propertyEditor.asJComponent(), BorderLayout.CENTER); |
|
88 |
|
|
89 |
// Create panel for commands |
|
90 |
JPanel commandsPanel = new JPanel(); |
|
91 |
commandsPanel.setLayout(new BoxLayout(commandsPanel, BoxLayout.X_AXIS)); |
|
92 |
commandsPanel.add(Box.createHorizontalGlue()); |
|
93 |
botAccept = |
|
94 |
usabManager.createJButton(swingManager.getTranslation("accept")); |
|
95 |
botAccept.addActionListener(this); |
|
96 |
|
|
97 |
botCancel = |
|
98 |
usabManager.createJButton(swingManager.getTranslation("cancel")); |
|
99 |
botCancel.addActionListener(this); |
|
100 |
|
|
101 |
commandsPanel.add(botAccept); |
|
102 |
commandsPanel.add(Box.createHorizontalStrut(10)); |
|
103 |
commandsPanel.add(botCancel); |
|
104 |
commandsPanel.add(Box.createHorizontalStrut(5)); |
|
105 |
add(commandsPanel, BorderLayout.SOUTH); |
|
106 |
} |
|
107 |
|
|
108 |
public void actionPerformed(ActionEvent e) { |
|
109 |
Object source = e.getSource(); |
|
110 |
if (source == botCancel) { |
|
111 |
close(); |
|
112 |
return; |
|
113 |
} |
|
114 |
if (source == botAccept) { |
|
115 |
propertyEditor.getValues(parameters); |
|
116 |
// TODO validate... but before solve CRS problem |
|
117 |
close(); |
|
118 |
return; |
|
119 |
} |
|
120 |
} |
|
121 |
|
|
122 |
/** |
|
123 |
* close dialog |
|
124 |
*/ |
|
125 |
private void close() { |
|
126 |
setVisible(false); |
|
127 |
} |
|
128 |
} |
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.102/org.gvsig.educa.portableview.swing/org.gvsig.educa.portableview.swing.impl/src/main/java/org/gvsig/educa/portableview/swing/impl/editor/addlayer/DataStoreTableModel.java | ||
---|---|---|
1 |
package org.gvsig.educa.portableview.swing.impl.editor.addlayer; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import javax.swing.table.DefaultTableModel; |
|
6 |
|
|
7 |
import org.gvsig.educa.portableview.swing.PortableViewSwingLocator; |
|
8 |
import org.gvsig.educa.portableview.swing.PortableViewSwingManager; |
|
9 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
10 |
|
|
11 |
/** |
|
12 |
* <p> |
|
13 |
* Table model for list {@link DataStoreParameters} |
|
14 |
* </p> |
|
15 |
* |
|
16 |
* <p> |
|
17 |
* This stores parameters, selection and layer names |
|
18 |
* </p> |
|
19 |
* |
|
20 |
* @author gvSIG Team |
|
21 |
* @version $Id$ |
|
22 |
* |
|
23 |
*/ |
|
24 |
class DataStoreTableModel extends DefaultTableModel { |
|
25 |
|
|
26 |
/** |
|
27 |
* |
|
28 |
*/ |
|
29 |
private static final long serialVersionUID = -6742064202466924241L; |
|
30 |
|
|
31 |
private final PortableViewSwingManager swingManager; |
|
32 |
|
|
33 |
private List<DataStoreParameters> parameters; |
|
34 |
|
|
35 |
private boolean[] selecteds; |
|
36 |
private String[] names; |
|
37 |
|
|
38 |
/** |
|
39 |
* |
|
40 |
*/ |
|
41 |
public DataStoreTableModel() { |
|
42 |
swingManager = PortableViewSwingLocator.getSwingManager(); |
|
43 |
} |
|
44 |
|
|
45 |
/** |
|
46 |
* Sets store parameters to use |
|
47 |
* |
|
48 |
* @param storeParameters |
|
49 |
*/ |
|
50 |
public void setStoreParameters(List<DataStoreParameters> storeParameters) { |
|
51 |
this.parameters = storeParameters; |
|
52 |
this.selecteds = new boolean[storeParameters.size()]; |
|
53 |
this.names = new String[storeParameters.size()]; |
|
54 |
fireTableDataChanged(); |
|
55 |
} |
|
56 |
|
|
57 |
/** |
|
58 |
* Gets parameters of the row |
|
59 |
* |
|
60 |
* @param i |
|
61 |
* row |
|
62 |
* |
|
63 |
* @return |
|
64 |
*/ |
|
65 |
public DataStoreParameters getStoreParameters(int i) { |
|
66 |
return parameters.get(i); |
|
67 |
} |
|
68 |
|
|
69 |
/** |
|
70 |
* Gets selected name for StoreParameters |
|
71 |
* |
|
72 |
* @param i |
|
73 |
* row |
|
74 |
* @return |
|
75 |
*/ |
|
76 |
public String getName(int i) { |
|
77 |
return names[i]; |
|
78 |
} |
|
79 |
|
|
80 |
/** |
|
81 |
* Informs if StoreParameters is selected to add |
|
82 |
* |
|
83 |
* @param i |
|
84 |
* row |
|
85 |
* @return |
|
86 |
*/ |
|
87 |
public boolean isSelected(int i) { |
|
88 |
if (selecteds == null) { |
|
89 |
return false; |
|
90 |
} |
|
91 |
return selecteds[i]; |
|
92 |
} |
|
93 |
|
|
94 |
@Override |
|
95 |
public int getRowCount() { |
|
96 |
if (selecteds == null) { |
|
97 |
return 0; |
|
98 |
} |
|
99 |
return selecteds.length; |
|
100 |
} |
|
101 |
|
|
102 |
@Override |
|
103 |
public int getColumnCount() { |
|
104 |
return 3; |
|
105 |
} |
|
106 |
|
|
107 |
@Override |
|
108 |
public Class<?> getColumnClass(int columnIndex) { |
|
109 |
switch (columnIndex) { |
|
110 |
case 0: |
|
111 |
return Boolean.class; |
|
112 |
case 2: |
|
113 |
return DataStoreParameters.class; |
|
114 |
default: |
|
115 |
return String.class; |
|
116 |
} |
|
117 |
} |
|
118 |
|
|
119 |
@Override |
|
120 |
public String getColumnName(int column) { |
|
121 |
switch (column) { |
|
122 |
case 0: |
|
123 |
return swingManager.getTranslation("add"); |
|
124 |
case 1: |
|
125 |
return swingManager.getTranslation("name"); |
|
126 |
case 2: |
|
127 |
return swingManager.getTranslation("parameters"); |
|
128 |
default: |
|
129 |
return ""; |
|
130 |
|
|
131 |
} |
|
132 |
} |
|
133 |
|
|
134 |
/** |
|
135 |
* Cells editables: {selection} {parameters} and {name (if it's selected)} |
|
136 |
*/ |
|
137 |
@Override |
|
138 |
public boolean isCellEditable(int row, int column) { |
|
139 |
switch (column) { |
|
140 |
case 0: |
|
141 |
case 2: |
|
142 |
return true; |
|
143 |
case 1: |
|
144 |
// name is editable only if this layer is selected to add |
|
145 |
return selecteds[row]; |
|
146 |
|
|
147 |
default: |
|
148 |
return false; |
|
149 |
} |
|
150 |
} |
|
151 |
|
|
152 |
@Override |
|
153 |
public Object getValueAt(int row, int column) { |
|
154 |
switch (column) { |
|
155 |
case 0: |
|
156 |
return selecteds[row]; |
|
157 |
case 1: |
|
158 |
return names[row]; |
|
159 |
case 2: |
|
160 |
return parameters.get(row); |
|
161 |
|
|
162 |
default: |
|
163 |
throw new IllegalArgumentException(); |
|
164 |
} |
|
165 |
} |
|
166 |
|
|
167 |
@Override |
|
168 |
public void setValueAt(Object aValue, int row, int column) { |
|
169 |
switch (column) { |
|
170 |
case 0: |
|
171 |
selecteds[row] = (Boolean) aValue; |
|
172 |
break; |
|
173 |
case 1: |
|
174 |
names[row] = (String) aValue; |
Also available in: Unified diff