Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / legend / gui / SingleSymbol.java @ 11734

History | View | Annotate | Download (7.53 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 com.iver.cit.gvsig.project.documents.view.legend.gui;
48

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

    
54
import javax.swing.BorderFactory;
55
import javax.swing.BoxLayout;
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.gui.beans.swing.GridBagLayoutPanel;
62
import org.gvsig.gui.beans.swing.JButton;
63

    
64
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
65
import com.iver.andami.PluginServices;
66
import com.iver.andami.messages.NotificationManager;
67
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
68
import com.iver.cit.gvsig.fmap.core.symbols.PictureMarkerSymbol;
69
import com.iver.cit.gvsig.fmap.layers.FLayer;
70
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
71
import com.iver.cit.gvsig.fmap.rendering.ILegend;
72
import com.iver.cit.gvsig.fmap.rendering.ZSort;
73
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend;
74
import com.iver.cit.gvsig.gui.styling.SymbolLevelsWindow;
75
import com.iver.cit.gvsig.gui.styling.SymbolPreviewer;
76
import com.iver.cit.gvsig.gui.styling.SymbolSelector;
77

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

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

    
106
        }
107

    
108
        public void setData(FLayer lyr, ILegend legend) {
109
                try {
110
                        shapeType = ((FLyrVect) lyr).getShapeType();
111
                } catch (ReadDriverException e) {
112
                        NotificationManager.addError("Could not find out the shape type" ,e);
113
                }
114
                if (legend instanceof SingleSymbolLegend) {
115
                        setSymbol(legend.getDefaultSymbol());
116
                        this.legend = (SingleSymbolLegend) legend;
117
                } else {
118
                        // TODO calculate a default symbol
119
                }
120

    
121
        }
122

    
123
        /* (non-Javadoc)
124
         * @see com.iver.cit.gvsig.gui.legendmanager.panels.ILegendPanel#getLegend()
125
         */
126
        public ILegend getLegend() {
127
                return new SingleSymbolLegend(getSymbolPreviewPanel().getSymbol());
128
        }
129

    
130
        public String getDescription() {
131
                return PluginServices.getText(this,"Muestra_todos_los_elementos_de_una_capa_usando_el_mismo_simbolo");
132
        }
133

    
134
        public Class getParentClass() {
135
                return Features.class;
136
        }
137

    
138
        public String getTitle() {
139
                return PluginServices.getText(this,"Simbolo_unico");
140
        }
141

    
142
        public JPanel getPanel() {
143
                return this;
144
        }
145

    
146
        public ISymbol getPreviewSymbol() {
147
                if (previewSymbol == null) {
148
                        try {
149
                                previewSymbol = new PictureMarkerSymbol(
150
                                                this.getClass().getClassLoader()
151
                                                                .getResource("images/single-symbol.png"));
152
                        } catch (IOException e) {
153
                                return null;
154
                        }
155
                }
156
                return previewSymbol;
157
        }
158

    
159
        public Class getLegendClass() {
160
                return SingleSymbolLegend.class;
161
        }
162
        /**
163
         * This method initializes symbolPanel
164
         *
165
         * @return javax.swing.JPanel
166
         */
167
        private JPanel getSymbolPanel() {
168
                if (symbolPanel == null) {
169
                        symbolPanel = new JPanel();
170
                        symbolPanel.setBorder(
171
                                        BorderFactory.createTitledBorder(null, "symbol", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
172
                        symbolPanel.add(getSymbolPreviewPanel());
173
                        symbolPanel.add(getBtnOpenSymbolSelector());
174
                        symbolPanel.add(getBtnOpenSymbolLevelsEditor());
175
                }
176
                return symbolPanel;
177
        }
178

    
179
        private JButton getBtnOpenSymbolLevelsEditor() {
180
                if (btnOpenSymbolLevelsEditor == null) {
181
                        btnOpenSymbolLevelsEditor = new JButton(PluginServices.getText(this, "symbol_levels"));
182
                        btnOpenSymbolLevelsEditor.addActionListener(this);
183
                }
184

    
185
                return btnOpenSymbolLevelsEditor;
186
        }
187
        private JButton getBtnOpenSymbolSelector() {
188
                if (btnOpenSymbolSelector == null) {
189
                        btnOpenSymbolSelector = new JButton();
190
                        btnOpenSymbolSelector.setText(PluginServices.getText(this, "choose_symbol"));
191
                        btnOpenSymbolSelector.addActionListener(this);
192
                }
193
                return btnOpenSymbolSelector;
194
        }
195

    
196
        private SymbolPreviewer getSymbolPreviewPanel() {
197
                if (symbolPreviewComponent == null) {
198
                        symbolPreviewComponent = new SymbolPreviewer();
199
                        symbolPreviewComponent.setBorder(BorderFactory.createBevelBorder(1));
200
                        symbolPreviewComponent.setPreferredSize(new Dimension(120, 40));
201
                }
202
                return symbolPreviewComponent;
203
        }
204
        /**
205
         * This method initializes legendPanel
206
         *
207
         * @return javax.swing.JPanel
208
         */
209
        private GridBagLayoutPanel getLegendPanel() {
210
                if (legendPanel == null) {
211
                        legendPanel = new GridBagLayoutPanel();
212
                        legendPanel.setBorder(BorderFactory.createTitledBorder(null,
213
                                        PluginServices.getText(this, "legend"), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, null, null));
214
                        legendPanel.addComponent(PluginServices.getText(this, "label_text_in_the_TOC") + ":", txtLabel = new JTextField(25));
215
                }
216
                return legendPanel;
217
        }
218

    
219
        public void setShapeType(int shapeType) {
220
                this.shapeType = shapeType;
221
        }
222

    
223
        public void setSymbol(ISymbol symbol) {
224
                getSymbolPreviewPanel().setSymbol(symbol);
225
        }
226

    
227
        public ISymbol getSymbol() {
228
                return getSymbolPreviewPanel().getSymbol();
229
        }
230

    
231
        public boolean isSuitableFor(FLayer layer) {
232
                return (layer instanceof FLyrVect) ;
233
        }
234

    
235
        public void actionPerformed(ActionEvent e) {
236
                JComponent c = (JComponent) e.getSource();
237
                if (c.equals(getBtnOpenSymbolSelector())){
238
                        SymbolSelector se = new SymbolSelector(getSymbol(), shapeType);
239
                        PluginServices.getMDIManager().addWindow(se);
240
                        ISymbol sym = (ISymbol) se.getSelectedObject();
241
                        if (sym != null) {
242
                                // no symbol, no changes
243
                                setSymbol((ISymbol) se.getSelectedObject());
244
                        }
245
                } else if (c.equals(getBtnOpenSymbolLevelsEditor())){
246
                        ILegend leg = getLegend();
247
                        if (leg != null) {
248
                                SymbolLevelsWindow sl = new SymbolLevelsWindow(new ZSort(leg));
249
                                PluginServices.getMDIManager().addWindow(sl);
250
                        }
251
                }
252
        }
253

    
254
}  //  @jve:decl-index=0:visual-constraint="10,10"