1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
|
/*
* Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package javax.media.j3d;
/**
* The LineAttributes object defines all rendering state that can be set
* as a component object of a Shape3D node.
* The line attributes that can be defined are:<P>
* <UL><LI>Pattern - specifies the pattern used to draw the line:<p>
* <ul>
* <li>PATTERN_SOLID - draws a solid line with no pattern. This is
* the default.</li>
* <p>
* <li>PATTERN_DASH - draws dashed lines. Ideally, these will be drawn with
* a repeating pattern of 8 pixels on and 8 pixels off.</li>
* <p>
* <li>PATTERN_DOT - draws dotted lines. Ideally, these will be drawn with
* a repeating pattern of 1 pixel on and 7 pixels off.</li>
* <p>
* <li>PATTERN_DASH_DOT - draws dashed-dotted lines. Ideally, these will be
* drawn with a repeating pattern of 7 pixels on, 4 pixels off, 1 pixel on,
* and 4 pixels off.</li>
* <p>
* <li>PATTERN_USER_DEFINED - draws lines with a user-defined line pattern.
* See "User-defined Line Patterns," below.</li><p>
* </ul>
* <p>
* <LI>Antialiasing (enabled or disabled). By default, antialiasing
* is disabled.</LI>
* <p>
* <p>
* If antialiasing is enabled, the lines are considered transparent
* for rendering purposes. They are rendered with all the other transparent
* objects and adhere to the other transparency settings such as the
* View transparency sorting policy and the View depth buffer freeze
* transparent enable.
* </p>
* <LI>Width (in pixels). The default is a line width of one pixel.
* </LI></UL><p>
*
* <b>User-defined Line Patterns</b>
* <p>
* A user-defined line pattern is specified with a pattern mask and
* an optional scale factor.
* <p>
* The Pattern Mask<p>
*
* The pattern is specified
* using a 16-bit mask that specifies on and off segments. Bit 0 in
* the pattern mask corresponds to the first pixel of the line or line
* strip primitive. A value of 1 for a bit in the pattern mask indicates
* that the corresponding pixel is drawn, while a value of 0
* indicates that the corresponding pixel is not drawn. After all 16 bits
* in the pattern are used, the pattern is repeated.
* <p>
* For example, a mask of 0x00ff defines a dashed line with a repeating
* pattern of 8 pixels on followed by 8 pixels off. A value of 0x0101
* defines a a dotted line with a repeating pattern of 1 pixel on and 7
* pixels off.
* <p>
* The pattern continues around individual line segments of a line strip
* primitive. It is restarted at the beginning of each new line strip.
* For line array primitives, the pattern is restarted at the beginning
* of each line.
* <p>
* The Scale Factor
* <p>
* The pattern is multiplied by the scale factor such that each bit in
* the pattern mask corresponds to that many consecutive pixels.
* For example, a scale factor of 3 applied to a pattern mask of 0x001f
* would produce a repeating pattern of 15 pixels on followed by 33
* pixels off. The valid range for this attribute is [1,15]. Values
* outside this range are clamped.<p>
*
* @see Appearance
* @see View
*/
public class LineAttributes extends NodeComponent {
/**
* Specifies that this LineAttributes object allows reading its
* line width information.
*/
public static final int
ALLOW_WIDTH_READ = CapabilityBits.LINE_ATTRIBUTES_ALLOW_WIDTH_READ;
/**
* Specifies that this LineAttributes object allows writing its
* line width information.
*/
public static final int
ALLOW_WIDTH_WRITE = CapabilityBits.LINE_ATTRIBUTES_ALLOW_WIDTH_WRITE;
/**
* Specifies that this LineAttributes object allows reading its
* line pattern information.
*/
public static final int
ALLOW_PATTERN_READ = CapabilityBits.LINE_ATTRIBUTES_ALLOW_PATTERN_READ;
/**
* Specifies that this LineAttributes object allows writing its
* line pattern information.
*/
public static final int
ALLOW_PATTERN_WRITE = CapabilityBits.LINE_ATTRIBUTES_ALLOW_PATTERN_WRITE;
/**
* Specifies that this LineAttributes object allows reading its
* line antialiasing flag.
*/
public static final int
ALLOW_ANTIALIASING_READ = CapabilityBits.LINE_ATTRIBUTES_ALLOW_ANTIALIASING_READ;
/**
* Specifies that this LineAttributes object allows writing its
* line antialiasing flag.
*/
public static final int
ALLOW_ANTIALIASING_WRITE = CapabilityBits.LINE_ATTRIBUTES_ALLOW_ANTIALIASING_WRITE;
/**
* Draw solid lines with no pattern.
* @see #setLinePattern
*/
public static final int PATTERN_SOLID = 0;
/**
* Draw dashed lines. Ideally, these will be drawn with
* a repeating pattern of 8 pixels on and 8 pixels off.
* @see #setLinePattern
*/
public static final int PATTERN_DASH = 1;
/**
* Draw dotted lines. Ideally, these will be drawn with
* a repeating pattern of 1 pixel on and 7 pixels off.
* @see #setLinePattern
*/
public static final int PATTERN_DOT = 2;
/**
* Draw dashed-dotted lines. Ideally, these will be drawn with
* a repeating pattern of 7 pixels on, 4 pixels off, 1 pixel on,
* and 4 pixels off.
* @see #setLinePattern
*/
public static final int PATTERN_DASH_DOT = 3;
/**
* Draw lines with a user-defined line pattern. The line pattern
* is specified with a pattern mask and scale factor.
* @see #setLinePattern
* @see #setPatternMask
* @see #setPatternScaleFactor
*
* @since Java 3D 1.2
*/
public static final int PATTERN_USER_DEFINED = 4;
// Array for setting default read capabilities
private static final int[] readCapabilities = {
ALLOW_ANTIALIASING_READ,
ALLOW_PATTERN_READ,
ALLOW_WIDTH_READ
};
/**
* Constructs a LineAttributes object with default parameters.
* The default values are as follows:
* <ul>
* line width : 1<br>
* line pattern : PATTERN_SOLID<br>
* pattern mask : 0xffff<br>
* pattern scale factor : 1<br>
* line antialiasing : false<br>
* </ul>
*/
public LineAttributes(){
// set default read capabilities
setDefaultReadCapabilities(readCapabilities);
}
/**
* Constructs a LineAttributes object with specified values.
* @param lineWidth the width of lines in pixels
* @param linePattern the line pattern, one of PATTERN_SOLID,
* PATTERN_DASH, PATTERN_DOT, or PATTERN_DASH_DOT
* @param lineAntialiasing flag to set line antialising ON or OFF
*/
public LineAttributes(float lineWidth, int linePattern,
boolean lineAntialiasing){
if (linePattern < PATTERN_SOLID || linePattern > PATTERN_DASH_DOT)
throw new IllegalArgumentException(J3dI18N.getString("LineAttributes0"));
// set default read capabilities
setDefaultReadCapabilities(readCapabilities);
((LineAttributesRetained)this.retained).initLineWidth(lineWidth);
((LineAttributesRetained)this.retained).initLinePattern(linePattern);
((LineAttributesRetained)this.retained).initLineAntialiasingEnable(lineAntialiasing);
}
/**
* Sets the line width for this LineAttributes component object.
* @param lineWidth the width, in pixels, of line primitives
* @exception CapabilityNotSetException if appropriate capability is
* not set and this object is part of live or compiled scene graph
*/
public void setLineWidth(float lineWidth) {
if (isLiveOrCompiled())
if(!this.getCapability(ALLOW_WIDTH_WRITE))
throw new CapabilityNotSetException(J3dI18N.getString("LineAttributes1"));
if (isLive())
((LineAttributesRetained)this.retained).setLineWidth(lineWidth);
else
((LineAttributesRetained)this.retained).initLineWidth(lineWidth);
}
/**
* Gets the line width for this LineAttributes component object.
* @return the width, in pixels, of line primitives
* @exception CapabilityNotSetException if appropriate capability is
* not set and this object is part of live or compiled scene graph
*/
public float getLineWidth() {
if (isLiveOrCompiled())
if(!this.getCapability(ALLOW_WIDTH_READ))
throw new CapabilityNotSetException(J3dI18N.getString("LineAttributes2"));
return ((LineAttributesRetained)this.retained).getLineWidth();
}
/**
* Sets the line pattern for this LineAttributes component object.
* @param linePattern the line pattern to be used, one of:
* PATTERN_SOLID, PATTERN_DASH, PATTERN_DOT, PATTERN_DASH_DOT, or
* PATTERN_USER_DEFINED.
* @exception CapabilityNotSetException if appropriate capability is
* not set and this object is part of live or compiled scene graph
*/
public void setLinePattern(int linePattern) {
if (isLiveOrCompiled())
if(!this.getCapability(ALLOW_PATTERN_WRITE))
throw new CapabilityNotSetException(J3dI18N.getString("LineAttributes3"));
if (linePattern < PATTERN_SOLID || linePattern > PATTERN_USER_DEFINED)
throw new IllegalArgumentException(J3dI18N.getString("LineAttributes4"));
if (isLive())
((LineAttributesRetained)this.retained).setLinePattern(linePattern);
else
((LineAttributesRetained)this.retained).initLinePattern(linePattern);
}
/**
* Gets the line pattern for this LineAttributes component object.
* @return the line pattern
* @exception CapabilityNotSetException if appropriate capability is
* not set and this object is part of live or compiled scene graph
*/
public int getLinePattern() {
if (isLiveOrCompiled())
if(!this.getCapability(ALLOW_PATTERN_READ))
throw new CapabilityNotSetException(J3dI18N.getString("LineAttributes5"));
return ((LineAttributesRetained)this.retained).getLinePattern();
}
/**
* Sets the line pattern mask to the specified value. This is
* used when the linePattern attribute is set to
* PATTERN_USER_DEFINED. In this mode, the pattern is specified
* using a 16-bit mask that specifies on and off segments. Bit 0
* in the pattern mask corresponds to the first pixel of the line
* or line strip primitive. A value of 1 for a bit in the pattern
* mask indicates that the corresponding pixel is drawn, while a
* value of 0 indicates that the corresponding pixel is not drawn.
* After all 16 bits in the pattern are used, the pattern is
* repeated. For example, a mask of 0x00ff defines a dashed line
* with a repeating pattern of 8 pixels on followed by 8 pixels
* off. A value of 0x0101 defines a a dotted line with a
* repeating pattern of 1 pixel on and 7 pixels off
* <p>
* The pattern continues around individual line segments of a line
* strip primitive. It is restarted at the beginning of each new
* line strip. For line array primitives, the pattern is
* restarted at the beginning of each line.
* @param mask the new line pattern mask
* @exception CapabilityNotSetException if appropriate capability is
* not set and this object is part of live or compiled scene graph
* @see #setPatternScaleFactor
*
* @since Java 3D 1.2
*/
public void setPatternMask(int mask) {
if (isLiveOrCompiled() &&
!this.getCapability(ALLOW_PATTERN_WRITE))
throw new CapabilityNotSetException(J3dI18N.getString("LineAttributes8"));
if (isLive())
((LineAttributesRetained)this.retained).setPatternMask(mask);
else
((LineAttributesRetained)this.retained).initPatternMask(mask);
}
/**
* Retrieves the line pattern mask.
* @return the line pattern mask
* @exception CapabilityNotSetException if appropriate capability is
* not set and this object is part of live or compiled scene graph
*
* @since Java 3D 1.2
*/
public int getPatternMask() {
if (isLiveOrCompiled() &&
!this.getCapability(ALLOW_PATTERN_READ))
throw new CapabilityNotSetException(J3dI18N.getString("LineAttributes9"));
return ((LineAttributesRetained)this.retained).getPatternMask();
}
/**
* Sets the line pattern scale factor to the specified value.
* This is used in conjunction with the patternMask when the
* linePattern attribute is set to PATTERN_USER_DEFINED. The
* pattern is multiplied by the scale factor such that each bit in
* the pattern mask corresponds to that many consecutive pixels.
* For example, a scale factor of 3 applied to a pattern mask of
* 0x001f would produce a repeating pattern of 15 pixels on
* followed by 33 pixels off. The valid range for this attribute
* is [1,15]. Values outside this range are clamped.
* @param scaleFactor the new line pattern scale factor
* @exception CapabilityNotSetException if appropriate capability is
* not set and this object is part of live or compiled scene graph
* @see #setPatternMask
*
* @since Java 3D 1.2
*/
public void setPatternScaleFactor(int scaleFactor) {
if (isLiveOrCompiled() &&
!this.getCapability(ALLOW_PATTERN_WRITE))
throw new CapabilityNotSetException(J3dI18N.getString("LineAttributes10"));
if (isLive())
((LineAttributesRetained)this.retained).setPatternScaleFactor(scaleFactor);
else
((LineAttributesRetained)this.retained).initPatternScaleFactor(scaleFactor);
}
/**
* Retrieves the line pattern scale factor.
* @return the line pattern scale factor
* @exception CapabilityNotSetException if appropriate capability is
* not set and this object is part of live or compiled scene graph
*
* @since Java 3D 1.2
*/
public int getPatternScaleFactor() {
if (isLiveOrCompiled() &&
!this.getCapability(ALLOW_PATTERN_READ))
throw new CapabilityNotSetException(J3dI18N.getString("LineAttributes11"));
return ((LineAttributesRetained)this.retained).getPatternScaleFactor();
}
/**
* Enables or disables line antialiasing
* for this LineAttributes component object.
* <p>
* If antialiasing is enabled, the lines are considered transparent
* for rendering purposes. They are rendered with all the other
* transparent objects and adhere to the other transparency settings
* such as the View transparency sorting policy and the View depth buffer
* freeze transparent enable.
* </p>
* @param state true or false to enable or disable line antialiasing
* @exception CapabilityNotSetException if appropriate capability is
* not set and this object is part of live or compiled scene graph
* @see View
*/
public void setLineAntialiasingEnable(boolean state) {
if (isLiveOrCompiled())
if(!this.getCapability(ALLOW_ANTIALIASING_WRITE))
throw new CapabilityNotSetException(J3dI18N.getString("LineAttributes6"));
if (isLive())
((LineAttributesRetained)this.retained).setLineAntialiasingEnable(state);
else
((LineAttributesRetained)this.retained).initLineAntialiasingEnable(state);
}
/**
* Retrieves the state of the line antialiasing flag.
* @return true if line antialiasing is enabled,
* false if line antialiasing is disabled
* @exception CapabilityNotSetException if appropriate capability is
* not set and this object is part of live or compiled scene graph
*/
public boolean getLineAntialiasingEnable() {
if (isLiveOrCompiled())
if(!this.getCapability(ALLOW_ANTIALIASING_READ))
throw new CapabilityNotSetException(J3dI18N.getString("LineAttributes7"));
return ((LineAttributesRetained)this.retained).getLineAntialiasingEnable();
}
/**
* Creates a retained mode LineAttributesRetained object that this
* LineAttributes component object will point to.
*/
@Override
void createRetained() {
this.retained = new LineAttributesRetained();
this.retained.setSource(this);
}
/**
* @deprecated replaced with cloneNodeComponent(boolean forceDuplicate)
*/
@Override
public NodeComponent cloneNodeComponent() {
LineAttributes la = new LineAttributes();
la.duplicateNodeComponent(this);
return la;
}
/**
* Copies all node information from <code>originalNodeComponent</code> into
* the current node. This method is called from the
* <code>duplicateNode</code> method. This routine does
* the actual duplication of all "local data" (any data defined in
* this object).
*
* @param originalNodeComponent the original node to duplicate.
* @param forceDuplicate when set to <code>true</code>, causes the
* <code>duplicateOnCloneTree</code> flag to be ignored. When
* <code>false</code>, the value of each node's
* <code>duplicateOnCloneTree</code> variable determines whether
* NodeComponent data is duplicated or copied.
*
* @see Node#cloneTree
* @see NodeComponent#setDuplicateOnCloneTree
*/
@Override
void duplicateAttributes(NodeComponent originalNodeComponent,
boolean forceDuplicate) {
super.duplicateAttributes(originalNodeComponent,
forceDuplicate);
LineAttributesRetained attr = (LineAttributesRetained)
originalNodeComponent.retained;
LineAttributesRetained rt = (LineAttributesRetained) retained;
rt.initLineWidth(attr.getLineWidth());
rt.initLinePattern(attr.getLinePattern());
rt.initLineAntialiasingEnable(attr.getLineAntialiasingEnable());
rt.initPatternMask(attr.getPatternMask());
rt.initPatternScaleFactor(attr.getPatternScaleFactor());
}
}
|