root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / legend / gui / ThemeManagerWindow.java @ 38608
History | View | Annotate | Download (8.99 KB)
1 |
/*
|
---|---|
2 |
*
|
3 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
4 |
*
|
5 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
6 |
*
|
7 |
* This program is free software; you can redistribute it and/or
|
8 |
* modify it under the terms of the GNU General Public License
|
9 |
* as published by the Free Software Foundation; either version 2
|
10 |
* of the License, or (at your option) any later version.
|
11 |
*
|
12 |
* This program is distributed in the hope that it will be useful,
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15 |
* GNU General Public License for more details.
|
16 |
*
|
17 |
* You should have received a copy of the GNU General Public License
|
18 |
* along with this program; if not, write to the Free Software
|
19 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
20 |
*
|
21 |
* For more information, contact:
|
22 |
*
|
23 |
* Generalitat Valenciana
|
24 |
* Conselleria d'Infraestructures i Transport
|
25 |
* Av. Blasco Ib??ez, 50
|
26 |
* 46010 VALENCIA
|
27 |
* SPAIN
|
28 |
*
|
29 |
* +34 963862235
|
30 |
* gvsig@gva.es
|
31 |
* www.gvsig.gva.es
|
32 |
*
|
33 |
* or
|
34 |
*
|
35 |
* IVER T.I. S.A
|
36 |
* Salamanca 50
|
37 |
* 46005 Valencia
|
38 |
* Spain
|
39 |
*
|
40 |
* +34 963163400
|
41 |
* dac@iver.es
|
42 |
*/
|
43 |
package org.gvsig.app.project.documents.view.legend.gui; |
44 |
|
45 |
import java.awt.BorderLayout; |
46 |
import java.awt.Dimension; |
47 |
import java.awt.FlowLayout; |
48 |
import java.awt.event.ActionEvent; |
49 |
import java.awt.event.ActionListener; |
50 |
import java.util.ArrayList; |
51 |
import java.util.Hashtable; |
52 |
|
53 |
import javax.swing.JOptionPane; |
54 |
import javax.swing.JPanel; |
55 |
import javax.swing.JTabbedPane; |
56 |
import javax.swing.event.ChangeListener; |
57 |
|
58 |
import org.gvsig.andami.PluginServices; |
59 |
import org.gvsig.andami.messages.NotificationManager; |
60 |
import org.gvsig.andami.ui.mdiFrame.MDIFrame; |
61 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
62 |
import org.gvsig.andami.ui.mdiManager.MDIManagerFactory; |
63 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
64 |
import org.gvsig.app.ApplicationLocator; |
65 |
import org.gvsig.app.ApplicationManager; |
66 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
67 |
import org.gvsig.fmap.mapcontext.layers.FLyrDefault; |
68 |
import org.gvsig.gui.beans.swing.JButton; |
69 |
import org.slf4j.Logger; |
70 |
import org.slf4j.LoggerFactory; |
71 |
|
72 |
|
73 |
/**
|
74 |
*
|
75 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
76 |
* @version 01-feb-2007
|
77 |
*/
|
78 |
public final class ThemeManagerWindow extends JPanel implements IWindow, ActionListener { |
79 |
private static final Logger logger = LoggerFactory.getLogger(ThemeManagerWindow.class); |
80 |
|
81 |
private static final long serialVersionUID = 4650656815369149211L; |
82 |
private static int selectedTabIndex = 0; |
83 |
private static ArrayList<Class<? extends AbstractThemeManagerPage>> pages = |
84 |
new ArrayList<Class<? extends AbstractThemeManagerPage>>(); |
85 |
private FLayer layer;
|
86 |
//private Legend legend; // Le asignaremos la leyenda del primer tema activo.
|
87 |
private JTabbedPane tabs = new JTabbedPane(); // @jve:decl-index=0: |
88 |
private JPanel panelButtons; |
89 |
private static Hashtable<Class<? extends AbstractThemeManagerPage>, ArrayList<Class<? extends FLyrDefault>>> s = |
90 |
new Hashtable<Class<? extends AbstractThemeManagerPage>, ArrayList<Class<? extends FLyrDefault>>>(); |
91 |
|
92 |
|
93 |
/**
|
94 |
* Sobrecarga del constructor. Este se utiliza cuando se llama a este
|
95 |
* di?logo desde la barra de comandos.
|
96 |
*
|
97 |
*/
|
98 |
public ThemeManagerWindow(FLayer l) {
|
99 |
this.layer = l;
|
100 |
|
101 |
// TODO falta definir leyenda para cualquier tipo de capa
|
102 |
// y decidir entonces qu? opciones soporta cada una para
|
103 |
// que el di?logo se autorrellene
|
104 |
initialize(); |
105 |
} |
106 |
|
107 |
private void initialize() { |
108 |
StringBuffer msgerr = new StringBuffer(); |
109 |
for (int i = 0; i < pages.size(); i++) { |
110 |
Class<? extends AbstractThemeManagerPage> pageClass = pages.get(i); |
111 |
AbstractThemeManagerPage tab = null;
|
112 |
try {
|
113 |
tab = pageClass.newInstance(); |
114 |
} catch (Exception e) { |
115 |
msgerr.append(translate("_Cant_add_property_page_related_to_{0}", pageClass.getName()))
|
116 |
.append("\n");
|
117 |
logger.info("Can't instance propety page from class "+pageClass.getName(),e);
|
118 |
continue;
|
119 |
} |
120 |
if (tab!=null){ |
121 |
if (s.get(tab.getClass()).contains(layer.getClass())){
|
122 |
String tabName = null; |
123 |
try {
|
124 |
tab.setModel(layer); |
125 |
tabName = tab.getName(); |
126 |
} catch( Throwable ex) { |
127 |
msgerr.append(translate("_Cant_initialice_property_page_{0}", tabName))
|
128 |
.append("\n");
|
129 |
logger.info("Can't set model of property page '"+tabName+"' from class '"+pageClass.getName()+"'."); |
130 |
} |
131 |
tabs.addTab(tabName, tab); |
132 |
} |
133 |
} |
134 |
} |
135 |
|
136 |
if (tabs.getComponentCount()>selectedTabIndex) {
|
137 |
tabs.setSelectedIndex(selectedTabIndex); |
138 |
} |
139 |
tabs.setPreferredSize(new java.awt.Dimension(640,390)); |
140 |
|
141 |
|
142 |
setLayout(new BorderLayout()); |
143 |
add(tabs, java.awt.BorderLayout.CENTER); |
144 |
|
145 |
// The listener must be added after the tabs are added to the window
|
146 |
tabs.addChangeListener(new ChangeListener() { |
147 |
public void stateChanged(javax.swing.event.ChangeEvent e) { |
148 |
//remember the visible tab
|
149 |
selectedTabIndex = tabs.getSelectedIndex(); |
150 |
if (selectedTabIndex<0) { |
151 |
selectedTabIndex = 0;
|
152 |
} |
153 |
}; |
154 |
}); |
155 |
add(getPanelButtons(), java.awt.BorderLayout.SOUTH); |
156 |
setSize(new Dimension(780, 540)); |
157 |
if( msgerr.length()>0 ) { |
158 |
PluginServices.getMainFrame().messageDialog(msgerr.toString(), "_Warning", JOptionPane.WARNING_MESSAGE); |
159 |
} |
160 |
} |
161 |
|
162 |
private String translate(String msg, String arg1) { |
163 |
String[] args = null; |
164 |
String translation = null; |
165 |
if (msg == null) { |
166 |
return ""; |
167 |
} |
168 |
if( arg1 != null ) { |
169 |
args = new String[] { arg1 }; |
170 |
} |
171 |
translation = org.gvsig.i18n.Messages.getText(msg, args); |
172 |
if (translation == null) { |
173 |
return "_"+msg.replace("_", " "); |
174 |
} |
175 |
return translation;
|
176 |
} |
177 |
|
178 |
private JPanel getPanelButtons() { |
179 |
if (panelButtons == null) { |
180 |
panelButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5,5)); |
181 |
|
182 |
JButton btnAceptar = new JButton(PluginServices.getText(this,"Aceptar")); |
183 |
btnAceptar.setActionCommand("OK");
|
184 |
btnAceptar.addActionListener(this);
|
185 |
|
186 |
JButton btnApply = new JButton(PluginServices.getText(this,"Apply")); |
187 |
btnApply.setActionCommand("APPLY");
|
188 |
btnApply.addActionListener(this);
|
189 |
|
190 |
|
191 |
JButton btnCancelar = new JButton(PluginServices.getText(this,"Cerrar")); |
192 |
btnCancelar.setActionCommand("CANCEL");
|
193 |
btnCancelar.addActionListener(this);
|
194 |
panelButtons.setPreferredSize(new java.awt.Dimension(493,33)); |
195 |
panelButtons.add(btnCancelar); |
196 |
panelButtons.add(btnApply); |
197 |
panelButtons.add(btnAceptar); |
198 |
} |
199 |
return panelButtons;
|
200 |
} |
201 |
|
202 |
public void actionPerformed(ActionEvent e) { |
203 |
if (e.getActionCommand() == "OK") { |
204 |
/* Causes all the tabs in the ThemeManagerWindow to perform THEIR apply-action
|
205 |
* then fires the LegendChanged event that causes the view to be refreshed.
|
206 |
* After that, it closes the window.
|
207 |
*/
|
208 |
actionPerformed(new ActionEvent(e.getSource(), e.getID(), "APPLY")); |
209 |
|
210 |
close(); |
211 |
} else if (e.getActionCommand() == "CANCEL") { |
212 |
/* Causes all the tabs in the ThemeManagerWindow to perform THEIR cancel-action
|
213 |
* then closes the window.
|
214 |
*/
|
215 |
for (int i = 0; i < tabs.getTabCount(); i++) { |
216 |
AbstractThemeManagerPage tab = (AbstractThemeManagerPage) tabs.getComponentAt(i); |
217 |
tab.cancelAction(); |
218 |
} |
219 |
close(); |
220 |
} else if (e.getActionCommand() == "APPLY") { |
221 |
/* Causes the current visible tab in the ThemeManagerWindow to perform
|
222 |
* ITS specific apply-action.
|
223 |
*/
|
224 |
for (int i = 0; i < tabs.getTabCount(); i++) { |
225 |
AbstractThemeManagerPage tab = (AbstractThemeManagerPage) tabs.getComponentAt(i); |
226 |
tab.applyAction(); |
227 |
} |
228 |
layer.getMapContext().callLegendChanged(); |
229 |
} else {}
|
230 |
// Lots of temporary objects were create.
|
231 |
// let's try some memory cleanup
|
232 |
System.gc();
|
233 |
} |
234 |
|
235 |
private void close() { |
236 |
PluginServices.getMDIManager().closeWindow(ThemeManagerWindow.this); |
237 |
} |
238 |
|
239 |
public WindowInfo getWindowInfo() {
|
240 |
WindowInfo viewInfo = new WindowInfo(WindowInfo.MODELESSDIALOG|WindowInfo.RESIZABLE);
|
241 |
viewInfo.setWidth(getWidth()); |
242 |
viewInfo.setHeight(getHeight()); |
243 |
viewInfo.setTitle(PluginServices.getText(this,"propiedades_de_la_capa")); |
244 |
return viewInfo;
|
245 |
} |
246 |
|
247 |
public static void addPage(Class<? extends AbstractThemeManagerPage> abstractThemeManagerPageClass) { |
248 |
pages.add(abstractThemeManagerPageClass); |
249 |
} |
250 |
|
251 |
public static void setTabEnabledForLayer(Class<? extends AbstractThemeManagerPage> abstractThemeManagerPageClass, Class<? extends FLyrDefault> fLayerClazz, boolean enabled) { |
252 |
ArrayList<Class<? extends FLyrDefault>> enabledLayers; |
253 |
if (enabled == true) { |
254 |
if (!s.containsKey(abstractThemeManagerPageClass)) {
|
255 |
enabledLayers = new ArrayList<Class<? extends FLyrDefault>> (); |
256 |
enabledLayers.add(fLayerClazz); |
257 |
s.put(abstractThemeManagerPageClass, enabledLayers); |
258 |
} else {
|
259 |
enabledLayers = s.get(abstractThemeManagerPageClass); |
260 |
enabledLayers.add(fLayerClazz); |
261 |
} |
262 |
} else {
|
263 |
if (!s.containsKey(abstractThemeManagerPageClass)) {
|
264 |
return;
|
265 |
} |
266 |
enabledLayers = s.get(abstractThemeManagerPageClass); |
267 |
enabledLayers.remove(fLayerClazz); |
268 |
} |
269 |
}; |
270 |
public Object getWindowProfile() { |
271 |
return WindowInfo.TOOL_PROFILE;
|
272 |
}; |
273 |
} // @jve:decl-index=0:visual-constraint="10,10"
|