Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / org.gvsig.arcims / src / org / gvsig / remoteclient / arcims / styling / symbols / SymbolUtils.java @ 32367

History | View | Annotate | Download (6.13 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
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
 * as published by the Free Software Foundation; either version 2
9
 * 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
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

    
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2010 Prodevelop S.L. main development
26
 * http://www.prodevelop.es
27
 */
28

    
29
package org.gvsig.remoteclient.arcims.styling.symbols;
30

    
31

    
32

    
33
import java.awt.Color;
34
import java.awt.Font;
35

    
36
import java.util.HashMap;
37

    
38
import org.gvsig.fmap.geom.Geometry;
39
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
40
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.FConstant;
41

    
42

    
43
/**
44
 * @author jsanz
45
 *
46
 */
47
public class SymbolUtils {
48
    /*
49
     * Point types
50
     */
51
    public static final String POINT_TYPE_CIRCLE = "circle";
52
    public static final String POINT_TYPE_TRIANGLE = "triangle";
53
    public static final String POINT_TYPE_SQUARE = "square";
54
    public static final String POINT_TYPE_CROSS = "cross";
55

    
56
    /*
57
     * Line types
58
     */
59
    public static final String LINE_TYPE_SOLID = "solid";
60
    public static final String LINE_TYPE_DASH = "dash";
61
    public static final String LINE_TYPE_DOT = "dot";
62
    public static final String LINE_TYPE_DASH_DOT = "dash_dot";
63
    public static final String LINE_TYPE_DASH_DOT_DOT = "dash_dot_dot";
64
    public static final HashMap LINE_TYPES = new HashMap();
65

    
66
    static {
67
        LINE_TYPES.put(LINE_TYPE_SOLID, "0");
68
        LINE_TYPES.put(LINE_TYPE_DASH, "2");
69
        LINE_TYPES.put(LINE_TYPE_DOT, "0.05,2");
70
        LINE_TYPES.put(LINE_TYPE_DASH_DOT, "2,2,0.01,2");
71
        LINE_TYPES.put(LINE_TYPE_DASH_DOT_DOT, "2,2,0.01,2,0.01,2");
72
    }
73

    
74
    /*
75
     * End line types
76
     */
77
    public static final String CAP_TYPE_BUTT = "butt";
78
    public static final String CAP_TYPE_ROUND = "round";
79
    public static final String CAP_TYPE_SQUARE = "square";
80

    
81
    /*
82
     * Joining line types
83
     */
84
    public static final String JOIN_TYPE_ROUND = "round";
85
    public static final String JOIN_TYPE_MITER = "miter";
86
    public static final String JOIN_TYPE_BEVEL = "bevel";
87

    
88
    /*
89
     * Polygon fill types
90
     */
91
    public static final String FILL_TYPE_SOLID = "solid";
92
    public static final String FILL_TYPE_BDIAG = "bdiagonal";
93
    public static final String FILL_TYPE_FDIAG = "fdiagonal";
94
    public static final String FILL_TYPE_CROSS = "cross";
95
    public static final String FILL_TYPE_DIAGC = "diagcross";
96
    public static final String FILL_TYPE_HORIZ = "horizontal";
97
    public static final String FILL_TYPE_VERT = "vertical";
98
    public static final String FILL_TYPE_GRAYFILL = "gray";
99
    public static final String FILL_TYPE_LIGHTGRAYFILL = "lightgray";
100
    public static final String FILL_TYPE_DARKGRAYFILL = "darkgray";
101

    
102
    /*
103
     * Text types
104
     */
105
    public static final String TEXT_TYPE_REGULAR = "regular";
106
    public static final String TEXT_TYPE_BOLD = "bold";
107
    public static final String TEXT_TYPE_ITALIC = "italic";
108
    public static final String TEXT_TYPE_UNDERLINE = "underline";
109
    public static final String TEXT_TYPE_OUTLINE = "outline";
110
    public static final String TEXT_TYPE_BOLDITALIC = "bolditalic";
111

    
112
    /**
113
     * Parses a <em>RR,GG,BB</em> string into a correct Color object
114
     * @see java.awt.Color#Color(int, int, int)
115
     * @param str
116
     * @return
117
     */
118
    public static Color getColor(String str, float alpha) {
119
        String[] strA = str.split(",");
120

    
121
        if (strA.length != 3) {
122
            return null;
123
        }
124

    
125
        int red = Integer.parseInt(strA[0]);
126
        int green = Integer.parseInt(strA[1]);
127
        int blue = Integer.parseInt(strA[2]);
128
        int ialpha = (int) alpha * 255;
129

    
130
        return new Color(red, green, blue, ialpha);
131
    }
132

    
133
    /**
134
     * Generates a String representations on the form <em>RR,GG,BB</em>
135
     * @see java.awt.Color
136
     * @param color
137
     * @return
138
     */
139
    public static String getStringColor(Color color) {
140
        return color.getRed() + "," + color.getGreen() + "," + color.getBlue();
141
    }
142

    
143
    /**
144
     * Returns a correct Shape type from an ArcIMS Symbol definition
145
     * @see IArcIMSSymbol
146
     * @see FConstant
147
     * @param isimb
148
     * @return
149
     */
150
    public static int getShapeType(IArcIMSSymbol isimb) {
151
        ISymbol simb = isimb.getFSymbol();
152
        int fsimbType = simb.getSymbolType();
153
        int type = Geometry.TYPES.NULL;
154

    
155
        if (fsimbType == FConstant.SYMBOL_TYPE_FILL) {
156
            type = Geometry.TYPES.SURFACE;
157
        } else if (fsimbType == FConstant.SYMBOL_TYPE_LINE) {
158
            type = Geometry.TYPES.CURVE;
159
        } else if (fsimbType == FConstant.SYMBOL_TYPE_MULTIPOINT) {
160
            type = Geometry.TYPES.MULTIPOINT;
161
        }
162

    
163
        return type;
164
    }
165

    
166
    public static int getFontStyle(String strStyle) {
167
        if (strStyle.equals(TEXT_TYPE_BOLD)) {
168
            return Font.BOLD;
169
        } else if (strStyle.equals(TEXT_TYPE_ITALIC)) {
170
            return Font.ITALIC;
171
        }
172
        //                else if (strStyle.equals(TEXT_TYPE_UNDERLINE))
173
        //                        return Font.HANGING_BASELINE; 
174
        //                else if (strStyle.equals(TEXT_TYPE_OUTLINE))
175
        //                        return Font.PLAIN; 
176
        else if (strStyle.equals(TEXT_TYPE_BOLDITALIC)) {
177
            return Font.BOLD + Font.ITALIC;
178
        }
179

    
180
        //If no type has found, return a plain type
181
        return Font.PLAIN;
182
    }
183

    
184
    public static boolean isVoid(String param) {
185
        boolean flag = true;
186

    
187
        if (param == null) {
188
            flag = false;
189
        } else if (param.equals("")) {
190
            flag = false;
191
        }
192

    
193
        return flag;
194
    }
195
}