001: /*
002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/nodeeditors/NodeEditorPanel.java,v 1.1 2005/04/20 22:21:01 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.Node;
023: import java.io.*;
024:
025: import org.jdesktop.j3dedit.scenegraph.SGNode;
026: import org.jdesktop.j3dedit.scenegraph.SGObject;
027:
028: /**
029: * Superclass for all node Editors
030: * @author Paul Byrne
031: * @version 1.10, 01/18/02
032: */
033: public abstract class NodeEditorPanel extends JPanel {
034:
035: /**
036: * Reference to node which is being edited
037: */
038: protected SGNode node;
039:
040: /*
041: * Frame containing this panel
042: */
043: protected EditorPanelContainer parentFrame;
044:
045: protected static int[] readCapabilities;
046:
047: protected static int[] writeCapabilities;
048:
049: /**
050: * Title that will appear in the frame containing this panel
051: */
052: protected String frameTitle;
053:
054: /**
055: * Set true each time user changes GUI values
056: */
057: private boolean updateFlag;
058: protected boolean readOnly;
059:
060: /**
061: * Users name for this node
062: */
063: private String nodeName = null;
064:
065: public NodeEditorPanel() {
066: super ();
067: }
068:
069: public String getTitle() {
070: return frameTitle;
071: }
072:
073: /**
074: * Set the panel to be read only, user can navigate the contents but
075: * can not make any changes.
076: *
077: * Default action is to call setEnabled on all components in this
078: * container
079: */
080: public void setReadOnly(boolean readOnly) {
081: this .readOnly = readOnly;
082:
083: for (int i = 0; i < getComponentCount(); i++)
084: getComponent(i).setEnabled(!readOnly);
085: }
086:
087: /**
088: * Return the readOnly flag
089: */
090: public boolean getReadOnly() {
091: return readOnly;
092: }
093:
094: /**
095: * Start editing this node
096: * Set the GUI components
097: */
098: public void startEdit(SGNode node, EditorPanelContainer frame) {
099: this .node = node;
100: parentFrame = frame;
101: parentFrame.setTitle(frameTitle);
102:
103: setControls();
104: }
105:
106: /**
107: * Finish editing this node
108: *
109: * This will cause any SGObjectExtraData to be set in this nodes SGObject.
110: */
111: public void finishEdit() {
112: node.setSGObjectExtraData(updateSGObjectExtraData(node
113: .getSGObjectExtraData()));
114: parentFrame = null;
115: }
116:
117: /**
118: * Set the capabilities of this node to the correct values
119: * depending on the Editor mode.
120: *
121: * Node must not be live
122: */
123: public void setEditorCapabilities(Node node) {
124: if (org.jdesktop.j3dedit.scenegrapheditor.PropertiesDialog.performanceLevel == org.jdesktop.j3dedit.scenegrapheditor.PropertiesDialog.READ_WRITE_ALLOWED) {
125: setReadWriteCapabilityBits(node);
126: } else if (org.jdesktop.j3dedit.scenegrapheditor.PropertiesDialog.performanceLevel == org.jdesktop.j3dedit.scenegrapheditor.PropertiesDialog.READ_ALLOWED) {
127: setReadCapabilityBits(node);
128: }
129: // Don't set any capability bits for NONE_ALLOWED
130: }
131:
132: /**
133: * Set the GUI controls to represent node
134: * Store the state of the node so any subsequent changes
135: * can be reset
136: */
137: protected abstract void setControls();
138:
139: /**
140: * Permanently apply the changes to the node
141: */
142: public abstract void applyChanges();
143:
144: /**
145: * Reset the changes to the state when setControls or applyChanges
146: * was last called
147: */
148: public abstract void resetChanges();
149:
150: protected abstract void setReadCapabilityBits(
151: javax.media.j3d.Node node);
152:
153: protected abstract void setReadWriteCapabilityBits(
154: javax.media.j3d.Node node);
155:
156: /**
157: * Called by NodeState when the user applies changes
158: * or when changes need applying
159: */
160: protected void setUpdateRequired(boolean update) {
161:
162: if (parentFrame == null || updateFlag == update)
163: return;
164:
165: updateFlag = update;
166:
167: if (update)
168: parentFrame.setTitle(frameTitle + " (*)");
169: else
170: parentFrame.setTitle(frameTitle);
171:
172: }
173:
174: /**
175: * Returns true if the user has changed the state using the GUI
176: */
177: protected boolean getUpdateRequired() {
178: return updateFlag;
179: }
180:
181: /**
182: * If orig is not null then update it with the new information in the panel
183: * If orig is null, and there is new information then create and return a
184: * new SGObjectExtraData object
185: */
186: protected SGObjectExtraData updateSGObjectExtraData(
187: SGObjectExtraData orig) {
188: return orig;
189: }
190:
191: /** Return the class which will store the extra data for this node type
192: */
193: public static Class getExtraDataClass() {
194: return SGObjectExtraData.class;
195: }
196:
197: /**
198: * Return a new SGObjectExtraData object of the correct type
199: */
200:
201: public SGObjectExtraData newSGObjectExtraData() {
202: try {
203: return (SGObjectExtraData) getExtraDataClass()
204: .newInstance();
205: } catch (Exception e) {
206: e.printStackTrace();
207: return null;
208: }
209: }
210:
211: /**
212: * Called by EditorFrame
213: */
214: public void setNodeName(String str) {
215: nodeName = str;
216: node.setNodeName(str);
217: }
218:
219: /**
220: * Called by EditorFrame
221: */
222: public String getNodeName() {
223: return nodeName;
224: }
225:
226: }
|