Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / gui / styling / Mask.java @ 30011

History | View | Annotate | Download (6.81 KB)

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

    
43
import java.awt.FlowLayout;
44
import java.awt.GridLayout;
45
import java.awt.event.ActionListener;
46

    
47
import javax.swing.BorderFactory;
48
import javax.swing.ButtonGroup;
49
import javax.swing.JLabel;
50
import javax.swing.JPanel;
51
import javax.swing.JRadioButton;
52

    
53
import org.gvsig.andami.PluginServices;
54
import org.gvsig.app.project.documents.view.legend.gui.ISymbolSelector;
55
import org.gvsig.fmap.geom.Geometry;
56
import org.gvsig.fmap.mapcontext.MapContextLocator;
57
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
58
import org.gvsig.gui.beans.swing.JButton;
59
import org.gvsig.gui.beans.swing.JIncrementalNumberField;
60
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
61
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.DefaultMask;
62
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMask;
63

    
64

    
65
/**
66
 * Implements a tab to modify attributes of a mask as style,size and
67
 * symbol (to represent a point in the map)which can be applied to
68
 * symbols like simple text, simple marker,picture marker and character marker.<p>
69
 * <p>
70
 * This tab is used several times in different places in our applicattion .For
71
 * this reason, in order to avoid the repetition of code, this class has been
72
 * created (instead of treat it like a simple tab). With this solution, the user
73
 * only has to refer it to use it (and do not need to create a tab and fill it again
74
 * and so on).
75
 *
76
 * @author jaume dominguez faus - jaume.dominguez@iver.es
77
 */
78
public class Mask extends JPanel {
79
        private JButton btnHaloSymbol;
80
        private JRadioButton rdBtnHalo;
81
        private JRadioButton rdBtnNone;
82
        private JIncrementalNumberField txtHaloSize;
83
        private IFillSymbol fill;
84
        private AbstractTypeSymbolEditor owner;
85
        private ActionListener action = new ActionListener() {
86
                public void actionPerformed(java.awt.event.ActionEvent e) {
87
                        owner.fireSymbolChangedEvent();
88
                };
89
        };
90
        /**
91
         * Constructor method that initializes the parameters to create a tab to modify
92
         * attributes of a mask for points such as style,size and symbol (to represent a point
93
         * in the map).
94
         * @param owner
95
         */
96
        public Mask(AbstractTypeSymbolEditor owner) {
97
                super();
98
                setName(PluginServices.getText(this, "mask"));
99

    
100
                this.owner = owner;
101

    
102
                GridBagLayoutPanel aux = new GridBagLayoutPanel();
103
                aux.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(this, "style")));
104
                JPanel stylePanel = new JPanel(new GridLayout(2, 1));
105
                stylePanel.add(getRdNone());
106
                stylePanel.add(getRdHalo());
107
                aux.addComponent(stylePanel);
108
                ButtonGroup group = new ButtonGroup();
109
                group.add(getRdNone());
110
                group.add(getRdHalo());
111

    
112
                JPanel aux2 = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
113
                aux2.add(new JLabel(PluginServices.getText(this, "size")+":"));
114
                aux2.add(getTxtHaloSize());
115
                aux2.add(getBtnHaloSymbol());
116

    
117
                getRdNone().addActionListener(action);
118
                getRdHalo().addActionListener(action);
119
                getTxtHaloSize().addActionListener(action);
120

    
121
                add(aux);
122
                add(aux2);
123
        }
124
        /**
125
         * Obbtains the size for the text halo.This size is taken from a
126
         * JIncrementalNumberField. If this component does not exist,
127
         * a new JIncrementalNumberField is created to specify it.
128
         * @return
129
         */
130
        private JIncrementalNumberField getTxtHaloSize() {
131
                if (txtHaloSize == null) {
132
                        txtHaloSize = new JIncrementalNumberField(String.valueOf(0), 5, 0, Double.MAX_VALUE, 1);
133
                }
134

    
135
                return txtHaloSize;
136
        }
137

    
138
        /**
139
         * Creates the button that allows the user to select the symbol that will substitute
140
         * a point in the map.
141
         * @return
142
         */
143
        private JButton getBtnHaloSymbol() {
144
                if (btnHaloSymbol == null) {
145
                        btnHaloSymbol = new JButton(PluginServices.getText(this, "symbol"));
146
                        btnHaloSymbol.addActionListener(new ActionListener() {
147
                                public void actionPerformed(java.awt.event.ActionEvent e) {
148
                                        ISymbolSelector symSel = SymbolSelector.createSymbolSelector(
149
                                                        fill, Geometry.TYPES.SURFACE);
150
                                        PluginServices.getMDIManager().addCentredWindow(symSel);
151
                                        fill = (IFillSymbol) symSel.getSelectedObject();
152
                                };
153
                        });
154
                }
155

    
156
                return btnHaloSymbol;
157
        }
158

    
159
        /**
160
         * Determines if the halo style is selected.If the Radio button
161
         * that determines this information does not exist, a new radio button
162
         * is created for this purpose.
163
         * @return
164
         */
165
        private JRadioButton getRdHalo() {
166
                if (rdBtnHalo == null) {
167
                        rdBtnHalo = new JRadioButton(PluginServices.getText(this, "halo"));
168
                }
169

    
170
                return rdBtnHalo;
171
        }
172

    
173
        /**
174
         * Determines if there will be no defined style for a point (without halo).
175
         * If the Radio button that determines this information does not exist,
176
         * a new radio button is created for this purpose.
177
         * @return
178
         */
179
        private JRadioButton getRdNone() {
180
                if (rdBtnNone == null) {
181
                        rdBtnNone = new JRadioButton(PluginServices.getText(this, "none"));
182
                        rdBtnNone.setSelected(true);
183
                }
184

    
185
                return rdBtnNone;
186
        }
187
        /**
188
         * Sets the graphical component that shows the properties of the model.
189
         * @param mask
190
         */
191
        public void setModel(IMask mask) {
192
                if (mask != null) {
193
                        getTxtHaloSize().setDouble(mask.getSize());
194
                        fill = mask.getFillSymbol();
195
                }
196
                getRdHalo().setSelected(mask != null);
197
        }
198
        /**
199
         * Returns an IMask or null depending on the option
200
         * that the user had decided (if he wants a mask or not)in the tab "mask" inside
201
         * the panel to edit the properities of a symbol (SymbolEditor).
202
         * If the user
203
         * wants it, a new IMask is created.
204
         * @return
205
         */
206
        public IMask getMask() {
207
                if (!getRdHalo().isSelected()) return null;
208

    
209
                IMask mask = new DefaultMask();
210
                if (fill == null) {
211
                        fill = (IFillSymbol) MapContextLocator.getMapContextManager()
212
                                        .createSymbol(IFillSymbol.SYMBOL_NAME);
213
                }
214
                mask.setFillSymbol(fill);
215
                mask.setSize(getTxtHaloSize().getDouble());
216
                return mask;
217
        }
218

    
219
}