root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / legend / gui / ThemeManagerWindow.java @ 24986
History | View | Annotate | Download (7.83 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 com.iver.cit.gvsig.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.JPanel; |
54 |
import javax.swing.JTabbedPane; |
55 |
import javax.swing.event.ChangeListener; |
56 |
|
57 |
import org.gvsig.gui.beans.swing.JButton; |
58 |
|
59 |
import com.iver.andami.PluginServices; |
60 |
import com.iver.andami.messages.NotificationManager; |
61 |
import com.iver.andami.ui.mdiManager.IWindow; |
62 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
63 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
64 |
import com.iver.cit.gvsig.fmap.layers.FLyrDefault; |
65 |
|
66 |
/**
|
67 |
*
|
68 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
69 |
* @version 01-feb-2007
|
70 |
*/
|
71 |
public final class ThemeManagerWindow extends JPanel implements IWindow, ActionListener { |
72 |
private static final long serialVersionUID = 4650656815369149211L; |
73 |
private static int selectedTabIndex = 0; |
74 |
private static ArrayList<Class<? extends AbstractThemeManagerPage>> pages = |
75 |
new ArrayList<Class<? extends AbstractThemeManagerPage>>(); |
76 |
private FLayer layer;
|
77 |
//private Legend legend; // Le asignaremos la leyenda del primer tema activo.
|
78 |
private JTabbedPane tabs = new JTabbedPane(); // @jve:decl-index=0: |
79 |
private JPanel panelButtons; |
80 |
private static Hashtable<Class<? extends AbstractThemeManagerPage>, ArrayList<Class<? extends FLyrDefault>>> s = |
81 |
new Hashtable<Class<? extends AbstractThemeManagerPage>, ArrayList<Class<? extends FLyrDefault>>>(); |
82 |
|
83 |
|
84 |
/**
|
85 |
* Sobrecarga del constructor. Este se utiliza cuando se llama a este
|
86 |
* di?logo desde la barra de comandos.
|
87 |
*
|
88 |
*/
|
89 |
public ThemeManagerWindow(FLayer l) {
|
90 |
this.layer = l;
|
91 |
|
92 |
// TODO falta definir leyenda para cualquier tipo de capa
|
93 |
// y decidir entonces qu? opciones soporta cada una para
|
94 |
// que el di?logo se autorrellene
|
95 |
initialize(); |
96 |
} |
97 |
|
98 |
private void initialize() { |
99 |
for (int i = 0; i < pages.size(); i++) { |
100 |
Class<? extends AbstractThemeManagerPage> pageClass = pages.get(i); |
101 |
AbstractThemeManagerPage tab; |
102 |
try {
|
103 |
tab = (AbstractThemeManagerPage) pageClass.newInstance(); |
104 |
// if (tab.isSuitableFor(layer)) {
|
105 |
if (s.get(tab.getClass()).contains(layer.getClass())){
|
106 |
tab.setModel(layer); |
107 |
tabs.addTab(tab.getName(), tab); |
108 |
} |
109 |
} catch (InstantiationException e) { |
110 |
NotificationManager.addError("Trying to instantiate an interface" +
|
111 |
" or abstract class + "+pageClass.getName(), e);
|
112 |
} catch (IllegalAccessException e) { |
113 |
NotificationManager.addError("IllegalAccessException: does " +
|
114 |
pageClass.getName() + " class have an anonymous" +
|
115 |
" constructor?", e);
|
116 |
} |
117 |
} |
118 |
|
119 |
if (tabs.getComponentCount()>selectedTabIndex) {
|
120 |
tabs.setSelectedIndex(selectedTabIndex); |
121 |
} |
122 |
tabs.setPreferredSize(new java.awt.Dimension(640,390)); |
123 |
|
124 |
|
125 |
setLayout(new BorderLayout()); |
126 |
add(tabs, java.awt.BorderLayout.CENTER); |
127 |
|
128 |
// The listener must be added after the tabs are added to the window
|
129 |
tabs.addChangeListener(new ChangeListener() { |
130 |
public void stateChanged(javax.swing.event.ChangeEvent e) { |
131 |
//remember the visible tab
|
132 |
selectedTabIndex = tabs.getSelectedIndex(); |
133 |
if (selectedTabIndex<0) |
134 |
selectedTabIndex = 0;
|
135 |
}; |
136 |
}); |
137 |
add(getPanelButtons(), java.awt.BorderLayout.SOUTH); |
138 |
setSize(new Dimension(790, 540)); |
139 |
} |
140 |
|
141 |
private JPanel getPanelButtons() { |
142 |
if (panelButtons == null) { |
143 |
panelButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5,5)); |
144 |
|
145 |
JButton btnAceptar = new JButton(PluginServices.getText(this,"Aceptar")); |
146 |
btnAceptar.setActionCommand("OK");
|
147 |
btnAceptar.addActionListener(this);
|
148 |
|
149 |
JButton btnApply = new JButton(PluginServices.getText(this,"Apply")); |
150 |
btnApply.setActionCommand("APPLY");
|
151 |
btnApply.addActionListener(this);
|
152 |
|
153 |
|
154 |
JButton btnCancelar = new JButton(PluginServices.getText(this,"Cerrar")); |
155 |
btnCancelar.setActionCommand("CANCEL");
|
156 |
btnCancelar.addActionListener(this);
|
157 |
panelButtons.setPreferredSize(new java.awt.Dimension(493,33)); |
158 |
panelButtons.add(btnCancelar); |
159 |
panelButtons.add(btnApply); |
160 |
panelButtons.add(btnAceptar); |
161 |
} |
162 |
return panelButtons;
|
163 |
} |
164 |
|
165 |
public void actionPerformed(ActionEvent e) { |
166 |
|
167 |
if (e.getActionCommand() == "OK") { |
168 |
/* Causes all the tabs in the ThemeManagerWindow to perform THEIR apply-action
|
169 |
* then fires the LegendChanged event that causes the view to be refreshed.
|
170 |
* After that, it closes the window.
|
171 |
*/
|
172 |
|
173 |
actionPerformed(new ActionEvent(e.getSource(), e.getID(), "APPLY")); |
174 |
close(); |
175 |
} else if (e.getActionCommand() == "CANCEL") { |
176 |
/* Causes all the tabs in the ThemeManagerWindow to perform THEIR cancel-action
|
177 |
* then closes the window.
|
178 |
*/
|
179 |
for (int i = 0; i < tabs.getTabCount(); i++) { |
180 |
AbstractThemeManagerPage tab = (AbstractThemeManagerPage) tabs.getComponentAt(i); |
181 |
tab.cancelAction(); |
182 |
} |
183 |
close(); |
184 |
} else if (e.getActionCommand() == "APPLY") { |
185 |
/* Causes the current visible tab in the ThemeManagerWindow to perform
|
186 |
* ITS specific apply-action.
|
187 |
*/
|
188 |
for (int i = 0; i < tabs.getTabCount(); i++) { |
189 |
AbstractThemeManagerPage tab = (AbstractThemeManagerPage) tabs.getComponentAt(i); |
190 |
tab.applyAction(); |
191 |
} |
192 |
layer.getMapContext().callLegendChanged(); |
193 |
} else {}
|
194 |
|
195 |
|
196 |
// Lots of temporary objects were create.
|
197 |
// let's try some memory cleanup
|
198 |
System.gc();
|
199 |
} |
200 |
|
201 |
private void close() { |
202 |
PluginServices.getMDIManager().closeWindow(ThemeManagerWindow.this); |
203 |
} |
204 |
|
205 |
public WindowInfo getWindowInfo() {
|
206 |
WindowInfo viewInfo = new WindowInfo(WindowInfo.MODELESSDIALOG|WindowInfo.RESIZABLE);
|
207 |
viewInfo.setWidth(getWidth()); |
208 |
viewInfo.setHeight(getHeight()); |
209 |
viewInfo.setTitle(PluginServices.getText(this,"propiedades_de_la_capa")); |
210 |
return viewInfo;
|
211 |
} |
212 |
|
213 |
public static void addPage(Class<? extends AbstractThemeManagerPage> abstractThemeManagerPageClass) { |
214 |
pages.add(abstractThemeManagerPageClass); |
215 |
} |
216 |
|
217 |
public static void setTabEnabledForLayer(Class<? extends AbstractThemeManagerPage> abstractThemeManagerPageClass, Class<? extends FLyrDefault> fLayerClazz, boolean enabled) { |
218 |
ArrayList<Class<? extends FLyrDefault>> enabledLayers; |
219 |
if (enabled == true) { |
220 |
if (!s.containsKey(abstractThemeManagerPageClass)) {
|
221 |
enabledLayers = new ArrayList<Class<? extends FLyrDefault>> (); |
222 |
enabledLayers.add(fLayerClazz); |
223 |
s.put(abstractThemeManagerPageClass, enabledLayers); |
224 |
} else {
|
225 |
enabledLayers = s.get(abstractThemeManagerPageClass); |
226 |
enabledLayers.add(fLayerClazz); |
227 |
} |
228 |
} else {
|
229 |
if (!s.containsKey(abstractThemeManagerPageClass)) return; |
230 |
enabledLayers = s.get(abstractThemeManagerPageClass); |
231 |
enabledLayers.remove(fLayerClazz); |
232 |
} |
233 |
} |
234 |
|
235 |
public Object getWindowProfile() { |
236 |
return WindowInfo.TOOL_PROFILE;
|
237 |
}; |
238 |
} // @jve:decl-index=0:visual-constraint="10,10"
|