Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / legend / gui / ThemeManagerWindow.java @ 29598

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 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.JPanel;
54
import javax.swing.JTabbedPane;
55
import javax.swing.event.ChangeListener;
56

    
57
import org.gvsig.andami.PluginServices;
58
import org.gvsig.andami.messages.NotificationManager;
59
import org.gvsig.andami.ui.mdiManager.IWindow;
60
import org.gvsig.andami.ui.mdiManager.WindowInfo;
61
import org.gvsig.fmap.mapcontext.layers.FLayer;
62
import org.gvsig.fmap.mapcontext.layers.FLyrDefault;
63
import org.gvsig.gui.beans.swing.JButton;
64

    
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 = 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
                });
138
                add(getPanelButtons(), java.awt.BorderLayout.SOUTH);
139
                setSize(new Dimension(780, 540));
140
        }
141

    
142
        private JPanel getPanelButtons() {
143
                if (panelButtons == null) {
144
                        panelButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5,5));
145

    
146
                        JButton btnAceptar = new JButton(PluginServices.getText(this,"Aceptar"));
147
                        btnAceptar.setActionCommand("OK");
148
                        btnAceptar.addActionListener(this);
149

    
150
                        JButton btnApply = new JButton(PluginServices.getText(this,"Apply"));
151
                        btnApply.setActionCommand("APPLY");
152
                        btnApply.addActionListener(this);
153

    
154

    
155
                        JButton btnCancelar = new JButton(PluginServices.getText(this,"Cerrar"));
156
                        btnCancelar.setActionCommand("CANCEL");
157
                        btnCancelar.addActionListener(this);
158
                        panelButtons.setPreferredSize(new java.awt.Dimension(493,33));
159
                        panelButtons.add(btnCancelar);
160
                        panelButtons.add(btnApply);
161
                        panelButtons.add(btnAceptar);
162
                }
163
                return panelButtons;
164
        }
165

    
166
        public void actionPerformed(ActionEvent e) {
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
                        actionPerformed(new ActionEvent(e.getSource(), e.getID(), "APPLY"));
173

    
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
//                 Lots of temporary objects were create.
195
                // let's try some memory cleanup
196
                System.gc();
197
        }
198

    
199
        private void close() {
200
                PluginServices.getMDIManager().closeWindow(ThemeManagerWindow.this);
201
        }
202

    
203
        public WindowInfo getWindowInfo() {
204
                WindowInfo viewInfo = new WindowInfo(WindowInfo.MODELESSDIALOG|WindowInfo.RESIZABLE);
205
                viewInfo.setWidth(getWidth());
206
                viewInfo.setHeight(getHeight());
207
                viewInfo.setTitle(PluginServices.getText(this,"propiedades_de_la_capa"));
208
                return viewInfo;
209
        }
210

    
211
        public static void addPage(Class<? extends AbstractThemeManagerPage> abstractThemeManagerPageClass) {
212
                pages.add(abstractThemeManagerPageClass);
213
        }
214

    
215
        public static void setTabEnabledForLayer(Class<? extends AbstractThemeManagerPage> abstractThemeManagerPageClass, Class<? extends FLyrDefault> fLayerClazz, boolean enabled) {
216
                ArrayList<Class<? extends FLyrDefault>> enabledLayers;
217
                if (enabled == true) {
218
                        if (!s.containsKey(abstractThemeManagerPageClass)) {
219
                                enabledLayers = new ArrayList<Class<? extends FLyrDefault>> ();
220
                                enabledLayers.add(fLayerClazz);
221
                                s.put(abstractThemeManagerPageClass, enabledLayers);
222
                        } else {
223
                                enabledLayers = s.get(abstractThemeManagerPageClass);
224
                                enabledLayers.add(fLayerClazz);
225
                        }
226
                } else {
227
                        if (!s.containsKey(abstractThemeManagerPageClass)) {
228
                                return;
229
                        }
230
                                enabledLayers = s.get(abstractThemeManagerPageClass);
231
                        enabledLayers.remove(fLayerClazz);
232
                }
233
        };
234
        public Object getWindowProfile() {
235
                return WindowInfo.TOOL_PROFILE;
236
        };
237
}  //  @jve:decl-index=0:visual-constraint="10,10"