root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / SymbolPreviewer.java @ 11009
History | View | Annotate | Download (3.78 KB)
1 | 10679 | jaume | /* 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$
|
||
45 | * $Log$
|
||
46 | * Revision 1.2 2007-03-09 11:25:00 jaume
|
||
47 | * Advanced symbology (start committing)
|
||
48 | *
|
||
49 | * Revision 1.1.2.3 2007/02/21 07:35:14 jaume
|
||
50 | * *** empty log message ***
|
||
51 | *
|
||
52 | * Revision 1.1.2.2 2007/02/08 15:43:05 jaume
|
||
53 | * some bug fixes in the editor and removed unnecessary imports
|
||
54 | *
|
||
55 | * Revision 1.1.2.1 2007/01/26 13:49:03 jaume
|
||
56 | * *** empty log message ***
|
||
57 | *
|
||
58 | * Revision 1.4 2007/01/16 11:52:11 jaume
|
||
59 | * *** empty log message ***
|
||
60 | *
|
||
61 | * Revision 1.8 2007/01/10 17:05:05 jaume
|
||
62 | * moved to FMap and gvSIG
|
||
63 | *
|
||
64 | * Revision 1.7 2006/10/30 19:30:35 jaume
|
||
65 | * *** empty log message ***
|
||
66 | *
|
||
67 | * Revision 1.6 2006/10/29 23:53:49 jaume
|
||
68 | * *** empty log message ***
|
||
69 | *
|
||
70 | * Revision 1.5 2006/10/29 21:45:12 jaume
|
||
71 | * centers in x the "none selected message"
|
||
72 | *
|
||
73 | * Revision 1.4 2006/10/29 21:43:34 jaume
|
||
74 | * *** empty log message ***
|
||
75 | *
|
||
76 | * Revision 1.3 2006/10/29 21:40:29 jaume
|
||
77 | * centers in x the "none selected message"
|
||
78 | *
|
||
79 | * Revision 1.2 2006/10/26 07:46:58 jaume
|
||
80 | * *** empty log message ***
|
||
81 | *
|
||
82 | * Revision 1.1 2006/10/25 10:50:41 jaume
|
||
83 | * movement of classes and gui stuff
|
||
84 | *
|
||
85 | * Revision 1.2 2006/10/24 19:54:55 jaume
|
||
86 | * *** empty log message ***
|
||
87 | *
|
||
88 | * Revision 1.1 2006/10/24 16:31:12 jaume
|
||
89 | * *** empty log message ***
|
||
90 | *
|
||
91 | *
|
||
92 | */
|
||
93 | package com.iver.cit.gvsig.gui.styling; |
||
94 | |||
95 | import java.awt.Color; |
||
96 | import java.awt.Font; |
||
97 | import java.awt.FontMetrics; |
||
98 | import java.awt.Graphics; |
||
99 | import java.awt.Graphics2D; |
||
100 | import java.awt.Rectangle; |
||
101 | import java.awt.geom.AffineTransform; |
||
102 | |||
103 | import javax.swing.JPanel; |
||
104 | |||
105 | import com.iver.andami.PluginServices; |
||
106 | import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
||
107 | |||
108 | public class SymbolPreviewer extends JPanel { |
||
109 | private int hGap = 5, vGap = 5; |
||
110 | private ISymbol symbol;
|
||
111 | |||
112 | |||
113 | public SymbolPreviewer() {
|
||
114 | super();
|
||
115 | setBackground(Color.WHITE);
|
||
116 | } |
||
117 | |||
118 | public ISymbol getSymbol() {
|
||
119 | return symbol;
|
||
120 | } |
||
121 | |||
122 | public void setSymbol(ISymbol symbol) { |
||
123 | this.symbol = symbol;
|
||
124 | repaint(); |
||
125 | } |
||
126 | |||
127 | public void paint(Graphics g) { |
||
128 | super.paint(g);
|
||
129 | Graphics2D g2 = (Graphics2D) g; |
||
130 | g2.translate(hGap, vGap); |
||
131 | Rectangle r = getBounds();
|
||
132 | r = new Rectangle(0, 0, (int) (r.getWidth()-(hGap*2)), (int) (r.getHeight()-(vGap*2))); |
||
133 | |||
134 | if (symbol != null) { |
||
135 | symbol.drawInsideRectangle(g2, new AffineTransform(), r); |
||
136 | } else {
|
||
137 | String noneSelected = "["+PluginServices.getText(this, "preview_not_available")+"]"; |
||
138 | FontMetrics fm = g2.getFontMetrics();
|
||
139 | int lineWidth = fm.stringWidth(noneSelected);
|
||
140 | float scale = (float) r.getWidth() / lineWidth; |
||
141 | Font f = g2.getFont();
|
||
142 | float fontSize = f.getSize()*scale;
|
||
143 | g2.setFont( f.deriveFont( fontSize ) ); |
||
144 | |||
145 | g2.drawString(noneSelected, (r.x*scale) - (hGap/2), r.height/2+vGap*scale); |
||
146 | } |
||
147 | } |
||
148 | } |