001: /*
002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/nodeeditors/panels/AppearancePanel.java,v 1.1 2005/04/20 22:21:03 paulby Exp $
003: *
004: * Sun Public License Notice
005: *
006: * The contents of this file are subject to the Sun Public License Version
007: * 1.0 (the "License"). You may not use this file except in compliance with
008: * the License. A copy of the License is available at http://www.sun.com/
009: *
010: * The Original Code is the Java 3D(tm) Scene Graph Editor.
011: * The Initial Developer of the Original Code is Paul Byrne.
012: * Portions created by Paul Byrne are Copyright (C) 2002.
013: * All Rights Reserved.
014: *
015: * Contributor(s): Paul Byrne.
016: *
017: **/
018: package org.jdesktop.j3dedit.scenegrapheditor.nodeeditors.panels;
019:
020: import javax.media.j3d.SceneGraphObject;
021: import javax.media.j3d.Node;
022: import javax.media.j3d.NodeComponent;
023: import javax.media.j3d.Shape3D;
024: import javax.media.j3d.Appearance;
025: import com.sun.j3d.utils.geometry.Primitive;
026: import org.jdesktop.j3dedit.scenegraph.SGObject;
027: import org.jdesktop.j3dedit.scenegraph.SGNodeComponent;
028: import org.jdesktop.j3dedit.scenegraph.SGAppearance;
029: import org.jdesktop.j3dedit.scenegraph.SGGeometryPrimitive;
030: import org.jdesktop.j3dedit.scenegraph.SGShape3D;
031: import org.jdesktop.j3dedit.scenegrapheditor.nodeeditors.NodeComponentEditorPanel;
032: import org.jdesktop.j3dedit.scenegrapheditor.nodeeditors.NodeEditorPanel;
033:
034: /**
035: * @author Paul Byrne
036: * @version $Id: AppearancePanel.java,v 1.1 2005/04/20 22:21:03 paulby Exp $
037: */
038: public class AppearancePanel extends NodeComponentEditorPanel {
039:
040: private PolygonAttributesPanel polygonAttr;
041: private TextureAttributesPanel textureAttr;
042: private TexturePanel texture;
043: private PointAttributesPanel pointAttr;
044: private TransparencyAttributesPanel transparencyAttr;
045: private MaterialPanel materialAttr;
046: private boolean appearanceWasNull;
047:
048: private java.awt.CardLayout cardLayout;
049:
050: public AppearancePanel() {
051: super ();
052: initComponents();
053:
054: polygonAttr = new PolygonAttributesPanel();
055: tabPane.addTab("Polygon Attributes", polygonAttr);
056:
057: textureAttr = new TextureAttributesPanel();
058: tabPane.addTab("Texture Attributes", textureAttr);
059:
060: texture = new TexturePanel();
061: tabPane.addTab("Texture", texture);
062:
063: // Texture and TextureAttrbiutes intereact so each need a
064: // reference to the other
065: textureAttr.setTexturePanel(texture);
066: texture.setTextureAttributesPanel(textureAttr);
067:
068: pointAttr = new PointAttributesPanel();
069: tabPane.addTab("Point Attributes", pointAttr);
070:
071: transparencyAttr = new TransparencyAttributesPanel();
072: tabPane.addTab("Transparency Attributes", transparencyAttr);
073:
074: materialAttr = new MaterialPanel();
075: tabPane.addTab("Material", materialAttr);
076:
077: tabPane.invalidate();
078:
079: cardLayout = (java.awt.CardLayout) this .getLayout();
080: }
081:
082: /**
083: * Start editing this node
084: *
085: * @param node The NodeComponent being edited, can be null
086: * @param nodeParent The SceneGraphObject that contains this component
087: * @param parentWindow The EditorPanel containing this panel
088: */
089: public void startEdit(SGNodeComponent node, SGObject nodeParent,
090: NodeEditorPanel parentWindow) {
091:
092: super .startEdit(node, nodeParent, parentWindow);
093: if (node == null) {
094: cardLayout.last(this );
095: appearanceWasNull = true;
096: } else {
097: Appearance app = (Appearance) node.getJ3dNode();
098: appearanceWasNull = false;
099: cardLayout.first(this );
100: polygonAttr.startEdit(((SGAppearance) node)
101: .getSGPolygonAttributes(), node, parentEditor);
102: textureAttr.startEdit(((SGAppearance) node)
103: .getSGTextureAttributes(), node, parentEditor);
104: texture.startEdit(((SGAppearance) node).getSGTexture(),
105: node, parentEditor);
106: pointAttr.startEdit(((SGAppearance) node)
107: .getSGPointAttributes(), node, parentEditor);
108: materialAttr.startEdit(((SGAppearance) node)
109: .getSGMaterial(), node, parentEditor);
110: transparencyAttr.startEdit(((SGAppearance) node)
111: .getSGTransparencyAttributes(), node, parentEditor);
112:
113: setUpdateRequired(false);
114: }
115: }
116:
117: public void finishEdit() {
118: super .finishEdit();
119: if (node.getJ3dNode() == null)
120: return;
121:
122: polygonAttr.finishEdit();
123: textureAttr.finishEdit();
124: texture.finishEdit();
125: pointAttr.finishEdit();
126: materialAttr.finishEdit();
127: transparencyAttr.finishEdit();
128: }
129:
130: /** This method is called from within the constructor to
131: * initialize the form.
132: * WARNING: Do NOT modify this code. The content of this method is
133: * always regenerated by the FormEditor.
134: */
135: private void initComponents() {//GEN-BEGIN:initComponents
136: java.awt.GridBagConstraints gridBagConstraints;
137:
138: normalPanel = new javax.swing.JPanel();
139: tabPane = new javax.swing.JTabbedPane();
140: ncCommonP = new org.jdesktop.j3dedit.scenegrapheditor.nodeeditors.panels.CommonNodeComponentPanel();
141: nullPanel = new javax.swing.JPanel();
142: jLabel1 = new javax.swing.JLabel();
143: createAppearanceB = new javax.swing.JButton();
144:
145: setLayout(new java.awt.CardLayout());
146:
147: normalPanel.setLayout(new java.awt.BorderLayout());
148:
149: normalPanel.add(tabPane, java.awt.BorderLayout.CENTER);
150:
151: ncCommonP.setFont(new java.awt.Font("Dialog", 0, 11));
152: normalPanel.add(ncCommonP, java.awt.BorderLayout.NORTH);
153:
154: add(normalPanel, "card1");
155:
156: nullPanel.setLayout(new java.awt.GridBagLayout());
157:
158: jLabel1.setFont(new java.awt.Font("Dialog", 1, 14));
159: jLabel1.setText("Appearance is Null");
160: nullPanel.add(jLabel1, new java.awt.GridBagConstraints());
161:
162: createAppearanceB.setText("New Appearance");
163: createAppearanceB
164: .addActionListener(new java.awt.event.ActionListener() {
165: public void actionPerformed(
166: java.awt.event.ActionEvent evt) {
167: createAppearanceBActionPerformed(evt);
168: }
169: });
170:
171: gridBagConstraints = new java.awt.GridBagConstraints();
172: gridBagConstraints.gridx = 0;
173: gridBagConstraints.gridy = 1;
174: gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0);
175: nullPanel.add(createAppearanceB, gridBagConstraints);
176:
177: add(nullPanel, "card2");
178:
179: }//GEN-END:initComponents
180:
181: private void createAppearanceBActionPerformed(
182: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createAppearanceBActionPerformed
183: // Add your handling code here:
184: Appearance app = new Appearance();
185: node = new SGAppearance(app, nodeParent.getContext());
186: if (org.jdesktop.j3dedit.scenegrapheditor.PropertiesDialog.performanceLevel == org.jdesktop.j3dedit.scenegrapheditor.PropertiesDialog.READ_ALLOWED)
187: setReadCapabilityBits((NodeComponent) node.getJ3dNode());
188: else if (org.jdesktop.j3dedit.scenegrapheditor.PropertiesDialog.performanceLevel == org.jdesktop.j3dedit.scenegrapheditor.PropertiesDialog.READ_WRITE_ALLOWED)
189: setReadWriteCapabilityBits((NodeComponent) node
190: .getJ3dNode());
191:
192: setAppearanceInParent();
193: setControls();
194: cardLayout.first(this );
195:
196: polygonAttr.startEdit(null, node, parentEditor);
197: textureAttr.startEdit(null, node, parentEditor);
198: texture.startEdit(null, node, parentEditor);
199: pointAttr.startEdit(null, node, parentEditor);
200: materialAttr.startEdit(null, node, parentEditor);
201: transparencyAttr.startEdit(null, node, parentEditor);
202:
203: ncCommonP.startEdit(node);
204: setUpdateRequired(true);
205: }//GEN-LAST:event_createAppearanceBActionPerformed
206:
207: public void setReadOnly(boolean readOnly) {
208: this .readOnly = readOnly;
209:
210: createAppearanceB.setEnabled(!readOnly);
211:
212: polygonAttr.setReadOnly(readOnly);
213: textureAttr.setReadOnly(readOnly);
214: texture.setReadOnly(readOnly);
215: pointAttr.setReadOnly(readOnly);
216: transparencyAttr.setReadOnly(readOnly);
217: materialAttr.setReadOnly(readOnly);
218: }
219:
220: /**
221: * Set the GUI controls to represent node
222: * Store the state of the node so any subsequent changes
223: * can be reset
224: */
225: protected void setControls() {
226: polygonAttr.setControls();
227: textureAttr.setControls();
228: texture.setControls();
229: pointAttr.setControls();
230: transparencyAttr.setControls();
231: materialAttr.setControls();
232: setUpdateRequired(false);
233: }
234:
235: /**
236: * Permanently apply the changes to the node
237: */
238: public void applyChanges() {
239: polygonAttr.applyChanges();
240: textureAttr.applyChanges();
241: texture.applyChanges();
242: pointAttr.applyChanges();
243: transparencyAttr.applyChanges();
244: materialAttr.applyChanges();
245:
246: setControls();
247: setUpdateRequired(false);
248: }
249:
250: /**
251: * Call setAppearance in the nodeParent, dealing with various
252: * nodeParent types
253: */
254: private void setAppearanceInParent() {
255: if (getParentJ3dNode() instanceof Shape3D) {
256: ((Shape3D) getParentJ3dNode())
257: .setAppearance((Appearance) node.getJ3dNode());
258: ((SGShape3D) nodeParent)
259: .setSGAppearance((SGAppearance) node);
260: } else if (getParentJ3dNode() instanceof Primitive) {
261: ((Primitive) getParentJ3dNode())
262: .setAppearance((Appearance) node.getJ3dNode());
263: ((SGGeometryPrimitive) nodeParent)
264: .setSGAppearance((SGAppearance) node);
265: }
266: }
267:
268: /**
269: * Reset the changes to the state when setControls or applyChanges
270: * was last called
271: */
272: public void resetChanges() {
273: if (appearanceWasNull) {
274: node = null;
275: setAppearanceInParent();
276: } else {
277: polygonAttr.resetChanges();
278: textureAttr.resetChanges();
279: texture.resetChanges();
280: pointAttr.resetChanges();
281: transparencyAttr.resetChanges();
282: materialAttr.resetChanges();
283: }
284:
285: setControls();
286: setUpdateRequired(false);
287: }
288:
289: /**
290: * Set capability bits for read-only operations on this
291: * Nodes properties
292: */
293: protected void setReadCapabilityBits(NodeComponent node) {
294: if (node == null || node.isLive())
295: return;
296:
297: Appearance app = (Appearance) node;
298: app.setCapability(Appearance.ALLOW_POLYGON_ATTRIBUTES_READ);
299: app.setCapability(Appearance.ALLOW_TEXTURE_ATTRIBUTES_READ);
300: app.setCapability(Appearance.ALLOW_TEXTURE_READ);
301: app.setCapability(Appearance.ALLOW_POINT_ATTRIBUTES_READ);
302: app
303: .setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_READ);
304: app.setCapability(Appearance.ALLOW_MATERIAL_READ);
305:
306: polygonAttr.setReadCapabilityBits(app.getPolygonAttributes());
307: textureAttr.setReadCapabilityBits(app.getTextureAttributes());
308: texture.setReadCapabilityBits(app.getTexture());
309: pointAttr.setReadCapabilityBits(app.getPointAttributes());
310: transparencyAttr.setReadCapabilityBits(app
311: .getTransparencyAttributes());
312: materialAttr.setReadCapabilityBits(app.getMaterial());
313: }
314:
315: /**
316: * Set capability bits for full read/write access to this
317: * nodes properties
318: */
319: protected void setReadWriteCapabilityBits(NodeComponent node) {
320: if (node == null || node.isLive())
321: return;
322:
323: Appearance app = (Appearance) node;
324: app.setCapability(Appearance.ALLOW_POLYGON_ATTRIBUTES_WRITE);
325: app.setCapability(Appearance.ALLOW_TEXTURE_ATTRIBUTES_WRITE);
326: app.setCapability(Appearance.ALLOW_TEXTURE_WRITE);
327: app.setCapability(Appearance.ALLOW_POINT_ATTRIBUTES_WRITE);
328: app
329: .setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE);
330: app.setCapability(Appearance.ALLOW_MATERIAL_WRITE);
331: app.setCapability(Appearance.ALLOW_POLYGON_ATTRIBUTES_READ);
332: app.setCapability(Appearance.ALLOW_TEXTURE_ATTRIBUTES_READ);
333: app.setCapability(Appearance.ALLOW_TEXTURE_READ);
334: app.setCapability(Appearance.ALLOW_POINT_ATTRIBUTES_READ);
335: app
336: .setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_READ);
337: app.setCapability(Appearance.ALLOW_MATERIAL_READ);
338:
339: polygonAttr.setReadWriteCapabilityBits(app
340: .getPolygonAttributes());
341: textureAttr.setReadWriteCapabilityBits(app
342: .getTextureAttributes());
343: texture.setReadWriteCapabilityBits(app.getTexture());
344: pointAttr.setReadWriteCapabilityBits(app.getPointAttributes());
345: transparencyAttr.setReadWriteCapabilityBits(app
346: .getTransparencyAttributes());
347: materialAttr.setReadWriteCapabilityBits(app.getMaterial());
348: }
349:
350: /**
351: * Get the CommonNodeComponentPanel
352: */
353: protected org.jdesktop.j3dedit.scenegrapheditor.nodeeditors.panels.CommonNodeComponentPanel getCommonNCPanel() {
354: return ncCommonP;
355: }
356:
357: // Variables declaration - do not modify//GEN-BEGIN:variables
358: private javax.swing.JPanel nullPanel;
359: private javax.swing.JTabbedPane tabPane;
360: private javax.swing.JPanel normalPanel;
361: private org.jdesktop.j3dedit.scenegrapheditor.nodeeditors.panels.CommonNodeComponentPanel ncCommonP;
362: private javax.swing.JLabel jLabel1;
363: private javax.swing.JButton createAppearanceB;
364: // End of variables declaration//GEN-END:variables
365:
366: }
|