Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / toc / actions / ChangeSymbolTocMenuEntry.java @ 24759

History | View | Annotate | Download (6.58 KB)

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

    
3
import org.apache.log4j.Logger;
4
import org.gvsig.fmap.dal.exception.ReadException;
5
import org.gvsig.fmap.mapcontext.MapContext;
6
import org.gvsig.fmap.mapcontext.layers.FLayer;
7
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
8
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedVectorLegend;
9
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
10
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
11
import org.gvsig.fmap.mapcontext.rendering.legend.SingleSymbolLegend;
12
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
13
import org.gvsig.fmap.mapcontext.rendering.symbols.MultiLayerFillSymbol;
14

    
15
import com.iver.andami.PluginServices;
16
import com.iver.andami.messages.NotificationManager;
17
import com.iver.cit.gvsig.ProjectExtension;
18
import com.iver.cit.gvsig.gui.styling.SymbolSelector;
19
import com.iver.cit.gvsig.project.Project;
20
import com.iver.cit.gvsig.project.documents.view.legend.gui.ISymbolSelector;
21
import com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction;
22
import com.iver.cit.gvsig.project.documents.view.toc.ITocItem;
23
import com.iver.cit.gvsig.project.documents.view.toc.TocItemLeaf;
24
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
25
 *
26
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
27
 *
28
 * This program is free software; you can redistribute it and/or
29
 * modify it under the terms of the GNU General Public License
30
 * as published by the Free Software Foundation; either version 2
31
 * of the License, or (at your option) any later version.
32
 *
33
 * This program is distributed in the hope that it will be useful,
34
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
36
 * GNU General Public License for more details.
37
 *
38
 * You should have received a copy of the GNU General Public License
39
 * along with this program; if not, write to the Free Software
40
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
41
 *
42
 * For more information, contact:
43
 *
44
 *  Generalitat Valenciana
45
 *   Conselleria d'Infraestructures i Transport
46
 *   Av. Blasco Ib??ez, 50
47
 *   46010 VALENCIA
48
 *   SPAIN
49
 *
50
 *      +34 963862235
51
 *   gvsig@gva.es
52
 *      www.gvsig.gva.es
53
 *
54
 *    or
55
 *
56
 *   IVER T.I. S.A
57
 *   Salamanca 50
58
 *   46005 Valencia
59
 *   Spain
60
 *
61
 *   +34 963163400
62
 *   dac@iver.es
63
 */
64
/* CVS MESSAGES:
65
 *
66
 * $Id: ChangeSymbolTocMenuEntry.java 24759 2008-11-04 16:08:30Z jmvivo $
67
 * $Log$
68
 * Revision 1.3  2007-09-19 15:50:42  jaume
69
 * refactor name IVectorialLegend -> IVectorLegend
70
 *
71
 * Revision 1.2  2007/09/17 09:22:21  jaume
72
 * view draw frame rate now customizable
73
 *
74
 * Revision 1.1  2007/09/10 15:34:39  jaume
75
 * improvements on usability (double-clicks on TOC and some minor shorcuts)
76
 *
77
 * Revision 1.5  2007/01/04 07:24:31  caballero
78
 * isModified
79
 *
80
 * Revision 1.4  2006/10/02 13:52:34  jaume
81
 * organize impots
82
 *
83
 * Revision 1.3  2006/09/29 07:07:41  caballero
84
 * llamada a listener
85
 *
86
 * Revision 1.2  2006/09/28 15:00:45  fjp
87
 * Usar siempre que se pueda ISymbol en lugar de FSymbol
88
 *
89
 * Revision 1.1  2006/09/15 10:41:30  caballero
90
 * extensibilidad de documentos
91
 *
92
 * Revision 1.1  2006/09/12 15:58:14  jorpiell
93
 * "Sacadas" las opcines del men? de FPopupMenu
94
 *
95
 *
96
 */
97
/**
98
 * Directly opens the Symbol Selector if it is invoked from the TOC avoiding
99
 * by-passing the Layer Properties window
100
 */
101
public class ChangeSymbolTocMenuEntry extends AbstractTocContextMenuAction {
102
        public String getGroup() {
103
                return "group1"; //FIXME
104
        }
105

    
106
        public int getGroupOrder() {
107
                return 10;
108
        }
109

    
110
        public int getOrder() {
111
                return 0;
112
        }
113

    
114
        public String getText() {
115
                return PluginServices.getText(this, "change_symbol");
116
        }
117

    
118
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
119
                return true;
120
        }
121

    
122
        public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
123
                return isTocItemLeaf(item);
124
        }
125

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

    
128
                boolean showDialog = isTocItemLeaf(item);
129

    
130
                if (!showDialog) {
131
                        return;
132
                }
133

    
134
                try {
135
                        FLyrVect layer = (FLyrVect) selectedItems[0];
136
                        ISymbol oldSymbol = ((TocItemLeaf) item).getSymbol();
137
                        // patch, figure out an ellegant way to solve this
138
                        if (oldSymbol instanceof MultiLayerFillSymbol) {
139
                                MultiLayerFillSymbol ms = (MultiLayerFillSymbol) oldSymbol;
140
                                for (int i = 0; i < ms.getLayerCount(); i++) {
141
                                        if (ms.getLayer(i).getClassName().equals("org.gvsig.symbology.symbols.DotDensityFillSymbol")) {
142
                                                /*
143
                                                 * since dot density symbol works together with the
144
                                                 * legend, there is no way to edit it from the symbol selector and editor
145
                                                 * we have to break now!
146
                                                 */
147
                                                return;
148
                                        }
149
                                }
150
                        }
151
                        // end patch
152

    
153

    
154
                        int shapeType = ((IVectorLegend) layer.getLegend()).getShapeType();
155
                        if (shapeType == 0) {
156
                                Logger.getLogger(ChangeNameTocMenuEntry.class).debug("Error legend "+layer.getLegend()+" does not have shapetype initialized");
157
                                shapeType = layer.getShapeType();
158
                        }
159

    
160
                        ISymbolSelector symSel = null;
161

    
162
                        try {
163
                                symSel = SymbolSelector.createSymbolSelector(oldSymbol, shapeType);
164
                        } catch (IllegalArgumentException iaEx) {
165
                                /*
166
                                 * this usually happens when the Legend has a composed
167
                                 * symbol that collides with the normal operation and
168
                                 * it only can be changed from the panel of the legend
169
                                 */
170
                                // TODO throw a signal and show a warning message box telling
171
                                // that the operation cannot be performed
172
                                return;
173
                        }
174
                        PluginServices.getMDIManager().addWindow(symSel);
175
                        ISymbol newSymbol = (ISymbol) symSel.getSelectedObject();
176

    
177
                        if (newSymbol == null) {
178
                                return;
179
                        }
180

    
181
                        newSymbol.setDescription(oldSymbol.getDescription());
182

    
183
                        for (int i = 0; i < selectedItems.length; i++) {
184
                                FLyrVect theLayer = ((FLyrVect) selectedItems[i]);
185

    
186
                                try {
187
                                        ILegend legend = theLayer.getLegend();
188
                                        if (legend instanceof IClassifiedVectorLegend) {
189
                                                IClassifiedVectorLegend cv = (IClassifiedVectorLegend) legend;
190
                                                cv.replace(oldSymbol, newSymbol);
191
                                        } else if (legend instanceof SingleSymbolLegend) {
192
                                                SingleSymbolLegend ss = (SingleSymbolLegend) legend;
193
                                                ss.setDefaultSymbol(newSymbol);
194
                                        }
195
                                } catch (Exception e) {
196
                                        NotificationManager.addWarning(PluginServices.getText(this, "skipped_symbol_changed_for_layer")+": "+theLayer.getName(), e);
197
                                }
198

    
199
                        }
200
                     // refresh view treak
201
                        MapContext mc = layer.getMapContext();
202
                        mc.invalidate();
203
                        Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject();
204
                        project.setModified(true);
205
                        mc.callLegendChanged();
206

    
207
                } catch (ReadException e) {
208
                        NotificationManager.addError(PluginServices.getText(this, "getting_shape_type"), e);
209
                }
210
        }
211
}
212