summaryrefslogtreecommitdiffstats
path: root/src/javax/media/j3d/Appearance.java
blob: a26eb84a3d0cd75a71cecc975dba8e394491a22a (plain)
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
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
/*
 * Copyright 1996-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;

import java.util.Hashtable;

/**
 * The Appearance object defines all rendering state that can be set
 * as a component object of a Shape3D node. The rendering state
 * consists of the following:<p>
 * <ul>
 * <li>Coloring attributes - defines attributes used in color selection
 * and shading. These attributes are defined in a ColoringAttributes
 * object.</li><p>
 *
 * <li>Line attributes - defines attributes used to define lines, including
 * the pattern, width, and whether antialiasing is to be used. These
 * attributes are defined in a LineAttributes object.</li><p>
 *
 * <li>Point attributes - defines attributes used to define points,
 * including the size and whether antialiasing is to be used. These
 * attributes are defined in a PointAttributes object.</li><p>
 *
 * <li>Polygon attributes - defines the attributes used to define
 * polygons, including culling, rasterization mode (filled, lines,
 * or points), constant offset, offset factor, and whether back
 * back facing normals are flipped. These attributes are defined
 * in a PolygonAttributes object.</li><p>
 *
 * <li>Rendering attributes - defines rendering operations,
 * including the alpha test function and test value, the raster
 * operation, whether vertex colors are ignored, whether invisible
 * objects are rendered, and whether the depth buffer is enabled.
 * These attributes are defined in a RenderingAttributes
 * object.</li><p>
 *
 * <li>Transparency attributes - defines the attributes that affect
 * transparency of the object, such as the transparency mode
 * (blended, screen-door), blending function (used in transparency
 * and antialiasing operations), and a blend value that defines
 * the amount of transparency to be applied to this Appearance
 * component object.</li><p>
 *
 * <li>Material - defines the appearance of an object under illumination,
 * such as the ambient color, diffuse color, specular color, emissive
 * color, and shininess. These attributes are defined in a Material
 * object.</li><p>
 *
 * <li>Texture - defines the texture image and filtering
 * parameters used when texture mapping is enabled. These attributes
 * are defined in a Texture object.</li><p>
 *
 * <li>Texture attributes - defines the attributes that apply to
 * texture mapping, such as the texture mode, texture transform,
 * blend color, and perspective correction mode. These attributes
 * are defined in a TextureAttributes object.</li><p>
 *
 * <li>Texture coordinate generation - defines the attributes
 * that apply to texture coordinate generation, such as whether
 * texture coordinate generation is enabled, coordinate format
 * (2D or 3D coordinates), coordinate generation mode (object
 * linear, eye linear, or spherical reflection mapping), and the
 * R, S, and T coordinate plane equations. These attributes
 * are defined in a TexCoordGeneration object.</li><p>
 *
 * <li>Texture unit state - array that defines texture state for each
 * of <i>N</i> separate texture units.  This allows multiple textures
 * to be applied to geometry.  Each TextureUnitState object contains a
 * Texture object, TextureAttributes, and TexCoordGeneration object
 * for one texture unit.  If the length of the texture unit state
 * array is greater than 0, then the array is used for all texture
 * state; the individual Texture, TextureAttributes, and
 * TexCoordGeneration objects in this Appearance object are not used
 * and and must not be set by an application. If the length of the
 * texture unit state array is 0, the multi-texture is disabled and
 * the Texture, TextureAttributes, and TexCoordGeneration objects
 * in the Appearance object are used. If the application sets the
 * existing Texture, TextureAttributes, and TexCoordGeneration
 * objects to non-null values, they effectively define the state
 * for texture unit 0. If the TextureUnitState array is set to a
 * non-null, non-empty array, the individual TextureUnitState
 * objects define the state for texture units 0 through <i>n</i>
 * -1. If both the old and new values are set, an exception is thrown.
 *
 * </li>
 * </ul>
 *
 * @see ColoringAttributes
 * @see LineAttributes
 * @see PointAttributes
 * @see PolygonAttributes
 * @see RenderingAttributes
 * @see TransparencyAttributes
 * @see Material
 * @see Texture
 * @see TextureAttributes
 * @see TexCoordGeneration
 * @see TextureUnitState
 */
public class Appearance extends NodeComponent {

  /**
   * Specifies that this Appearance object
   * allows reading its coloringAttributes component
   * information.
   */
  public static final int
    ALLOW_COLORING_ATTRIBUTES_READ = CapabilityBits.APPEARANCE_ALLOW_COLORING_ATTRIBUTES_READ;

  /**
   * Specifies that this Appearance object
   * allows writing its coloringAttributes component
   * information.
   */
  public static final int
    ALLOW_COLORING_ATTRIBUTES_WRITE = CapabilityBits.APPEARANCE_ALLOW_COLORING_ATTRIBUTES_WRITE;

  /**
   * Specifies that this Appearance object
   * allows reading its transparency component
   * information.
   */
  public static final int
    ALLOW_TRANSPARENCY_ATTRIBUTES_READ = CapabilityBits.APPEARANCE_ALLOW_TRANSPARENCY_ATTRIBUTES_READ;

  /**
   * Specifies that this Appearance object
   * allows writing its transparency component
   * information.
   */
  public static final int
    ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE = CapabilityBits.APPEARANCE_ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE;

  /**
   * Specifies that this Appearance object
   * allows reading its rendering/rasterization component
   * information.
   */
  public static final int
    ALLOW_RENDERING_ATTRIBUTES_READ = CapabilityBits.APPEARANCE_ALLOW_RENDERING_ATTRIBUTES_READ;

  /**
   * Specifies that this Appearance object
   * allows writing its rendering/rasterization component
   * information.
   */
  public static final int
    ALLOW_RENDERING_ATTRIBUTES_WRITE = CapabilityBits.APPEARANCE_ALLOW_RENDERING_ATTRIBUTES_WRITE;

  /**
   * Specifies that this Appearance object
   * allows reading its polygon component
   * information.
   */
  public static final int
    ALLOW_POLYGON_ATTRIBUTES_READ = CapabilityBits.APPEARANCE_ALLOW_POLYGON_ATTRIBUTES_READ;

  /**
   * Specifies that this Appearance object
   * allows writing its polygon component
   * information.
   */
  public static final int
    ALLOW_POLYGON_ATTRIBUTES_WRITE = CapabilityBits.APPEARANCE_ALLOW_POLYGON_ATTRIBUTES_WRITE;

  /**
   * Specifies that this Appearance object
   * allows reading its line component
   * information.
   */
  public static final int
    ALLOW_LINE_ATTRIBUTES_READ = CapabilityBits.APPEARANCE_ALLOW_LINE_ATTRIBUTES_READ;

  /**
   * Specifies that this Appearance object
   * allows writing its line component
   * information.
   */
  public static final int
    ALLOW_LINE_ATTRIBUTES_WRITE = CapabilityBits.APPEARANCE_ALLOW_LINE_ATTRIBUTES_WRITE;

  /**
   * Specifies that this Appearance object
   * allows reading its point component
   * information.
   */
  public static final int
    ALLOW_POINT_ATTRIBUTES_READ = CapabilityBits.APPEARANCE_ALLOW_POINT_ATTRIBUTES_READ;

  /**
   * Specifies that this Appearance object
   * allows writing its point component
   * information.
   */
  public static final int
    ALLOW_POINT_ATTRIBUTES_WRITE = CapabilityBits.APPEARANCE_ALLOW_POINT_ATTRIBUTES_WRITE;

  /**
   * Specifies that this Appearance object
   * allows reading its material component information.
   */
  public static final int
    ALLOW_MATERIAL_READ = CapabilityBits.APPEARANCE_ALLOW_MATERIAL_READ;

  /**
   * Specifies that this Appearance object
   * allows writing its material component information.
   */
  public static final int
    ALLOW_MATERIAL_WRITE = CapabilityBits.APPEARANCE_ALLOW_MATERIAL_WRITE;

  /**
   * Specifies that this Appearance object
   * allows reading its texture component information.
   */
  public static final int
    ALLOW_TEXTURE_READ = CapabilityBits.APPEARANCE_ALLOW_TEXTURE_READ;

  /**
   * Specifies that this Appearance object
   * allows writing its texture component information.
   */
  public static final int
    ALLOW_TEXTURE_WRITE = CapabilityBits.APPEARANCE_ALLOW_TEXTURE_WRITE;

  /**
   * Specifies that this Appearance object
   * allows reading its textureAttributes component
   * information.
   */
  public static final int
    ALLOW_TEXTURE_ATTRIBUTES_READ = CapabilityBits.APPEARANCE_ALLOW_TEXTURE_ATTRIBUTES_READ;

  /**
   * Specifies that this Appearance object
   * allows writing its textureAttributes component
   * information.
   */
  public static final int
    ALLOW_TEXTURE_ATTRIBUTES_WRITE = CapabilityBits.APPEARANCE_ALLOW_TEXTURE_ATTRIBUTES_WRITE;

  /**
   * Specifies that this Appearance object
   * allows reading its texture coordinate generation component
   * information.
   */
  public static final int
    ALLOW_TEXGEN_READ = CapabilityBits.APPEARANCE_ALLOW_TEXGEN_READ;

  /**
   * Specifies that this Appearance object
   * allows writing its texture coordinate generation component
   * information.
   */
  public static final int
    ALLOW_TEXGEN_WRITE = CapabilityBits.APPEARANCE_ALLOW_TEXGEN_WRITE;

  /**
   * Specifies that this Appearance object
   * allows reading its texture unit state component
   * information.
   *
   * @since Java 3D 1.2
   */
  public static final int ALLOW_TEXTURE_UNIT_STATE_READ =
    CapabilityBits.APPEARANCE_ALLOW_TEXTURE_UNIT_STATE_READ;

  /**
   * Specifies that this Appearance object
   * allows writing its texture unit state  component
   * information.
   *
   * @since Java 3D 1.2
   */
  public static final int ALLOW_TEXTURE_UNIT_STATE_WRITE =
    CapabilityBits.APPEARANCE_ALLOW_TEXTURE_UNIT_STATE_WRITE;

   // Array for setting default read capabilities
    private static final int[] readCapabilities = {
        ALLOW_COLORING_ATTRIBUTES_READ,
        ALLOW_LINE_ATTRIBUTES_READ,
        ALLOW_MATERIAL_READ,
        ALLOW_POINT_ATTRIBUTES_READ,
        ALLOW_POLYGON_ATTRIBUTES_READ,
        ALLOW_RENDERING_ATTRIBUTES_READ,
        ALLOW_TEXGEN_READ,
        ALLOW_TEXTURE_ATTRIBUTES_READ,
        ALLOW_TEXTURE_READ,
        ALLOW_TEXTURE_UNIT_STATE_READ,
        ALLOW_TRANSPARENCY_ATTRIBUTES_READ
    };

    /**
     * Constructs an Appearance component object using defaults for all
     * state variables. All component object references are initialized
     * to null.
     */
    public Appearance() {
	// Just use default values
        // set default read capabilities
        setDefaultReadCapabilities(readCapabilities);
    }

    /**
     * Creates the retained mode AppearanceRetained object that this
     * Appearance component object will point to.
     */
    @Override
    void createRetained() {
	this.retained = new AppearanceRetained();
	this.retained.setSource(this);
    }

    /**
     * Sets the material object to the specified object.
     * Setting it to null disables lighting.
     * @param material object that specifies the desired material
     * properties
     * @exception CapabilityNotSetException if appropriate capability is
     * not set and this object is part of live or compiled scene graph
     */
    public void setMaterial(Material material) {
	if (isLiveOrCompiled())
	  if (!this.getCapability(ALLOW_MATERIAL_WRITE))
		throw new CapabilityNotSetException(J3dI18N.getString("Appearance0"));
	((AppearanceRetained)this.retained).setMaterial(material);
    }

    /**
     * Retrieves the current material object.
     * @return the material object
     * @exception CapabilityNotSetException if appropriate capability is
     * not set and this object is part of live or compiled scene graph
     */
    public Material getMaterial() {
	if (isLiveOrCompiled())
	  if (!this.getCapability(ALLOW_MATERIAL_READ))
		throw new CapabilityNotSetException(J3dI18N.getString("Appearance1"));
	return ((AppearanceRetained)this.retained).getMaterial();
    }

    /**
     * Sets the coloringAttributes object to the specified object.
     * Setting it to null will result in default attribute usage.
     * @param coloringAttributes object that specifies the desired
     * coloringAttributes parameters
     * @exception CapabilityNotSetException if appropriate capability is
     * not set and this object is part of live or compiled scene graph
     */
    public void setColoringAttributes(ColoringAttributes coloringAttributes) {
	if (isLiveOrCompiled())
	  if (!this.getCapability(ALLOW_COLORING_ATTRIBUTES_WRITE))
		throw new CapabilityNotSetException(J3dI18N.getString("Appearance6"));
	((AppearanceRetained)this.retained).setColoringAttributes(coloringAttributes);
    }

    /**
     * Retrieves the current coloringAttributes object.
     * @return the coloringAttributes object
     * @exception CapabilityNotSetException if appropriate capability is
     * not set and this object is part of live or compiled scene graph
     */
    public ColoringAttributes getColoringAttributes() {
	if (isLiveOrCompiled())
	  if (!this.getCapability(ALLOW_COLORING_ATTRIBUTES_READ))
		throw new CapabilityNotSetException(J3dI18N.getString("Appearance7"));
	return ((AppearanceRetained)this.retained).getColoringAttributes();
    }

    /**
     * Sets the transparencyAttributes object to the specified object.
     * Setting it to null will result in default attribute usage.
     * @param transparencyAttributes object that specifies the desired
     * transparencyAttributes parameters
     * @exception CapabilityNotSetException if appropriate capability is
     * not set and this object is part of live or compiled scene graph
     */
    public void setTransparencyAttributes(TransparencyAttributes transparencyAttributes) {
	if (isLiveOrCompiled())
	  if (!this.getCapability(ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE))
		throw new CapabilityNotSetException(J3dI18N.getString("Appearance8"));
	((AppearanceRetained)this.retained).setTransparencyAttributes(transparencyAttributes);
    }

    /**
     * Retrieves the current transparencyAttributes object.
     * @return the transparencyAttributes object
     * @exception CapabilityNotSetException if appropriate capability is
     * not set and this object is part of live or compiled scene graph
     */
    public TransparencyAttributes getTransparencyAttributes() {
	if (isLiveOrCompiled())
	  if (!this.getCapability(ALLOW_TRANSPARENCY_ATTRIBUTES_READ))
		throw new CapabilityNotSetException(J3dI18N.getString("Appearance9"));
	return ((AppearanceRetained)this.retained).getTransparencyAttributes();
    }

    /**
     * Sets the renderingAttributes object to the specified object.
     * Setting it to null will result in default attribute usage.
     * @param renderingAttributes object that specifies the desired
     * renderingAttributes parameters
     * @exception CapabilityNotSetException if appropriate capability is
     * not set and this object is part of live or compiled scene graph
     */
    public void setRenderingAttributes(RenderingAttributes renderingAttributes) {
	if (isLiveOrCompiled())
	  if (!this.getCapability(ALLOW_RENDERING_ATTRIBUTES_WRITE))
		throw new CapabilityNotSetException(J3dI18N.getString("Appearance10"));
	((AppearanceRetained)this.retained).setRenderingAttributes(renderingAttributes);
    }

    /**
     * Retrieves the current renderingAttributes object.
     * @return the renderingAttributes object
     * @exception CapabilityNotSetException if appropriate capability is
     * not set and this object is part of live or compiled scene graph
     */
    public RenderingAttributes getRenderingAttributes() {
	if (isLiveOrCompiled())
	  if (!this.getCapability(ALLOW_RENDERING_ATTRIBUTES_READ))
		throw new CapabilityNotSetException(J3dI18N.getString("Appearance11"));
	return ((AppearanceRetained)this.retained).getRenderingAttributes();
    }

    /**
     * Sets the polygonAttributes object to the specified object.
     * Setting it to null will result in default attribute usage.
     * @param polygonAttributes object that specifies the desired
     * polygonAttributes parameters
     * @exception CapabilityNotSetException if appropriate capability is
     * not set and this object is part of live or compiled scene graph
     */
    public void setPolygonAttributes(PolygonAttributes polygonAttributes) {
	if (isLiveOrCompiled())
	  if (!this.getCapability(ALLOW_POLYGON_ATTRIBUTES_WRITE))
		throw new CapabilityNotSetException(J3dI18N.getString("Appearance12"));
	((AppearanceRetained)this.retained).setPolygonAttributes(polygonAttributes);
    }

    /**
     * Retrieves the current polygonAttributes object.
     * @return the polygonAttributes object
     * @exception CapabilityNotSetException if appropriate capability is
     * not set and this object is part of live or compiled scene graph
     */
    public PolygonAttributes getPolygonAttributes() {
	if (isLiveOrCompiled())
	  if (!this.getCapability(ALLOW_POLYGON_ATTRIBUTES_READ))
		throw new CapabilityNotSetException(J3dI18N.getString("Appearance13"));
	return ((AppearanceRetained)this.retained).getPolygonAttributes();
    }

    /**
     * Sets the lineAttributes object to the specified object.
     * Setting it to null will result in default attribute usage.
     * @param lineAttributes object that specifies the desired
     * lineAttributes parameters
     * @exception CapabilityNotSetException if appropriate capability is
     * not set and this object is part of live or compiled scene graph
     */
    public void setLineAttributes(LineAttributes lineAttributes) {
	if (isLiveOrCompiled())
	  if (!this.getCapability(ALLOW_LINE_ATTRIBUTES_WRITE))
		throw new CapabilityNotSetException(J3dI18N.getString("Appearance14"));
	((AppearanceRetained)this.retained).setLineAttributes(lineAttributes);
    }

    /**
     * Retrieves the current lineAttributes object.
     * @return the lineAttributes object
     * @exception CapabilityNotSetException if appropriate capability is
     * not set and this object is part of live or compiled scene graph
     */
    public LineAttributes getLineAttributes() {
	if (isLiveOrCompiled())
	  if (!this.getCapability(ALLOW_LINE_ATTRIBUTES_READ))
		throw new CapabilityNotSetException(J3dI18N.getString("Appearance15"));
	return ((AppearanceRetained)this.retained).getLineAttributes();
    }

    /**
     * Sets the pointAttributes object to the specified object.
     * Setting it to null will result in default attribute usage.
     * @param pointAttributes object that specifies the desired
     * pointAttributes parameters
     * @exception CapabilityNotSetException if appropriate capability is
     * not set and this object is part of live or compiled scene graph
     */
    public void setPointAttributes(PointAttributes pointAttributes) {
	if (isLiveOrCompiled())
	  if (!this.getCapability(ALLOW_POINT_ATTRIBUTES_WRITE))
		throw new CapabilityNotSetException(J3dI18N.getString("Appearance16"));
	((AppearanceRetained)this.retained).setPointAttributes(pointAttributes);
    }

    /**
     * Retrieves the current pointAttributes object.
     * @return the pointAttributes object
     * @exception CapabilityNotSetException if appropriate capability is
     * not set and this object is part of live or compiled scene graph
     */
    public PointAttributes getPointAttributes() {
	if (isLiveOrCompiled())
	  if (!this.getCapability(ALLOW_POINT_ATTRIBUTES_READ))
		throw new CapabilityNotSetException(J3dI18N.getString("Appearance17"));
	return ((AppearanceRetained)this.retained).getPointAttributes();
    }

    /**
     * Sets the texture object to the specified object.
     * Setting it to null disables texture mapping.
     *
     * <p>
     * Applications must not set individual texture component objects
     * (texture, textureAttributes, or texCoordGeneration) and
     * the texture unit state array in the same Appearance object.
     * Doing so will result in an exception being thrown.
     *
     * @param texture object that specifies the desired texture
     * map and texture parameters
     *
     * @exception CapabilityNotSetException if appropriate capability is
     * not set and this object is part of live or compiled scene graph
     *
     * @exception IllegalStateException if the specified texture
     * object is non-null and the texture unit state array in this
     * appearance object is already non-null.
     *
     * @exception IllegalSharingException if this Appearance is live and
     * the specified texture refers to an ImageComponent2D that is being used
     * by a Canvas3D as an off-screen buffer.
     *
     * @exception IllegalSharingException if this Appearance is
     * being used by an immediate mode context and
     * the specified texture refers to an ImageComponent2D that is being used
     * by a Canvas3D as an off-screen buffer.
     */
    public void setTexture(Texture texture) {
	if (isLiveOrCompiled())
	  if (!this.getCapability(ALLOW_TEXTURE_WRITE))
		throw new CapabilityNotSetException(J3dI18N.getString("Appearance2"));

        // Do illegal sharing check
        if(texture != null) {
            ImageComponent[] images = ((TextureRetained)(texture.retained)).getImages();
            if(images != null) {
                for(int i=0; i<images.length; i++) {
                    validateImageIllegalSharing(images[i]);
                }
            }
        }

        ((AppearanceRetained)this.retained).setTexture(texture);
    }

    /**
     * Retrieves the current texture object.
     * @return the texture object
     * @exception CapabilityNotSetException if appropriate capability is
     * not set and this object is part of live or compiled scene graph
     */
    public Texture getTexture() {
	if (isLiveOrCompiled())
	  if (!this.getCapability(ALLOW_TEXTURE_READ))
		throw new CapabilityNotSetException(J3dI18N.getString("Appearance3"));
	return ((AppearanceRetained)this.retained).getTexture();
    }

    /**
     * Sets the textureAttributes object to the specified object.
     * Setting it to null will result in default attribute usage.
     *
     * <p>
     * Applications must not set individual texture component objects
     * (texture, textureAttributes, or texCoordGeneration) and
     * the texture unit state array in the same Appearance object.
     * Doing so will result in an exception being thrown.
     *
     * @param textureAttributes object that specifies the desired
     * textureAttributes map and textureAttributes parameters
     *
     * @exception CapabilityNotSetException if appropriate capability is
     * not set and this object is part of live or compiled scene graph
     *
     * @exception IllegalStateException if the specified textureAttributes
     * object is non-null and the texture unit state array in this
     * appearance object is already non-null.
     */
    public void setTextureAttributes(TextureAttributes textureAttributes) {
	if (isLiveOrCompiled())
	  if (!this.getCapability(ALLOW_TEXTURE_ATTRIBUTES_WRITE))
		throw new CapabilityNotSetException(J3dI18N.getString("Appearance4"));
	((AppearanceRetained)this.retained).setTextureAttributes(textureAttributes);
    }

    /**
     * Retrieves the current textureAttributes object.
     * @return the textureAttributes object
     * @exception CapabilityNotSetException if appropriate capability is
     * not set and this object is part of live or compiled scene graph
     */
    public TextureAttributes getTextureAttributes() {
	if (isLiveOrCompiled())
	  if (!this.getCapability(ALLOW_TEXTURE_ATTRIBUTES_READ))
		throw new CapabilityNotSetException(J3dI18N.getString("Appearance5"));
	return ((AppearanceRetained)this.retained).getTextureAttributes();
    }

    /**
     * Sets the texCoordGeneration object to the specified object.
     * Setting it to null disables texture coordinate generation.
     *
     * <p>
     * Applications must not set individual texture component objects
     * (texture, textureAttributes, or texCoordGeneration) and
     * the texture unit state array in the same Appearance object.
     * Doing so will result in an exception being thrown.
     *
     * @param texCoordGeneration object that specifies the texture coordinate
     * generation parameters
     *
     * @exception CapabilityNotSetException if appropriate capability is
     * not set and this object is part of live or compiled scene graph
     *
     * @exception IllegalStateException if the specified texCoordGeneration
     * object is non-null and the texture unit state array in this
     * appearance object is already non-null.
     */
    public void setTexCoordGeneration(TexCoordGeneration texCoordGeneration) {
	if (isLiveOrCompiled())
	  if (!this.getCapability(ALLOW_TEXGEN_WRITE))
		throw new CapabilityNotSetException(J3dI18N.getString("Appearance18"));
	((AppearanceRetained)this.retained).setTexCoordGeneration(texCoordGeneration);
    }

    /**
     * Retrieves the current texCoordGeneration object.
     * @return the texCoordGeneration object
     * @exception CapabilityNotSetException if appropriate capability is
     * not set and this object is part of live or compiled scene graph
     */
    public TexCoordGeneration getTexCoordGeneration() {
	if (isLiveOrCompiled())
	  if (!this.getCapability(ALLOW_TEXGEN_READ))
		throw new CapabilityNotSetException(J3dI18N.getString("Appearance19"));
	return ((AppearanceRetained)this.retained).getTexCoordGeneration();
    }

    /**
     * Sets the texture unit state array for this appearance object to the
     * specified array.  A shallow copy of the array of references to
     * the TextureUnitState objects is made.  If the specified array
     * is null or if the length of the array is 0, multi-texture is
     * disabled.  Within the array, a null TextureUnitState element
     * disables the corresponding texture unit.
     *
     * <p>
     * Applications must not set individual texture component objects
     * (texture, textureAttributes, or texCoordGeneration) and
     * the texture unit state array in the same Appearance object.
     * Doing so will result in an exception being thrown.
     *
     * @param stateArray array of TextureUnitState objects that
     * specify the desired texture state for each unit.  The length of
     * this array specifies the maximum number of texture units that
     * will be used by this appearance object.  The texture units are
     * numbered from <code>0</code> through
     * <code>stateArray.length-1</code>.
     *
     * @exception CapabilityNotSetException if appropriate capability is
     * not set and this object is part of live or compiled scene graph
     *
     * @exception IllegalStateException if the specified array is
     * non-null and any of the texture object, textureAttributes
     * object, or texCoordGeneration object in this appearance object
     * is already non-null.
     *
     * @exception IllegalSharingException if this Appearance is live and
     * any of the specified textures refers to an ImageComponent2D that is
     * being used by a Canvas3D as an off-screen buffer.
     *
     * @exception IllegalSharingException if this Appearance is
     * being used by an immediate mode context and
     * any of the specified textures refers to an ImageComponent2D that is
     * being used by a Canvas3D as an off-screen buffer.
     *
     * @since Java 3D 1.2
     */
    public void setTextureUnitState(TextureUnitState[] stateArray) {
        if (isLiveOrCompiled())
            if (!this.getCapability(ALLOW_TEXTURE_UNIT_STATE_WRITE))
                throw new CapabilityNotSetException(J3dI18N.getString("Appearance20"));

        // Do illegal sharing check
        if (stateArray != null) {
            for(int j=0; j<stateArray.length; j++) {
                if(stateArray[j] != null) {
                    TextureRetained texRetained =
                            ((TextureUnitStateRetained)stateArray[j].retained).texture;
                    if(texRetained != null) {
                        ImageComponent[] images = texRetained.getImages();
                        if(images != null) {
                            for(int i=0; i<images.length; i++) {
                                validateImageIllegalSharing(images[i]);
                            }
                        }
                    }
                }
            }
        }

	((AppearanceRetained)this.retained).setTextureUnitState(stateArray);
    }

    /**
     * Sets the texture unit state object at the specified index
     * within the texture unit state array to the specified object.
     * If the specified object is null, the corresponding texture unit
     * is disabled.  The index must be within the range
     * <code>[0,&nbsp;stateArray.length-1]</code>.
     *
     * @param index the array index of the object to be set
     *
     * @param state new texture unit state object
     *
     * @exception CapabilityNotSetException if appropriate capability is
     * not set and this object is part of live or compiled scene graph
     * @exception NullPointerException if the texture unit state array is
     * null.
     * @exception ArrayIndexOutOfBoundsException if <code>index >=
     * stateArray.length</code>.
     *
     * @exception IllegalSharingException if this Appearance is live and
     * the specified texture refers to an ImageComponent2D that is being used
     * by a Canvas3D as an off-screen buffer.
     *
     * @exception IllegalSharingException if this Appearance is
     * being used by an immediate mode context and
     * the specified texture refers to an ImageComponent2D that is being used
     * by a Canvas3D as an off-screen buffer.
     *
     * @since Java 3D 1.2
     */
    public void setTextureUnitState(int index, TextureUnitState state) {
	if (isLiveOrCompiled())
	  if (!this.getCapability(ALLOW_TEXTURE_UNIT_STATE_WRITE))
		throw new CapabilityNotSetException(J3dI18N.getString("Appearance20"));

        // Do illegal sharing check
        if (state != null) {
            TextureRetained texRetained =
                    ((TextureUnitStateRetained)state.retained).texture;
            if(texRetained != null) {
                ImageComponent[] images = texRetained.getImages();
                if(images != null) {
                    for(int i=0; i<images.length; i++) {
                        validateImageIllegalSharing(images[i]);
                    }
                }
            }
        }

	((AppearanceRetained)this.retained).setTextureUnitState(index, state);
    }

    /**
     * Retrieves the array of texture unit state objects from this
     * Appearance object.  A shallow copy of the array of references to
     * the TextureUnitState objects is returned.
     *
     * @return the array of texture unit state objects
     *
     * @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 TextureUnitState[] getTextureUnitState() {
	if (isLiveOrCompiled())
	  if (!this.getCapability(ALLOW_TEXTURE_UNIT_STATE_READ))
		throw new CapabilityNotSetException(J3dI18N.getString("Appearance21"));

	return ((AppearanceRetained)this.retained).getTextureUnitState();
    }

    /**
     * Retrieves the texture unit state object at the specified
     * index within the texture unit state array.  The index must be
     * within the range <code>[0,&nbsp;stateArray.length-1]</code>.
     *
     * @param index the array index of the object to be retrieved
     *
     * @return the texture unit state object at the specified index
     *
     * @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 TextureUnitState getTextureUnitState(int index) {
	if (isLiveOrCompiled())
	  if (!this.getCapability(ALLOW_TEXTURE_UNIT_STATE_READ))
		throw new CapabilityNotSetException(J3dI18N.getString("Appearance21"));

	return ((AppearanceRetained)this.retained).getTextureUnitState(index);
    }

    /**
     * Retrieves the length of the texture unit state array from
     * this appearance object.  The length of this array specifies the
     * maximum number of texture units that will be used by this
     * appearance object.  If the array is null, a count of 0 is
     * returned.
     *
     * @return the length of the texture unit state array
     *
     * @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 getTextureUnitCount() {
	if (isLiveOrCompiled())
	  if (!this.getCapability(ALLOW_TEXTURE_UNIT_STATE_READ))
		throw new CapabilityNotSetException(J3dI18N.getString("Appearance21"));

	return ((AppearanceRetained)this.retained).getTextureUnitCount();
    }


   /**
     * @deprecated replaced with cloneNodeComponent(boolean forceDuplicate)
     */
    @Override
    public NodeComponent cloneNodeComponent() {
        Appearance a = new Appearance();
        a.duplicateNodeComponent(this);
        return a;
    }

    /**
     * NOTE: Applications should <i>not</i> call this method directly.
     * It should only be called by the cloneNode method.
     *
     * @deprecated replaced with duplicateNodeComponent(
     *  NodeComponent originalNodeComponent, boolean forceDuplicate)
     */
    @Override
    public void duplicateNodeComponent(NodeComponent originalNodeComponent) {
	checkDuplicateNodeComponent(originalNodeComponent);
    }

   /**
     * Copies all Appearance information from
     * <code>originalNodeComponent</code> into
     * the current node.  This method is called from the
     * <code>cloneNode</code> method which is, in turn, called by the
     * <code>cloneTree</code> method.<P>
     *
     * @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.
     *
     * @exception RestrictedAccessException if this object is part of a live
     *  or compiled scenegraph.
     *
     * @see Node#cloneTree
     * @see NodeComponent#setDuplicateOnCloneTree
     */
    @Override
    void duplicateAttributes(NodeComponent originalNodeComponent,
			     boolean forceDuplicate) {
	super.duplicateAttributes(originalNodeComponent, forceDuplicate);

	Hashtable hashtable = originalNodeComponent.nodeHashtable;

	AppearanceRetained app = (AppearanceRetained) originalNodeComponent.retained;

	AppearanceRetained rt = (AppearanceRetained) retained;

	rt.setMaterial((Material) getNodeComponent(app.getMaterial(),
						forceDuplicate,
						hashtable));

	rt.setColoringAttributes((ColoringAttributes) getNodeComponent(
					    app.getColoringAttributes(),
					    forceDuplicate,
					    hashtable));


	rt.setTransparencyAttributes((TransparencyAttributes) getNodeComponent(
					    app.getTransparencyAttributes(),
					    forceDuplicate,
					    hashtable));


	rt.setRenderingAttributes((RenderingAttributes) getNodeComponent(
				      app.getRenderingAttributes(),
				      forceDuplicate,
				      hashtable));


	rt.setPolygonAttributes((PolygonAttributes) getNodeComponent(
					  app.getPolygonAttributes(),
					  forceDuplicate,
					  hashtable));


	rt.setLineAttributes((LineAttributes) getNodeComponent(
					    app.getLineAttributes(),
					    forceDuplicate,
					    hashtable));


	rt.setPointAttributes((PointAttributes) getNodeComponent(
					      app.getPointAttributes(),
					      forceDuplicate,
					      hashtable));

	rt.setTexture((Texture) getNodeComponent(app.getTexture(),
					      forceDuplicate,
					      hashtable));

	rt.setTextureAttributes((TextureAttributes) getNodeComponent(
						  app.getTextureAttributes(),
						  forceDuplicate,
						  hashtable));

	rt.setTexCoordGeneration((TexCoordGeneration) getNodeComponent(
					    app.getTexCoordGeneration(),
					    forceDuplicate,
					    hashtable));

	TextureUnitState state[] = app.getTextureUnitState();
	if (state != null) {
	    rt.setTextureUnitState(state);
	    for (int i=0; i < state.length; i++) {
		rt.setTextureUnitState(i, (TextureUnitState)
				       getNodeComponent(state[i],
							forceDuplicate,
							hashtable));
	    }
	}

    }

    /**
     *  This function is called from getNodeComponent() to see if any of
     *  the sub-NodeComponents  duplicateOnCloneTree flag is true.
     *  If it is the case, current NodeComponent needs to
     *  duplicate also even though current duplicateOnCloneTree flag is false.
     *  This should be overwrite by NodeComponent which contains sub-NodeComponent.
     */
    @Override
    boolean duplicateChild() {
	if (getDuplicateOnCloneTree())
	    return true;

	AppearanceRetained rt = (AppearanceRetained) retained;

	NodeComponent nc;

	nc = rt.getMaterial();
	if ((nc != null) && nc.getDuplicateOnCloneTree())
	    return true;

	nc = rt.getColoringAttributes();
	if ((nc != null) && nc.getDuplicateOnCloneTree())
	    return true;

	nc = rt.getTransparencyAttributes();
	if ((nc != null) && nc.getDuplicateOnCloneTree())
	    return true;

	nc = rt.getPolygonAttributes();
	if ((nc != null) && nc.getDuplicateOnCloneTree())
	    return true;

	nc = rt.getLineAttributes();
	if ((nc != null) && nc.getDuplicateOnCloneTree())
	    return true;

	nc = rt.getPointAttributes();
	if ((nc != null) && nc.getDuplicateOnCloneTree())
	    return true;

	nc = rt.getTexture();
	if ((nc != null) && nc.duplicateChild())
	    return true;

	nc = rt.getTextureAttributes();
	if ((nc != null) && nc.getDuplicateOnCloneTree())
	    return true;

	nc = rt.getTexCoordGeneration();
	if ((nc != null) && nc.getDuplicateOnCloneTree())
	    return true;

	// XXXX: TextureUnitState

	return false;
    }

}