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 / legend / gui / SingleSymbol.java @ 40558

History | View | Annotate | Download (9.52 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
/*
25
 * Created on 30-abr-2004
26
 *
27
 * To change the template for this generated file go to
28
 * Window>Preferences>Java>Code Generation>Code and Comments
29
 */
30
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
31
 *
32
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
33
 *
34
 * This program is free software; you can redistribute it and/or
35
 * modify it under the terms of the GNU General Public License
36
 * as published by the Free Software Foundation; either version 2
37
 * of the License, or (at your option) any later version.
38
 *
39
 * This program is distributed in the hope that it will be useful,
40
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
41
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
42
 * GNU General Public License for more details.
43
 *
44
 * You should have received a copy of the GNU General Public License
45
 * along with this program; if not, write to the Free Software
46
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
47
 *
48
 * For more information, contact:
49
 *
50
 *  Generalitat Valenciana
51
 *   Conselleria d'Infraestructures i Transport
52
 *   Av. Blasco Ib??ez, 50
53
 *   46010 VALENCIA
54
 *   SPAIN
55
 *
56
 *      +34 963862235
57
 *   gvsig@gva.es
58
 *      www.gvsig.gva.es
59
 *
60
 *    or
61
 *
62
 *   IVER T.I. S.A
63
 *   Salamanca 50
64
 *   46005 Valencia
65
 *   Spain
66
 *
67
 *   +34 963163400
68
 *   dac@iver.es
69
 */
70
package org.gvsig.app.project.documents.view.legend.gui;
71

    
72
import java.awt.Dimension;
73
import java.awt.event.ActionEvent;
74
import java.awt.event.ActionListener;
75

    
76
import javax.swing.BorderFactory;
77
import javax.swing.BoxLayout;
78
import javax.swing.ImageIcon;
79
import javax.swing.JComponent;
80
import javax.swing.JPanel;
81
import javax.swing.JTextField;
82
import javax.swing.border.TitledBorder;
83

    
84
import org.gvsig.andami.IconThemeHelper;
85
import org.gvsig.andami.PluginServices;
86
import org.gvsig.andami.messages.NotificationManager;
87
import org.gvsig.app.gui.styling.SymbolLevelsWindow;
88
import org.gvsig.app.gui.styling.SymbolPreviewer;
89
import org.gvsig.app.gui.styling.SymbolSelector;
90
import org.gvsig.fmap.dal.exception.ReadException;
91
import org.gvsig.fmap.mapcontext.MapContextLocator;
92
import org.gvsig.fmap.mapcontext.layers.FLayer;
93
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
94
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
95
import org.gvsig.fmap.mapcontext.rendering.legend.ZSort;
96
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
97
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
98
import org.gvsig.gui.beans.swing.JButton;
99
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractVectorialLegend;
100
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.SingleSymbolLegend;
101

    
102

    
103
/**
104
 * @author jaume dominguez faus - jaume.dominguez@iver.es
105
 */
106
public class SingleSymbol extends JPanel implements ILegendPanel, ActionListener {
107
        private JPanel symbolPanel = null;
108
        private int shapeType;
109
        private GridBagLayoutPanel legendPanel = null;
110
        private SymbolPreviewer symbolPreviewComponent;
111
        private JButton btnOpenSymbolSelector;
112
        private JTextField txtLabel;
113
        private JButton btnOpenSymbolLevelsEditor;
114
        private SingleSymbolLegend legend;
115
        private ZSort zSort;
116

    
117

    
118
        public SingleSymbol() {
119
                super();
120
                initialize();
121
        }
122
        /**
123
         * This method initializes this
124
         *
125
         */
126
        private void initialize() {
127
        this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
128
        this.setSize(new java.awt.Dimension(490,379));
129
        this.add(getSymbolPanel(), null);
130
        this.add(getLegendPanel(), null);
131

    
132
        }
133

    
134
        public void setData(FLayer lyr, ILegend legend) {
135
                try {
136
                        shapeType = ((FLyrVect) lyr).getShapeType();
137
                } catch (ReadException e) {
138
                        NotificationManager.addError("Could not find out the shape type" ,e);
139
                }
140
                if (legend instanceof SingleSymbolLegend) {
141
                        setSymbol(legend.getDefaultSymbol());
142
                        this.legend = (SingleSymbolLegend) legend;
143

    
144
                } else {
145
                        this.legend = (SingleSymbolLegend) MapContextLocator
146
                                        .getMapContextManager().createLegend(
147
                                                        SingleSymbolLegend.LEGEND_NAME);
148
                        this.legend.setShapeType(shapeType);
149
//                        LegendFactory.
150
//                                        createSingleSymbolLegend(shapeType);
151
                }
152
                getSymbolPreviewPanel().setSymbol(this.legend.getDefaultSymbol());
153
                getBtnOpenSymbolLevelsEditor().setEnabled(legend!=null);
154
                this.txtLabel.setText(legend.getDefaultSymbol().getDescription());
155
        }
156

    
157
        /* (non-Javadoc)
158
         * @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
159
         */
160
        public ILegend getLegend() {
161
                ISymbol symbol = getSymbolPreviewPanel().getSymbol();
162
                symbol.setDescription(txtLabel.getText());
163
                AbstractVectorialLegend leg = new SingleSymbolLegend();
164
                leg.setShapeType(shapeType);
165
                leg.setDefaultSymbol(symbol);
166
                leg.setZSort(zSort);
167
                return leg;
168
        }
169

    
170
        public String getDescription() {
171
                return PluginServices.getText(this,"Muestra_todos_s_elementos_de_una_capa_usando_el_mismo_simbolo");
172
        }
173

    
174
        public Class getParentClass() {
175
                return Features.class;
176
        }
177

    
178
        public String getTitle() {
179
                return PluginServices.getText(this,"Simbolo_unico");
180
        }
181

    
182
        public JPanel getPanel() {
183
                return this;
184
        }
185

    
186
        public ImageIcon getIcon() {
187
                return IconThemeHelper.getImageIcon("legend-overview-single-symbol");
188
        }
189

    
190
        public Class getLegendClass() {
191
                return SingleSymbolLegend.class;
192
        }
193
        /**
194
         * This method initializes symbolPanel
195
         *
196
         * @return javax.swing.JPanel
197
         */
198
        private JPanel getSymbolPanel() {
199
                if (symbolPanel == null) {
200
                        symbolPanel = new JPanel();
201
                        symbolPanel.setBorder(
202
                                        BorderFactory.createTitledBorder(null, "symbol", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
203
                        symbolPanel.add(getSymbolPreviewPanel());
204
                        symbolPanel.add(getBtnOpenSymbolSelector());
205
                        symbolPanel.add(getBtnOpenSymbolLevelsEditor());
206
                }
207
                return symbolPanel;
208
        }
209

    
210
        private JButton getBtnOpenSymbolLevelsEditor() {
211
                if (btnOpenSymbolLevelsEditor == null) {
212
                        btnOpenSymbolLevelsEditor = new JButton(PluginServices.getText(this, "symbol_levels"));
213
                        btnOpenSymbolLevelsEditor.addActionListener(this);
214
                        btnOpenSymbolLevelsEditor.setEnabled(legend != null);
215
                }
216

    
217
                return btnOpenSymbolLevelsEditor;
218
        }
219
        private JButton getBtnOpenSymbolSelector() {
220
                if (btnOpenSymbolSelector == null) {
221
                        btnOpenSymbolSelector = new JButton();
222
                        btnOpenSymbolSelector.setText(PluginServices.getText(this, "choose_symbol"));
223
                        btnOpenSymbolSelector.addActionListener(this);
224
                }
225
                return btnOpenSymbolSelector;
226
        }
227

    
228
        private SymbolPreviewer getSymbolPreviewPanel() {
229
                if (symbolPreviewComponent == null) {
230
                        symbolPreviewComponent = new SymbolPreviewer();
231
                        symbolPreviewComponent.setBorder(BorderFactory.createBevelBorder(1));
232
                        symbolPreviewComponent.setPreferredSize(new Dimension(120, 40));
233
                }
234
                return symbolPreviewComponent;
235
        }
236
        /**
237
         * This method initializes legendPanel
238
         *
239
         * @return javax.swing.JPanel
240
         */
241
        private GridBagLayoutPanel getLegendPanel() {
242
                if (legendPanel == null) {
243
                        legendPanel = new GridBagLayoutPanel();
244
                        legendPanel.setBorder(BorderFactory.createTitledBorder(null,
245
                                        PluginServices.getText(this, "legend"), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
246
                        legendPanel.addComponent(PluginServices.getText(this, "label_text_in_the_TOC") + ":", txtLabel = new JTextField(25));
247
                        txtLabel.addActionListener(this);
248
                }
249
                return legendPanel;
250
        }
251

    
252
        public void setShapeType(int shapeType) {
253
                this.shapeType = shapeType;
254
        }
255

    
256
        public void setSymbol(ISymbol symbol) {
257
                setOnlySymbol(symbol);
258
                if(symbol.getDescription() != null) {
259
                        txtLabel.setText(symbol.getDescription());
260
                }
261
        }
262

    
263
        private void setOnlySymbol(ISymbol symbol){
264
                getSymbolPreviewPanel().setSymbol(symbol);
265
                if (legend != null){
266
                        legend.setDefaultSymbol(symbol);
267
                }
268
        }
269

    
270

    
271
        public ISymbol getSymbol() {
272
                ISymbol symbol = getSymbolPreviewPanel().getSymbol();
273
                symbol.setDescription(txtLabel.getText());
274
                return symbol;
275
        }
276
        public boolean isSuitableFor(FLayer layer) {
277
                return (layer instanceof FLyrVect) ;
278
        }
279

    
280
        public void actionPerformed(ActionEvent e) {
281
                JComponent c = (JComponent) e.getSource();
282
                if (c.equals(getBtnOpenSymbolSelector())){
283
                        ISymbolSelector se = SymbolSelector.createSymbolSelector(getSymbol(), shapeType);
284
                        PluginServices.getMDIManager().addWindow(se);
285
                        ISymbol sym = (ISymbol) se.getSelectedObject();
286
                        if (sym != null) {
287
                                // no symbol, no changes
288
                                setOnlySymbol(sym);
289
                        }
290
                } else if (c.equals(getBtnOpenSymbolLevelsEditor())){
291
                        if (legend != null) {
292
                                ZSort myZSort = legend.getZSort();
293
                                if (myZSort == null) {
294
                                        myZSort = new ZSort(legend);
295
                                }
296
                                SymbolLevelsWindow sl = new SymbolLevelsWindow(myZSort);
297
                                PluginServices.getMDIManager().addWindow(sl);
298
                                zSort = sl.getZSort();
299
                        }
300
                }else if (c.equals(txtLabel)){
301
                        getSymbolPreviewPanel().getSymbol().setDescription(txtLabel.getText());
302
                }
303
        }
304

    
305
}