001: /*
002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/NavigationControlPanel.java,v 1.1 2005/04/20 22:20:47 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;
019:
020: import javax.media.j3d.TransformGroup;
021: import javax.media.j3d.BranchGroup;
022: import javax.media.j3d.Canvas3D;
023: import javax.media.j3d.BoundingSphere;
024: import javax.vecmath.Point3d;
025: import com.sun.j3d.utils.behaviors.mouse.*;
026:
027: /**
028: * @author Paul Byrne
029: * @version 1.7, 01/18/02
030: */
031: public class NavigationControlPanel extends javax.swing.JPanel {
032:
033: private Canvas3D canvas;
034: private MouseRotate rotate = new MouseRotate(
035: MouseBehavior.MANUAL_WAKEUP);
036: private MouseTranslate translate = new MouseTranslate(
037: MouseBehavior.MANUAL_WAKEUP);
038: private MouseZoom zoom = new MouseZoom(MouseBehavior.MANUAL_WAKEUP);
039:
040: /** Creates new form NavigationControlPanel */
041: public NavigationControlPanel() {
042: initComponents();
043: rotateTF.setText(Double.toString(rotate.getXFactor()));
044: zoomTF.setText(Double.toString(zoom.getFactor()));
045: translateTF.setText(Double.toString(translate.getXFactor()));
046: }
047:
048: public void setTransformGroup(BranchGroup toolRoot,
049: TransformGroup tg) {
050: rotate.setTransformGroup(tg);
051: rotate.setSchedulingBounds(new BoundingSphere(new Point3d(),
052: Double.POSITIVE_INFINITY));
053: zoom.setTransformGroup(tg);
054: zoom.setSchedulingBounds(new BoundingSphere(new Point3d(),
055: Double.POSITIVE_INFINITY));
056: translate.setTransformGroup(tg);
057: translate.setSchedulingBounds(new BoundingSphere(new Point3d(),
058: Double.POSITIVE_INFINITY));
059: NavigationControlVisualTool bg = new NavigationControlVisualTool();
060: bg.addChild(rotate);
061: bg.addChild(zoom);
062: bg.addChild(translate);
063: toolRoot.addChild(bg);
064: }
065:
066: public void setCanvas3D(Canvas3D canvas) {
067: this .canvas = canvas;
068: }
069:
070: /** This method is called from within the constructor to
071: * initialize the form.
072: * WARNING: Do NOT modify this code. The content of this method is
073: * always regenerated by the FormEditor.
074: */
075: private void initComponents() {//GEN-BEGIN:initComponents
076: inputP = new javax.swing.JPanel();
077: jPanel1 = new javax.swing.JPanel();
078: jLabel1 = new javax.swing.JLabel();
079: jLabel2 = new javax.swing.JLabel();
080: zoomTF = new javax.swing.JTextField();
081: translateTF = new javax.swing.JTextField();
082: rotateTF = new javax.swing.JTextField();
083: jLabel3 = new javax.swing.JLabel();
084: jPanel2 = new javax.swing.JPanel();
085: jLabel4 = new javax.swing.JLabel();
086: jLabel5 = new javax.swing.JLabel();
087:
088: setLayout(new java.awt.BorderLayout());
089:
090: inputP
091: .setBorder(new javax.swing.border.MatteBorder(
092: new java.awt.Insets(1, 1, 1, 1),
093: java.awt.Color.orange));
094: inputP.setToolTipText("");
095: inputP.setPreferredSize(new java.awt.Dimension(60, 60));
096: inputP.setMinimumSize(new java.awt.Dimension(60, 60));
097: inputP.addMouseListener(new java.awt.event.MouseAdapter() {
098: public void mousePressed(java.awt.event.MouseEvent evt) {
099: inputPMouseEvent(evt);
100: }
101:
102: public void mouseReleased(java.awt.event.MouseEvent evt) {
103: inputPMouseEvent(evt);
104: intputPMouseReleased(evt);
105: }
106:
107: public void mouseClicked(java.awt.event.MouseEvent evt) {
108: inputPMouseEvent(evt);
109: }
110: });
111:
112: inputP
113: .addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
114: public void mouseMoved(java.awt.event.MouseEvent evt) {
115: inputPMouseEvent(evt);
116: }
117:
118: public void mouseDragged(
119: java.awt.event.MouseEvent evt) {
120: inputPMouseEvent(evt);
121: }
122: });
123:
124: add(inputP, java.awt.BorderLayout.CENTER);
125:
126: jPanel1.setLayout(new java.awt.GridBagLayout());
127: java.awt.GridBagConstraints gridBagConstraints1;
128:
129: jPanel1.setBorder(new javax.swing.border.EtchedBorder());
130: jLabel1.setText("Zoom Factor :");
131: gridBagConstraints1 = new java.awt.GridBagConstraints();
132: gridBagConstraints1.insets = new java.awt.Insets(0, 0, 0, 4);
133: gridBagConstraints1.anchor = java.awt.GridBagConstraints.EAST;
134: jPanel1.add(jLabel1, gridBagConstraints1);
135:
136: jLabel2.setText("Translate Factor :");
137: gridBagConstraints1 = new java.awt.GridBagConstraints();
138: gridBagConstraints1.gridx = 0;
139: gridBagConstraints1.gridy = 1;
140: gridBagConstraints1.insets = new java.awt.Insets(0, 0, 0, 4);
141: gridBagConstraints1.anchor = java.awt.GridBagConstraints.EAST;
142: jPanel1.add(jLabel2, gridBagConstraints1);
143:
144: zoomTF
145: .setDocument(new org.jdesktop.j3dfly.utils.gui.FloatDocument());
146: zoomTF.setMinimumSize(new java.awt.Dimension(57, 21));
147: gridBagConstraints1 = new java.awt.GridBagConstraints();
148: jPanel1.add(zoomTF, gridBagConstraints1);
149:
150: translateTF
151: .setDocument(new org.jdesktop.j3dfly.utils.gui.FloatDocument());
152: translateTF.setMinimumSize(new java.awt.Dimension(57, 21));
153: gridBagConstraints1 = new java.awt.GridBagConstraints();
154: gridBagConstraints1.gridx = 1;
155: gridBagConstraints1.gridy = 1;
156: jPanel1.add(translateTF, gridBagConstraints1);
157:
158: rotateTF
159: .setDocument(new org.jdesktop.j3dfly.utils.gui.FloatDocument());
160: rotateTF.setMinimumSize(new java.awt.Dimension(57, 21));
161: gridBagConstraints1 = new java.awt.GridBagConstraints();
162: gridBagConstraints1.gridx = 1;
163: gridBagConstraints1.gridy = 2;
164: jPanel1.add(rotateTF, gridBagConstraints1);
165:
166: jLabel3.setText("Rotate Factor :");
167: gridBagConstraints1 = new java.awt.GridBagConstraints();
168: gridBagConstraints1.gridx = 0;
169: gridBagConstraints1.gridy = 2;
170: gridBagConstraints1.insets = new java.awt.Insets(0, 0, 0, 4);
171: gridBagConstraints1.anchor = java.awt.GridBagConstraints.EAST;
172: jPanel1.add(jLabel3, gridBagConstraints1);
173:
174: add(jPanel1, java.awt.BorderLayout.NORTH);
175:
176: jPanel2.setLayout(new java.awt.BorderLayout());
177:
178: jLabel4
179: .setText("Move the mouse in the Yellow Area to change the View");
180: jPanel2.add(jLabel4, java.awt.BorderLayout.NORTH);
181:
182: jLabel5.setText("Mouse Buttons : Rotate, Zoom, Translate");
183: jPanel2.add(jLabel5, java.awt.BorderLayout.SOUTH);
184:
185: add(jPanel2, java.awt.BorderLayout.SOUTH);
186:
187: }//GEN-END:initComponents
188:
189: private void intputPMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_intputPMouseReleased
190: // Add your handling code here:
191: canvas.dispatchEvent(evt);
192: }//GEN-LAST:event_intputPMouseReleased
193:
194: private void inputPMouseEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_inputPMouseEvent
195: // Add your handling code here
196: rotate.wakeup();
197: zoom.wakeup();
198: translate.wakeup();
199:
200: canvas.dispatchEvent(evt);
201: }//GEN-LAST:event_inputPMouseEvent
202:
203: private void closeBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeBActionPerformed
204: // Add your handling code here:
205: }//GEN-LAST:event_closeBActionPerformed
206:
207: // Variables declaration - do not modify//GEN-BEGIN:variables
208: private javax.swing.JPanel inputP;
209: private javax.swing.JPanel jPanel1;
210: private javax.swing.JLabel jLabel1;
211: private javax.swing.JLabel jLabel2;
212: private javax.swing.JTextField zoomTF;
213: private javax.swing.JTextField translateTF;
214: private javax.swing.JTextField rotateTF;
215: private javax.swing.JLabel jLabel3;
216: private javax.swing.JPanel jPanel2;
217: private javax.swing.JLabel jLabel4;
218: private javax.swing.JLabel jLabel5;
219: // End of variables declaration//GEN-END:variables
220:
221: }
222:
223: class NavigationControlVisualTool extends
224: org.jdesktop.j3dedit.scenegrapheditor.visualtools.VisualTool {
225:
226: public void reset() {
227: }
228: }
|