001: /*
002: * $RCSfile: PointAttributes.java,v $
003: *
004: * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
006: *
007: * This code is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License version 2 only, as
009: * published by the Free Software Foundation. Sun designates this
010: * particular file as subject to the "Classpath" exception as provided
011: * by Sun in the LICENSE file that accompanied this code.
012: *
013: * This code is distributed in the hope that it will be useful, but WITHOUT
014: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: * version 2 for more details (a copy is included in the LICENSE file that
017: * accompanied this code).
018: *
019: * You should have received a copy of the GNU General Public License version
020: * 2 along with this work; if not, write to the Free Software Foundation,
021: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
022: *
023: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
024: * CA 95054 USA or visit www.sun.com if you need additional information or
025: * have any questions.
026: *
027: * $Revision: 1.6 $
028: * $Date: 2008/02/28 20:17:28 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: /**
035: * The PointAttributes object defines all attributes that apply to
036: * point primitives. The point attributes that can be defined are:<p>
037: * <ul>
038: * <li>Size - the size of the point, in pixels. The default is a point
039: * size of one pixel.</li><p>
040: * <li>Antialiasing - for points greater than one-pixel in size,
041: * antialiasing smooths the outline of the point when it is rendered.</li>
042: * <p></ul>
043: * If antialiasing is disabled (the default), fractional point sizes
044: * are rounded to integer sizes, and a screen-aligned square region
045: * of pixels is drawn.<p>
046: * <p>
047: * If antialiasing is enabled, the points are considered transparent
048: * for rendering purposes. They are rendered with all the other transparent
049: * objects and adhere to the other transparency settings such as the
050: * View transparency sorting policy and the View depth buffer freeze
051: * transparent enable.
052: * </p>
053: *
054: * @see Appearance
055: * @see View
056: */
057: public class PointAttributes extends NodeComponent {
058:
059: /**
060: * Specifies that this PointAttributes object allows reading its
061: * point size information.
062: */
063: public static final int ALLOW_SIZE_READ = CapabilityBits.POINT_ATTRIBUTES_ALLOW_SIZE_READ;
064:
065: /**
066: * Specifies that this PointAttributes object allows writing its
067: * point size information.
068: */
069: public static final int ALLOW_SIZE_WRITE = CapabilityBits.POINT_ATTRIBUTES_ALLOW_SIZE_WRITE;
070:
071: /**
072: * Specifies that this PointAttributes object allows reading its
073: * point antialiasing flag.
074: */
075: public static final int ALLOW_ANTIALIASING_READ = CapabilityBits.POINT_ATTRIBUTES_ALLOW_ANTIALIASING_READ;
076:
077: /**
078: * Specifies that this PointAttributes object allows writing its
079: * point antialiasing flag.
080: */
081: public static final int ALLOW_ANTIALIASING_WRITE = CapabilityBits.POINT_ATTRIBUTES_ALLOW_ANTIALIASING_WRITE;
082:
083: // Array for setting default read capabilities
084: private static final int[] readCapabilities = { ALLOW_SIZE_READ,
085: ALLOW_ANTIALIASING_READ };
086:
087: /**
088: * Constructs a PointAttributes object with default parameters.
089: * The default values are as follows:
090: * <ul>
091: * point size : 1<br>
092: * point antialiasing : false<br>
093: * </ul>
094: */
095: public PointAttributes() {
096: // set default read capabilities
097: setDefaultReadCapabilities(readCapabilities);
098: }
099:
100: /**
101: * Constructs a PointAttributes object with specified values.
102: * @param pointSize the size of points, in pixels
103: * @param pointAntialiasing flag to set point antialising ON or OFF
104: */
105: public PointAttributes(float pointSize, boolean pointAntialiasing) {
106: // set default read capabilities
107: setDefaultReadCapabilities(readCapabilities);
108:
109: ((PointAttributesRetained) this .retained)
110: .initPointSize(pointSize);
111: ((PointAttributesRetained) this .retained)
112: .initPointAntialiasingEnable(pointAntialiasing);
113: }
114:
115: /**
116: * Sets the point size for this appearance component object.
117: * @param pointSize the size, in pixels, of point primitives
118: * @exception CapabilityNotSetException if appropriate capability is
119: * not set and this object is part of live or compiled scene graph
120: */
121: public void setPointSize(float pointSize) {
122: if (isLiveOrCompiled())
123: if (!this .getCapability(ALLOW_SIZE_WRITE))
124: throw new CapabilityNotSetException(J3dI18N
125: .getString("PointAttributes0"));
126:
127: if (isLive())
128: ((PointAttributesRetained) this .retained)
129: .setPointSize(pointSize);
130: else
131: ((PointAttributesRetained) this .retained)
132: .initPointSize(pointSize);
133:
134: }
135:
136: /**
137: * Gets the point size for this appearance component object.
138: * @return the size, in pixels, of point primitives
139: * @exception CapabilityNotSetException if appropriate capability is
140: * not set and this object is part of live or compiled scene graph
141: */
142: public float getPointSize() {
143: if (isLiveOrCompiled())
144: if (!this .getCapability(ALLOW_SIZE_READ))
145: throw new CapabilityNotSetException(J3dI18N
146: .getString("PointAttributes1"));
147: return ((PointAttributesRetained) this .retained).getPointSize();
148: }
149:
150: /**
151: * Enables or disables point antialiasing
152: * for this appearance component object.
153: * <p>
154: * If antialiasing is enabled, the points are considered transparent
155: * for rendering purposes. They are rendered with all the other
156: * transparent objects and adhere to the other transparency settings
157: * such as the View transparency sorting policy and the View depth
158: * buffer freeze transparent enable.
159: * </p>
160: * @param state true or false to enable or disable point antialiasing
161: * @exception CapabilityNotSetException if appropriate capability is
162: * not set and this object is part of live or compiled scene graph
163: * @see View
164: */
165: public void setPointAntialiasingEnable(boolean state) {
166: if (isLiveOrCompiled())
167: if (!this .getCapability(ALLOW_ANTIALIASING_WRITE))
168: throw new CapabilityNotSetException(J3dI18N
169: .getString("PointAttributes2"));
170: if (isLive())
171: ((PointAttributesRetained) this .retained)
172: .setPointAntialiasingEnable(state);
173: else
174: ((PointAttributesRetained) this .retained)
175: .initPointAntialiasingEnable(state);
176:
177: }
178:
179: /**
180: * Retrieves the state of the point antialiasing flag.
181: * @return true if point antialiasing is enabled,
182: * false if point antialiasing is disabled
183: * @exception CapabilityNotSetException if appropriate capability is
184: * not set and this object is part of live or compiled scene graph
185: */
186: public boolean getPointAntialiasingEnable() {
187: if (isLiveOrCompiled())
188: if (!this .getCapability(ALLOW_ANTIALIASING_READ))
189: throw new CapabilityNotSetException(J3dI18N
190: .getString("PointAttributes3"));
191: return ((PointAttributesRetained) this .retained)
192: .getPointAntialiasingEnable();
193: }
194:
195: /**
196: * Creates a retained mode PointAttributesRetained object that this
197: * PointAttributes component object will point to.
198: */
199: void createRetained() {
200: this .retained = new PointAttributesRetained();
201: this .retained.setSource(this );
202: }
203:
204: /**
205: * @deprecated replaced with cloneNodeComponent(boolean forceDuplicate)
206: */
207: public NodeComponent cloneNodeComponent() {
208: PointAttributes pa = new PointAttributes();
209: pa.duplicateNodeComponent(this );
210: return pa;
211: }
212:
213: /**
214: * Copies all node information from <code>originalNodeComponent</code> into
215: * the current node. This method is called from the
216: * <code>duplicateNode</code> method. This routine does
217: * the actual duplication of all "local data" (any data defined in
218: * this object).
219: *
220: * @param originalNodeComponent the original node to duplicate.
221: * @param forceDuplicate when set to <code>true</code>, causes the
222: * <code>duplicateOnCloneTree</code> flag to be ignored. When
223: * <code>false</code>, the value of each node's
224: * <code>duplicateOnCloneTree</code> variable determines whether
225: * NodeComponent data is duplicated or copied.
226: *
227: * @see Node#cloneTree
228: * @see NodeComponent#setDuplicateOnCloneTree
229: */
230: void duplicateAttributes(NodeComponent originalNodeComponent,
231: boolean forceDuplicate) {
232: super
233: .duplicateAttributes(originalNodeComponent,
234: forceDuplicate);
235:
236: PointAttributesRetained attr = (PointAttributesRetained) originalNodeComponent.retained;
237: PointAttributesRetained rt = (PointAttributesRetained) retained;
238:
239: rt.initPointSize(attr.getPointSize());
240: rt.initPointAntialiasingEnable(attr
241: .getPointAntialiasingEnable());
242: }
243:
244: }
|