001: /*
002: * $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/utils/gui/Tuple3dPanel.java,v 1.1 2005/04/20 21:05:00 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: /**
021: * @author Paul Byrne
022: * @version 1.4, 01/18/02
023: */
024: public class Tuple3dPanel extends javax.swing.JPanel {
025:
026: private Tuple3dChangeListener changeListener;
027: private double origX;
028: private double origY;
029: private double origZ;
030:
031: /** Creates new form point3fPanel */
032: public Tuple3dPanel() {
033: initComponents();
034: }
035:
036: /**
037: * Set the point on which this panel operates
038: */
039: public void setTuple(javax.vecmath.Tuple3d point) {
040: origX = point.x;
041: origY = point.y;
042: origZ = point.z;
043: xTF.setText(Double.toString(point.x));
044: yTF.setText(Double.toString(point.y));
045: zTF.setText(Double.toString(point.z));
046: }
047:
048: public void setChangeListener(Tuple3dChangeListener changeListener) {
049: this .changeListener = changeListener;
050: }
051:
052: public void setReadOnly(boolean readOnly) {
053: xTF.setEditable(!readOnly);
054: yTF.setEditable(!readOnly);
055: zTF.setEditable(!readOnly);
056: }
057:
058: /** This method is called from within the constructor to
059: * initialize the form.
060: * WARNING: Do NOT modify this code. The content of this method is
061: * always regenerated by the FormEditor.
062: */
063: private void initComponents() {//GEN-BEGIN:initComponents
064: jLabel1 = new javax.swing.JLabel();
065: jLabel2 = new javax.swing.JLabel();
066: jLabel3 = new javax.swing.JLabel();
067: xTF = new javax.swing.JTextField();
068: yTF = new javax.swing.JTextField();
069: zTF = new javax.swing.JTextField();
070: setLayout(new java.awt.GridBagLayout());
071: java.awt.GridBagConstraints gridBagConstraints1;
072:
073: jLabel1.setText("X :");
074:
075: gridBagConstraints1 = new java.awt.GridBagConstraints();
076: gridBagConstraints1.insets = new java.awt.Insets(0, 0, 0, 3);
077: gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
078: add(jLabel1, gridBagConstraints1);
079:
080: jLabel2.setText("Y :");
081:
082: gridBagConstraints1 = new java.awt.GridBagConstraints();
083: gridBagConstraints1.gridx = 0;
084: gridBagConstraints1.gridy = 1;
085: gridBagConstraints1.insets = new java.awt.Insets(0, 0, 0, 3);
086: gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
087: add(jLabel2, gridBagConstraints1);
088:
089: jLabel3.setText("Z :");
090:
091: gridBagConstraints1 = new java.awt.GridBagConstraints();
092: gridBagConstraints1.gridx = 0;
093: gridBagConstraints1.gridy = 2;
094: gridBagConstraints1.insets = new java.awt.Insets(0, 0, 0, 3);
095: gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
096: add(jLabel3, gridBagConstraints1);
097:
098: xTF.setPreferredSize(new java.awt.Dimension(90, 21));
099: xTF.setToolTipText("X coordinate (double)");
100: xTF.setText("000000");
101: xTF.setMinimumSize(new java.awt.Dimension(90, 21));
102: xTF.setDocument(new FloatDocument());
103: xTF.addActionListener(new java.awt.event.ActionListener() {
104: public void actionPerformed(java.awt.event.ActionEvent evt) {
105: tfAction(evt);
106: }
107: });
108: xTF.addFocusListener(new java.awt.event.FocusAdapter() {
109: public void focusLost(java.awt.event.FocusEvent evt) {
110: tfFocusLost(evt);
111: }
112: });
113:
114: gridBagConstraints1 = new java.awt.GridBagConstraints();
115: gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
116: gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
117: add(xTF, gridBagConstraints1);
118:
119: yTF.setToolTipText("Y coordinate (double)");
120: yTF.setText("000000");
121: yTF.setMinimumSize(new java.awt.Dimension(40, 21));
122: yTF.setDocument(new FloatDocument());
123: yTF.addActionListener(new java.awt.event.ActionListener() {
124: public void actionPerformed(java.awt.event.ActionEvent evt) {
125: tfAction(evt);
126: }
127: });
128: yTF.addFocusListener(new java.awt.event.FocusAdapter() {
129: public void focusLost(java.awt.event.FocusEvent evt) {
130: tfFocusLost(evt);
131: }
132: });
133:
134: gridBagConstraints1 = new java.awt.GridBagConstraints();
135: gridBagConstraints1.gridx = 1;
136: gridBagConstraints1.gridy = 1;
137: gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
138: gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
139: add(yTF, gridBagConstraints1);
140:
141: zTF.setToolTipText("Z coordinate (double)");
142: zTF.setText("000000");
143: zTF.setMinimumSize(new java.awt.Dimension(40, 21));
144: zTF.setDocument(new FloatDocument());
145: zTF.addActionListener(new java.awt.event.ActionListener() {
146: public void actionPerformed(java.awt.event.ActionEvent evt) {
147: tfAction(evt);
148: }
149: });
150: zTF.addFocusListener(new java.awt.event.FocusAdapter() {
151: public void focusLost(java.awt.event.FocusEvent evt) {
152: tfFocusLost(evt);
153: }
154: });
155:
156: gridBagConstraints1 = new java.awt.GridBagConstraints();
157: gridBagConstraints1.gridx = 1;
158: gridBagConstraints1.gridy = 2;
159: gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
160: gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
161: add(zTF, gridBagConstraints1);
162:
163: }//GEN-END:initComponents
164:
165: private void tfAction(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfAction
166: // Add your handling code here:
167: processChange();
168: }//GEN-LAST:event_tfAction
169:
170: private void tfFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfFocusLost
171: // Add your handling code here:
172: processChange();
173: }//GEN-LAST:event_tfFocusLost
174:
175: private void processChange() {
176: try {
177: double x = Double.parseDouble(xTF.getText());
178: double y = Double.parseDouble(yTF.getText());
179: double z = Double.parseDouble(zTF.getText());
180: if (x != origX || y != origY || z != origZ) {
181: changeListener.pointChanged(this , x, y, z);
182: origX = x;
183: origY = y;
184: origZ = z;
185: }
186: } catch (NumberFormatException e) {
187: // Should never reach here because format is checked by FloatDocument
188: e.printStackTrace();
189: }
190: }
191:
192: // Variables declaration - do not modify//GEN-BEGIN:variables
193: private javax.swing.JLabel jLabel1;
194: private javax.swing.JLabel jLabel2;
195: private javax.swing.JLabel jLabel3;
196: private javax.swing.JTextField xTF;
197: private javax.swing.JTextField yTF;
198: private javax.swing.JTextField zTF;
199: // End of variables declaration//GEN-END:variables
200:
201: }
|