1 package org.lcsim.geometry.compact;
2
3 import java.awt.Color;
4
5 import org.jdom.DataConversionException;
6 import org.jdom.Element;
7
8
9
10
11
12
13
14
15 public class VisAttributes
16 {
17
18 private float[] rgba = new float[4];
19 private Color color = null;
20 private String name = null;
21 private String linestyle = "unbroken";
22 private String drawingstyle = "wireframe";
23 private boolean visible = true;
24 private boolean showdaughters = true;
25
26
27
28
29
30 public VisAttributes( String name )
31 {
32 this.name = name;
33 }
34
35
36
37
38
39 protected VisAttributes( Element node )
40 {
41 try
42 {
43 this.name = node.getAttributeValue( "name" );
44
45
46 if ( node.getAttribute( "r" ) != null )
47 {
48 this.rgba[ 0 ] = (float) node.getAttribute( "r" ).getDoubleValue();
49 }
50
51 if ( node.getAttribute( "g" ) != null )
52 {
53 this.rgba[ 1 ] = (float) node.getAttribute( "g" ).getDoubleValue();
54 }
55
56 if ( node.getAttribute( "b" ) != null )
57 {
58 this.rgba[ 2 ] = (float) node.getAttribute( "b" ).getDoubleValue();
59 }
60
61 if ( node.getAttribute( "alpha" ) != null )
62 {
63 this.rgba[ 3 ] = (float) node.getAttribute( "alpha" ).getDoubleValue();
64 }
65
66
67 this.color = new Color( rgba[ 0 ], rgba[ 1 ], rgba[ 2 ], rgba[ 3 ] );
68
69 if ( node.getAttribute( "lineStyle" ) != null )
70 {
71 this.linestyle = node.getAttributeValue( "lineStyle" );
72 }
73
74 if ( node.getAttribute( "showDaughters" ) != null )
75 {
76 this.showdaughters = node.getAttribute( "showDaughters" )
77 .getBooleanValue();
78 }
79
80 if ( node.getAttribute( "visible" ) != null )
81 {
82 this.visible = node.getAttribute( "visible" ).getBooleanValue();
83 }
84
85 if ( node.getAttribute( "drawingStyle" ) != null )
86 {
87 this.drawingstyle = node.getAttributeValue( "drawingStyle" );
88 }
89 }
90 catch ( DataConversionException e )
91 {
92 throw new RuntimeException( e );
93 }
94 }
95
96
97
98
99
100 public void setVisible( boolean visible )
101 {
102 this.visible = visible;
103 }
104
105
106
107
108
109
110
111
112 public final void setColor( float r, float g, float b, float a )
113 {
114 rgba[ 0 ] = r;
115 rgba[ 1 ] = g;
116 rgba[ 2 ] = b;
117 rgba[ 3 ] = a;
118
119 color = new Color( r, g, b, a );
120 }
121
122
123
124
125
126 public final void setColor( Color color )
127 {
128 this.color = color;
129
130 rgba[ 0 ] = color.getRed();
131 rgba[ 1 ] = color.getGreen();
132 rgba[ 2 ] = color.getBlue();
133 rgba[ 3 ] = color.getAlpha();
134 }
135
136
137
138
139
140 public final void setShowDaughters( boolean b )
141 {
142 showdaughters = b;
143 }
144
145
146
147
148
149 public final void setDrawingStyle( String drawingstyle )
150 {
151 this.drawingstyle = drawingstyle;
152 }
153
154
155
156
157
158 public final void setLineStyle( String s )
159 {
160 this.linestyle = s;
161 }
162
163
164
165
166
167 public final Color getColor()
168 {
169 return color;
170 }
171
172
173
174
175
176 public final boolean getVisible()
177 {
178 return visible;
179 }
180
181
182
183
184
185 public final boolean isVisible()
186 {
187 return visible;
188 }
189
190
191
192
193
194 public final boolean getShowDaughters()
195 {
196 return showdaughters;
197 }
198
199
200
201
202
203
204 public final String getDrawingStyle()
205 {
206 return drawingstyle;
207 }
208
209
210
211
212
213
214 public final String getLineStyle()
215 {
216 return linestyle;
217 }
218
219
220
221
222
223 public final String getName()
224 {
225 return name;
226 }
227
228
229
230
231
232 public final float[] getRGBA()
233 {
234 return rgba;
235 }
236 }