Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / toc / actions / FSymbolChangeColorTocMenuEntry.java @ 9532

History | View | Annotate | Download (5.49 KB)

1
package com.iver.cit.gvsig.project.documents.view.toc.actions;
2

    
3
import java.awt.Color;
4

    
5
import javax.swing.JColorChooser;
6

    
7
import com.iver.andami.PluginServices;
8
import com.iver.cit.gvsig.ProjectExtension;
9
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
10
import com.iver.cit.gvsig.fmap.layers.FLayer;
11
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
12
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend;
13
import com.iver.cit.gvsig.project.Project;
14
import com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction;
15
import com.iver.cit.gvsig.project.documents.view.toc.ITocItem;
16
import com.iver.cit.gvsig.project.documents.view.toc.TocItemLeaf;
17
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
18
 *
19
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
20
 *
21
 * This program is free software; you can redistribute it and/or
22
 * modify it under the terms of the GNU General Public License
23
 * as published by the Free Software Foundation; either version 2
24
 * of the License, or (at your option) any later version.
25
 *
26
 * This program is distributed in the hope that it will be useful,
27
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29
 * GNU General Public License for more details.
30
 *
31
 * You should have received a copy of the GNU General Public License
32
 * along with this program; if not, write to the Free Software
33
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
34
 *
35
 * For more information, contact:
36
 *
37
 *  Generalitat Valenciana
38
 *   Conselleria d'Infraestructures i Transport
39
 *   Av. Blasco Ib??ez, 50
40
 *   46010 VALENCIA
41
 *   SPAIN
42
 *
43
 *      +34 963862235
44
 *   gvsig@gva.es
45
 *      www.gvsig.gva.es
46
 *
47
 *    or
48
 *
49
 *   IVER T.I. S.A
50
 *   Salamanca 50
51
 *   46005 Valencia
52
 *   Spain
53
 *
54
 *   +34 963163400
55
 *   dac@iver.es
56
 */
57
/* CVS MESSAGES:
58
 *
59
 * $Id: FSymbolChangeColorTocMenuEntry.java 9532 2007-01-04 07:24:32Z caballero $
60
 * $Log$
61
 * Revision 1.5  2007-01-04 07:24:31  caballero
62
 * isModified
63
 *
64
 * Revision 1.4  2006/10/02 13:52:34  jaume
65
 * organize impots
66
 *
67
 * Revision 1.3  2006/09/29 07:07:41  caballero
68
 * llamada a listener
69
 *
70
 * Revision 1.2  2006/09/28 15:00:45  fjp
71
 * Usar siempre que se pueda ISymbol en lugar de FSymbol
72
 *
73
 * Revision 1.1  2006/09/15 10:41:30  caballero
74
 * extensibilidad de documentos
75
 *
76
 * Revision 1.1  2006/09/12 15:58:14  jorpiell
77
 * "Sacadas" las opcines del men? de FPopupMenu
78
 *
79
 *
80
 */
81
/**
82
 * Realiza el cambio de color si se pulsa OK
83
 * @author Luis W. Sevilla (sevilla_lui@gva.es)
84
 */
85
public class FSymbolChangeColorTocMenuEntry extends AbstractTocContextMenuAction {
86
        public String getGroup() {
87
                return "group1"; //FIXME
88
        }
89

    
90
        public int getGroupOrder() {
91
                return 10;
92
        }
93

    
94
        public int getOrder() {
95
                return 0;
96
        }
97

    
98
        public String getText() {
99
                return PluginServices.getText(this, "Cambio_Color");
100
        }
101

    
102
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
103
                return true;
104
        }
105

    
106
        public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
107
                boolean bShow = false;
108
                if (isTocItemBranch(item))
109
                {
110
                        FLayer lyr = getNodeLayer(item);
111
                    if ((lyr instanceof ClassifiableVectorial))
112
                    {
113
                        ClassifiableVectorial lyrVect = (ClassifiableVectorial) lyr;
114
                        if (lyrVect.getLegend() instanceof SingleSymbolLegend)
115
                                if (lyrVect.getLegend().getDefaultSymbol() instanceof FSymbol)
116
                            bShow = true;
117
                    }
118
                } else if (isTocItemLeaf(item)) {
119
                    //bShow = true;
120

    
121
                }
122
                return bShow;
123
        }
124

    
125
        public void execute(ITocItem item, FLayer[] selectedItems) {
126

    
127
                boolean showDialog=false;
128
                if (isTocItemBranch(item)) {
129
                        FLayer[] actives = getMapContext().getLayers().getActives();
130
                        if (actives.length > 0) {
131
                for (int i=0;i<actives.length;i++){
132
                    if ((actives[i] instanceof ClassifiableVectorial))
133
                    {
134
                        ClassifiableVectorial lyrVect = (ClassifiableVectorial) actives[i];
135
                        if (lyrVect.getLegend() instanceof SingleSymbolLegend && actives[i].isAvailable() )
136
                        {
137
                            showDialog=true;
138
                            break;
139
                        }
140
                    }
141
                }
142
                        }
143
                }
144

    
145
                if (!showDialog) return;
146

    
147
        Color newColor = JColorChooser.showDialog(null,
148
                PluginServices.getText(this, "Elegir_Color"),
149
                null);
150
        if (newColor != null)
151
        {
152
                        if (isTocItemBranch(item))
153
                        {
154
                                //FLayer lyr = getNodeLayer();
155
                FLayer[] actives = getMapContext().getLayers().getActives();
156
                for (int i=0;i<actives.length;i++){
157
                    if ((actives[i] instanceof ClassifiableVectorial))
158
                    {
159
                        ClassifiableVectorial lyrVect = (ClassifiableVectorial) actives[i];
160
                        if (lyrVect.getLegend() instanceof SingleSymbolLegend)
161
                        {
162
                            SingleSymbolLegend leg = (SingleSymbolLegend) lyrVect.getLegend();
163
                            ((FSymbol)leg.getDefaultSymbol()).setColor(newColor);
164
                        }
165
                    }
166
                }
167
                        }
168
                        else
169
                        {
170
                    TocItemLeaf leaf = (TocItemLeaf) item;
171
                    FSymbol sym = (FSymbol) leaf.getSymbol();
172
                    sym.setColor(newColor);
173

    
174
                        }
175
                // TRUCO PARA REFRESCAR.
176
                getMapContext().invalidate();
177
                Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject();
178
                        project.setModified(true);
179
                        getMapContext().callLegendChanged();
180
        }
181

    
182
        }
183
}
184