View Javadoc

1   /* -------------------------------------------------------------------
2    * Java source file for the class ColoringAttributes
3    * 
4    * Copyright (c), 2003, Masahiro Takatsuka.
5    * All Rights Researved.
6    * 
7    * Original Author: Masahiro Takatsuka (masa@jbeans.net)
8    * $Author: takatsukam $
9    * 
10   * $Date: 2004/03/03 11:53:06 $
11   * 
12   * $Id: ColoringAttributes.java,v 1.3 2004/03/03 11:53:06 takatsukam Exp $
13   * 
14   * Reference:		Document no:
15   * ___				___
16   * 
17   * To Do:
18   * ___
19   * 
20  ------------------------------------------------------------------- */
21  
22  /* --------------------------- Package ---------------------------- */
23  package net.jbeans.j3d.scenegraph;
24  
25  /* ------------------ Import classes (packages) ------------------- *//package-summary/html">class="comment"> ------------------ Import classes (packages) ------------------- *//package-summary.html">class="comment">/* ------------------ Import classes (packages) ------------------- *//package-summary.html">class="comment"> ------------------ Import classes (packages) ------------------- */
26  import java.awt.*;
27  import java.io.*;
28  import java.lang.reflect.*;
29  import java.util.*;
30  import javax.swing.event.*;
31  
32  import javax.vecmath.*;
33  
34  import net.jbeans.j3d.light.*;
35  import net.jbeans.util.*;
36  import net.jbeans.util.debug.*;
37  
38  /*====================================================================
39                Implementation of class ColoringAttributes              
40  ====================================================================*/
41  /***
42   * generally describe ColoringAttributes in here
43   * 
44   * @version $Revision: 1.3 $
45   * @author Masahiro Takatsuka (masa@jbeans.net)
46   * @see javax.media.j3d.ColoringAttributes
47   * @see Serializable
48   */
49  
50  public class ColoringAttributes extends javax.media.j3d.ColoringAttributes implements Serializable {
51  	private static final boolean DEBUG = Debug.getDebugFlag(ColoringAttributes.class);
52  
53  	/* ------------------------ not serialized ------------------------ */
54  	transient private Color3f tmpColor;
55  	
56  	public ColoringAttributes() {
57  		this(LightUtil.WHITE, SHADE_GOURAUD);
58  	}
59  
60  	public ColoringAttributes(Color3f color, int shadeModel) {
61  		this(color.x, color.y, color.z, shadeModel);
62  	}
63  
64  	public ColoringAttributes(float red, float green, float blue, int shadeModel) {
65  		super(red, green, blue, shadeModel);
66  
67  		initialize();
68  	}
69  	
70  	private final void initialize() {
71  		setCapabilities();
72  	}
73  
74  	private final void setCapabilities() {
75  		setCapability(ALLOW_COLOR_READ);
76  		setCapability(ALLOW_COLOR_WRITE);
77  		setCapability(ALLOW_SHADE_MODEL_READ);
78  		setCapability(ALLOW_SHADE_MODEL_WRITE);		
79  	}
80  
81      /***
82       * Serialization methods
83       */
84      private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
85  		initialize();
86      }
87  
88  	public void setColor(Color color) {
89  		if (this.tmpColor == null) {
90  			this.tmpColor = new Color3f(color);
91  		} else {
92  			this.tmpColor.set(color);
93  		}
94  		setColor(this.tmpColor);
95  	}
96  
97  	public Color getColor() {
98  		if (this.tmpColor == null) {
99  			this.tmpColor = new Color3f();
100 		}
101 		getColor(this.tmpColor);
102 
103 		return new Color(this.tmpColor.x, this.tmpColor.y, this.tmpColor.z);
104 	}
105 }
106