Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2057 / applications / appgvSIG / src / org / gvsig / app / project / documents / view / legend / gui / SingleSymbol.java @ 39147

History | View | Annotate | Download (8.58 KB)

1
/*
2
 * Created on 30-abr-2004
3
 *
4
 * To change the template for this generated file go to
5
 * Window>Preferences>Java>Code Generation>Code and Comments
6
 */
7
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
8
 *
9
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
10
 *
11
 * This program is free software; you can redistribute it and/or
12
 * modify it under the terms of the GNU General Public License
13
 * as published by the Free Software Foundation; either version 2
14
 * of the License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
24
 *
25
 * For more information, contact:
26
 *
27
 *  Generalitat Valenciana
28
 *   Conselleria d'Infraestructures i Transport
29
 *   Av. Blasco Ib??ez, 50
30
 *   46010 VALENCIA
31
 *   SPAIN
32
 *
33
 *      +34 963862235
34
 *   gvsig@gva.es
35
 *      www.gvsig.gva.es
36
 *
37
 *    or
38
 *
39
 *   IVER T.I. S.A
40
 *   Salamanca 50
41
 *   46005 Valencia
42
 *   Spain
43
 *
44
 *   +34 963163400
45
 *   dac@iver.es
46
 */
47
package org.gvsig.app.project.documents.view.legend.gui;
48

    
49
import java.awt.Dimension;
50
import java.awt.event.ActionEvent;
51
import java.awt.event.ActionListener;
52

    
53
import javax.swing.BorderFactory;
54
import javax.swing.BoxLayout;
55
import javax.swing.ImageIcon;
56
import javax.swing.JComponent;
57
import javax.swing.JPanel;
58
import javax.swing.JTextField;
59
import javax.swing.border.TitledBorder;
60

    
61
import org.gvsig.andami.IconThemeHelper;
62
import org.gvsig.andami.PluginServices;
63
import org.gvsig.andami.messages.NotificationManager;
64
import org.gvsig.app.gui.styling.SymbolLevelsWindow;
65
import org.gvsig.app.gui.styling.SymbolPreviewer;
66
import org.gvsig.app.gui.styling.SymbolSelector;
67
import org.gvsig.fmap.dal.exception.ReadException;
68
import org.gvsig.fmap.mapcontext.MapContextLocator;
69
import org.gvsig.fmap.mapcontext.layers.FLayer;
70
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
71
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend;
72
import org.gvsig.fmap.mapcontext.rendering.legend.ZSort;
73
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
74
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
75
import org.gvsig.gui.beans.swing.JButton;
76
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractVectorialLegend;
77
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.SingleSymbolLegend;
78

    
79

    
80
/**
81
 * @author jaume dominguez faus - jaume.dominguez@iver.es
82
 */
83
public class SingleSymbol extends JPanel implements ILegendPanel, ActionListener {
84
        private JPanel symbolPanel = null;
85
        private int shapeType;
86
        private GridBagLayoutPanel legendPanel = null;
87
        private SymbolPreviewer symbolPreviewComponent;
88
        private JButton btnOpenSymbolSelector;
89
        private JTextField txtLabel;
90
        private JButton btnOpenSymbolLevelsEditor;
91
        private SingleSymbolLegend legend;
92
        private ZSort zSort;
93

    
94

    
95
        public SingleSymbol() {
96
                super();
97
                initialize();
98
        }
99
        /**
100
         * This method initializes this
101
         *
102
         */
103
        private void initialize() {
104
        this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
105
        this.setSize(new java.awt.Dimension(490,379));
106
        this.add(getSymbolPanel(), null);
107
        this.add(getLegendPanel(), null);
108

    
109
        }
110

    
111
        public void setData(FLayer lyr, ILegend legend) {
112
                try {
113
                        shapeType = ((FLyrVect) lyr).getShapeType();
114
                } catch (ReadException e) {
115
                        NotificationManager.addError("Could not find out the shape type" ,e);
116
                }
117
                if (legend instanceof SingleSymbolLegend) {
118
                        setSymbol(legend.getDefaultSymbol());
119
                        this.legend = (SingleSymbolLegend) legend;
120

    
121
                } else {
122
                        this.legend = (SingleSymbolLegend) MapContextLocator
123
                                        .getMapContextManager().createLegend(
124
                                                        SingleSymbolLegend.LEGEND_NAME);
125
                        this.legend.setShapeType(shapeType);
126
//                        LegendFactory.
127
//                                        createSingleSymbolLegend(shapeType);
128
                }
129
                getSymbolPreviewPanel().setSymbol(this.legend.getDefaultSymbol());
130
                getBtnOpenSymbolLevelsEditor().setEnabled(legend!=null);
131
                this.txtLabel.setText(legend.getDefaultSymbol().getDescription());
132
        }
133

    
134
        /* (non-Javadoc)
135
         * @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
136
         */
137
        public ILegend getLegend() {
138
                ISymbol symbol = getSymbolPreviewPanel().getSymbol();
139
                symbol.setDescription(txtLabel.getText());
140
                AbstractVectorialLegend leg = new SingleSymbolLegend();
141
                leg.setShapeType(shapeType);
142
                leg.setDefaultSymbol(symbol);
143
                leg.setZSort(zSort);
144
                return leg;
145
        }
146

    
147
        public String getDescription() {
148
                return PluginServices.getText(this,"Muestra_todos_s_elementos_de_una_capa_usando_el_mismo_simbolo");
149
        }
150

    
151
        public Class getParentClass() {
152
                return Features.class;
153
        }
154

    
155
        public String getTitle() {
156
                return PluginServices.getText(this,"Simbolo_unico");
157
        }
158

    
159
        public JPanel getPanel() {
160
                return this;
161
        }
162

    
163
        public ImageIcon getIcon() {
164
                return IconThemeHelper.getImageIcon("legend-overview-single-symbol");
165
        }
166

    
167
        public Class getLegendClass() {
168
                return SingleSymbolLegend.class;
169
        }
170
        /**
171
         * This method initializes symbolPanel
172
         *
173
         * @return javax.swing.JPanel
174
         */
175
        private JPanel getSymbolPanel() {
176
                if (symbolPanel == null) {
177
                        symbolPanel = new JPanel();
178
                        symbolPanel.setBorder(
179
                                        BorderFactory.createTitledBorder(null, "symbol", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
180
                        symbolPanel.add(getSymbolPreviewPanel());
181
                        symbolPanel.add(getBtnOpenSymbolSelector());
182
                        symbolPanel.add(getBtnOpenSymbolLevelsEditor());
183
                }
184
                return symbolPanel;
185
        }
186

    
187
        private JButton getBtnOpenSymbolLevelsEditor() {
188
                if (btnOpenSymbolLevelsEditor == null) {
189
                        btnOpenSymbolLevelsEditor = new JButton(PluginServices.getText(this, "symbol_levels"));
190
                        btnOpenSymbolLevelsEditor.addActionListener(this);
191
                        btnOpenSymbolLevelsEditor.setEnabled(legend != null);
192
                }
193

    
194
                return btnOpenSymbolLevelsEditor;
195
        }
196
        private JButton getBtnOpenSymbolSelector() {
197
                if (btnOpenSymbolSelector == null) {
198
                        btnOpenSymbolSelector = new JButton();
199
                        btnOpenSymbolSelector.setText(PluginServices.getText(this, "choose_symbol"));
200
                        btnOpenSymbolSelector.addActionListener(this);
201
                }
202
                return btnOpenSymbolSelector;
203
        }
204

    
205
        private SymbolPreviewer getSymbolPreviewPanel() {
206
                if (symbolPreviewComponent == null) {
207
                        symbolPreviewComponent = new SymbolPreviewer();
208
                        symbolPreviewComponent.setBorder(BorderFactory.createBevelBorder(1));
209
                        symbolPreviewComponent.setPreferredSize(new Dimension(120, 40));
210
                }
211
                return symbolPreviewComponent;
212
        }
213
        /**
214
         * This method initializes legendPanel
215
         *
216
         * @return javax.swing.JPanel
217
         */
218
        private GridBagLayoutPanel getLegendPanel() {
219
                if (legendPanel == null) {
220
                        legendPanel = new GridBagLayoutPanel();
221
                        legendPanel.setBorder(BorderFactory.createTitledBorder(null,
222
                                        PluginServices.getText(this, "legend"), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
223
                        legendPanel.addComponent(PluginServices.getText(this, "label_text_in_the_TOC") + ":", txtLabel = new JTextField(25));
224
                        txtLabel.addActionListener(this);
225
                }
226
                return legendPanel;
227
        }
228

    
229
        public void setShapeType(int shapeType) {
230
                this.shapeType = shapeType;
231
        }
232

    
233
        public void setSymbol(ISymbol symbol) {
234
                setOnlySymbol(symbol);
235
                if(symbol.getDescription() != null) {
236
                        txtLabel.setText(symbol.getDescription());
237
                }
238
        }
239

    
240
        private void setOnlySymbol(ISymbol symbol){
241
                getSymbolPreviewPanel().setSymbol(symbol);
242
                if (legend != null){
243
                        legend.setDefaultSymbol(symbol);
244
                }
245
        }
246

    
247

    
248
        public ISymbol getSymbol() {
249
                ISymbol symbol = getSymbolPreviewPanel().getSymbol();
250
                symbol.setDescription(txtLabel.getText());
251
                return symbol;
252
        }
253
        public boolean isSuitableFor(FLayer layer) {
254
                return (layer instanceof FLyrVect) ;
255
        }
256

    
257
        public void actionPerformed(ActionEvent e) {
258
                JComponent c = (JComponent) e.getSource();
259
                if (c.equals(getBtnOpenSymbolSelector())){
260
                        ISymbolSelector se = SymbolSelector.createSymbolSelector(getSymbol(), shapeType);
261
                        PluginServices.getMDIManager().addWindow(se);
262
                        ISymbol sym = (ISymbol) se.getSelectedObject();
263
                        if (sym != null) {
264
                                // no symbol, no changes
265
                                setOnlySymbol(sym);
266
                        }
267
                } else if (c.equals(getBtnOpenSymbolLevelsEditor())){
268
                        if (legend != null) {
269
                                ZSort myZSort = legend.getZSort();
270
                                if (myZSort == null) {
271
                                        myZSort = new ZSort(legend);
272
                                }
273
                                SymbolLevelsWindow sl = new SymbolLevelsWindow(myZSort);
274
                                PluginServices.getMDIManager().addWindow(sl);
275
                                zSort = sl.getZSort();
276
                        }
277
                }else if (c.equals(txtLabel)){
278
                        getSymbolPreviewPanel().getSymbol().setDescription(txtLabel.getText());
279
                }
280
        }
281

    
282
}