svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.symbology / org.gvsig.symbology.swing / org.gvsig.symbology.swing.api / src / main / java / org / gvsig / app / gui / styling / StylePreviewer.java @ 42257
History | View | Annotate | Download (5.17 KB)
1 | 40560 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40560 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40560 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | 40560 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | 40435 | jjdelcerro | *
|
21 | 40560 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | /* CVS MESSAGES:
|
||
25 | *
|
||
26 | * $Id: StylePreviewer.java 30892 2009-09-21 12:02:19Z cordinyana $
|
||
27 | * $Log$
|
||
28 | * Revision 1.6 2007-08-16 06:54:35 jvidal
|
||
29 | * javadoc updated
|
||
30 | *
|
||
31 | * Revision 1.5 2007/08/13 11:33:03 jvidal
|
||
32 | * javadoc
|
||
33 | *
|
||
34 | * Revision 1.4 2007/07/30 12:56:04 jaume
|
||
35 | * organize imports, java 5 code downgraded to 1.4 and added PictureFillSymbol
|
||
36 | *
|
||
37 | * Revision 1.3 2007/05/08 15:44:07 jaume
|
||
38 | * *** empty log message ***
|
||
39 | *
|
||
40 | * Revision 1.2 2007/04/04 16:01:14 jaume
|
||
41 | * *** empty log message ***
|
||
42 | *
|
||
43 | * Revision 1.2 2007/03/09 11:25:00 jaume
|
||
44 | * Advanced symbology (start committing)
|
||
45 | *
|
||
46 | * Revision 1.1.2.4 2007/02/21 07:35:14 jaume
|
||
47 | * *** empty log message ***
|
||
48 | *
|
||
49 | * Revision 1.1.2.3 2007/02/08 15:43:04 jaume
|
||
50 | * some bug fixes in the editor and removed unnecessary imports
|
||
51 | *
|
||
52 | * Revision 1.1.2.2 2007/01/30 18:10:10 jaume
|
||
53 | * start commiting labeling stuff
|
||
54 | *
|
||
55 | * Revision 1.1.2.1 2007/01/26 13:49:03 jaume
|
||
56 | * *** empty log message ***
|
||
57 | *
|
||
58 | *
|
||
59 | */
|
||
60 | package org.gvsig.app.gui.styling; |
||
61 | |||
62 | import java.awt.Color; |
||
63 | import java.awt.Font; |
||
64 | import java.awt.FontMetrics; |
||
65 | import java.awt.Graphics; |
||
66 | import java.awt.Graphics2D; |
||
67 | import java.awt.Rectangle; |
||
68 | |||
69 | import org.gvsig.fmap.mapcontext.MapContextLocator; |
||
70 | import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
||
71 | import org.gvsig.fmap.mapcontext.rendering.symbols.IWarningSymbol; |
||
72 | import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException; |
||
73 | import org.gvsig.fmap.mapcontext.rendering.symbols.styles.IStyle; |
||
74 | import org.gvsig.i18n.Messages; |
||
75 | |||
76 | |||
77 | /**
|
||
78 | * Defines the properties of the symbols that are showed in the
|
||
79 | * SymbolPreviewer panel.Also the user has methods to set this attributes.
|
||
80 | *
|
||
81 | * @author jaume dominguez faus - jaume.dominguez@iver.es
|
||
82 | *
|
||
83 | */
|
||
84 | public class StylePreviewer extends SymbolPreviewer{ |
||
85 | /**
|
||
86 | *
|
||
87 | */
|
||
88 | private static final long serialVersionUID = -1690697926703748637L; |
||
89 | private int hGap = 5, vGap = 5; |
||
90 | private IStyle style;
|
||
91 | private boolean showOutline; |
||
92 | |||
93 | /**
|
||
94 | * Constructor method
|
||
95 | *
|
||
96 | */
|
||
97 | public StylePreviewer() {
|
||
98 | super();
|
||
99 | setBackground(Color.WHITE);
|
||
100 | } |
||
101 | /**
|
||
102 | * Obtains the style of the symbol showed in the SymbolPreviewer panel
|
||
103 | * @return style,IStyle
|
||
104 | */
|
||
105 | public IStyle getStyle() {
|
||
106 | return style;
|
||
107 | } |
||
108 | |||
109 | 40678 | jldominguez | public void setShowOutline(boolean so) { |
110 | this.showOutline = so;
|
||
111 | } |
||
112 | |||
113 | 40435 | jjdelcerro | public ISymbol getSymbol() {
|
114 | throw new Error(Messages.getText("undefined_for_StylePreviewer_use") |
||
115 | +" getStyle() "+
|
||
116 | Messages.getText("instead") );
|
||
117 | |||
118 | } |
||
119 | |||
120 | public void setSymbol(ISymbol symbol) { |
||
121 | throw new Error(Messages.getText("undefined_for_StylePreviewer_use") |
||
122 | +" setStyle(IStyle) "+
|
||
123 | Messages.getText("instead") );
|
||
124 | |||
125 | } |
||
126 | /**
|
||
127 | * Defines the style of the symbol showed in the SymbolPreviewer panel
|
||
128 | * @param style,IStyle
|
||
129 | */
|
||
130 | |||
131 | public void setStyle(IStyle style) { |
||
132 | this.style = style;
|
||
133 | // repaint();
|
||
134 | |||
135 | } |
||
136 | |||
137 | public void paint(Graphics g) { |
||
138 | Graphics2D g2 = (Graphics2D) g; |
||
139 | Rectangle r = getBounds();
|
||
140 | g2.translate(hGap, vGap); |
||
141 | r = new Rectangle(0, 0, (int) (r.getWidth()-(hGap*2)), (int) (r.getHeight()-(vGap*2))); |
||
142 | |||
143 | if (style != null) { |
||
144 | try {
|
||
145 | if (showOutline) {
|
||
146 | // this is a trick for the editor
|
||
147 | style.drawOutline(g2, r); |
||
148 | |||
149 | } else {
|
||
150 | style.drawInsideRectangle(g2, r); |
||
151 | } |
||
152 | } catch (SymbolDrawingException e) {
|
||
153 | if (e.getType() == SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS) {
|
||
154 | try {
|
||
155 | IWarningSymbol warning = |
||
156 | (IWarningSymbol) MapContextLocator.getSymbolManager() |
||
157 | .getWarningSymbol( |
||
158 | SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS, |
||
159 | "",
|
||
160 | SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS); |
||
161 | warning.drawInsideRectangle(g2, null, r,null); |
||
162 | } catch (SymbolDrawingException e1) {
|
||
163 | // IMPOSSIBLE TO REACH THIS
|
||
164 | } |
||
165 | } else {
|
||
166 | // should be unreachable code
|
||
167 | throw new Error(Messages.getText("symbol_shapetype_mismatch")); |
||
168 | } |
||
169 | } |
||
170 | } else {
|
||
171 | String noneSelected = "["+Messages.getText("preview_not_available")+"]"; |
||
172 | FontMetrics fm = g2.getFontMetrics();
|
||
173 | int lineWidth = fm.stringWidth(noneSelected);
|
||
174 | float scale = (float) r.getWidth() / lineWidth; |
||
175 | Font f = g2.getFont();
|
||
176 | float fontSize = f.getSize()*scale;
|
||
177 | g2.setFont( f.deriveFont( fontSize ) ); |
||
178 | |||
179 | g2.drawString(noneSelected, (r.x*scale) - (hGap/2), r.height/2+vGap*scale); |
||
180 | } |
||
181 | } |
||
182 | |||
183 | 40678 | jldominguez | public int getHGap() { |
184 | return hGap;
|
||
185 | 40435 | jjdelcerro | } |
186 | 40678 | jldominguez | |
187 | public int getVGap() { |
||
188 | return vGap;
|
||
189 | } |
||
190 | |||
191 | 40435 | jjdelcerro | } |