svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.labeling.app / org.gvsig.labeling.app.mainplugin / src / main / java / org / gvsig / labeling / gui / styling / LineFill.java @ 40665
History | View | Annotate | Download (7.35 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 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.labeling.gui.styling; |
42 |
|
43 |
import java.awt.Color; |
44 |
import java.awt.Dimension; |
45 |
import java.awt.FlowLayout; |
46 |
import java.awt.event.ActionEvent; |
47 |
import java.awt.event.ActionListener; |
48 |
import java.util.ArrayList; |
49 |
|
50 |
import javax.swing.JCheckBox; |
51 |
import javax.swing.JPanel; |
52 |
|
53 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
54 |
import org.gvsig.gui.beans.swing.JIncrementalNumberField; |
55 |
import org.gvsig.symbology.fmap.symbols.LineFillSymbol; |
56 |
|
57 |
import com.iver.andami.PluginServices; |
58 |
import com.iver.cit.gvsig.fmap.core.FShape; |
59 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
60 |
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol; |
61 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
62 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
63 |
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel; |
64 |
import com.iver.cit.gvsig.gui.styling.AbstractTypeSymbolEditor; |
65 |
import com.iver.cit.gvsig.gui.styling.EditorTool; |
66 |
import com.iver.cit.gvsig.gui.styling.SymbolEditor; |
67 |
import com.iver.cit.gvsig.project.documents.view.legend.gui.JSymbolPreviewButton; |
68 |
|
69 |
/**
|
70 |
* <b>LineFill</b> allows to store and modify the properties that fills a
|
71 |
* polygon with a padding composed of lines<p>
|
72 |
* <p>
|
73 |
* This functionality is carried out thanks to a tab (line fill)which is included
|
74 |
* in the panel to edit the properities of a symbol (SymbolEditor)how is explained
|
75 |
* in AbstractTypeSymbolEditor.<p>
|
76 |
* <p>
|
77 |
* This tab permits the user to change the line that composes the padding
|
78 |
* (<b>btnLineSymbol</b>),the outline of the polygon (<b>btnOutlineSymbol</b>),
|
79 |
* the color between the lines (<b>jcc</b>),the angle of the line(<b>incrAngle</b>),
|
80 |
* the offset between paralel lines(<b>incrOffset</b>) and the separation
|
81 |
* (<b>incrSeparation</b>).
|
82 |
*
|
83 |
*
|
84 |
*@see AbstractTypeSymbolEditor
|
85 |
*@author jaume dominguez faus - jaume.dominguez@iver.es
|
86 |
*/
|
87 |
public class LineFill extends AbstractTypeSymbolEditor implements ActionListener { |
88 |
private ArrayList<JPanel> tabs = new ArrayList<JPanel>(); |
89 |
private ColorChooserPanel jcc;
|
90 |
private JIncrementalNumberField incrAngle;
|
91 |
private JIncrementalNumberField incrOffset;
|
92 |
private JIncrementalNumberField incrSeparation;
|
93 |
private JSymbolPreviewButton btnOutlineSymbol;
|
94 |
private JSymbolPreviewButton btnLineSymbol;
|
95 |
private ILineSymbol outline;
|
96 |
private JCheckBox useBorder; |
97 |
private ILineSymbol line = SymbologyFactory.createDefaultLineSymbol();
|
98 |
public LineFill(SymbolEditor owner) {
|
99 |
super(owner);
|
100 |
initialize(); |
101 |
} |
102 |
|
103 |
/**
|
104 |
* Initializes the parameters that allows the user to fill the padding of
|
105 |
* a polygon with a simpleline style.To do it, a tab (line fill) is created inside the
|
106 |
* SymbolEditor panel with default values for the different attributes.
|
107 |
*/
|
108 |
|
109 |
private void initialize() { |
110 |
|
111 |
GridBagLayoutPanel content = new GridBagLayoutPanel();
|
112 |
content.setName(PluginServices.getText(this, "line_fill")); |
113 |
JPanel aux;
|
114 |
aux = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0)); |
115 |
aux.add(jcc = new ColorChooserPanel(true,true)); |
116 |
jcc.setAlpha(255);
|
117 |
content.addComponent(PluginServices.getText(this, "color")+":", |
118 |
aux); |
119 |
|
120 |
aux = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0)); |
121 |
aux.add(incrAngle = new JIncrementalNumberField("0", 5)); |
122 |
content.addComponent(PluginServices.getText(this, "angle")+":", |
123 |
aux); |
124 |
|
125 |
aux = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0)); |
126 |
aux.add(incrOffset = new JIncrementalNumberField("0", 5)); |
127 |
content.addComponent(PluginServices.getText(this, "offset")+":", |
128 |
aux); |
129 |
|
130 |
aux = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0)); |
131 |
aux.add(incrSeparation = new JIncrementalNumberField(
|
132 |
"5",
|
133 |
5,
|
134 |
1,
|
135 |
Double.POSITIVE_INFINITY,
|
136 |
1));
|
137 |
incrSeparation.setDouble(5);
|
138 |
content.addComponent(PluginServices.getText(this, "separation")+":", |
139 |
aux); |
140 |
|
141 |
aux = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0)); |
142 |
aux.add(btnLineSymbol = new JSymbolPreviewButton(FShape.LINE));
|
143 |
btnLineSymbol.setPreferredSize(new Dimension(100, 35)); |
144 |
content.addComponent(PluginServices.getText(this, "line")+":", aux); |
145 |
|
146 |
|
147 |
|
148 |
|
149 |
aux = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0)); |
150 |
aux.add(btnOutlineSymbol = new JSymbolPreviewButton(FShape.LINE));
|
151 |
btnOutlineSymbol.setPreferredSize(new Dimension(100, 35)); |
152 |
useBorder = new JCheckBox(PluginServices.getText(this, "use_outline")); |
153 |
content.addComponent(useBorder); |
154 |
content.addComponent(PluginServices.getText(this, "outline")+":", aux); |
155 |
|
156 |
jcc.addActionListener(this);
|
157 |
incrAngle.addActionListener(this);
|
158 |
incrOffset.addActionListener(this);
|
159 |
incrSeparation.addActionListener(this);
|
160 |
btnOutlineSymbol.addActionListener(this);
|
161 |
btnLineSymbol.addActionListener(this);
|
162 |
useBorder.addActionListener(this);
|
163 |
|
164 |
tabs.add(content); |
165 |
|
166 |
} |
167 |
|
168 |
public EditorTool[] getEditorTools() { |
169 |
return null; |
170 |
} |
171 |
|
172 |
public ISymbol getLayer() {
|
173 |
LineFillSymbol sym = new LineFillSymbol();
|
174 |
sym.setAngle(incrAngle.getDouble()*FConstant.DEGREE_TO_RADIANS); |
175 |
sym.setOffset(incrOffset.getDouble()); |
176 |
sym.setSeparation(incrSeparation.getDouble()); |
177 |
|
178 |
sym.setHasFill(jcc.getUseColorisSelected()); |
179 |
Color c = jcc.getColor();
|
180 |
if (c != null) |
181 |
c = new Color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha()); |
182 |
|
183 |
sym.setFillColor(c); |
184 |
|
185 |
|
186 |
sym.setHasOutline(useBorder.isSelected()); |
187 |
outline = (ILineSymbol) btnOutlineSymbol.getSymbol(); |
188 |
sym.setOutline(outline); |
189 |
|
190 |
|
191 |
sym.setLineSymbol(line); |
192 |
|
193 |
return sym;
|
194 |
} |
195 |
|
196 |
public String getName() { |
197 |
return PluginServices.getText(this, "line_fill_symbol"); |
198 |
} |
199 |
|
200 |
public Class<? extends ISymbol> getSymbolClass() { |
201 |
return LineFillSymbol.class;
|
202 |
} |
203 |
|
204 |
public JPanel[] getTabs() { |
205 |
return (JPanel[]) tabs.toArray(new JPanel[tabs.size()]); |
206 |
} |
207 |
|
208 |
public void refreshControls(ISymbol layer) { |
209 |
LineFillSymbol lfs = (LineFillSymbol) layer; |
210 |
incrAngle.setDouble(lfs.getAngle()/FConstant.DEGREE_TO_RADIANS); |
211 |
incrOffset.setDouble(lfs.getOffset()); |
212 |
incrSeparation.setDouble(lfs.getSeparation()); |
213 |
jcc.setUseColorIsSelected(lfs.hasFill()); |
214 |
jcc.setColor(lfs.getFillColor()); |
215 |
|
216 |
outline=lfs.getOutline(); |
217 |
btnOutlineSymbol.setSymbol(outline); |
218 |
useBorder.setSelected(lfs.hasOutline()); |
219 |
|
220 |
line = lfs.getLineSymbol(); |
221 |
btnLineSymbol.setSymbol(line); |
222 |
|
223 |
} |
224 |
|
225 |
public void actionPerformed(ActionEvent e) { |
226 |
Object s = e.getSource();
|
227 |
|
228 |
line = (ILineSymbol) btnLineSymbol.getSymbol(); |
229 |
outline = (ILineSymbol) btnOutlineSymbol.getSymbol(); |
230 |
fireSymbolChangedEvent(); |
231 |
} |
232 |
|
233 |
} |