001: /*
002: * $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/plugins/StereoControlPanel.java,v 1.1 2005/04/20 21:04:43 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.plugins;
019:
020: import org.jdesktop.j3dfly.J3dFlyContext;
021: import javax.vecmath.Point3d;
022: import javax.vecmath.Vector3d;
023:
024: /**
025: *
026: * @author Paul Byrne
027: * @version $Revision: 1.1 $
028: */
029: public class StereoControlPanel extends javax.swing.JPanel {
030:
031: private J3dFlyContext j3dflyContext;
032:
033: /** Creates new form StereoControlPanel */
034: public StereoControlPanel(J3dFlyContext j3dflyContext) {
035: super ();
036: this .j3dflyContext = j3dflyContext;
037: initComponents();
038: j3dflyContext.getUniverse().getViewer().getView()
039: .setWindowEyepointPolicy(
040: javax.media.j3d.View.RELATIVE_TO_COEXISTENCE);
041:
042: if (!j3dflyContext.getUniverse().getViewer().getCanvas3Ds()[0]
043: .getStereoAvailable()) {
044: eyeSepTF.setEnabled(false);
045: eyeSepSB.setEnabled(false);
046: } else {
047: this .remove(noStereoLabel1);
048: this .remove(noStereoLabel2);
049: }
050: }
051:
052: /** This method is called from within the constructor to
053: * initialize the form.
054: * WARNING: Do NOT modify this code. The content of this method is
055: * always regenerated by the Form Editor.
056: */
057: private void initComponents() {//GEN-BEGIN:initComponents
058: java.awt.GridBagConstraints gridBagConstraints;
059:
060: jLabel1 = new javax.swing.JLabel();
061: eyeSepTF = new javax.swing.JTextField();
062: jLabel2 = new javax.swing.JLabel();
063: eyeSepSB = new javax.swing.JScrollBar();
064: noStereoLabel1 = new javax.swing.JLabel();
065: noStereoLabel2 = new javax.swing.JLabel();
066:
067: setLayout(new java.awt.GridBagLayout());
068:
069: setBorder(new javax.swing.border.EmptyBorder(
070: new java.awt.Insets(10, 10, 10, 10)));
071: addAncestorListener(new javax.swing.event.AncestorListener() {
072: public void ancestorMoved(
073: javax.swing.event.AncestorEvent evt) {
074: }
075:
076: public void ancestorAdded(
077: javax.swing.event.AncestorEvent evt) {
078: formAncestorAdded(evt);
079: }
080:
081: public void ancestorRemoved(
082: javax.swing.event.AncestorEvent evt) {
083: }
084: });
085:
086: jLabel1.setText("Eye Seperation");
087: gridBagConstraints = new java.awt.GridBagConstraints();
088: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 4);
089: add(jLabel1, gridBagConstraints);
090:
091: eyeSepTF
092: .setDocument(new org.jdesktop.j3dfly.utils.gui.FloatDocument());
093: eyeSepTF.setToolTipText("Distance between the eyes in mm");
094: eyeSepTF.setMargin(new java.awt.Insets(0, 2, 0, 2));
095: eyeSepTF.setMinimumSize(new java.awt.Dimension(44, 21));
096: eyeSepTF.setPreferredSize(new java.awt.Dimension(44, 21));
097: eyeSepTF.addActionListener(new java.awt.event.ActionListener() {
098: public void actionPerformed(java.awt.event.ActionEvent evt) {
099: eyeSepTFActionPerformed(evt);
100: }
101: });
102:
103: eyeSepTF.addFocusListener(new java.awt.event.FocusAdapter() {
104: public void focusLost(java.awt.event.FocusEvent evt) {
105: eyeSepTFFocusLost(evt);
106: }
107: });
108:
109: add(eyeSepTF, new java.awt.GridBagConstraints());
110:
111: jLabel2.setText("mm");
112: gridBagConstraints = new java.awt.GridBagConstraints();
113: gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 0);
114: add(jLabel2, gridBagConstraints);
115:
116: eyeSepSB.setMaximum(1000);
117: eyeSepSB.setMinimum(1);
118: eyeSepSB.setOrientation(javax.swing.JScrollBar.HORIZONTAL);
119: eyeSepSB.setValue(660);
120: eyeSepSB
121: .addAdjustmentListener(new java.awt.event.AdjustmentListener() {
122: public void adjustmentValueChanged(
123: java.awt.event.AdjustmentEvent evt) {
124: eyeSepSBAdjustmentValueChanged(evt);
125: }
126: });
127:
128: gridBagConstraints = new java.awt.GridBagConstraints();
129: gridBagConstraints.gridx = 0;
130: gridBagConstraints.gridy = 1;
131: gridBagConstraints.gridwidth = 3;
132: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
133: add(eyeSepSB, gridBagConstraints);
134:
135: noStereoLabel1.setText("Your current Java3D Universe");
136: gridBagConstraints = new java.awt.GridBagConstraints();
137: gridBagConstraints.gridx = 0;
138: gridBagConstraints.gridy = 2;
139: gridBagConstraints.gridwidth = 3;
140: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
141: gridBagConstraints.insets = new java.awt.Insets(20, 0, 0, 0);
142: add(noStereoLabel1, gridBagConstraints);
143:
144: noStereoLabel2.setText("is not running in Stereo.");
145: gridBagConstraints = new java.awt.GridBagConstraints();
146: gridBagConstraints.gridx = 0;
147: gridBagConstraints.gridy = 3;
148: gridBagConstraints.gridwidth = 3;
149: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
150: add(noStereoLabel2, gridBagConstraints);
151:
152: }//GEN-END:initComponents
153:
154: private void eyeSepTFFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_eyeSepTFFocusLost
155: // Add your handling code here:
156: processTFUpdate();
157: }//GEN-LAST:event_eyeSepTFFocusLost
158:
159: private void formAncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_formAncestorAdded
160: // Add your handling code here:
161: Point3d leftEye = new Point3d();
162: Point3d rightEye = new Point3d();
163: j3dflyContext.getUniverse().getViewer().getView()
164: .getRightManualEyeInCoexistence(rightEye);
165: j3dflyContext.getUniverse().getViewer().getView()
166: .getLeftManualEyeInCoexistence(leftEye);
167:
168: Vector3d distance = new Vector3d();
169: distance.sub(leftEye, rightEye);
170:
171: double eyeSep = Math.abs(distance.length() * 1000);
172: eyeSepTF.setText(Double.toString(eyeSep));
173: eyeSepSB.setValue((int) (eyeSep * 10));
174: }//GEN-LAST:event_formAncestorAdded
175:
176: private void eyeSepTFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_eyeSepTFActionPerformed
177: // Add your handling code here:
178: processTFUpdate();
179: }//GEN-LAST:event_eyeSepTFActionPerformed
180:
181: private void eyeSepSBAdjustmentValueChanged(
182: java.awt.event.AdjustmentEvent evt) {//GEN-FIRST:event_eyeSepSBAdjustmentValueChanged
183: // Add your handling code here:
184: double eyeSep = ((double) eyeSepSB.getValue()) / 10.0;
185: eyeSepTF.setText(Double.toString(eyeSep));
186: updateSeperation(eyeSep);
187: }//GEN-LAST:event_eyeSepSBAdjustmentValueChanged
188:
189: /**
190: * Read the value of the TF and update the scroll bar
191: * and the eye seperation in the universe
192: */
193: private void processTFUpdate() {
194: try {
195: double eyeSep = Double.parseDouble(eyeSepTF.getText());
196: eyeSepSB.setValue((int) (eyeSep * 10));
197: updateSeperation(eyeSep);
198: } catch (NumberFormatException e) {
199: double eyeSep = ((double) eyeSepSB.getValue()) / 10.0;
200: eyeSepTF.setText(Double.toString(eyeSep));
201: }
202:
203: }
204:
205: /**
206: * Change the eye seperation for viewer 0 of the universe
207: *
208: * @param eyeSeperation eye seperation in mm
209: */
210: private void updateSeperation(double eyeSeperation) {
211: eyeSeperation /= 1000;
212: j3dflyContext.getUniverse().getViewer().getView()
213: .setRightManualEyeInCoexistence(
214: new Point3d(eyeSeperation / 2, 0, 0.45));
215: j3dflyContext.getUniverse().getViewer().getView()
216: .setLeftManualEyeInCoexistence(
217: new Point3d(-eyeSeperation / 2, 0, 0.45));
218: }
219:
220: // Variables declaration - do not modify//GEN-BEGIN:variables
221: private javax.swing.JScrollBar eyeSepSB;
222: private javax.swing.JLabel noStereoLabel2;
223: private javax.swing.JLabel noStereoLabel1;
224: private javax.swing.JTextField eyeSepTF;
225: private javax.swing.JLabel jLabel2;
226: private javax.swing.JLabel jLabel1;
227: // End of variables declaration//GEN-END:variables
228:
229: }
|