Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / properties / dialog / RegistrableTabPanel.java @ 12168

History | View | Annotate | Download (5.13 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.rastertools.properties.dialog;
20

    
21
import java.util.Hashtable;
22
import java.util.Iterator;
23

    
24
import javax.swing.JPanel;
25
import javax.swing.event.ChangeEvent;
26
import javax.swing.event.ChangeListener;
27

    
28
import com.iver.utiles.extensionPoints.ExtensionPoint;
29
import com.iver.utiles.extensionPoints.ExtensionPoints;
30
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
31
/**
32
 * Panel que contiene todos los paneles de los tabs del cuadro de dialogo
33
 * de bandas y transparencias
34
 *
35
 * @author Nacho Brodin (brodin_ign@gva.es)
36
 */
37
public class RegistrableTabPanel extends DefaultTabPanel implements ChangeListener {
38
        final private static long serialVersionUID = 0;
39

    
40
        private ExtensionPoints   extensionPoints  = null;
41
        private ExtensionPoint    extensionPoint   = null;
42

    
43
        static public Hashtable initialProperties = new Hashtable();
44
        /**
45
         * Tama?o en X del panel
46
         */
47
        protected int                                 sizePanelX = 0;
48

    
49
        /**
50
         * Tama?o en Y del panel
51
         */
52
        protected int                                 sizePanelY = 0;
53

    
54
        /**
55
         * Constructor. Inicializa los paneles y propiedades
56
         * @param props        Propiedades
57
         */
58
        public RegistrableTabPanel() {
59
                this.loadTabsFromExtensionPoints();
60
                getTabPane().addChangeListener(this);
61
        }
62

    
63
        /**
64
         * Load register tabs inside the panel, reading these from extension points.
65
         */
66
        private void loadTabsFromExtensionPoints() {
67
                extensionPoints = ExtensionPointsSingleton.getInstance();
68
                extensionPoint = (ExtensionPoint) extensionPoints.get("RasterSEPropertiesDialog");
69
                if (extensionPoint == null)
70
                        return;
71
                Iterator iterator = extensionPoint.keySet().iterator();
72
                while (iterator.hasNext()) {
73
                        try {
74
                                String key = (String) iterator.next();
75
                                JPanel panel = (JPanel) extensionPoint.get(key);
76
                                super.addTab(key, panel);
77
                        } catch (ClassCastException e) {
78
                                // No se a?ade el panel y se sigue con el siguiente
79
                                continue;
80
                        }
81
                }
82
        }
83

    
84
        /**
85
         * Obtiene el indice del tab seleccionado
86
         * @return N?mero de tab seleccionado
87
         */
88
        public int getSelectedTab() {
89
                return super.getTab().getSelectedIndex();
90
        }
91

    
92
        /**
93
         * Ejecuta la acci?n de aceptar en el panel seleccionado
94
         */
95
        public void acceptSelectedTab() {
96
                execAction(0);
97
        }
98

    
99
        /**
100
         * Ejecuta la acci?n de aplicar en el panel seleccionado
101
         */
102
        public void applySelectedTab() {
103
                execAction(1);
104
        }
105

    
106
        /**
107
         * Ejecuta la acci?n de cancelar en el panel seleccionado
108
         */
109
        public void cancelSelectedTab() {
110
                execAction(2);
111
        }
112

    
113
        /**
114
         * Ejecuta la acci?n en el panel seleccionado que se le indica en el
115
         * par?metro
116
         * @param action indicador de la acci?n a realizar
117
         */
118
        private void execAction(int action) {
119
                if (extensionPoint == null)
120
                        return;
121
                if (getTab().getSelectedIndex() == -1)
122
                        return;
123
//                String title = getTab().getTitleAt(getTab().getSelectedIndex());
124

    
125
                Iterator iterator = extensionPoint.keySet().iterator();
126
                while (iterator.hasNext()) {
127
                        try {
128
                                String key = (String) iterator.next();
129
                                IRegistrablePanel panel = (IRegistrablePanel) extensionPoint.get(key);
130
//                                if (key.equals(title)) {
131
                                switch (action) {
132
                                        case 0:
133
                                                panel.accept();
134
                                                break;
135
                                        case 1:
136
                                                panel.apply();
137
                                                break;
138
                                        case 2:
139
                                                panel.cancel();
140
                                                break;
141
                                }
142
//                                }
143
                        } catch (ClassCastException e) {
144
                                // No se ejecuta
145
                                continue;
146
                        }
147
                }
148
        }
149

    
150
        /**
151
         * Asigna la visibilidad de un tab a verdadero o falso. La
152
         * selecci?n del tab se hace por el identificador.
153
         * @param tab        Identificador del tab. Variable nom del mismo
154
         * @param active        True o false para visible o invisible.
155
         */
156
        public void setTabVisible(String tab, boolean active){
157

    
158
        }
159

    
160
        /**
161
         * Selecciona el panel indicado por index
162
         * @param index        panel seleccionado
163
         */
164
        public void setSelectedIndex(int index) {
165
                tabbedPane.setSelectedIndex(index);
166
        }
167

    
168
        /**
169
         * Propagamos el evento de cambiar de pesta?a a todos los paneles.
170
         */
171
        public void stateChanged(ChangeEvent e) {
172
                        if(extensionPoint == null)
173
                        return;
174
                        if(getTab().getSelectedIndex() == -1)
175
                                return;
176
                        String title = getTab().getTitleAt(getTab().getSelectedIndex());
177

    
178
                        Iterator iterator = extensionPoint.keySet().iterator();
179
                while (iterator.hasNext()) {
180
                        try {
181
                                String key = (String)iterator.next();
182
                                if(key.equals(title)){
183
                                        IRegistrablePanel panel = (IRegistrablePanel)extensionPoint.get(key);
184
                                        panel.selectTab(key);
185
                                }
186
                        } catch (ClassCastException ex) {
187
                                //No se ejecuta
188
                                continue;
189
                        }
190
                }
191
        }
192
}