Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / StylePreviewer.java @ 13008

History | View | Annotate | Download (3.99 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 12826 2007-07-30 12:56:04Z jaume $
45
* $Log$
46
* Revision 1.4  2007-07-30 12:56:04  jaume
47
* organize imports, java 5 code downgraded to 1.4 and added PictureFillSymbol
48
*
49
* Revision 1.3  2007/05/08 15:44:07  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.2  2007/04/04 16:01:14  jaume
53
* *** empty log message ***
54
*
55
* Revision 1.2  2007/03/09 11:25:00  jaume
56
* Advanced symbology (start committing)
57
*
58
* Revision 1.1.2.4  2007/02/21 07:35:14  jaume
59
* *** empty log message ***
60
*
61
* Revision 1.1.2.3  2007/02/08 15:43:04  jaume
62
* some bug fixes in the editor and removed unnecessary imports
63
*
64
* Revision 1.1.2.2  2007/01/30 18:10:10  jaume
65
* start commiting labeling stuff
66
*
67
* Revision 1.1.2.1  2007/01/26 13:49:03  jaume
68
* *** empty log message ***
69
*
70
*
71
*/
72
package com.iver.cit.gvsig.gui.styling;
73

    
74
import java.awt.Color;
75
import java.awt.Font;
76
import java.awt.FontMetrics;
77
import java.awt.Graphics;
78
import java.awt.Graphics2D;
79
import java.awt.Rectangle;
80

    
81
import com.iver.andami.PluginServices;
82
import com.iver.cit.gvsig.fmap.core.styles.IStyle;
83
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
84

    
85
/**
86
*
87
* @author jaume dominguez faus - jaume.dominguez@iver.es
88
*
89
*/
90
public class StylePreviewer extends SymbolPreviewer{
91
        private int hGap = 5, vGap = 5;
92
        private IStyle style;
93
        private boolean showOutline;
94

    
95

    
96
        public StylePreviewer() {
97
                super();
98
                setBackground(Color.WHITE);
99
        }
100

    
101
        public IStyle getStyle() {
102
                return style;
103
        }
104

    
105
        public ISymbol getSymbol() {
106
                throw new Error(PluginServices.getText(this, "undefined_for_StylePreviewer_use")
107
                                +" getStyle() "+
108
                                PluginServices.getText(this, "instead") );
109

    
110
        }
111

    
112
        public void setSymbol(ISymbol symbol) {
113
                throw new Error(PluginServices.getText(this, "undefined_for_StylePreviewer_use")
114
                                +" setStyle(IStyle) "+
115
                                PluginServices.getText(this, "instead") );
116

    
117
        }
118

    
119

    
120
        public void setStyle(IStyle style) {
121
                this.style = style;
122
//                repaint();
123

    
124
        }
125

    
126
        public void paint(Graphics g) {
127
                Graphics2D g2 = (Graphics2D) g;
128
                Rectangle r = getBounds();
129
                g2.translate(hGap, vGap);
130
                r = new Rectangle(0, 0, (int) (r.getWidth()-(hGap*2)), (int) (r.getHeight()-(vGap*2)));
131

    
132
                if (style != null) {
133
                        if (showOutline) {
134
                                // this is a trick for the editor
135
                                style.drawOutline(g2, r);
136
                        } else {
137
                                style.drawInsideRectangle(g2, r);
138
                        }
139
                } else {
140
                        String noneSelected = "["+PluginServices.getText(this, "preview_not_available")+"]";
141
                        FontMetrics fm = g2.getFontMetrics();
142
                        int lineWidth = fm.stringWidth(noneSelected);
143
                        float scale = (float) r.getWidth() / lineWidth;
144
                        Font f = g2.getFont();
145
                        float fontSize = f.getSize()*scale;
146
                        g2.setFont(        f.deriveFont( fontSize ) );
147

    
148
                        g2.drawString(noneSelected,         (r.x*scale) - (hGap/2), r.height/2+vGap*scale);
149
                }
150
        }
151

    
152
        /**
153
         * Allows to choose between paint styles Outline or the style itself.
154
         * @param b
155
         */
156
        public void setShowOutline(boolean b) {
157
                this.showOutline = b;
158
        }
159
}