001: /*
002: * $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/utils/gui/BoundsPanel.java,v 1.1 2005/04/20 21:04:56 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 Java 3D(tm) Fly Through.
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.j3dfly.utils.gui;
019:
020: import javax.media.j3d.Bounds;
021: import javax.media.j3d.BoundingSphere;
022: import javax.media.j3d.BoundingBox;
023: import javax.media.j3d.BoundingPolytope;
024: import javax.vecmath.Point3d;
025:
026: /**
027: * @author Paul Byrne
028: * @version 1.4, 01/18/02
029: */
030: public class BoundsPanel extends javax.swing.JPanel implements
031: Tuple3dChangeListener {
032:
033: private java.awt.CardLayout cardLayout;
034: private Bounds currentBounds;
035: private BoundsChangeListener changeListener = null;
036:
037: /** Creates new form BoundsPanel */
038: public BoundsPanel() {
039: initComponents();
040: cardLayout = (java.awt.CardLayout) cardPanel.getLayout();
041: upperCornerPanel.setChangeListener(this );
042: lowerCornerPanel.setChangeListener(this );
043: centerPanel.setChangeListener(this );
044: }
045:
046: public void setBounds(javax.media.j3d.Bounds bounds) {
047: currentBounds = bounds;
048: setControls();
049: }
050:
051: public void setBoundsChangeListener(BoundsChangeListener listener) {
052: changeListener = listener;
053: }
054:
055: public void setReadOnly(boolean readOnly) {
056: centerPanel.setReadOnly(readOnly);
057: radiusTF.setEditable(!readOnly);
058: boundsTypeC.setEnabled(!readOnly);
059: }
060:
061: /** This method is called from within the constructor to
062: * initialize the form.
063: * WARNING: Do NOT modify this code. The content of this method is
064: * always regenerated by the FormEditor.
065: */
066: private void initComponents() {//GEN-BEGIN:initComponents
067: cardPanel = new javax.swing.JPanel();
068: boxPanel = new javax.swing.JPanel();
069: jPanel3 = new javax.swing.JPanel();
070: lowerCornerPanel = new org.jdesktop.j3dfly.utils.gui.Tuple3dPanel();
071: jPanel4 = new javax.swing.JPanel();
072: upperCornerPanel = new org.jdesktop.j3dfly.utils.gui.Tuple3dPanel();
073: spherePanel = new javax.swing.JPanel();
074: radiusL = new javax.swing.JLabel();
075: radiusTF = new javax.swing.JTextField();
076: centerL = new javax.swing.JLabel();
077: jPanel1 = new javax.swing.JPanel();
078: centerPanel = new org.jdesktop.j3dfly.utils.gui.Tuple3dPanel();
079: polytopePanel = new javax.swing.JPanel();
080: jLabel1 = new javax.swing.JLabel();
081: nullPanel = new javax.swing.JPanel();
082: jLabel6 = new javax.swing.JLabel();
083: jPanel2 = new javax.swing.JPanel();
084: boundsTypeC = new javax.swing.JComboBox(new String[] {
085: "Bounding Sphere", "Bounding Box", "Bounding Polytope",
086: "Null Bounds" });
087: showBoundsCB = new javax.swing.JCheckBox();
088: setLayout(new java.awt.BorderLayout());
089:
090: cardPanel.setLayout(new java.awt.CardLayout());
091: cardPanel.setBorder(new javax.swing.border.EtchedBorder());
092:
093: boxPanel.setLayout(new java.awt.GridBagLayout());
094: java.awt.GridBagConstraints gridBagConstraints1;
095:
096: java.awt.GridBagConstraints gridBagConstraints2;
097: lowerCornerPanel.setBorder(new javax.swing.border.TitledBorder(
098: "Lower"));
099: jPanel3.add(lowerCornerPanel);
100:
101: gridBagConstraints1 = new java.awt.GridBagConstraints();
102: boxPanel.add(jPanel3, gridBagConstraints1);
103:
104: java.awt.GridBagConstraints gridBagConstraints3;
105: upperCornerPanel.setBorder(new javax.swing.border.TitledBorder(
106: "Upper"));
107: jPanel4.add(upperCornerPanel);
108:
109: gridBagConstraints1 = new java.awt.GridBagConstraints();
110: boxPanel.add(jPanel4, gridBagConstraints1);
111:
112: cardPanel.add(boxPanel, "boxCard");
113:
114: spherePanel.setLayout(new java.awt.GridBagLayout());
115: java.awt.GridBagConstraints gridBagConstraints4;
116:
117: radiusL.setText("Radius :");
118: gridBagConstraints4 = new java.awt.GridBagConstraints();
119: spherePanel.add(radiusL, gridBagConstraints4);
120:
121: radiusTF.setText("jTextField1");
122: gridBagConstraints4 = new java.awt.GridBagConstraints();
123: gridBagConstraints4.anchor = java.awt.GridBagConstraints.WEST;
124: spherePanel.add(radiusTF, gridBagConstraints4);
125:
126: centerL.setText("Center :");
127: gridBagConstraints4 = new java.awt.GridBagConstraints();
128: gridBagConstraints4.gridx = 0;
129: gridBagConstraints4.gridy = 1;
130: spherePanel.add(centerL, gridBagConstraints4);
131:
132: java.awt.GridBagConstraints gridBagConstraints5;
133: jPanel1.add(centerPanel);
134:
135: gridBagConstraints4 = new java.awt.GridBagConstraints();
136: gridBagConstraints4.gridx = 1;
137: gridBagConstraints4.gridy = 1;
138: spherePanel.add(jPanel1, gridBagConstraints4);
139:
140: cardPanel.add(spherePanel, "sphereCard");
141:
142: jLabel1.setText("Not Implemented");
143: polytopePanel.add(jLabel1);
144:
145: cardPanel.add(polytopePanel, "polytopeCard");
146:
147: jLabel6.setText("Null Bounds");
148: nullPanel.add(jLabel6);
149:
150: cardPanel.add(nullPanel, "nullCard");
151:
152: add(cardPanel, java.awt.BorderLayout.CENTER);
153:
154: boundsTypeC.addItemListener(new java.awt.event.ItemListener() {
155: public void itemStateChanged(java.awt.event.ItemEvent evt) {
156: boundsTypeCItemStateChanged(evt);
157: }
158: });
159: jPanel2.add(boundsTypeC);
160:
161: showBoundsCB.setText("Show Bounds");
162: showBoundsCB
163: .addChangeListener(new javax.swing.event.ChangeListener() {
164: public void stateChanged(
165: javax.swing.event.ChangeEvent evt) {
166: showBoundsCBStateChanged(evt);
167: }
168: });
169: jPanel2.add(showBoundsCB);
170:
171: add(jPanel2, java.awt.BorderLayout.NORTH);
172:
173: }//GEN-END:initComponents
174:
175: private void showBoundsCBStateChanged(
176: javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_showBoundsCBStateChanged
177: // Add your handling code here:
178: changeListener.showBounds(this , showBoundsCB.isSelected());
179: }//GEN-LAST:event_showBoundsCBStateChanged
180:
181: private void boundsTypeCItemStateChanged(
182: java.awt.event.ItemEvent evt) {//GEN-FIRST:event_boundsTypeCItemStateChanged
183: // Add your handling code here:
184: switch (boundsTypeC.getSelectedIndex()) {
185: case 0:
186: currentBounds = new BoundingSphere();
187: break;
188: case 1:
189: currentBounds = new BoundingBox();
190: break;
191: case 2:
192: currentBounds = new BoundingPolytope();
193: break;
194: case 3:
195: currentBounds = null;
196: break;
197: }
198: setControls();
199: if (changeListener != null)
200: changeListener.boundsChanged(this , currentBounds);
201: else
202: throw new RuntimeException(
203: "BoundPanel ChangeListener is null");
204: }//GEN-LAST:event_boundsTypeCItemStateChanged
205:
206: /**
207: * Set controls to represent currentBounds
208: */
209: private void setControls() {
210: if (currentBounds == null) {
211: cardLayout.show(cardPanel, "nullCard");
212: boundsTypeC.setSelectedIndex(3);
213: } else {
214: if (currentBounds instanceof javax.media.j3d.BoundingSphere)
215: processBoundingSphere();
216: else if (currentBounds instanceof javax.media.j3d.BoundingBox)
217: processBoundingBox();
218: else if (currentBounds instanceof javax.media.j3d.BoundingPolytope)
219: processBoundingPolytope();
220: }
221: }
222:
223: private void processBoundingSphere() {
224: javax.media.j3d.BoundingSphere bSphere = (javax.media.j3d.BoundingSphere) currentBounds;
225: cardLayout.show(cardPanel, "sphereCard");
226: boundsTypeC.setSelectedIndex(0);
227: radiusTF.setText(Double.toString(bSphere.getRadius()));
228: Point3d center = new Point3d();
229: bSphere.getCenter(center);
230: centerPanel.setTuple(center);
231: }
232:
233: private void processBoundingBox() {
234: cardLayout.show(cardPanel, "boxCard");
235: boundsTypeC.setSelectedIndex(1);
236: Point3d upperCorner = new Point3d();
237: Point3d lowerCorner = new Point3d();
238: ((BoundingBox) currentBounds).getUpper(upperCorner);
239: ((BoundingBox) currentBounds).getLower(lowerCorner);
240: upperCornerPanel.setTuple(upperCorner);
241: lowerCornerPanel.setTuple(lowerCorner);
242: }
243:
244: private void processBoundingPolytope() {
245: cardLayout.show(cardPanel, "polytopeCard");
246: boundsTypeC.setSelectedIndex(2);
247: }
248:
249: // Variables declaration - do not modify//GEN-BEGIN:variables
250: private javax.swing.JPanel cardPanel;
251: private javax.swing.JPanel boxPanel;
252: private javax.swing.JPanel jPanel3;
253: private org.jdesktop.j3dfly.utils.gui.Tuple3dPanel lowerCornerPanel;
254: private javax.swing.JPanel jPanel4;
255: private org.jdesktop.j3dfly.utils.gui.Tuple3dPanel upperCornerPanel;
256: private javax.swing.JPanel spherePanel;
257: private javax.swing.JLabel radiusL;
258: private javax.swing.JTextField radiusTF;
259: private javax.swing.JLabel centerL;
260: private javax.swing.JPanel jPanel1;
261: private org.jdesktop.j3dfly.utils.gui.Tuple3dPanel centerPanel;
262: private javax.swing.JPanel polytopePanel;
263: private javax.swing.JLabel jLabel1;
264: private javax.swing.JPanel nullPanel;
265: private javax.swing.JLabel jLabel6;
266: private javax.swing.JPanel jPanel2;
267: private javax.swing.JComboBox boundsTypeC;
268: private javax.swing.JCheckBox showBoundsCB;
269:
270: // End of variables declaration//GEN-END:variables
271:
272: /**
273: * Called whenever the user changes the values in the Tuple3dPanel
274: */
275: public void pointChanged(Tuple3dPanel source, double x, double y,
276: double z) {
277: System.out.println("Tuple Changed " + source);
278: }
279: }
|