001: /*
002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/nodeeditors/EditorFrame.java,v 1.1 2005/04/20 22:20:59 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 org.jdesktop.j3dfly.namecontrol.NameControl;
021: import javax.swing.JOptionPane;
022: import org.jdesktop.j3dedit.scenegraph.SGNode;
023:
024: /**
025: * @author Paul Byrne
026: * @version 1.11, 01/18/02
027: */
028: public class EditorFrame extends javax.swing.JFrame implements
029: EditorPanelContainer {
030:
031: private NodeEditorPanel editorPanel;
032: private CapabilityPanel capabilityPanel = null;
033: private boolean readOnly = false;
034: private EditorManager editorManager;
035:
036: private String origNodeName = null;
037:
038: /** Creates new form EditorFrame
039: * The frame is disabled by default
040: */
041: public EditorFrame(EditorManager editorManager) {
042: this .editorManager = editorManager;
043: initComponents();
044: setEnabled(false);
045: }
046:
047: /** This method is called from within the constructor to
048: * initialize the form.
049: * WARNING: Do NOT modify this code. The content of this method is
050: * always regenerated by the FormEditor.
051: */
052: private void initComponents() {//GEN-BEGIN:initComponents
053: jPanel1 = new javax.swing.JPanel();
054: jLabel2 = new javax.swing.JLabel();
055: sceneNameTF = new javax.swing.JTextField();
056: jLabel1 = new javax.swing.JLabel();
057: nodeNameTF = new javax.swing.JTextField();
058: showCapabilitiesCB = new javax.swing.JCheckBox();
059: jPanel2 = new javax.swing.JPanel();
060: applyButton = new javax.swing.JButton();
061: cancelButton = new javax.swing.JButton();
062: detailsPanel = new javax.swing.JScrollPane();
063: capabilityContainer = new javax.swing.JPanel();
064:
065: addWindowListener(new java.awt.event.WindowAdapter() {
066: public void windowClosing(java.awt.event.WindowEvent evt) {
067: exitForm(evt);
068: }
069: });
070:
071: jLabel2.setText("Scene :");
072: jPanel1.add(jLabel2);
073:
074: sceneNameTF.setEditable(false);
075: sceneNameTF.setText(" ");
076: sceneNameTF
077: .setToolTipText("Name of the Scene containing this node");
078: sceneNameTF.setMinimumSize(new java.awt.Dimension(80, 21));
079: sceneNameTF.setPreferredSize(new java.awt.Dimension(80, 21));
080: jPanel1.add(sceneNameTF);
081:
082: jLabel1.setText("Node Name :");
083: jPanel1.add(jLabel1);
084:
085: nodeNameTF
086: .setToolTipText("The name for this node in the Java Source code");
087: nodeNameTF.setMinimumSize(new java.awt.Dimension(80, 21));
088: nodeNameTF.setPreferredSize(new java.awt.Dimension(80, 21));
089: nodeNameTF
090: .addActionListener(new java.awt.event.ActionListener() {
091: public void actionPerformed(
092: java.awt.event.ActionEvent evt) {
093: nodeNameTFActionPerformed(evt);
094: }
095: });
096:
097: nodeNameTF.addFocusListener(new java.awt.event.FocusAdapter() {
098: public void focusLost(java.awt.event.FocusEvent evt) {
099: nodeNameTFFocusLost(evt);
100: }
101: });
102:
103: jPanel1.add(nodeNameTF);
104:
105: showCapabilitiesCB.setText("Show Capabilities");
106: showCapabilitiesCB
107: .addActionListener(new java.awt.event.ActionListener() {
108: public void actionPerformed(
109: java.awt.event.ActionEvent evt) {
110: showCapabilitiesCBActionPerformed(evt);
111: }
112: });
113:
114: jPanel1.add(showCapabilitiesCB);
115:
116: getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
117:
118: applyButton.setText("Apply");
119: applyButton
120: .addActionListener(new java.awt.event.ActionListener() {
121: public void actionPerformed(
122: java.awt.event.ActionEvent evt) {
123: applyButtonActionPerformed(evt);
124: }
125: });
126:
127: jPanel2.add(applyButton);
128:
129: cancelButton.setText("Cancel");
130: cancelButton
131: .addActionListener(new java.awt.event.ActionListener() {
132: public void actionPerformed(
133: java.awt.event.ActionEvent evt) {
134: cancelButtonActionPerformed(evt);
135: }
136: });
137:
138: jPanel2.add(cancelButton);
139:
140: getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);
141:
142: detailsPanel.setMinimumSize(new java.awt.Dimension(350, 250));
143: detailsPanel.setPreferredSize(new java.awt.Dimension(350, 250));
144: getContentPane()
145: .add(detailsPanel, java.awt.BorderLayout.CENTER);
146:
147: getContentPane().add(capabilityContainer,
148: java.awt.BorderLayout.EAST);
149:
150: }//GEN-END:initComponents
151:
152: private void nodeNameTFFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_nodeNameTFFocusLost
153: // Add your handling code here:
154: userChangedNodeName();
155: }//GEN-LAST:event_nodeNameTFFocusLost
156:
157: private void nodeNameTFActionPerformed(
158: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nodeNameTFActionPerformed
159: // Add your handling code here:
160: userChangedNodeName();
161: }//GEN-LAST:event_nodeNameTFActionPerformed
162:
163: /**
164: * User has changed the node name
165: */
166: private void userChangedNodeName() {
167: if (nodeNameTF.getText().length() == 0)
168: if (origNodeName != null) {
169: JOptionPane
170: .showMessageDialog(
171: null,
172: "Node Names cannot be set back to null in this version",
173: "Illegal Name",
174: JOptionPane.ERROR_MESSAGE);
175: nodeNameTF.setText(origNodeName);
176: return;
177: } else
178: return;
179:
180: if (editorManager.getCurrentNode().getNodeName() != null
181: && editorManager.getCurrentNode().getNodeName().equals(
182: nodeNameTF.getText()))
183: return;
184:
185: if (editorManager.getCurrentNode().getContext()
186: .getNameControl().isUnique(sceneNameTF.getText(),
187: nodeNameTF.getText())) {
188: editorManager.notifyNameChange(nodeNameTF.getText());
189: editorPanel.setNodeName(nodeNameTF.getText());
190: editorPanel.setUpdateRequired(true);
191: editorManager.getCurrentNode().repaint();
192: } else {
193: // TODO Show the dialog in a SwingWorker
194: JOptionPane.showMessageDialog(null, "Name "
195: + nodeNameTF.getText() + " is not unqiue in scene "
196: + sceneNameTF.getText(), "Node name is not unique",
197: JOptionPane.ERROR_MESSAGE);
198: nodeNameTF.selectAll();
199: }
200: }
201:
202: public void setNodeName(String nodeName) {
203: origNodeName = nodeName;
204: nodeNameTF.setText(origNodeName);
205: }
206:
207: public void setSceneName(String sceneName) {
208: sceneNameTF.setText(sceneName);
209: }
210:
211: private void showCapabilitiesCBActionPerformed(
212: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showCapabilitiesCBActionPerformed
213: // Add your handling code here:
214: if (showCapabilitiesCB.isSelected()) {
215: if (capabilityPanel == null) {
216: capabilityPanel = new CapabilityPanel();
217: }
218: capabilityContainer.add(capabilityPanel);
219: validate();
220: } else {
221: capabilityContainer.remove(capabilityPanel);
222: validate();
223: }
224: }//GEN-LAST:event_showCapabilitiesCBActionPerformed
225:
226: protected void capabilityStartEdit(
227: org.jdesktop.j3dedit.scenegraph.SGObject obj) {
228: if (capabilityPanel != null)
229: capabilityPanel.startEdit(obj);
230: }
231:
232: protected void capabilityFinishEdit() {
233: if (capabilityPanel != null)
234: capabilityPanel.finishEdit();
235: }
236:
237: private void applyButtonActionPerformed(
238: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyButtonActionPerformed
239: // Add your handling code here:
240: editorManager.applyChanges();
241: }//GEN-LAST:event_applyButtonActionPerformed
242:
243: private void cancelButtonActionPerformed(
244: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
245: // Add your handling code here:
246: editorManager.resetChanges();
247: }//GEN-LAST:event_cancelButtonActionPerformed
248:
249: /** Exit the Application */
250: private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
251: System.exit(0);
252: }//GEN-LAST:event_exitForm
253:
254: public void setEnabled(boolean enabled) {
255: super .setEnabled(enabled);
256: applyButton.setEnabled(enabled);
257: cancelButton.setEnabled(enabled);
258: showCapabilitiesCB.setEnabled(enabled);
259: }
260:
261: public void showPanel(NodeEditorPanel panel) {
262: editorPanel = panel;
263: setTitle(panel.getTitle());
264: panel.setNodeName(origNodeName);
265: detailsPanel.setViewportView(panel);
266: detailsPanel.validate();
267: }
268:
269: public void setReadOnly(boolean readOnly) {
270: this .readOnly = readOnly;
271: applyButton.setEnabled(!readOnly);
272: cancelButton.setEnabled(!readOnly);
273: }
274:
275: /**
276: * Set the title of the container
277: */
278: public void setTitle(String title) {
279: super .setTitle(title);
280: }
281:
282: // Variables declaration - do not modify//GEN-BEGIN:variables
283: private javax.swing.JPanel jPanel2;
284: private javax.swing.JPanel jPanel1;
285: private javax.swing.JCheckBox showCapabilitiesCB;
286: private javax.swing.JTextField sceneNameTF;
287: private javax.swing.JScrollPane detailsPanel;
288: private javax.swing.JTextField nodeNameTF;
289: private javax.swing.JButton cancelButton;
290: private javax.swing.JPanel capabilityContainer;
291: private javax.swing.JLabel jLabel2;
292: private javax.swing.JLabel jLabel1;
293: private javax.swing.JButton applyButton;
294: // End of variables declaration//GEN-END:variables
295:
296: }
|