Statistics
| Revision:

svn-gvsig-desktop / branches / simbologia / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / legend / gui / ThemeManagerWindow.java @ 10437

History | View | Annotate | Download (6.82 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.FlowLayout;
47
import java.awt.event.ActionEvent;
48
import java.awt.event.ActionListener;
49
import java.text.NumberFormat;
50
import java.util.ArrayList;
51

    
52
import javax.swing.JDialog;
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.layerOperations.ClassifiableVectorial;
65
import com.iver.cit.gvsig.fmap.rendering.Legend;
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 int selectedTabIndex = 0;
73
        private static ArrayList pages = new ArrayList();
74
        private FLayer layer;
75
        private Legend legend; // Le asignaremos la leyenda del primer tema activo.
76
        private JTabbedPane tabs = new JTabbedPane();  //  @jve:decl-index=0:
77
        private JPanel panelButtons;
78

    
79

    
80

    
81
        /**
82
         * Sobrecarga del constructor. Este se utiliza cuando se llama a este
83
         * di?logo desde la barra de comandos.
84
         *
85
         */
86
        public ThemeManagerWindow(FLayer l) {
87
                this.layer = l;
88

    
89
                // TODO falta definir leyenda para cualquier tipo de capa
90
                // y decidir entonces qu? opciones soporta cada una para
91
                // que el di?logo se autorrellene
92
                this.legend = ((ClassifiableVectorial) l).getLegend();
93
                initialize();
94
        }
95

    
96
        private  void initialize() {
97
                for (int i = 0; i < pages.size(); i++) {
98
                        Class pageClass = (Class) pages.get(i);
99
                        AbstractThemeManagerPage tab;
100
                        try {
101
                                tab = (AbstractThemeManagerPage) pageClass.newInstance();
102
                                tab.setModel(layer, legend);
103
                                tabs.addTab(tab.getName(), tab);
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
                }
113

    
114
                tabs.setSelectedIndex(selectedTabIndex);
115
                tabs.setPreferredSize(new java.awt.Dimension(640,390));
116

    
117

    
118
                setLayout(new BorderLayout());
119
                add(tabs, java.awt.BorderLayout.CENTER);
120

    
121
                // The listener must be added after the tabs are added to the window
122
                tabs.addChangeListener(new ChangeListener() {
123
                        public void stateChanged(javax.swing.event.ChangeEvent e) {
124
                                //remember the visible tab
125
                                selectedTabIndex = tabs.getSelectedIndex();
126
                                if (selectedTabIndex<0)
127
                                        selectedTabIndex = 0;
128
                        };
129
                });
130
                add(getPanelButtons(), java.awt.BorderLayout.SOUTH);
131
                setSize(new java.awt.Dimension(723,468));
132

    
133

    
134
        }
135

    
136
        private JPanel getPanelButtons() {
137
                if (panelButtons == null) {
138
                        panelButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5,5));
139

    
140
                        JButton btnAceptar = new JButton(PluginServices.getText(this,"Aceptar"));
141
                        btnAceptar.setActionCommand("OK");
142
                        btnAceptar.addActionListener(this);
143

    
144
                        JButton btnApply = new JButton(PluginServices.getText(this,"Aplicar"));
145
                        btnApply.setActionCommand("APPLY");
146
                        btnApply.addActionListener(this);
147

    
148

    
149
                        JButton btnCancelar = new JButton(PluginServices.getText(this,"Cerrar"));
150
                        btnCancelar.setActionCommand("CANCEL");
151
                        btnCancelar.addActionListener(this);
152
                        panelButtons.setPreferredSize(new java.awt.Dimension(493,33));
153
                        panelButtons.add(btnCancelar);
154
                        panelButtons.add(btnApply);
155
                        panelButtons.add(btnAceptar);
156
                }
157
                return panelButtons;
158
        }
159

    
160
        public void actionPerformed(ActionEvent e) {
161
                if (e.getActionCommand() == "OK") {
162
                        /* Causes all the tabs in the ThemeManagerWindow to perform THEIR apply-action
163
                         * then fires the LegendChanged event that causes the view to be refreshed.
164
                         * After that, it closes the window.
165
                         */
166
                        for (int i = 0; i < tabs.getTabCount(); i++) {
167
                                AbstractThemeManagerPage tab = (AbstractThemeManagerPage) tabs.getComponentAt(i);
168
                                tab.applyAction();
169
                        }
170

    
171
                        layer.getMapContext().callLegendChanged();
172

    
173
                        if (PluginServices.getMainFrame() == null) {
174
                                ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
175
                        } else
176
                                PluginServices.getMDIManager().closeWindow(ThemeManagerWindow.this);
177

    
178
                } else if (e.getActionCommand() == "CANCEL") {
179
                        /* Causes all the tabs in the ThemeManagerWindow to perform THEIR cancel-action
180
                         * then closes the window.
181
                         */
182
                        for (int i = 0; i < tabs.getTabCount(); i++) {
183
                                AbstractThemeManagerPage tab = (AbstractThemeManagerPage) tabs.getComponentAt(i);
184
                                tab.cancelAction();
185
                        }
186
                        if (PluginServices.getMainFrame() == null)
187
                                ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
188
                        else
189
                                PluginServices.getMDIManager().closeWindow(ThemeManagerWindow.this);
190

    
191
                } else if (e.getActionCommand() == "APPLY") {
192
                        /* Causes the current visible tab in the ThemeManagerWindow to perform
193
                         * ITS specific apply-action.
194
                         */
195
                        ((AbstractThemeManagerPage) tabs.getSelectedComponent()).applyAction();
196
                        layer.getMapContext().callLegendChanged();
197
                } else {}
198
        }
199

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

    
208
        public static void addPage(Class abstractThemeManagerPageClass) {
209
                pages.add(abstractThemeManagerPageClass);
210
        }
211
}  //  @jve:decl-index=0:visual-constraint="10,10"