Statistics
| Revision:

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

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

    
80
        public int getGroupOrder() {
81
                return 10;
82
        }
83

    
84
        public int getOrder() {
85
                return 0;
86
        }
87

    
88
        public String getText() {
89
                return PluginServices.getText(this, "Cambio_Color");
90
        }
91

    
92
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
93
                return true;
94
        }
95

    
96
        public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
97
                boolean bShow = false;
98
                if (isTocItemBranch(item))
99
                {
100
                        FLayer lyr = getNodeLayer(item);
101
                    if ((lyr instanceof ClassifiableVectorial))
102
                    {
103
                        ClassifiableVectorial lyrVect = (ClassifiableVectorial) lyr;
104
                        if (lyrVect.getLegend() instanceof SingleSymbolLegend)
105
                                if (lyrVect.getLegend().getDefaultSymbol() instanceof FSymbol)
106
                            bShow = true;
107
                    }
108
                } else if (isTocItemLeaf(item)) {
109
                    //bShow = true;
110

    
111
                }
112
                return bShow;
113
        }
114

    
115
        public void execute(ITocItem item, FLayer[] selectedItems) {
116

    
117
                boolean showDialog=false;
118
                if (isTocItemBranch(item)) {
119
                        FLayer[] actives = getMapContext().getLayers().getActives();
120
                        if (actives.length > 0) {
121
                for (int i=0;i<actives.length;i++){
122
                    if ((actives[i] instanceof ClassifiableVectorial))
123
                    {
124
                        ClassifiableVectorial lyrVect = (ClassifiableVectorial) actives[i];
125
                        if (lyrVect.getLegend() instanceof SingleSymbolLegend && actives[i].isAvailable() )
126
                        {
127
                            showDialog=true;
128
                            break;
129
                        }
130
                    }
131
                }
132
                        }
133
                }
134

    
135
                if (!showDialog) return;
136

    
137
        Color newColor = JColorChooser.showDialog(null,
138
                PluginServices.getText(this, "Elegir_Color"),
139
                null);
140
        if (newColor != null)
141
        {
142
                        if (isTocItemBranch(item))
143
                        {
144
                                //FLayer lyr = getNodeLayer();
145
                FLayer[] actives = getMapContext().getLayers().getActives();
146
                for (int i=0;i<actives.length;i++){
147
                    if ((actives[i] instanceof ClassifiableVectorial))
148
                    {
149
                        ClassifiableVectorial lyrVect = (ClassifiableVectorial) actives[i];
150
                        if (lyrVect.getLegend() instanceof SingleSymbolLegend)
151
                        {
152
                            SingleSymbolLegend leg = (SingleSymbolLegend) lyrVect.getLegend();
153
                            ((FSymbol)leg.getDefaultSymbol()).setColor(newColor);
154
                        }
155
                    }
156
                }
157
                        }
158
                        else
159
                        {
160
                    TocItemLeaf leaf = (TocItemLeaf) item;
161
                    FSymbol sym = (FSymbol) leaf.getSymbol();
162
                    sym.setColor(newColor);
163

    
164
                        }
165
                // TRUCO PARA REFRESCAR.
166
                getMapContext().invalidate();
167

    
168
        }
169

    
170
        }
171
}
172