001: /*
002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/nodeeditors/panels/PolygonAttributesPanel.java,v 1.1 2005/04/20 22:21:07 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.*;
021: import org.jdesktop.j3dedit.scenegraph.SGPolygonAttributes;
022: import org.jdesktop.j3dedit.scenegraph.SGAppearance;
023: import org.jdesktop.j3dedit.scenegrapheditor.nodeeditors.NodeComponentEditorPanel;
024:
025: /**
026: * @author Paul Byrne
027: * @version 1.7, 01/18/02
028: */
029: public class PolygonAttributesPanel extends NodeComponentEditorPanel {
030:
031: // Variable to allow reset of node state
032: private int origCullFace;
033: private int origPolygonMode;
034: private float origPolygonOffset;
035: private java.awt.CardLayout cardLayout;
036: private boolean attributeWasNull = false;
037:
038: private boolean doingSetControls = false;
039:
040: /** Creates new form PolygonAttributesPanel */
041: public PolygonAttributesPanel() {
042: super ();
043: initComponents();
044: cardLayout = (java.awt.CardLayout) getLayout();
045: }
046:
047: public void setReadOnly(boolean readOnly) {
048: this .readOnly = readOnly;
049:
050: createAttributeB.setEnabled(!readOnly);
051: polygonModeC.setEnabled(!readOnly);
052: cullFaceCombo.setEnabled(!readOnly);
053: }
054:
055: /** This method is called from within the constructor to
056: * initialize the form.
057: * WARNING: Do NOT modify this code. The content of this method is
058: * always regenerated by the FormEditor.
059: */
060: private void initComponents() {//GEN-BEGIN:initComponents
061: java.awt.GridBagConstraints gridBagConstraints;
062:
063: normalPanel = new javax.swing.JPanel();
064: jPanel1 = new javax.swing.JPanel();
065: cullFaceCombo = new javax.swing.JComboBox(new String[] {
066: "CULL_NONE", "CULL_FRONT", "CULL_BACK" });
067: jLabel1 = new javax.swing.JLabel();
068: jLabel2 = new javax.swing.JLabel();
069: polygonModeC = new javax.swing.JComboBox(new String[] {
070: "POLYGON_POINT", "POLYGON_LINE", "POLYGON_FILL" });
071: jLabel3 = new javax.swing.JLabel();
072: polygonOffsetTF = new javax.swing.JTextField();
073: ncCommonP = new org.jdesktop.j3dedit.scenegrapheditor.nodeeditors.panels.CommonNodeComponentPanel();
074: nullPanel = new javax.swing.JPanel();
075: jPanel2 = new javax.swing.JPanel();
076: jLabel4 = new javax.swing.JLabel();
077: createAttributeB = new javax.swing.JButton();
078:
079: setLayout(new java.awt.CardLayout());
080:
081: jPanel1.setLayout(new java.awt.GridBagLayout());
082:
083: cullFaceCombo.setToolTipText("Select Polgon face culling mode");
084: cullFaceCombo
085: .addItemListener(new java.awt.event.ItemListener() {
086: public void itemStateChanged(
087: java.awt.event.ItemEvent evt) {
088: cullFaceComboItemStateChanged(evt);
089: }
090: });
091:
092: gridBagConstraints = new java.awt.GridBagConstraints();
093: gridBagConstraints.gridx = 1;
094: gridBagConstraints.gridy = 1;
095: jPanel1.add(cullFaceCombo, gridBagConstraints);
096:
097: jLabel1.setText("Cull Face");
098: gridBagConstraints = new java.awt.GridBagConstraints();
099: gridBagConstraints.gridx = 0;
100: gridBagConstraints.gridy = 1;
101: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
102: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 4);
103: jPanel1.add(jLabel1, gridBagConstraints);
104:
105: jLabel2.setText("Polygon Mode");
106: gridBagConstraints = new java.awt.GridBagConstraints();
107: gridBagConstraints.gridx = 0;
108: gridBagConstraints.gridy = 2;
109: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
110: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 4);
111: jPanel1.add(jLabel2, gridBagConstraints);
112:
113: polygonModeC.addItemListener(new java.awt.event.ItemListener() {
114: public void itemStateChanged(java.awt.event.ItemEvent evt) {
115: polygonModeCItemStateChanged(evt);
116: }
117: });
118:
119: gridBagConstraints = new java.awt.GridBagConstraints();
120: gridBagConstraints.gridx = 1;
121: gridBagConstraints.gridy = 2;
122: jPanel1.add(polygonModeC, gridBagConstraints);
123:
124: jLabel3.setText("Polygon Offset");
125: gridBagConstraints = new java.awt.GridBagConstraints();
126: gridBagConstraints.gridx = 0;
127: gridBagConstraints.gridy = 3;
128: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
129: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 4);
130: jPanel1.add(jLabel3, gridBagConstraints);
131:
132: polygonOffsetTF.setEditable(false);
133: polygonOffsetTF.setText("jTextField1");
134: polygonOffsetTF.setEnabled(false);
135: polygonOffsetTF
136: .addActionListener(new java.awt.event.ActionListener() {
137: public void actionPerformed(
138: java.awt.event.ActionEvent evt) {
139: polygonOffsetTFActionPerformed(evt);
140: }
141: });
142:
143: gridBagConstraints = new java.awt.GridBagConstraints();
144: gridBagConstraints.gridx = 1;
145: gridBagConstraints.gridy = 3;
146: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
147: jPanel1.add(polygonOffsetTF, gridBagConstraints);
148:
149: gridBagConstraints = new java.awt.GridBagConstraints();
150: gridBagConstraints.gridwidth = 2;
151: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
152: jPanel1.add(ncCommonP, gridBagConstraints);
153:
154: normalPanel.add(jPanel1);
155:
156: add(normalPanel, "card4");
157:
158: jPanel2.setLayout(new java.awt.GridBagLayout());
159:
160: jLabel4.setFont(new java.awt.Font("Dialog", 1, 14));
161: jLabel4.setText("Attribute is Null");
162: jPanel2.add(jLabel4, new java.awt.GridBagConstraints());
163:
164: createAttributeB.setText("Create Attribute");
165: createAttributeB
166: .addActionListener(new java.awt.event.ActionListener() {
167: public void actionPerformed(
168: java.awt.event.ActionEvent evt) {
169: createAttributeBActionPerformed(evt);
170: }
171: });
172:
173: gridBagConstraints = new java.awt.GridBagConstraints();
174: gridBagConstraints.gridx = 0;
175: gridBagConstraints.gridy = 1;
176: gridBagConstraints.insets = new java.awt.Insets(9, 0, 0, 0);
177: jPanel2.add(createAttributeB, gridBagConstraints);
178:
179: nullPanel.add(jPanel2);
180:
181: add(nullPanel, "card5");
182:
183: }//GEN-END:initComponents
184:
185: private void polygonModeCItemStateChanged(
186: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_polygonModeCItemStateChanged
187: // Add your handling code here:
188:
189: int polygonMode;
190:
191: if (parentEditor == null || doingSetControls)
192: return;
193:
194: setUpdateRequired(true);
195:
196: switch (polygonModeC.getSelectedIndex()) {
197: case 0:
198: polygonMode = PolygonAttributes.POLYGON_POINT;
199: break;
200: case 1:
201: polygonMode = PolygonAttributes.POLYGON_LINE;
202: break;
203: case 2:
204: polygonMode = PolygonAttributes.POLYGON_FILL;
205: break;
206: default:
207: throw (new RuntimeException("Bad Choice item"));
208: }
209:
210: ((PolygonAttributes) node.getJ3dNode())
211: .setPolygonMode(polygonMode);
212: }//GEN-LAST:event_polygonModeCItemStateChanged
213:
214: private void cullFaceComboItemStateChanged(
215: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cullFaceComboItemStateChanged
216: // Add your handling code here:
217: int cullFace;
218:
219: if (parentEditor == null || doingSetControls)
220: return;
221:
222: setUpdateRequired(true);
223:
224: switch (cullFaceCombo.getSelectedIndex()) {
225: case 0:
226: cullFace = PolygonAttributes.CULL_NONE;
227: break;
228: case 1:
229: cullFace = PolygonAttributes.CULL_FRONT;
230: break;
231: case 2:
232: cullFace = PolygonAttributes.CULL_BACK;
233: break;
234: default:
235: throw (new RuntimeException("Bad Choice item"));
236: }
237:
238: ((PolygonAttributes) node.getJ3dNode()).setCullFace(cullFace);
239:
240: }//GEN-LAST:event_cullFaceComboItemStateChanged
241:
242: private void createAttributeBActionPerformed(
243: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createAttributeBActionPerformed
244: // Add your handling code here:
245: node = new SGPolygonAttributes(new PolygonAttributes(),
246: nodeParent.getContext());
247: ((SGAppearance) nodeParent)
248: .setSGPolygonAttributes((SGPolygonAttributes) node);
249:
250: if (readOnly)
251: setReadCapabilityBits((NodeComponent) node.getJ3dNode());
252: else
253: setReadWriteCapabilityBits((NodeComponent) node
254: .getJ3dNode());
255:
256: ((Appearance) getParentJ3dNodeComponent())
257: .setPolygonAttributes((PolygonAttributes) node
258: .getJ3dNode());
259: setControls();
260: cardLayout.first(this );
261:
262: ncCommonP.startEdit(node);
263: setUpdateRequired(true);
264: }//GEN-LAST:event_createAttributeBActionPerformed
265:
266: private void polygonOffsetTFActionPerformed(
267: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_polygonOffsetTFActionPerformed
268: // Add your handling code here:
269: setUpdateRequired(true);
270: }//GEN-LAST:event_polygonOffsetTFActionPerformed
271:
272: /**
273: * Set the GUI controls for represent node
274: */
275: protected void setControls() {
276:
277: if (node == null || node.getJ3dNode() == null) {
278: cardLayout.last(this );
279: attributeWasNull = true;
280: } else {
281: doingSetControls = true;
282: cardLayout.first(this );
283: attributeWasNull = false;
284:
285: PolygonAttributes polyAttr = (PolygonAttributes) node
286: .getJ3dNode();
287:
288: origCullFace = polyAttr.getCullFace();
289: switch (origCullFace) {
290: case PolygonAttributes.CULL_NONE:
291: cullFaceCombo.setSelectedIndex(0);
292: break;
293: case PolygonAttributes.CULL_FRONT:
294: cullFaceCombo.setSelectedIndex(1);
295: break;
296: case PolygonAttributes.CULL_BACK:
297: cullFaceCombo.setSelectedIndex(2);
298: break;
299: default:
300: throw (new RuntimeException("Internal Error"));
301: }
302:
303: origPolygonMode = polyAttr.getPolygonMode();
304: switch (origPolygonMode) {
305: case PolygonAttributes.POLYGON_POINT:
306: polygonModeC.setSelectedIndex(0);
307: break;
308: case PolygonAttributes.POLYGON_LINE:
309: polygonModeC.setSelectedIndex(1);
310: break;
311: case PolygonAttributes.POLYGON_FILL:
312: polygonModeC.setSelectedIndex(2);
313: break;
314: }
315:
316: origPolygonOffset = polyAttr.getPolygonOffset();
317: polygonOffsetTF.setText(Float.toString(origPolygonOffset));
318: doingSetControls = false;
319: }
320: }
321:
322: public void applyChanges() {
323: setControls();
324: attributeWasNull = false;
325: setUpdateRequired(false);
326: }
327:
328: public void resetChanges() {
329: if (attributeWasNull) {
330: ((Appearance) getParentJ3dNodeComponent())
331: .setPolygonAttributes(null);
332: node = null;
333: } else {
334: PolygonAttributes polyAttr = (PolygonAttributes) node
335: .getJ3dNode();
336: polyAttr.setPolygonOffset(origPolygonOffset);
337: polyAttr.setPolygonMode(origPolygonMode);
338: polyAttr.setCullFace(origCullFace);
339: }
340: setControls();
341: setUpdateRequired(false);
342: }
343:
344: /**
345: * Set capability bits for read-only operations on this
346: * Nodes properties
347: */
348: protected void setReadCapabilityBits(NodeComponent node) {
349: if (node == null || node.isLive())
350: return;
351:
352: node.setCapability(PolygonAttributes.ALLOW_CULL_FACE_READ);
353: node.setCapability(PolygonAttributes.ALLOW_MODE_READ);
354: node.setCapability(PolygonAttributes.ALLOW_OFFSET_READ);
355:
356: }
357:
358: /**
359: * Set capability bits for write-only operations on this
360: * Nodes properties.
361: *
362: * This will probably only be used by setReadWriteCapabilityBits
363: */
364: protected void setReadWriteCapabilityBits(NodeComponent node) {
365: if (node == null || node.isLive())
366: return;
367:
368: node.setCapability(PolygonAttributes.ALLOW_CULL_FACE_READ);
369: node.setCapability(PolygonAttributes.ALLOW_MODE_READ);
370: node.setCapability(PolygonAttributes.ALLOW_OFFSET_READ);
371: node.setCapability(PolygonAttributes.ALLOW_CULL_FACE_WRITE);
372: node.setCapability(PolygonAttributes.ALLOW_MODE_WRITE);
373: node.setCapability(PolygonAttributes.ALLOW_OFFSET_WRITE);
374:
375: }
376:
377: /**
378: * Get the CommonNodeComponentPanel
379: */
380: protected org.jdesktop.j3dedit.scenegrapheditor.nodeeditors.panels.CommonNodeComponentPanel getCommonNCPanel() {
381: return ncCommonP;
382: }
383:
384: // Variables declaration - do not modify//GEN-BEGIN:variables
385: private javax.swing.JPanel nullPanel;
386: private javax.swing.JPanel jPanel2;
387: private javax.swing.JPanel jPanel1;
388: private javax.swing.JComboBox polygonModeC;
389: private javax.swing.JTextField polygonOffsetTF;
390: private javax.swing.JComboBox cullFaceCombo;
391: private javax.swing.JPanel normalPanel;
392: private org.jdesktop.j3dedit.scenegrapheditor.nodeeditors.panels.CommonNodeComponentPanel ncCommonP;
393: private javax.swing.JLabel jLabel4;
394: private javax.swing.JLabel jLabel3;
395: private javax.swing.JLabel jLabel2;
396: private javax.swing.JLabel jLabel1;
397: private javax.swing.JButton createAttributeB;
398: // End of variables declaration//GEN-END:variables
399:
400: }
|