Statistics
| Revision:

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

History | View | Annotate | Download (6.71 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

    
52
import javax.swing.JPanel;
53
import javax.swing.JTabbedPane;
54
import javax.swing.event.ChangeListener;
55

    
56
import org.gvsig.gui.beans.swing.JButton;
57

    
58
import com.iver.andami.PluginServices;
59
import com.iver.andami.messages.NotificationManager;
60
import com.iver.andami.ui.mdiManager.IWindow;
61
import com.iver.andami.ui.mdiManager.WindowInfo;
62
import com.iver.cit.gvsig.fmap.layers.FLayer;
63

    
64
/**
65
 *
66
 * @author jaume dominguez faus - jaume.dominguez@iver.es
67
 * @version 01-feb-2007
68
 */
69
public final class ThemeManagerWindow extends JPanel implements IWindow, ActionListener {
70
        private static int selectedTabIndex = 0;
71
        private static ArrayList pages = new ArrayList();
72
        private FLayer layer;
73
        //private Legend legend; // Le asignaremos la leyenda del primer tema activo.
74
        private JTabbedPane tabs = new JTabbedPane();  //  @jve:decl-index=0:
75
        private JPanel panelButtons;
76

    
77

    
78

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

    
87
                // TODO falta definir leyenda para cualquier tipo de capa
88
                // y decidir entonces qu? opciones soporta cada una para
89
                // que el di?logo se autorrellene
90
                initialize();
91
        }
92

    
93
        private  void initialize() {
94
                for (int i = 0; i < pages.size(); i++) {
95
                        Class pageClass = (Class) pages.get(i);
96
                        AbstractThemeManagerPage tab;
97
                        try {
98
                                tab = (AbstractThemeManagerPage) pageClass.newInstance();
99
                                if (tab.isSuitableFor(layer)) {
100
                                        tab.setModel(layer);
101
                                        tabs.addTab(tab.getName(), tab);
102
                                }
103
                        } catch (InstantiationException e) {
104
                                NotificationManager.addError("Trying to instantiate an interface" +
105
                                                " or abstract class + "+pageClass.getName(), e);
106
                        } catch (IllegalAccessException e) {
107
                                NotificationManager.addError("IllegalAccessException: does " +
108
                                                pageClass.getName()        + " class have an anonymous" +
109
                                                " constructor?", e);
110
                        }
111
                }
112

    
113
                if (tabs.getComponentCount()>selectedTabIndex) {
114
                        tabs.setSelectedIndex(selectedTabIndex);
115
                }
116
                tabs.setPreferredSize(new java.awt.Dimension(640,390));
117

    
118

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

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

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

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

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

    
147

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

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

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

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

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

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

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

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