001: /*
002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/nodeeditors/panels/PrimitiveGeometryPanel.java,v 1.1 2005/04/20 22:21:08 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 Jan Becicka.
012: * Portions created by Jan Becicka are Copyright (C) 2002.
013: * All Rights Reserved.
014: *
015: * Contributor(s): Jan Becicka.
016: *
017: **/
018: package org.jdesktop.j3dedit.scenegrapheditor.nodeeditors.panels;
019:
020: import java.awt.Frame;
021: import javax.media.j3d.*;
022: import com.sun.j3d.utils.geometry.Primitive;
023: import org.jdesktop.j3dedit.scenegraph.SGNode;
024: import org.jdesktop.j3dedit.scenegraph.SGNodeComponent;
025: import org.jdesktop.j3dedit.scenegraph.SGGeometryPrimitive;
026: import org.jdesktop.j3dedit.scenegrapheditor.nodeeditors.NodeEditorPanel;
027: import org.jdesktop.j3dedit.scenegrapheditor.nodeeditors.EditorPanelContainer;
028: import com.sun.j3d.utils.geometry.Box;
029: import javax.media.j3d.Node;
030: import org.jdesktop.j3dedit.scenegrapheditor.nodeeditors.panels.AppearancePanel;
031:
032: /**
033: * @author Jan Becicka
034: * @version
035: */
036: public class PrimitiveGeometryPanel extends NodeEditorPanel {
037:
038: protected AppearancePanel appearancePanel;
039:
040: /** Creates new form BoxPanel */
041: public PrimitiveGeometryPanel() {
042: super ();
043: initComponents();
044: appearancePanel = new AppearancePanel();
045: appearanceP.add(appearancePanel);
046: }
047:
048: public void startEdit(SGNode node, EditorPanelContainer frame) {
049: this .node = node;
050: parentFrame = frame;
051: parentFrame.setTitle(frameTitle);
052:
053: SGNodeComponent sgAppearance = ((SGGeometryPrimitive) node)
054: .getSGAppearance();
055:
056: appearancePanel.startEdit(sgAppearance, node, this );
057:
058: setControls();
059: }
060:
061: public void finishEdit() {
062: super .finishEdit();
063: appearancePanel.finishEdit();
064: }
065:
066: private Appearance getAppearance(Node n) {
067: return ((Primitive) n).getAppearance();
068:
069: /*
070: Appearance ap;
071: boolean wasLive = isLive();
072: setLive(false);
073: if (n instanceof Primitive){
074: ((Primitive) n).setCapability(Primitive.ENABLE_APPEARANCE_MODIFY);
075: ap=((Primitive) n).getAppearance();
076: }
077: else {
078: ((Shape3D) n).setCapability(Shape3D.ALLOW_APPEARANCE_READ);
079: ((Shape3D) n).setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
080: ap = ((Shape3D) n).getAppearance();
081: }
082: setLive(wasLive);
083: return ap;
084: */
085: }
086:
087: protected boolean isLive() {
088: if (node == null)
089: return true;
090: return node.getContext().getLocale().getLive();
091: }
092:
093: protected void setLive(boolean on) {
094: if (node == null)
095: return;
096: node.getContext().getLocale().setLive(on);
097: }
098:
099: /** This method is called from within the constructor to
100: * initialize the form.
101: * WARNING: Do NOT modify this code. The content of this method is
102: * always regenerated by the FormEditor.
103: */
104: private void initComponents() {//GEN-BEGIN:initComponents
105: jTabbedPane1 = new javax.swing.JTabbedPane();
106: geometryP = new javax.swing.JPanel();
107: appearanceP = new javax.swing.JPanel();
108:
109: setLayout(new java.awt.CardLayout());
110:
111: jTabbedPane1.addTab("Geometry", null, geometryP, "");
112:
113: jTabbedPane1.addTab("Appearance", null, appearanceP, "");
114:
115: add(jTabbedPane1, "jTabbedPane1");
116:
117: }//GEN-END:initComponents
118:
119: /**
120: * Set the GUI controls to represent node
121: * Store the state of the node so any subsequent changes
122: * can be reset
123: */
124: protected void setControls() {
125: appearancePanel.setControls();
126: setUpdateRequired(false);
127: }
128:
129: public void applyChanges() {
130: appearancePanel.applyChanges();
131: setUpdateRequired(false);
132: }
133:
134: public void resetChanges() {
135: try {
136: appearancePanel.resetChanges();
137: } catch (NullPointerException e) {
138: System.out.println("TODO: Fix this NPE");
139: e.printStackTrace();
140: }
141: setUpdateRequired(false);
142: }
143:
144: /**
145: * Set capability bits for read-only operations on this
146: * Nodes properties
147: */
148: protected void setReadCapabilityBits(Node node) {
149:
150: // Appearance READ and WRITE capability set when Primitive create
151:
152: // Primitive can throw a null pointer exception if it contains no Shapes
153: appearancePanel.setReadCapabilityBits(getAppearance(node));
154: }
155:
156: /**
157: * Set capability bits for read/write operations on this
158: * Nodes properties.
159: */
160: protected void setReadWriteCapabilityBits(Node node) {
161:
162: // Appearance READ and WRITE capability set when Primitive created
163: // Primitive can throw a null pointer exception if it contains no Shapes
164: //if (((Primitive)node).getShape(0)!=null)
165: appearancePanel.setReadWriteCapabilityBits(getAppearance(node));
166:
167: }
168:
169: protected void replaceNode(Node n) {
170:
171: Node j3dnode = node.getJ3dNode();
172: Group parent = (Group) j3dnode.getParent();
173:
174: int i = 0;
175: while (parent.getChild(i) != j3dnode)
176: i++;
177: parent.removeChild(i);
178: parent.insertChild(n, i);
179: node.setJ3dNode(n);
180: }
181:
182: // Variables declaration - do not modify//GEN-BEGIN:variables
183: private javax.swing.JPanel appearanceP;
184: protected javax.swing.JPanel geometryP;
185: private javax.swing.JTabbedPane jTabbedPane1;
186: // End of variables declaration//GEN-END:variables
187:
188: }
|