Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / legend / gui / AbstractThemeManagerPage.java @ 43913

History | View | Annotate | Download (5.44 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.app.project.documents.view.legend.gui;
25

    
26
import javax.swing.JComponent;
27
import javax.swing.JOptionPane;
28
import javax.swing.JPanel;
29

    
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.andami.messages.Messages;
32
import org.gvsig.fmap.mapcontext.layers.FLayer;
33
import org.gvsig.fmap.mapcontext.layers.FLayers;
34
import org.gvsig.fmap.mapcontext.layers.operations.Classifiable;
35
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
36
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
37
import org.gvsig.propertypage.PropertiesPage;
38

    
39

    
40
public abstract class AbstractThemeManagerPage extends JPanel implements PropertiesPage {
41
        /**
42
         * Cuando hay varios capas vectoriales seleccionados, devolver? el ?ltimo.
43
         *
44
         * @param layers Grupo de layers.
45
         *
46
         * @return la primera flayer seleccionada.
47
         */
48
        protected FLayer getFirstActiveLayerVect(FLayers layers) {
49
                // Comprobar en openLegendManager que hay alg?n capa activo!
50
                FLayer[] activeLyrs = layers.getActives();
51

    
52
                if (activeLyrs.length == 0) {
53
                        JOptionPane.showMessageDialog(null,
54
                                Messages.getString("necesita_una_capa_activa"), "",
55
                                JOptionPane.ERROR_MESSAGE);
56

    
57
                        return null;
58
                }
59

    
60
                FLayer lyr = null;
61

    
62
                for (int i = 0; i < activeLyrs.length; i++) {
63
                        if (activeLyrs[i] instanceof FLayers) {
64
                                lyr = getFirstActiveLayerVect((FLayers) activeLyrs[i]);
65
                        }
66

    
67
                        if (activeLyrs[i] instanceof Classifiable) {
68
                                Classifiable auxC = (Classifiable) activeLyrs[i];
69
                                ILegend theLegend = auxC.getLegend();
70

    
71
                                if (theLegend instanceof IVectorLegend) {
72
                                        lyr = (FLayer) auxC;
73
                                }
74
                        }
75
                }
76

    
77
                if (lyr == null) {
78
                        JOptionPane.showMessageDialog(null,
79
                                Messages.getString(
80
                                                PluginServices.getText(this, "necesita_una_capa_vectorial_activa") +
81
                                                "\n\n"+
82
                                                PluginServices.getText(this, "Por_favor_active_la_capa") + "."),
83
                                "",
84
                                JOptionPane.ERROR_MESSAGE);
85
                        return null;
86
                }
87

    
88
                return lyr;
89
        }
90

    
91
        @Override
92
        public void setData(Object data) {
93

    
94
        }
95

    
96
        public boolean isTabEnabledForLayer(FLayer layer) {
97
            return ThemeManagerWindow.isTabEnabledForLayer(this, layer);
98
        }
99
        
100
        /**
101
         * Retorna la prioridad usada para determinar la posicion de la pesta?a.
102
         * 
103
         * Cuanto mas alta sea esta mas a la izquierda estara la pesta?a.
104
         * @return La prioridad 
105
         */
106
        public int getPriority() {
107
            return 50;
108
        }
109
        
110
        /**
111
         * Returns the name of this ThemeManagerPage's tab, the text returned by this
112
         * method will be shown in the text of this panel's tab.
113
         */
114
        public abstract String getName();
115

    
116
        /**
117
         * <p>
118
         * Method invoked when the Ok button is pressed from the ThemeManagerWindow.
119
         * It will cause the changes performed by the user to take effect into the
120
         * layer if the Apply button wasn't pressed yet. In case Apply button was
121
         * pressed, then the programmer can choose between apply the changes again or
122
         * not.<br>
123
         * </p>
124
         * <p>
125
         * It shouldn't be a problem rather than the potential consumption of time
126
         * required in when applying such changes.<br>
127
         * </p>
128
         * <p>
129
         * <b>Notice</b> that after the call of this method the ThemeManagerWindow will be closed.
130
         * </p>
131
         */
132
        public abstract void acceptAction();
133

    
134
        /**
135
         * <p>
136
         * Method invoked when the Cancel button is pressed from the ThemeManagerWindow.
137
         * It will cause that the changes performed will be discarded.
138
         * </p>
139
         */
140
        public abstract void cancelAction();
141

    
142
        /**
143
         * Method invoked when the Apply button is pressed from the ThemeManagerWindow.
144
         * It will cause the changes performed by the user to take effect inmediately
145
         * into the the layer.
146
         */
147
        public abstract void applyAction();
148

    
149
        /**
150
         * This method is invoked during the initialization of the ThemeManagerWindow
151
         * and causes the dialog to be updated to reflect the current settings of
152
         * the layer in the context that this panel was designed for.
153
         * @param layer, the target FLayer
154
         */
155
        public abstract void setModel(FLayer layer);
156

    
157
    void setModel(Object obj) {
158
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
159
    }
160
    
161
    public String getTitle() {
162
        return this.getName();
163
    }
164
    
165
    public boolean whenAccept()  {
166
        acceptAction();
167
        return true;
168
    }
169

    
170
    public boolean whenApply()  {
171
        applyAction();
172
        return true;
173
    }
174

    
175
    public boolean whenCancel()  {
176
        cancelAction();
177
        return true;
178
    }
179

    
180
    public JComponent asJComponent() {
181
        return this;
182
    }
183
    
184
    
185
    
186
}