svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / legend / gui / ThemeManagerWindow.java @ 41255
History | View | Annotate | Download (8.73 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.app.project.documents.view.legend.gui; |
25 |
|
26 |
import java.awt.BorderLayout; |
27 |
import java.awt.Dimension; |
28 |
import java.awt.FlowLayout; |
29 |
import java.awt.event.ActionEvent; |
30 |
import java.awt.event.ActionListener; |
31 |
import java.util.ArrayList; |
32 |
import java.util.Hashtable; |
33 |
|
34 |
import javax.swing.JOptionPane; |
35 |
import javax.swing.JPanel; |
36 |
import javax.swing.JTabbedPane; |
37 |
import javax.swing.event.ChangeListener; |
38 |
|
39 |
import org.gvsig.andami.PluginServices; |
40 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
41 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
42 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
43 |
import org.gvsig.gui.beans.swing.JButton; |
44 |
import org.slf4j.Logger; |
45 |
import org.slf4j.LoggerFactory; |
46 |
|
47 |
|
48 |
/**
|
49 |
*
|
50 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
51 |
* @version 01-feb-2007
|
52 |
*/
|
53 |
public final class ThemeManagerWindow extends JPanel implements IWindow, ActionListener { |
54 |
private static final Logger logger = LoggerFactory.getLogger(ThemeManagerWindow.class); |
55 |
|
56 |
private static final long serialVersionUID = 4650656815369149211L; |
57 |
private static int selectedTabIndex = 0; |
58 |
private static ArrayList<Class<? extends AbstractThemeManagerPage>> pages = |
59 |
new ArrayList<Class<? extends AbstractThemeManagerPage>>(); |
60 |
private FLayer layer;
|
61 |
//private Legend legend; // Le asignaremos la leyenda del primer tema activo.
|
62 |
private JTabbedPane tabs = new JTabbedPane(); // @jve:decl-index=0: |
63 |
private JPanel panelButtons; |
64 |
private static Hashtable<Class<? extends AbstractThemeManagerPage>, ArrayList<Class<? extends FLayer>>> s = |
65 |
new Hashtable<Class<? extends AbstractThemeManagerPage>, ArrayList<Class<? extends FLayer>>>(); |
66 |
|
67 |
|
68 |
/**
|
69 |
* Sobrecarga del constructor. Este se utiliza cuando se llama a este
|
70 |
* di?logo desde la barra de comandos.
|
71 |
*
|
72 |
*/
|
73 |
public ThemeManagerWindow(FLayer l) {
|
74 |
this.layer = l;
|
75 |
|
76 |
// TODO falta definir leyenda para cualquier tipo de capa
|
77 |
// y decidir entonces qu? opciones soporta cada una para
|
78 |
// que el di?logo se autorrellene
|
79 |
initialize(); |
80 |
} |
81 |
|
82 |
private void initialize() { |
83 |
StringBuffer msgerr = new StringBuffer(); |
84 |
for (int i = 0; i < pages.size(); i++) { |
85 |
Class<? extends AbstractThemeManagerPage> pageClass = pages.get(i); |
86 |
AbstractThemeManagerPage tab = null;
|
87 |
try {
|
88 |
tab = pageClass.newInstance(); |
89 |
} catch (Exception e) { |
90 |
msgerr.append(translate("_Cant_add_property_page_related_to_{0}", pageClass.getName()))
|
91 |
.append("\n");
|
92 |
logger.info("Can't instance propety page from class "+pageClass.getName(),e);
|
93 |
continue;
|
94 |
} |
95 |
if (tab!=null){ |
96 |
if( tab.isTabEnabledForLayer(layer) ) {
|
97 |
String tabName = null; |
98 |
try {
|
99 |
tab.setModel(layer); |
100 |
tabName = tab.getName(); |
101 |
} catch( Throwable ex) { |
102 |
msgerr.append(translate("_Cant_initialice_property_page_{0}", tabName))
|
103 |
.append("\n");
|
104 |
logger.info("Can't set model of property page '"+tabName+"' from class '"+pageClass.getName()+"'."); |
105 |
} |
106 |
tabs.addTab(tabName, tab); |
107 |
} |
108 |
} |
109 |
} |
110 |
|
111 |
if (tabs.getComponentCount()>selectedTabIndex) {
|
112 |
tabs.setSelectedIndex(selectedTabIndex); |
113 |
} |
114 |
tabs.setPreferredSize(new java.awt.Dimension(640,390)); |
115 |
|
116 |
|
117 |
setLayout(new BorderLayout()); |
118 |
add(tabs, java.awt.BorderLayout.CENTER); |
119 |
|
120 |
// The listener must be added after the tabs are added to the window
|
121 |
tabs.addChangeListener(new ChangeListener() { |
122 |
public void stateChanged(javax.swing.event.ChangeEvent e) { |
123 |
//remember the visible tab
|
124 |
selectedTabIndex = tabs.getSelectedIndex(); |
125 |
if (selectedTabIndex<0) { |
126 |
selectedTabIndex = 0;
|
127 |
} |
128 |
}; |
129 |
}); |
130 |
add(getPanelButtons(), java.awt.BorderLayout.SOUTH); |
131 |
setSize(new Dimension(780, 540)); |
132 |
if( msgerr.length()>0 ) { |
133 |
PluginServices.getMainFrame().messageDialog(msgerr.toString(), "_Warning", JOptionPane.WARNING_MESSAGE); |
134 |
} |
135 |
} |
136 |
|
137 |
private String translate(String msg, String arg1) { |
138 |
String[] args = null; |
139 |
String translation = null; |
140 |
if (msg == null) { |
141 |
return ""; |
142 |
} |
143 |
if( arg1 != null ) { |
144 |
args = new String[] { arg1 }; |
145 |
} |
146 |
translation = org.gvsig.i18n.Messages.getText(msg, args); |
147 |
if (translation == null) { |
148 |
return "_"+msg.replace("_", " "); |
149 |
} |
150 |
return translation;
|
151 |
} |
152 |
|
153 |
private JPanel getPanelButtons() { |
154 |
if (panelButtons == null) { |
155 |
panelButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5,5)); |
156 |
|
157 |
JButton btnAceptar = new JButton(PluginServices.getText(this,"Aceptar")); |
158 |
btnAceptar.setActionCommand("OK");
|
159 |
btnAceptar.addActionListener(this);
|
160 |
|
161 |
JButton btnApply = new JButton(PluginServices.getText(this,"Apply")); |
162 |
btnApply.setActionCommand("APPLY");
|
163 |
btnApply.addActionListener(this);
|
164 |
|
165 |
|
166 |
JButton btnCancelar = new JButton(PluginServices.getText(this,"Cerrar")); |
167 |
btnCancelar.setActionCommand("CANCEL");
|
168 |
btnCancelar.addActionListener(this);
|
169 |
panelButtons.setPreferredSize(new java.awt.Dimension(493,33)); |
170 |
panelButtons.add(btnCancelar); |
171 |
panelButtons.add(btnApply); |
172 |
panelButtons.add(btnAceptar); |
173 |
} |
174 |
return panelButtons;
|
175 |
} |
176 |
|
177 |
public void actionPerformed(ActionEvent e) { |
178 |
if (e.getActionCommand() == "OK") { |
179 |
/* Causes all the tabs in the ThemeManagerWindow to perform THEIR apply-action
|
180 |
* then fires the LegendChanged event that causes the view to be refreshed.
|
181 |
* After that, it closes the window.
|
182 |
*/
|
183 |
actionPerformed(new ActionEvent(e.getSource(), e.getID(), "APPLY")); |
184 |
|
185 |
close(); |
186 |
} else if (e.getActionCommand() == "CANCEL") { |
187 |
/* Causes all the tabs in the ThemeManagerWindow to perform THEIR cancel-action
|
188 |
* then closes the window.
|
189 |
*/
|
190 |
for (int i = 0; i < tabs.getTabCount(); i++) { |
191 |
AbstractThemeManagerPage tab = (AbstractThemeManagerPage) tabs.getComponentAt(i); |
192 |
tab.cancelAction(); |
193 |
} |
194 |
close(); |
195 |
} else if (e.getActionCommand() == "APPLY") { |
196 |
/* Causes the current visible tab in the ThemeManagerWindow to perform
|
197 |
* ITS specific apply-action.
|
198 |
*/
|
199 |
for (int i = 0; i < tabs.getTabCount(); i++) { |
200 |
AbstractThemeManagerPage tab = (AbstractThemeManagerPage) tabs.getComponentAt(i); |
201 |
tab.applyAction(); |
202 |
} |
203 |
layer.getMapContext().callLegendChanged(); |
204 |
} else {}
|
205 |
// Lots of temporary objects were create.
|
206 |
// let's try some memory cleanup
|
207 |
System.gc();
|
208 |
} |
209 |
|
210 |
private void close() { |
211 |
PluginServices.getMDIManager().closeWindow(ThemeManagerWindow.this); |
212 |
} |
213 |
|
214 |
public WindowInfo getWindowInfo() {
|
215 |
WindowInfo viewInfo = new WindowInfo(WindowInfo.MODELESSDIALOG|WindowInfo.RESIZABLE);
|
216 |
viewInfo.setWidth(getWidth()); |
217 |
viewInfo.setHeight(getHeight()); |
218 |
viewInfo.setTitle(PluginServices.getText(this,"propiedades_de_la_capa")); |
219 |
return viewInfo;
|
220 |
} |
221 |
|
222 |
public static void addPage(Class<? extends AbstractThemeManagerPage> abstractThemeManagerPageClass) { |
223 |
pages.add(abstractThemeManagerPageClass); |
224 |
} |
225 |
|
226 |
public static void setTabEnabledForLayer(Class<? extends AbstractThemeManagerPage> abstractThemeManagerPageClass, Class<? extends FLayer> fLayerClazz, boolean enabled) { |
227 |
ArrayList<Class<? extends FLayer>> enabledLayers; |
228 |
if (enabled == true) { |
229 |
if (!s.containsKey(abstractThemeManagerPageClass)) {
|
230 |
enabledLayers = new ArrayList<Class<? extends FLayer>> (); |
231 |
enabledLayers.add(fLayerClazz); |
232 |
s.put(abstractThemeManagerPageClass, enabledLayers); |
233 |
} else {
|
234 |
enabledLayers = s.get(abstractThemeManagerPageClass); |
235 |
enabledLayers.add(fLayerClazz); |
236 |
} |
237 |
} else {
|
238 |
if (!s.containsKey(abstractThemeManagerPageClass)) {
|
239 |
return;
|
240 |
} |
241 |
enabledLayers = s.get(abstractThemeManagerPageClass); |
242 |
enabledLayers.remove(fLayerClazz); |
243 |
} |
244 |
}; |
245 |
|
246 |
public static boolean isTabEnabledForLayer(AbstractThemeManagerPage page, FLayer layer) { |
247 |
try {
|
248 |
return s.get(page.getClass()).contains(layer.getClass());
|
249 |
} catch( Exception ex) { |
250 |
return false; |
251 |
} |
252 |
} |
253 |
|
254 |
public Object getWindowProfile() { |
255 |
return WindowInfo.TOOL_PROFILE;
|
256 |
}; |
257 |
} // @jve:decl-index=0:visual-constraint="10,10"
|