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 / toc / actions / ChangeSymbolTocMenuEntry.java @ 40558

History | View | Annotate | Download (7.76 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.toc.actions;
25

    
26
import org.gvsig.andami.PluginServices;
27
import org.gvsig.andami.messages.NotificationManager;
28
import org.gvsig.app.extension.ProjectExtension;
29
import org.gvsig.app.gui.styling.SymbolSelector;
30
import org.gvsig.app.project.Project;
31
import org.gvsig.app.project.documents.view.legend.gui.ISymbolSelector;
32
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction;
33
import org.gvsig.app.project.documents.view.toc.ITocItem;
34
import org.gvsig.app.project.documents.view.toc.TocItemLeaf;
35
import org.gvsig.fmap.dal.exception.ReadException;
36
import org.gvsig.fmap.mapcontext.MapContext;
37
import org.gvsig.fmap.mapcontext.layers.FLayer;
38
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
39
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedVectorLegend;
40
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
41
import org.gvsig.fmap.mapcontext.rendering.legend.ISingleSymbolLegend;
42
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend;
43
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
44
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.MultiLayerFillSymbol;
45
import org.slf4j.Logger;
46
import org.slf4j.LoggerFactory;
47

    
48
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
49
 *
50
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
51
 *
52
 * This program is free software; you can redistribute it and/or
53
 * modify it under the terms of the GNU General Public License
54
 * as published by the Free Software Foundation; either version 2
55
 * of the License, or (at your option) any later version.
56
 *
57
 * This program is distributed in the hope that it will be useful,
58
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
59
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
60
 * GNU General Public License for more details.
61
 *
62
 * You should have received a copy of the GNU General Public License
63
 * along with this program; if not, write to the Free Software
64
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
65
 *
66
 * For more information, contact:
67
 *
68
 *  Generalitat Valenciana
69
 *   Conselleria d'Infraestructures i Transport
70
 *   Av. Blasco Ib??ez, 50
71
 *   46010 VALENCIA
72
 *   SPAIN
73
 *
74
 *      +34 963862235
75
 *   gvsig@gva.es
76
 *      www.gvsig.gva.es
77
 *
78
 *    or
79
 *
80
 *   IVER T.I. S.A
81
 *   Salamanca 50
82
 *   46005 Valencia
83
 *   Spain
84
 *
85
 *   +34 963163400
86
 *   dac@iver.es
87
 */
88
/* CVS MESSAGES:
89
 *
90
 * $Id: ChangeSymbolTocMenuEntry.java 31631 2009-11-17 09:15:25Z jpiera $
91
 * $Log$
92
 * Revision 1.3  2007-09-19 15:50:42  jaume
93
 * refactor name IVectorialLegend -> IVectorLegend
94
 *
95
 * Revision 1.2  2007/09/17 09:22:21  jaume
96
 * view draw frame rate now customizable
97
 *
98
 * Revision 1.1  2007/09/10 15:34:39  jaume
99
 * improvements on usability (double-clicks on TOC and some minor shorcuts)
100
 *
101
 * Revision 1.5  2007/01/04 07:24:31  caballero
102
 * isModified
103
 *
104
 * Revision 1.4  2006/10/02 13:52:34  jaume
105
 * organize impots
106
 *
107
 * Revision 1.3  2006/09/29 07:07:41  caballero
108
 * llamada a listener
109
 *
110
 * Revision 1.2  2006/09/28 15:00:45  fjp
111
 * Usar siempre que se pueda ISymbol en lugar de FSymbol
112
 *
113
 * Revision 1.1  2006/09/15 10:41:30  caballero
114
 * extensibilidad de documentos
115
 *
116
 * Revision 1.1  2006/09/12 15:58:14  jorpiell
117
 * "Sacadas" las opcines del men? de FPopupMenu
118
 *
119
 *
120
 */
121
/**
122
 * Directly opens the Symbol Selector if it is invoked from the TOC avoiding
123
 * by-passing the Layer Properties window
124
 */
125
public class ChangeSymbolTocMenuEntry extends AbstractTocContextMenuAction {
126
    private static final Logger logger = LoggerFactory
127
            .getLogger(ChangeSymbolTocMenuEntry.class);
128

    
129
        public String getGroup() {
130
                return "group1"; //FIXME
131
        }
132

    
133
        public int getGroupOrder() {
134
                return 10;
135
        }
136

    
137
        public int getOrder() {
138
                return 0;
139
        }
140

    
141
        public String getText() {
142
                return PluginServices.getText(this, "change_symbol");
143
        }
144

    
145
        public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
146
                return true;
147
        }
148

    
149
        public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
150
                return isTocItemLeaf(item);
151
        }
152

    
153
        public void execute(ITocItem item, FLayer[] selectedItems) {
154

    
155
                boolean showDialog = isTocItemLeaf(item);
156

    
157
                if (!showDialog) {
158
                        return;
159
                }
160

    
161
                try {
162
                        if(!(selectedItems[0] instanceof FLyrVect))
163
                                return;
164
                        FLyrVect layer = (FLyrVect) selectedItems[0];
165
                        ISymbol oldSymbol = ((TocItemLeaf) item).getSymbol();
166
                        // patch, figure out an ellegant way to solve this
167
                        if (oldSymbol instanceof MultiLayerFillSymbol) {
168
                                MultiLayerFillSymbol ms = (MultiLayerFillSymbol) oldSymbol;
169
                                for (int i = 0; i < ms.getLayerCount(); i++) {
170
                                        if (ms.getLayer(i).getClass().getName().equals("org.gvsig.symbology.symbols.DotDensityFillSymbol")) {
171
                                                /*
172
                                                 * since dot density symbol works together with the
173
                                                 * legend, there is no way to edit it from the symbol selector and editor
174
                                                 * we have to break now!
175
                                                 */
176
                                                return;
177
                                        }
178
                                }
179
                        }
180
                        // end patch
181

    
182

    
183
                        int shapeType = ((IVectorLegend) layer.getLegend()).getShapeType();
184
                        if (shapeType == 0) {
185
                                logger.debug("Error legend " + layer.getLegend()
186
                        + " does not have shapetype initialized");
187
                                shapeType = layer.getShapeType();
188
                        }
189

    
190
                        ISymbolSelector symSel = null;
191

    
192
                        try {
193
                                symSel = SymbolSelector.createSymbolSelector(oldSymbol, shapeType);
194
                        } catch (IllegalArgumentException iaEx) {
195
                                /*
196
                                 * this usually happens when the Legend has a composed
197
                                 * symbol that collides with the normal operation and
198
                                 * it only can be changed from the panel of the legend
199
                                 */
200
                                // TODO throw a signal and show a warning message box telling
201
                                // that the operation cannot be performed
202
                                return;
203
                        }
204
                        PluginServices.getMDIManager().addWindow(symSel);
205
                        ISymbol newSymbol = (ISymbol) symSel.getSelectedObject();
206

    
207
                        if (newSymbol == null) {
208
                                return;
209
                        }
210

    
211
                        newSymbol.setDescription(oldSymbol.getDescription());
212

    
213
                        for (int i = 0; i < selectedItems.length; i++) {
214
                                FLyrVect theLayer = ((FLyrVect) selectedItems[i]);
215

    
216
                                try {
217
                                        ILegend legend = theLayer.getLegend();
218
                                        if (legend instanceof IClassifiedVectorLegend) {
219
                                                IClassifiedVectorLegend cv = (IClassifiedVectorLegend) legend;
220
                                                cv.replace(oldSymbol, newSymbol);
221
                                        } else if (legend instanceof ISingleSymbolLegend) {
222
                                                ISingleSymbolLegend ss = (ISingleSymbolLegend) legend;
223
                                                ss.setDefaultSymbol(newSymbol);
224
                                        }
225
                                } catch (Exception e) {
226
                                        NotificationManager.addWarning(PluginServices.getText(this, "skipped_symbol_changed_for_layer")+": "+theLayer.getName(), e);
227
                                }
228

    
229
                        }
230
                     // refresh view treak
231
                        MapContext mc = layer.getMapContext();
232
                        mc.invalidate();
233
                        Project project=((ProjectExtension)PluginServices.getExtension(ProjectExtension.class)).getProject();
234
                        project.setModified(true);
235
                        mc.callLegendChanged();
236

    
237
                } catch (ReadException e) {
238
                        NotificationManager.addError(PluginServices.getText(this, "getting_shape_type"), e);
239
                }
240
        }
241
}
242