root / branches / v2_0_0_prep / libraries / org.gvsig.symbology / org.gvsig.symbology.swing / org.gvsig.symbology.swing.api / src / main / java / org / gvsig / app / gui / styling / StylePreviewer.java @ 34294
History | View | Annotate | Download (5.43 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 |
|
42 |
/* CVS MESSAGES:
|
43 |
*
|
44 |
* $Id: StylePreviewer.java 30892 2009-09-21 12:02:19Z cordinyana $
|
45 |
* $Log$
|
46 |
* Revision 1.6 2007-08-16 06:54:35 jvidal
|
47 |
* javadoc updated
|
48 |
*
|
49 |
* Revision 1.5 2007/08/13 11:33:03 jvidal
|
50 |
* javadoc
|
51 |
*
|
52 |
* Revision 1.4 2007/07/30 12:56:04 jaume
|
53 |
* organize imports, java 5 code downgraded to 1.4 and added PictureFillSymbol
|
54 |
*
|
55 |
* Revision 1.3 2007/05/08 15:44:07 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.2 2007/04/04 16:01:14 jaume
|
59 |
* *** empty log message ***
|
60 |
*
|
61 |
* Revision 1.2 2007/03/09 11:25:00 jaume
|
62 |
* Advanced symbology (start committing)
|
63 |
*
|
64 |
* Revision 1.1.2.4 2007/02/21 07:35:14 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
* Revision 1.1.2.3 2007/02/08 15:43:04 jaume
|
68 |
* some bug fixes in the editor and removed unnecessary imports
|
69 |
*
|
70 |
* Revision 1.1.2.2 2007/01/30 18:10:10 jaume
|
71 |
* start commiting labeling stuff
|
72 |
*
|
73 |
* Revision 1.1.2.1 2007/01/26 13:49:03 jaume
|
74 |
* *** empty log message ***
|
75 |
*
|
76 |
*
|
77 |
*/
|
78 |
package org.gvsig.app.gui.styling; |
79 |
|
80 |
import java.awt.Color; |
81 |
import java.awt.Font; |
82 |
import java.awt.FontMetrics; |
83 |
import java.awt.Graphics; |
84 |
import java.awt.Graphics2D; |
85 |
import java.awt.Rectangle; |
86 |
|
87 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
88 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
89 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IWarningSymbol; |
90 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException; |
91 |
import org.gvsig.fmap.mapcontext.rendering.symbols.styles.IStyle; |
92 |
import org.gvsig.i18n.Messages; |
93 |
|
94 |
|
95 |
/**
|
96 |
* Defines the properties of the symbols that are showed in the
|
97 |
* SymbolPreviewer panel.Also the user has methods to set this attributes.
|
98 |
*
|
99 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
100 |
*
|
101 |
*/
|
102 |
public class StylePreviewer extends SymbolPreviewer{ |
103 |
/**
|
104 |
*
|
105 |
*/
|
106 |
private static final long serialVersionUID = -1690697926703748637L; |
107 |
private int hGap = 5, vGap = 5; |
108 |
private IStyle style;
|
109 |
private boolean showOutline; |
110 |
|
111 |
/**
|
112 |
* Constructor method
|
113 |
*
|
114 |
*/
|
115 |
public StylePreviewer() {
|
116 |
super();
|
117 |
setBackground(Color.WHITE);
|
118 |
} |
119 |
/**
|
120 |
* Obtains the style of the symbol showed in the SymbolPreviewer panel
|
121 |
* @return style,IStyle
|
122 |
*/
|
123 |
public IStyle getStyle() {
|
124 |
return style;
|
125 |
} |
126 |
|
127 |
public ISymbol getSymbol() {
|
128 |
throw new Error(Messages.getText("undefined_for_StylePreviewer_use") |
129 |
+" getStyle() "+
|
130 |
Messages.getText("instead") );
|
131 |
|
132 |
} |
133 |
|
134 |
public void setSymbol(ISymbol symbol) { |
135 |
throw new Error(Messages.getText("undefined_for_StylePreviewer_use") |
136 |
+" setStyle(IStyle) "+
|
137 |
Messages.getText("instead") );
|
138 |
|
139 |
} |
140 |
/**
|
141 |
* Defines the style of the symbol showed in the SymbolPreviewer panel
|
142 |
* @param style,IStyle
|
143 |
*/
|
144 |
|
145 |
public void setStyle(IStyle style) { |
146 |
this.style = style;
|
147 |
// repaint();
|
148 |
|
149 |
} |
150 |
|
151 |
public void paint(Graphics g) { |
152 |
Graphics2D g2 = (Graphics2D) g; |
153 |
Rectangle r = getBounds();
|
154 |
g2.translate(hGap, vGap); |
155 |
r = new Rectangle(0, 0, (int) (r.getWidth()-(hGap*2)), (int) (r.getHeight()-(vGap*2))); |
156 |
|
157 |
if (style != null) { |
158 |
try {
|
159 |
if (showOutline) {
|
160 |
// this is a trick for the editor
|
161 |
style.drawOutline(g2, r); |
162 |
|
163 |
} else {
|
164 |
style.drawInsideRectangle(g2, r); |
165 |
} |
166 |
} catch (SymbolDrawingException e) {
|
167 |
if (e.getType() == SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS) {
|
168 |
try {
|
169 |
IWarningSymbol warning = |
170 |
(IWarningSymbol) MapContextLocator.getSymbolManager() |
171 |
.getWarningSymbol( |
172 |
SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS, |
173 |
"",
|
174 |
SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS); |
175 |
warning.drawInsideRectangle(g2, null, r,null); |
176 |
} catch (SymbolDrawingException e1) {
|
177 |
// IMPOSSIBLE TO REACH THIS
|
178 |
} |
179 |
} else {
|
180 |
// should be unreachable code
|
181 |
throw new Error(Messages.getText("symbol_shapetype_mismatch")); |
182 |
} |
183 |
} |
184 |
} else {
|
185 |
String noneSelected = "["+Messages.getText("preview_not_available")+"]"; |
186 |
FontMetrics fm = g2.getFontMetrics();
|
187 |
int lineWidth = fm.stringWidth(noneSelected);
|
188 |
float scale = (float) r.getWidth() / lineWidth; |
189 |
Font f = g2.getFont();
|
190 |
float fontSize = f.getSize()*scale;
|
191 |
g2.setFont( f.deriveFont( fontSize ) ); |
192 |
|
193 |
g2.drawString(noneSelected, (r.x*scale) - (hGap/2), r.height/2+vGap*scale); |
194 |
} |
195 |
} |
196 |
|
197 |
/**
|
198 |
* Allows to choose between paint styles Outline or the style itself.
|
199 |
* @param b
|
200 |
*/
|
201 |
public void setShowOutline(boolean b) { |
202 |
this.showOutline = b;
|
203 |
} |
204 |
} |