Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / toc / actions / FSymbolChangeColorTocMenuEntry.java @ 7223

History | View | Annotate | Download (4.68 KB)

1
package com.iver.cit.gvsig.gui.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.gui.toc.AbstractTocContextMenuAction;
13
import com.iver.cit.gvsig.gui.toc.ITocItem;
14
import com.iver.cit.gvsig.gui.toc.TocItemLeaf;
15

    
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 7223 2006-09-12 15:58:14Z jorpiell $
59
 * $Log$
60
 * Revision 1.1  2006-09-12 15:58:14  jorpiell
61
 * "Sacadas" las opcines del men? de FPopupMenu
62
 *
63
 *
64
 */
65
/**
66
 * Realiza el cambio de color si se pulsa OK
67
 * @author Luis W. Sevilla (sevilla_lui@gva.es)
68
 */
69
public class FSymbolChangeColorTocMenuEntry extends AbstractTocContextMenuAction {
70
        public String getGroup() {
71
                return "group1"; //FIXME
72
        }
73

    
74
        public int getGroupOrder() {
75
                return 10;
76
        }
77

    
78
        public int getOrder() {
79
                return 0;
80
        }
81

    
82
        public String getText() {
83
                return PluginServices.getText(this, "Cambio_Color");
84
        }
85

    
86
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
87
                return true;
88
        }
89

    
90
        public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
91
                boolean bShow = false;
92
                if (isTocItemBranch(item))
93
                {
94
                        FLayer lyr = getNodeLayer(item);
95
                    if ((lyr instanceof ClassifiableVectorial))
96
                    {
97
                        ClassifiableVectorial lyrVect = (ClassifiableVectorial) lyr;
98
                        if (lyrVect.getLegend() instanceof SingleSymbolLegend)
99
                            bShow = true;
100
                    }
101
                } else if (isTocItemLeaf(item)) {
102
                    //bShow = true;
103

    
104
                }
105
                return bShow;
106
        }
107

    
108
        public void execute(ITocItem item, FLayer[] selectedItems) {
109

    
110
                boolean showDialog=false;
111
                if (isTocItemBranch(item)) {
112
                        FLayer[] actives = getMapContext().getLayers().getActives();
113
                        if (actives.length > 0) {
114
                for (int i=0;i<actives.length;i++){
115
                    if ((actives[i] instanceof ClassifiableVectorial))
116
                    {
117
                        ClassifiableVectorial lyrVect = (ClassifiableVectorial) actives[i];
118
                        if (lyrVect.getLegend() instanceof SingleSymbolLegend && actives[i].isAvailable() )
119
                        {
120
                            showDialog=true;
121
                            break;
122
                        }
123
                    }
124
                }
125
                        }
126
                }
127

    
128
                if (!showDialog) return;
129

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

    
157
                        }
158
                // TRUCO PARA REFRESCAR.
159
                getMapContext().invalidate();
160

    
161
        }
162

    
163
        }
164
}
165