Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / legend / gui / ThemeManagerWindow.java @ 10679

History | View | Annotate | Download (6.76 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
 * 
69
 * @author jaume dominguez faus - jaume.dominguez@iver.es
70
 * @version 01-feb-2007
71
 */
72
public final class ThemeManagerWindow extends JPanel implements IWindow, ActionListener {
73
        private static int selectedTabIndex = 0;
74
        private static ArrayList pages = new ArrayList();
75
        private FLayer layer;
76
        //private Legend legend; // Le asignaremos la leyenda del primer tema activo.
77
        private JTabbedPane tabs = new JTabbedPane();  //  @jve:decl-index=0:
78
        private JPanel panelButtons;
79

    
80

    
81

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

    
90
                // TODO falta definir leyenda para cualquier tipo de capa
91
                // y decidir entonces qu? opciones soporta cada una para
92
                // que el di?logo se autorrellene
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);
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
        private JPanel getPanelButtons() {
135
                if (panelButtons == null) {
136
                        panelButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5,5));
137

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

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

    
146

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

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

    
169
                        layer.getMapContext().callLegendChanged();
170

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

    
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
                        if (PluginServices.getMainFrame() == null)
185
                                ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
186
                        else
187
                                PluginServices.getMDIManager().closeWindow(ThemeManagerWindow.this);
188

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

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

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