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 @ 42176

History | View | Annotate | Download (5.37 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
        public boolean isTabEnabledForLayer(FLayer layer) {
92
            return ThemeManagerWindow.isTabEnabledForLayer(this, layer);
93
        }
94
        
95
        /**
96
         * Retorna la prioridad usada para determinar la posicion de la pesta?a.
97
         * 
98
         * Cuanto mas alta sea esta mas a la izquierda estara la pesta?a.
99
         * @return La prioridad 
100
         */
101
        public int getPriority() {
102
            return 50;
103
        }
104
        
105
        /**
106
         * Returns the name of this ThemeManagerPage's tab, the text returned by this
107
         * method will be shown in the text of this panel's tab.
108
         */
109
        public abstract String getName();
110

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

    
129
        /**
130
         * <p>
131
         * Method invoked when the Cancel button is pressed from the ThemeManagerWindow.
132
         * It will cause that the changes performed will be discarded.
133
         * </p>
134
         */
135
        public abstract void cancelAction();
136

    
137
        /**
138
         * Method invoked when the Apply button is pressed from the ThemeManagerWindow.
139
         * It will cause the changes performed by the user to take effect inmediately
140
         * into the the layer.
141
         */
142
        public abstract void applyAction();
143

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

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

    
165
    public boolean whenApply()  {
166
        applyAction();
167
        return true;
168
    }
169

    
170
    public boolean whenCancel()  {
171
        cancelAction();
172
        return true;
173
    }
174

    
175
    public JComponent asJComponent() {
176
        return this;
177
    }
178
    
179
    
180
    
181
}