gvsig-vectorediting / org.gvsig.vectorediting / trunk / org.gvsig.vectorediting / org.gvsig.vectorediting.swing / org.gvsig.vectorediting.swing.impl / src / main / java / org / gvsig / vectorediting / swing / impl / DefaultEditingSwingManager.java @ 89
History | View | Annotate | Download (5.31 KB)
1 |
/*
|
---|---|
2 |
* Copyright 2014 DiSiD Technologies S.L.L. All rights reserved.
|
3 |
*
|
4 |
* Project : DiSiD org.gvsig.vectorediting.swing.impl
|
5 |
* SVN Id : $Id$
|
6 |
*/
|
7 |
package org.gvsig.vectorediting.swing.impl; |
8 |
|
9 |
import java.awt.BorderLayout; |
10 |
import java.awt.Component; |
11 |
import java.awt.Font; |
12 |
import java.awt.GridBagConstraints; |
13 |
import java.awt.GridBagLayout; |
14 |
import java.awt.Insets; |
15 |
import java.util.HashMap; |
16 |
import java.util.Map; |
17 |
|
18 |
import javax.swing.JLabel; |
19 |
import javax.swing.JOptionPane; |
20 |
import javax.swing.JPanel; |
21 |
|
22 |
import org.gvsig.fmap.mapcontrol.MapControl; |
23 |
import org.gvsig.tools.ToolsLocator; |
24 |
import org.gvsig.tools.dynobject.DynObject; |
25 |
import org.gvsig.tools.i18n.I18nManager; |
26 |
import org.gvsig.tools.service.AbstractManager; |
27 |
import org.gvsig.tools.service.Service; |
28 |
import org.gvsig.tools.service.ServiceException; |
29 |
import org.gvsig.vectorediting.lib.impl.DefaultEditingProviderManager; |
30 |
import org.gvsig.vectorediting.swing.api.EditingContext; |
31 |
import org.gvsig.vectorediting.swing.api.EditingSwingManager; |
32 |
|
33 |
public class DefaultEditingSwingManager extends AbstractManager implements |
34 |
EditingSwingManager { |
35 |
|
36 |
private I18nManager i18nManager = ToolsLocator.getI18nManager();
|
37 |
|
38 |
Map<MapControl, EditingContext> editingContexts = new HashMap<MapControl, EditingContext>(); |
39 |
|
40 |
public DefaultEditingSwingManager() {
|
41 |
super(new DefaultEditingProviderManager()); |
42 |
} |
43 |
|
44 |
public EditingContext getEditingContext(MapControl mapControl) {
|
45 |
if(editingContexts.containsKey(mapControl)){
|
46 |
return editingContexts.get(mapControl);
|
47 |
} else{
|
48 |
EditingContext editingContext = new DefaultEditingContext(mapControl);
|
49 |
editingContexts.put(mapControl, editingContext); |
50 |
return editingContext;
|
51 |
} |
52 |
} |
53 |
|
54 |
private JPanel getExplanationPanel(String question, String action, |
55 |
String description) {
|
56 |
JPanel resp = new JPanel(new BorderLayout(10, 10)); |
57 |
|
58 |
JLabel topLabel = new JLabel(question); |
59 |
|
60 |
JPanel mainPanel = new JPanel(new GridBagLayout()); |
61 |
GridBagConstraints cc = new GridBagConstraints(); |
62 |
|
63 |
cc.gridx = 0;
|
64 |
cc.gridy = 0;
|
65 |
cc.anchor = GridBagConstraints.WEST;
|
66 |
|
67 |
cc.insets = new Insets(3, 6, 3, 6); |
68 |
|
69 |
Font boldf = mainPanel.getFont().deriveFont(Font.BOLD); |
70 |
|
71 |
JLabel lbl = new JLabel(action); |
72 |
lbl.setFont(boldf); |
73 |
mainPanel.add(lbl, cc); |
74 |
cc.gridx = 1;
|
75 |
mainPanel.add(new JLabel(description), cc); |
76 |
|
77 |
cc.gridx = 0;
|
78 |
cc.gridy = 1;
|
79 |
lbl = new JLabel(i18nManager.getTranslation("discard")); |
80 |
lbl.setFont(boldf); |
81 |
mainPanel.add(lbl, cc); |
82 |
cc.gridx = 1;
|
83 |
mainPanel |
84 |
.add( |
85 |
new JLabel(i18nManager.getTranslation("discard_and_loose_changes")), |
86 |
cc); |
87 |
|
88 |
cc.gridx = 0;
|
89 |
cc.gridy = 2;
|
90 |
lbl = new JLabel(i18nManager.getTranslation("continue")); |
91 |
lbl.setFont(boldf); |
92 |
mainPanel.add(lbl, cc); |
93 |
cc.gridx = 1;
|
94 |
mainPanel.add( |
95 |
new JLabel(i18nManager |
96 |
.getTranslation("do_not_save_yet_stay_in_editing_mode")), cc);
|
97 |
|
98 |
resp.add(mainPanel, BorderLayout.CENTER);
|
99 |
resp.add(topLabel, BorderLayout.NORTH);
|
100 |
return resp;
|
101 |
} |
102 |
|
103 |
public Service getService(DynObject parameters) throws ServiceException { |
104 |
return null; |
105 |
} |
106 |
|
107 |
public int showPanelExportOrDiscard(MapControl parent, String name) { |
108 |
Object[] options = { i18nManager.getTranslation("export"), |
109 |
" " + i18nManager.getTranslation("discard") + " ", |
110 |
i18nManager.getTranslation("continue") };
|
111 |
|
112 |
String question = i18nManager
|
113 |
.getTranslation("no_existe_writer_para_este_formato_de_capa_o_no_tiene_permisos_de_escritura_los_datos_que_desea_hacer");
|
114 |
String firstLabel = i18nManager.getTranslation("export"); |
115 |
String firstDesc = i18nManager.getTranslation("export_to_another_format"); |
116 |
|
117 |
JPanel explanation_panel = getExplanationPanel(question, firstLabel,
|
118 |
firstDesc); |
119 |
|
120 |
int resp = JOptionPane.showOptionDialog( |
121 |
(Component) parent, explanation_panel,
|
122 |
i18nManager.getTranslation("stop_edition"),
|
123 |
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, |
124 |
options, options[2]);
|
125 |
|
126 |
if (resp == JOptionPane.NO_OPTION) { |
127 |
return EditingContext.DISCARD_CHANGES;
|
128 |
} |
129 |
else if (resp == JOptionPane.YES_OPTION) { |
130 |
return EditingContext.EXPORT_LAYER;
|
131 |
} |
132 |
return EditingContext.CANCEL;
|
133 |
} |
134 |
|
135 |
public int showPanelSaveOrDiscard(MapControl parent, String name) { |
136 |
Object[] options = { i18nManager.getTranslation("_Guardar"), |
137 |
" " + i18nManager.getTranslation("_Descartar") + " ", |
138 |
i18nManager.getTranslation("_Continuar") };
|
139 |
|
140 |
String question = i18nManager
|
141 |
.getTranslation("realmente_desea_guardar_la_capa");
|
142 |
question = question + " '" + name + "'?"; |
143 |
String firstLabel = i18nManager.getTranslation("guardar"); |
144 |
String firstDesc = i18nManager.getTranslation("save_changes_performed"); |
145 |
JPanel explanation_panel = getExplanationPanel(question, firstLabel,
|
146 |
firstDesc); |
147 |
|
148 |
int resp = JOptionPane.showOptionDialog( |
149 |
(Component) parent, explanation_panel,
|
150 |
i18nManager.getTranslation("stop_edition"),
|
151 |
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, |
152 |
options, options[2]);
|
153 |
|
154 |
if (resp == JOptionPane.YES_OPTION) { |
155 |
return EditingContext.SAVE_CHANGES;
|
156 |
} |
157 |
else if (resp == JOptionPane.NO_OPTION) { |
158 |
return EditingContext.DISCARD_CHANGES;
|
159 |
} |
160 |
return EditingContext.CANCEL;
|
161 |
} |
162 |
} |