Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / legend / gui / SingleSymbol.java @ 39117

History | View | Annotate | Download (8.56 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(symbol);
141
                leg.setShapeType(shapeType);
142
                leg.setZSort(zSort);
143
                return leg;
144
        }
145

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

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

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

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

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

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

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

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

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

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

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

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

    
246

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

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

    
281
}