gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster.2.4 / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.legend / org.gvsig.raster.lib.legend.impl / src / main / java / org / gvsig / raster / lib / legend / impl / DefaultTransparencyRange.java @ 6322
History | View | Annotate | Download (5.08 KB)
1 |
package org.gvsig.raster.lib.legend.impl; |
---|---|
2 |
|
3 |
import org.gvsig.raster.lib.legend.api.TransparencyRange; |
4 |
import org.gvsig.tools.ToolsLocator; |
5 |
import org.gvsig.tools.dynobject.DynStruct; |
6 |
import org.gvsig.tools.persistence.PersistenceManager; |
7 |
import org.gvsig.tools.persistence.PersistentState; |
8 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
9 |
|
10 |
/**
|
11 |
* @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
|
12 |
*
|
13 |
*/
|
14 |
public class DefaultTransparencyRange implements TransparencyRange { |
15 |
|
16 |
private static final String PERSISTENCE_NAME = "transparencyRange"; |
17 |
private static final String PERSISTENCE_DESCRIPTION = "transparencyRange"; |
18 |
|
19 |
private static final String IS_AND_PERSISTENCE_FIELD = "isAnd"; |
20 |
private static final String RED_PERSISTENCE_FIELD = "red"; |
21 |
private static final String GREEN_PERSISTENCE_FIELD = "green"; |
22 |
private static final String BLUE_PERSISTENCE_FIELD = "blue"; |
23 |
private static final String ALPHA_PERSISTENCE_FIELD = "aplha"; |
24 |
|
25 |
private boolean isAnd; |
26 |
private int[] red; |
27 |
private int[] green; |
28 |
private int[] blue; |
29 |
private int alpha; |
30 |
|
31 |
public DefaultTransparencyRange() {
|
32 |
this.isAnd = false; |
33 |
this.red = new int[2]; |
34 |
this.green = new int[2]; |
35 |
this.blue = new int[2]; |
36 |
this.alpha = 255; |
37 |
} |
38 |
|
39 |
public DefaultTransparencyRange(int[] redRange, int[] greenRange, int[] blueRange, int alpha, boolean isAnd) { |
40 |
this.isAnd = isAnd;
|
41 |
setRGB(redRange, greenRange, blueRange); |
42 |
setAlpha(alpha); |
43 |
} |
44 |
|
45 |
@Override
|
46 |
public boolean isAnd() { |
47 |
return this.isAnd; |
48 |
} |
49 |
|
50 |
@Override
|
51 |
public void setAnd(boolean flag) { |
52 |
this.isAnd = flag;
|
53 |
} |
54 |
|
55 |
@Override
|
56 |
public int[] getBlue() { |
57 |
return this.blue; |
58 |
} |
59 |
|
60 |
@Override
|
61 |
public void setRGB(int[] red, int[] green, int[] blue) { |
62 |
|
63 |
if (red.length != 2 || green.length != 2 || blue.length != 2) { |
64 |
throw new IllegalArgumentException( |
65 |
"Transparency range values only accepts 2 values for each color");
|
66 |
} |
67 |
|
68 |
this.red = red;
|
69 |
this.green = green;
|
70 |
this.blue = blue;
|
71 |
} |
72 |
|
73 |
@Override
|
74 |
public void setBlue(int[] blue) { |
75 |
if (blue.length != 2) { |
76 |
throw new IllegalArgumentException( |
77 |
"Transparency range values only accepts 2 values for each color");
|
78 |
} |
79 |
|
80 |
this.blue = blue;
|
81 |
} |
82 |
|
83 |
@Override
|
84 |
public int[] getGreen() { |
85 |
return this.green; |
86 |
} |
87 |
|
88 |
@Override
|
89 |
public void setGreen(int[] green) { |
90 |
if (green.length != 2) { |
91 |
throw new IllegalArgumentException( |
92 |
"Transparency range values only accepts 2 values for each color");
|
93 |
} |
94 |
|
95 |
this.green = green;
|
96 |
} |
97 |
|
98 |
@Override
|
99 |
public int[] getRed() { |
100 |
return this.red; |
101 |
} |
102 |
|
103 |
@Override
|
104 |
public void setRed(int[] red) { |
105 |
if (red.length != 2) { |
106 |
throw new IllegalArgumentException( |
107 |
"Transparency range values only accepts 2 values for each color");
|
108 |
} |
109 |
|
110 |
this.red = red;
|
111 |
} |
112 |
|
113 |
@Override
|
114 |
public int getAlpha() { |
115 |
return this.alpha; |
116 |
} |
117 |
|
118 |
@Override
|
119 |
public void setAlpha(int alpha) { |
120 |
|
121 |
if (alpha < 0 || alpha > 256) { |
122 |
throw new IllegalArgumentException("Alpha value has to be between 0 and 255"); |
123 |
} |
124 |
|
125 |
this.alpha = alpha;
|
126 |
} |
127 |
|
128 |
public static void registerDefinition() { |
129 |
|
130 |
PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
131 |
DynStruct definition = persistenceManager.getDefinition(PERSISTENCE_NAME); |
132 |
if (definition == null) { |
133 |
definition = |
134 |
persistenceManager.addDefinition(DefaultTransparencyRange.class, PERSISTENCE_NAME, |
135 |
PERSISTENCE_DESCRIPTION, null, null); |
136 |
definition.addDynFieldArray(RED_PERSISTENCE_FIELD).setClassOfValue(Integer.class)
|
137 |
.setMandatory(false);
|
138 |
definition.addDynFieldArray(GREEN_PERSISTENCE_FIELD).setClassOfValue(Integer.class)
|
139 |
.setMandatory(false);
|
140 |
definition.addDynFieldArray(BLUE_PERSISTENCE_FIELD).setClassOfValue(Integer.class)
|
141 |
.setMandatory(false);
|
142 |
definition.addDynFieldBoolean(IS_AND_PERSISTENCE_FIELD).setMandatory(false);
|
143 |
definition.addDynFieldInt(ALPHA_PERSISTENCE_FIELD).setMandatory(false);
|
144 |
} |
145 |
} |
146 |
|
147 |
@Override
|
148 |
public void saveToState(PersistentState state) throws PersistenceException { |
149 |
state.set(RED_PERSISTENCE_FIELD, this.getRed());
|
150 |
state.set(BLUE_PERSISTENCE_FIELD, this.getBlue());
|
151 |
state.set(GREEN_PERSISTENCE_FIELD, this.getGreen());
|
152 |
state.set(IS_AND_PERSISTENCE_FIELD, isAnd); |
153 |
state.set(ALPHA_PERSISTENCE_FIELD, alpha); |
154 |
} |
155 |
|
156 |
@Override
|
157 |
public void loadFromState(PersistentState state) throws PersistenceException { |
158 |
this.red = state.getIntArray(RED_PERSISTENCE_FIELD);
|
159 |
this.green = state.getIntArray(GREEN_PERSISTENCE_FIELD);
|
160 |
this.blue = state.getIntArray(BLUE_PERSISTENCE_FIELD);
|
161 |
this.alpha = state.getInt(ALPHA_PERSISTENCE_FIELD);
|
162 |
this.isAnd = state.getBoolean(IS_AND_PERSISTENCE_FIELD);
|
163 |
} |
164 |
} |