001: /*
002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/nodeeditors/NodeComponentEditorPanel.java,v 1.1 2005/04/20 22:21:00 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;
019:
020: import java.awt.Frame;
021: import javax.swing.JPanel;
022: import javax.media.j3d.NodeComponent;
023: import javax.media.j3d.SceneGraphObject;
024: import org.jdesktop.j3dedit.scenegraph.SGObject;
025: import org.jdesktop.j3dedit.scenegraph.SGNodeComponent;
026: import org.jdesktop.j3dedit.scenegraph.SGNode;
027:
028: /**
029: * Superclass for all Component Editors
030: *
031: * @author Paul Byrne
032: * @version 1.5, 01/18/02
033: */
034: public abstract class NodeComponentEditorPanel extends JPanel {
035:
036: /**
037: * Reference to node which is being edited
038: */
039: protected SGNodeComponent node;
040:
041: /**
042: * EditorPanel in which thiscomponent editor is working
043: */
044: protected NodeEditorPanel parentEditor;
045:
046: /**
047: * The SceneGraphObject that contains this nodeComponents parent
048: */
049: protected SGObject nodeParent;
050:
051: private boolean updateFlag; // Set true each time user changes GUI values
052: protected boolean readOnly;
053:
054: public NodeComponentEditorPanel() {
055: super ();
056: }
057:
058: /**
059: * Start editing this node
060: *
061: * @param node The NodeComponent being edited, can be null
062: * @param nodeParent The SceneGraphObject that contains this component
063: * @param parentWindow The EditorPanel for the parent Node
064: */
065: public void startEdit(SGNodeComponent node, SGObject nodeParent,
066: NodeEditorPanel parentWindow) {
067: this .node = node;
068: this .nodeParent = nodeParent;
069:
070: parentEditor = parentWindow;
071: getCommonNCPanel().startEdit(node);
072: setControls();
073: }
074:
075: /**
076: * Finish editing this node
077: * This will cause any SGObjectExtraData to be set in this nodes SGObject.
078: */
079: public void finishEdit() {
080: if (node != null)
081: node.setSGObjectExtraData(updateSGObjectExtraData(node
082: .getSGObjectExtraData()));
083: parentEditor = null;
084: }
085:
086: /**
087: * Set the panel to be read only, user can navigate the contents but
088: * can not make any changes.
089: *
090: * Default action is to call setEnabled on all components in this
091: * container
092: */
093: public void setReadOnly(boolean readOnly) {
094: this .readOnly = readOnly;
095:
096: for (int i = 0; i < getComponentCount(); i++)
097: getComponent(i).setEnabled(!readOnly);
098: }
099:
100: /**
101: * Return the readOnly flag
102: */
103: public boolean getReadOnly() {
104: return readOnly;
105: }
106:
107: /**
108: * Set the GUI controls for represent node
109: */
110: protected abstract void setControls();
111:
112: /**
113: * Permanently apply the changes to the node
114: */
115: public abstract void applyChanges();
116:
117: /**
118: * Reset the changes to the state when setControls or applyChanges
119: * was last called
120: */
121: public abstract void resetChanges();
122:
123: /**
124: * Set the capabilities of this node to the correct values
125: * depending on the Editor mode.
126: *
127: * Node must not be live
128: */
129: public void setEditorCapabilities(NodeComponent node) {
130: if (org.jdesktop.j3dedit.scenegrapheditor.PropertiesDialog.performanceLevel == org.jdesktop.j3dedit.scenegrapheditor.PropertiesDialog.READ_WRITE_ALLOWED)
131: setReadWriteCapabilityBits(node);
132: else if (org.jdesktop.j3dedit.scenegrapheditor.PropertiesDialog.performanceLevel == org.jdesktop.j3dedit.scenegrapheditor.PropertiesDialog.READ_ALLOWED)
133: setReadCapabilityBits(node);
134:
135: // Don't set any capability bits for NONE_ALLOWED
136: }
137:
138: /**
139: * Set capability bits for read-only operations on this
140: * Nodes properties
141: */
142: protected abstract void setReadCapabilityBits(NodeComponent node);
143:
144: /**
145: * Set capability bits for full read/write access to this
146: * nodes properties
147: */
148: protected abstract void setReadWriteCapabilityBits(
149: NodeComponent node);
150:
151: /**
152: * Called by NodeState when the user applies changes
153: * or when changes need applying
154: */
155: protected void setUpdateRequired(boolean update) {
156: updateFlag = update;
157:
158: parentEditor.setUpdateRequired(update);
159: }
160:
161: /**
162: * Returns true if the user has changed the state using the GUI
163: */
164: protected boolean getUpdateRequired() {
165: return updateFlag;
166: }
167:
168: /**
169: * If orig is not null then update it with the new information in the panel
170: * If orig is null, and there is new information then create and return a
171: * new SGObjectExtraData object
172: */
173: protected SGObjectExtraData updateSGObjectExtraData(
174: SGObjectExtraData orig) {
175: return orig;
176: }
177:
178: /**
179: * Get the J3d Node of this node components parent
180: */
181: protected javax.media.j3d.Node getParentJ3dNode() {
182: return ((SGNode) nodeParent).getJ3dNode();
183: }
184:
185: /**
186: * Get the J3d NodeComponent of this node components parent
187: */
188: protected javax.media.j3d.NodeComponent getParentJ3dNodeComponent() {
189: return ((SGNodeComponent) nodeParent).getJ3dNode();
190: }
191:
192: /**
193: * Get the CommonNodeComponentPanel
194: */
195: protected abstract org.jdesktop.j3dedit.scenegrapheditor.nodeeditors.panels.CommonNodeComponentPanel getCommonNCPanel();
196: }
|