Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / legend / gui / ThemeManagerWindow.java @ 34114

History | View | Annotate | Download (7.84 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 = null;
102
                        try {
103
                                tab = pageClass.newInstance();
104
                        } catch (InstantiationException e) {
105
                                NotificationManager.addError("Trying to instantiate an interface" +
106
                                                " or abstract class + "+pageClass.getName(), e);
107
                        } catch (IllegalAccessException e) {
108
                                NotificationManager.addError("IllegalAccessException: does " +
109
                                                pageClass.getName()        + " class have an anonymous" +
110
                                                " constructor?", e);
111
                        }
112
                        if (tab!=null){
113
                            if (s.get(tab.getClass()).contains(layer.getClass())){
114
                                tab.setModel(layer);
115
                                tabs.addTab(tab.getName(), tab);
116
                            }
117
                        }
118
                }
119

    
120
                if (tabs.getComponentCount()>selectedTabIndex) {
121
                        tabs.setSelectedIndex(selectedTabIndex);
122
                }
123
                tabs.setPreferredSize(new java.awt.Dimension(640,390));
124

    
125

    
126
                setLayout(new BorderLayout());
127
                add(tabs, java.awt.BorderLayout.CENTER);
128

    
129
                // The listener must be added after the tabs are added to the window
130
                tabs.addChangeListener(new ChangeListener() {
131
                        public void stateChanged(javax.swing.event.ChangeEvent e) {
132
                                //remember the visible tab
133
                                selectedTabIndex = tabs.getSelectedIndex();
134
                                if (selectedTabIndex<0) {
135
                                        selectedTabIndex = 0;
136
                                }
137
                        };
138
                });
139
                add(getPanelButtons(), java.awt.BorderLayout.SOUTH);
140
                setSize(new Dimension(780, 540));
141
        }
142

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

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

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

    
155

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

    
167
        public void actionPerformed(ActionEvent e) {
168
                if (e.getActionCommand() == "OK") {
169
                        /* Causes all the tabs in the ThemeManagerWindow to perform THEIR apply-action
170
                         * then fires the LegendChanged event that causes the view to be refreshed.
171
                         * After that, it closes the window.
172
                         */
173
                        actionPerformed(new ActionEvent(e.getSource(), e.getID(), "APPLY"));
174

    
175
                        close();
176
                } else if (e.getActionCommand() == "CANCEL") {
177
                        /* Causes all the tabs in the ThemeManagerWindow to perform THEIR cancel-action
178
                         * then closes the window.
179
                         */
180
                        for (int i = 0; i < tabs.getTabCount(); i++) {
181
                                AbstractThemeManagerPage tab = (AbstractThemeManagerPage) tabs.getComponentAt(i);
182
                                tab.cancelAction();
183
                        }
184
                        close();
185
                } else if (e.getActionCommand() == "APPLY") {
186
                        /* Causes the current visible tab in the ThemeManagerWindow to perform
187
                         * ITS specific apply-action.
188
                         */
189
                        for (int i = 0; i < tabs.getTabCount(); i++) {
190
                                AbstractThemeManagerPage tab = (AbstractThemeManagerPage) tabs.getComponentAt(i);
191
                                tab.applyAction();
192
                        }
193
                        layer.getMapContext().callLegendChanged();
194
                } else {}
195
//                 Lots of temporary objects were create.
196
                // let's try some memory cleanup
197
                System.gc();
198
        }
199

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

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

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

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