root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / panels / StopEditingPanel.java @ 30099
History | View | Annotate | Download (8.41 KB)
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 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2009 {Iver T.I.} {Task}
|
26 |
*/
|
27 |
|
28 |
package com.iver.cit.gvsig.gui.cad.panels; |
29 |
|
30 |
import java.awt.event.ActionEvent; |
31 |
import java.awt.event.ActionListener; |
32 |
import java.util.HashMap; |
33 |
import java.util.Iterator; |
34 |
|
35 |
import javax.swing.ButtonGroup; |
36 |
import javax.swing.JPanel; |
37 |
import javax.swing.JRadioButton; |
38 |
import javax.swing.JScrollPane; |
39 |
import javax.swing.JTextArea; |
40 |
|
41 |
import org.gvsig.gui.beans.swing.JButton; |
42 |
|
43 |
import com.iver.andami.PluginServices; |
44 |
import com.iver.andami.messages.NotificationManager; |
45 |
import com.iver.andami.plugins.IExtension; |
46 |
import com.iver.andami.ui.mdiManager.IWindow; |
47 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
48 |
import com.iver.cit.gvsig.CADExtension; |
49 |
import com.iver.cit.gvsig.StopEditing; |
50 |
import com.iver.cit.gvsig.exceptions.layers.CancelEditingLayerException; |
51 |
import com.iver.cit.gvsig.exceptions.table.CancelEditingTableException; |
52 |
import com.iver.cit.gvsig.fmap.MapControl; |
53 |
import com.iver.cit.gvsig.fmap.drivers.shp.IndexedShpDriver; |
54 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
55 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
56 |
import com.iver.cit.gvsig.fmap.rendering.IVectorLegend; |
57 |
import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
58 |
import com.iver.utiles.swing.JComboBox; |
59 |
|
60 |
/**
|
61 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
62 |
*/
|
63 |
public class StopEditingPanel extends JPanel implements ActionListener, IWindow{ |
64 |
private JPanel buttonsPanel; |
65 |
private JButton acceptButton; |
66 |
private JButton closeButton; |
67 |
private JComboBox formatCombo; |
68 |
private JRadioButton closeRButton; |
69 |
private JRadioButton exportRButton; |
70 |
private JTextArea massageTextArea; |
71 |
private JScrollPane messageScrollPanel; |
72 |
private JPanel optionsPanel; |
73 |
private JPanel topPanel; |
74 |
private ButtonGroup buttonGroup = null; |
75 |
private WindowInfo windowInfo = null; |
76 |
private StopEditing stopEditing = null; |
77 |
private FLyrVect layer = null; |
78 |
private MapControl mapControl = null; |
79 |
|
80 |
public StopEditingPanel(StopEditing stopEditing, FLyrVect layer,
|
81 |
MapControl mapControl) { |
82 |
super();
|
83 |
initComponents(); |
84 |
initLabels(); |
85 |
initCombos(); |
86 |
initListeners(); |
87 |
this.stopEditing = stopEditing;
|
88 |
this.layer = layer;
|
89 |
this.mapControl = mapControl;
|
90 |
} |
91 |
|
92 |
private void initListeners() { |
93 |
acceptButton.addActionListener(this);
|
94 |
acceptButton.setActionCommand("a");
|
95 |
closeButton.addActionListener(this);
|
96 |
closeButton.setActionCommand("c");
|
97 |
} |
98 |
|
99 |
private void initLabels() { |
100 |
closeButton.setText(PluginServices.getText(this, "close")); |
101 |
acceptButton.setText(PluginServices.getText(this, "accept")); |
102 |
massageTextArea.setText(PluginServices.getText(this, "stop_editing_message")); |
103 |
exportRButton.setText(PluginServices.getText(this, "export_to")); |
104 |
closeRButton.setText(PluginServices.getText(this, "stop_editing_close")); |
105 |
} |
106 |
|
107 |
private void initCombos(){ |
108 |
HashMap<String, Class> formats = StopEditing.getSupportedFormats(); |
109 |
Iterator<String> it = formats.keySet().iterator(); |
110 |
while (it.hasNext()){
|
111 |
formatCombo.addItem(it.next()); |
112 |
} |
113 |
} |
114 |
|
115 |
private void initComponents() { |
116 |
java.awt.GridBagConstraints gridBagConstraints; |
117 |
|
118 |
buttonsPanel = new JPanel(); |
119 |
closeButton = new JButton(); |
120 |
acceptButton = new JButton(); |
121 |
topPanel = new JPanel(); |
122 |
messageScrollPanel = new JScrollPane(); |
123 |
massageTextArea = new JTextArea(); |
124 |
optionsPanel = new JPanel(); |
125 |
closeRButton = new JRadioButton(); |
126 |
exportRButton = new JRadioButton(); |
127 |
formatCombo = new JComboBox(); |
128 |
buttonGroup = new ButtonGroup(); |
129 |
|
130 |
setLayout(new java.awt.BorderLayout());
|
131 |
|
132 |
buttonsPanel.setLayout(new java.awt.GridBagLayout());
|
133 |
|
134 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
135 |
gridBagConstraints.insets = new java.awt.Insets(2, 2, 5, 2); |
136 |
buttonsPanel.add(closeButton, gridBagConstraints); |
137 |
|
138 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
139 |
gridBagConstraints.insets = new java.awt.Insets(2, 2, 5, 2); |
140 |
buttonsPanel.add(acceptButton, gridBagConstraints); |
141 |
|
142 |
buttonGroup.add(closeRButton); |
143 |
buttonGroup.add(exportRButton); |
144 |
closeRButton.setSelected(true);
|
145 |
|
146 |
add(buttonsPanel, java.awt.BorderLayout.SOUTH); |
147 |
|
148 |
topPanel.setLayout(new java.awt.GridBagLayout());
|
149 |
|
150 |
messageScrollPanel.setBorder(null);
|
151 |
|
152 |
massageTextArea.setColumns(20);
|
153 |
massageTextArea.setEditable(false);
|
154 |
massageTextArea.setLineWrap(true);
|
155 |
massageTextArea.setRows(4);
|
156 |
massageTextArea.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); |
157 |
messageScrollPanel.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); |
158 |
messageScrollPanel.setViewportView(massageTextArea); |
159 |
|
160 |
|
161 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
162 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
163 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; |
164 |
gridBagConstraints.weightx = 1.0;
|
165 |
topPanel.add(messageScrollPanel, gridBagConstraints); |
166 |
|
167 |
optionsPanel.setLayout(new java.awt.GridBagLayout());
|
168 |
|
169 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
170 |
gridBagConstraints.gridwidth = 2;
|
171 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
172 |
optionsPanel.add(closeRButton, gridBagConstraints); |
173 |
|
174 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
175 |
gridBagConstraints.gridx = 0;
|
176 |
gridBagConstraints.gridy = 1;
|
177 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
178 |
optionsPanel.add(exportRButton, gridBagConstraints); |
179 |
|
180 |
formatCombo.setModel(new javax.swing.DefaultComboBoxModel());
|
181 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
182 |
gridBagConstraints.gridx = 1;
|
183 |
gridBagConstraints.gridy = 1;
|
184 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
185 |
optionsPanel.add(formatCombo, gridBagConstraints); |
186 |
|
187 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
188 |
gridBagConstraints.gridx = 0;
|
189 |
gridBagConstraints.gridy = 1;
|
190 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
191 |
gridBagConstraints.weightx = 1.0;
|
192 |
topPanel.add(optionsPanel, gridBagConstraints); |
193 |
|
194 |
add(topPanel, java.awt.BorderLayout.PAGE_START); |
195 |
} |
196 |
|
197 |
public void actionPerformed(ActionEvent e) { |
198 |
if (e.getActionCommand().equals("a")){ |
199 |
try {
|
200 |
acceptButtonActionPerformed(); |
201 |
} catch (Exception e1) { |
202 |
NotificationManager.addError(e1); |
203 |
} |
204 |
}else if (e.getActionCommand().equals("c")){ |
205 |
closeButtonActionPerformed(); |
206 |
} |
207 |
} |
208 |
|
209 |
private void closeButtonActionPerformed() { |
210 |
PluginServices.getMDIManager().closeWindow(this);
|
211 |
} |
212 |
|
213 |
private void acceptButtonActionPerformed() throws Exception { |
214 |
if (closeRButton.isSelected()){
|
215 |
stopEditing(); |
216 |
closeButtonActionPerformed(); |
217 |
}else if (exportRButton.isSelected()){ |
218 |
Object obj = formatCombo.getSelectedItem();
|
219 |
if (obj != null){ |
220 |
Class extensionClass = StopEditing.getSupportedFormats().get(obj);
|
221 |
IExtension extension = PluginServices.getExtension(extensionClass); |
222 |
if (extension != null){ |
223 |
closeButtonActionPerformed(); |
224 |
extension.execute((String)obj);
|
225 |
stopEditing(); |
226 |
} |
227 |
} |
228 |
} |
229 |
} |
230 |
|
231 |
public void stopEditing() throws Exception { |
232 |
stopEditing.cancelEdition(layer); |
233 |
VectorialEditableAdapter vea = (VectorialEditableAdapter) layer |
234 |
.getSource(); |
235 |
vea.getCommandRecord().removeCommandListener(mapControl); |
236 |
if (!(layer.getSource().getDriver() instanceof IndexedShpDriver)){ |
237 |
VectorialLayerEdited vle=(VectorialLayerEdited)CADExtension.getEditionManager().getLayerEdited(layer); |
238 |
layer.setLegend((IVectorLegend)vle.getLegend()); |
239 |
} |
240 |
layer.setEditing(false);
|
241 |
} |
242 |
|
243 |
public WindowInfo getWindowInfo() {
|
244 |
if (windowInfo == null){ |
245 |
windowInfo = new WindowInfo(WindowInfo.DIALOG_PROFILE);
|
246 |
windowInfo.setWidth(400);
|
247 |
windowInfo.setHeight(150);
|
248 |
} |
249 |
return windowInfo;
|
250 |
} |
251 |
|
252 |
public Object getWindowProfile() { |
253 |
return WindowInfo.DIALOG_PROFILE;
|
254 |
} |
255 |
} |
256 |
|