Statistics
| Revision:

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

History | View | Annotate | Download (5.33 KB)

1 10740 nacho
/* 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.Iterator;
22
23
import javax.swing.JPanel;
24
import javax.swing.event.ChangeEvent;
25
import javax.swing.event.ChangeListener;
26
27
import com.iver.utiles.extensionPoints.ExtensionPoint;
28
import com.iver.utiles.extensionPoints.ExtensionPoints;
29
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
30
31
32
/**
33
 * Panel que contiene todos los paneles de los tabs del cuadro de dialogo
34
 * de bandas y transparencias
35
 *
36
 * @author Nacho Brodin (brodin_ign@gva.es)
37
 */
38
public class RegistrableTabPanel extends DefaultTabPanel implements ChangeListener{
39
    final private static long         serialVersionUID = 0;
40
41
    private ExtensionPoints                extensionPoints = null;
42
    private ExtensionPoint                 extensionPoint = null;
43
    /**
44
     * Tama?o en X del panel
45
     */
46
    protected int                                 sizePanelX = 0;
47
    /**
48
     * Tama?o en Y del panel
49
     */
50
    protected int                                 sizePanelY = 0;
51
52
    /**
53
     * Constructor. Inicializa los paneles y propiedades
54
     * @param props        Propiedades
55
     */
56
    public RegistrableTabPanel(int sizex, int sizey) {
57
        super(sizex, sizey);
58
                this.loadTabsFromExtensionPoints();
59
        getTabPane().addChangeListener(this);
60
    }
61
62
    /**
63
     * Load register tabs inside the panel, reading these from extension points.
64
     */
65
    private void loadTabsFromExtensionPoints(){
66
            extensionPoints = ExtensionPointsSingleton.getInstance();
67
                extensionPoint = (ExtensionPoint)extensionPoints.get("RasterSEPropertiesDialog");
68
                if(extensionPoint == null)
69
                        return;
70
                Iterator iterator = extensionPoint.keySet().iterator();
71
                while (iterator.hasNext()) {
72
                        try {
73
                                String key = (String)iterator.next();
74
                                JPanel panel = (JPanel)extensionPoint.get(key);
75
                                super.addTab(key, panel);
76
                        } catch (ClassCastException e) {
77
                                //No se a?ade el panel y se sigue con el siguiente
78
                                continue;
79
                        }
80
                }
81
    }
82
83
    /**
84
     * Obtiene el indice del tab seleccionado
85
     * @return N?mero de tab seleccionado
86
     */
87
    public int getSelectedTab(){
88
            return super.getTab().getSelectedIndex();
89
    }
90
91
    /**
92
     * Ejecuta la acci?n de aceptar en el panel seleccionado
93
     */
94
    public void acceptSelectedTab(){
95
            execAction(0);
96
    }
97
98
    /**
99
     * Ejecuta la acci?n de aplicar en el panel seleccionado
100
     */
101
    public void applySelectedTab(){
102
            execAction(1);
103
    }
104
105
    /**
106
     * Ejecuta la acci?n de cancelar en el panel seleccionado
107
     */
108
    public void cancelSelectedTab(){
109
            execAction(2);
110
    }
111
112
    /**
113
     * Ejecuta la acci?n en el panel seleccionado que se le indica en el
114
     * par?metro
115
     * @param action indicador de la acci?n a realizar
116
     */
117
    private void execAction(int action){
118
            if(extensionPoint == null)
119
                        return;
120
            if(getTab().getSelectedIndex() == -1)
121
                    return;
122
            String title = getTab().getTitleAt(getTab().getSelectedIndex());
123
124
            Iterator iterator = extensionPoint.keySet().iterator();
125
                while (iterator.hasNext()) {
126
                        try {
127
                                String key = (String)iterator.next();
128
                                if(key.equals(title)){
129
                                        IRegistrablePanel panel = (IRegistrablePanel)extensionPoint.get(key);
130
                                        switch(action){
131
                                        case 0: panel.accept(); break;
132
                                        case 1: panel.apply(); break;
133
                                        case 2: panel.cancel(); break;
134
                                        }
135
                                }
136
                        } catch (ClassCastException e) {
137
                                //No se ejecuta
138
                                continue;
139
                        }
140
                }
141
    }
142
143
    /**
144
     * Asigna la visibilidad de un tab a verdadero o falso. La
145
     * selecci?n del tab se hace por el identificador.
146
     * @param tab        Identificador del tab. Variable nom del mismo
147
     * @param active        True o false para visible o invisible.
148
     */
149
    public void setTabVisible(String tab, boolean active){
150
151
    }
152
153
    /**
154
     * Selecciona el panel indicado por index
155
     * @param index        panel seleccionado
156
     */
157
    public void setSelectedIndex(int index) {
158
        tabbedPane.setSelectedIndex(index);
159
    }
160
161
    /**
162
     * Propagamos el evento de cambiar de pesta?a a todos los paneles.
163
     */
164
        public void stateChanged(ChangeEvent e) {
165
            if(extensionPoint == null)
166
                        return;
167
            if(getTab().getSelectedIndex() == -1)
168
                    return;
169
            String title = getTab().getTitleAt(getTab().getSelectedIndex());
170
171
            Iterator iterator = extensionPoint.keySet().iterator();
172
                while (iterator.hasNext()) {
173
                        try {
174
                                String key = (String)iterator.next();
175
                                if(key.equals(title)){
176
                                        IRegistrablePanel panel = (IRegistrablePanel)extensionPoint.get(key);
177
                                        panel.selectTab(key);
178
                                }
179
                        } catch (ClassCastException ex) {
180
                                //No se ejecuta
181
                                continue;
182
                        }
183
                }
184
        }
185
186
}