Statistics
| Revision:

root / trunk / libraries / libArcIMS / src / org / gvsig / remoteClient / arcims / styling / symbols / SymbolUtils.java @ 8109

History | View | Annotate | Download (6.39 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 Prodevelop 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
 *   Prodevelop Integraci?n de Tecnolog?as SL
34
 *   Conde Salvatierra de ?lava , 34-10
35
 *   46004 Valencia
36
 *   Spain
37
 *
38
 *   +34 963 510 612
39
 *   +34 963 510 968
40
 *   gis@prodevelop.es
41
 *   http://www.prodevelop.es
42
 */
43

    
44
/**
45
 *
46
 */
47
package org.gvsig.remoteClient.arcims.styling.symbols;
48

    
49
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
50
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
51

    
52
import java.awt.Color;
53
import java.awt.Font;
54

    
55
import java.util.HashMap;
56

    
57

    
58
/**
59
 * @author jsanz
60
 *
61
 */
62
public class SymbolUtils {
63
    /*
64
     * Point types
65
     */
66
    public static final String POINT_TYPE_CIRCLE = "circle";
67
    public static final String POINT_TYPE_TRIANGLE = "triangle";
68
    public static final String POINT_TYPE_SQUARE = "square";
69
    public static final String POINT_TYPE_CROSS = "cross";
70

    
71
    /*
72
     * Line types
73
     */
74
    public static final String LINE_TYPE_SOLID = "solid";
75
    public static final String LINE_TYPE_DASH = "dash";
76
    public static final String LINE_TYPE_DOT = "dot";
77
    public static final String LINE_TYPE_DASH_DOT = "dash_dot";
78
    public static final String LINE_TYPE_DASH_DOT_DOT = "dash_dot_dot";
79
    public static final HashMap LINE_TYPES = new HashMap();
80

    
81
    static {
82
        LINE_TYPES.put(LINE_TYPE_SOLID, "0");
83
        LINE_TYPES.put(LINE_TYPE_DASH, "2");
84
        LINE_TYPES.put(LINE_TYPE_DOT, "0.05,2");
85
        LINE_TYPES.put(LINE_TYPE_DASH_DOT, "2,2,0.01,2");
86
        LINE_TYPES.put(LINE_TYPE_DASH_DOT_DOT, "2,2,0.01,2,0.01,2");
87
    }
88

    
89
    /*
90
     * End line types
91
     */
92
    public static final String CAP_TYPE_BUTT = "butt";
93
    public static final String CAP_TYPE_ROUND = "round";
94
    public static final String CAP_TYPE_SQUARE = "square";
95

    
96
    /*
97
     * Joining line types
98
     */
99
    public static final String JOIN_TYPE_ROUND = "round";
100
    public static final String JOIN_TYPE_MITER = "miter";
101
    public static final String JOIN_TYPE_BEVEL = "bevel";
102

    
103
    /*
104
     * Polygon fill types
105
     */
106
    public static final String FILL_TYPE_SOLID = "solid";
107
    public static final String FILL_TYPE_BDIAG = "bdiagonal";
108
    public static final String FILL_TYPE_FDIAG = "fdiagonal";
109
    public static final String FILL_TYPE_CROSS = "cross";
110
    public static final String FILL_TYPE_DIAGC = "diagcross";
111
    public static final String FILL_TYPE_HORIZ = "horizontal";
112
    public static final String FILL_TYPE_VERT = "vertical";
113
    public static final String FILL_TYPE_GRAYFILL = "gray";
114
    public static final String FILL_TYPE_LIGHTGRAYFILL = "lightgray";
115
    public static final String FILL_TYPE_DARKGRAYFILL = "darkgray";
116

    
117
    /*
118
     * Text types
119
     */
120
    public static final String TEXT_TYPE_REGULAR = "regular";
121
    public static final String TEXT_TYPE_BOLD = "bold";
122
    public static final String TEXT_TYPE_ITALIC = "italic";
123
    public static final String TEXT_TYPE_UNDERLINE = "underline";
124
    public static final String TEXT_TYPE_OUTLINE = "outline";
125
    public static final String TEXT_TYPE_BOLDITALIC = "bolditalic";
126

    
127
    /**
128
     * Parses a <em>RR,GG,BB</em> string into a correct Color object
129
     * @see java.awt.Color#Color(int, int, int)
130
     * @param str
131
     * @return
132
     */
133
    public static Color getColor(String str, float alpha) {
134
        String[] strA = str.split(",");
135

    
136
        if (strA.length != 3) {
137
            return null;
138
        }
139

    
140
        int red = Integer.parseInt(strA[0]);
141
        int green = Integer.parseInt(strA[1]);
142
        int blue = Integer.parseInt(strA[2]);
143
        int ialpha = (int) alpha * 255;
144

    
145
        return new Color(red, green, blue, ialpha);
146
    }
147

    
148
    /**
149
     * Generates a String representations on the form <em>RR,GG,BB</em>
150
     * @see java.awt.Color
151
     * @param color
152
     * @return
153
     */
154
    public static String getStringColor(Color color) {
155
        return color.getRed() + "," + color.getGreen() + "," + color.getBlue();
156
    }
157

    
158
    /**
159
     * Returns a correct Shape type from an ArcIMS Symbol definition
160
     * @see IArcIMSSymbol
161
     * @see FConstant
162
     * @param isimb
163
     * @return
164
     */
165
    public static int getShapeType(IArcIMSSymbol isimb) {
166
        FSymbol simb = isimb.getFSymbol();
167
        int fsimbType = simb.getSymbolType();
168
        int type = FConstant.SHAPE_TYPE_NULL;
169

    
170
        if (fsimbType == FConstant.SYMBOL_TYPE_FILL) {
171
            type = FConstant.SHAPE_TYPE_POLYGON;
172
        } else if (fsimbType == FConstant.SYMBOL_TYPE_LINE) {
173
            type = FConstant.SHAPE_TYPE_POLYLINE;
174
        } else if (fsimbType == FConstant.SYMBOL_TYPE_MULTIPOINT) {
175
            type = FConstant.SHAPE_TYPE_MULTIPOINT;
176
        }
177

    
178
        return type;
179
    }
180

    
181
    public static int getFontStyle(String strStyle) {
182
        if (strStyle.equals(TEXT_TYPE_BOLD)) {
183
            return Font.BOLD;
184
        } else if (strStyle.equals(TEXT_TYPE_ITALIC)) {
185
            return Font.ITALIC;
186
        }
187
        //                else if (strStyle.equals(TEXT_TYPE_UNDERLINE))
188
        //                        return Font.HANGING_BASELINE; 
189
        //                else if (strStyle.equals(TEXT_TYPE_OUTLINE))
190
        //                        return Font.PLAIN; 
191
        else if (strStyle.equals(TEXT_TYPE_BOLDITALIC)) {
192
            return Font.BOLD + Font.ITALIC;
193
        }
194

    
195
        //If no type has found, return a plain type
196
        return Font.PLAIN;
197
    }
198

    
199
    public static boolean isVoid(String param) {
200
        boolean flag = true;
201

    
202
        if (param == null) {
203
            flag = false;
204
        } else if (param.equals("")) {
205
            flag = false;
206
        }
207

    
208
        return flag;
209
    }
210
}