001: /*
002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/nodeeditors/panels/PointLightPanel.java,v 1.1 2005/04/20 22:21:06 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.PointLight;
021: import javax.vecmath.Color3f;
022: import javax.vecmath.Point3f;
023: import java.awt.Color;
024: import org.jdesktop.j3dedit.scenegrapheditor.nodeeditors.NodeEditorPanel;
025:
026: /**
027: * @author Paul Byrne
028: * @version 1.6, 01/18/02
029: */
030: public class PointLightPanel extends NodeEditorPanel {
031:
032: private Point3f origPosition = new Point3f();
033: private boolean origEnabled;
034: private Color3f origColor;
035:
036: /** Creates new form PointLightPanel */
037: public PointLightPanel() {
038: super ();
039: frameTitle = "Point Light";
040: initComponents();
041:
042: System.out
043: .println("TODO - Test PointLightPanel, implement Attenuation controls");
044: }
045:
046: /** This method is called from within the constructor to
047: * initialize the form.
048: * WARNING: Do NOT modify this code. The content of this method is
049: * always regenerated by the FormEditor.
050: */
051: private void initComponents() {//GEN-BEGIN:initComponents
052: lightEnableCB = new javax.swing.JCheckBox();
053: colorB = new javax.swing.JButton();
054: positionPanel = new javax.swing.JPanel();
055: xLabel = new javax.swing.JLabel();
056: yLabel = new javax.swing.JLabel();
057: zLabel = new javax.swing.JLabel();
058: xTF = new javax.swing.JTextField();
059: zTF = new javax.swing.JTextField();
060: yTF = new javax.swing.JTextField();
061: colorPanel = new javax.swing.JPanel();
062: attenuationPanel = new javax.swing.JPanel();
063: jLabel1 = new javax.swing.JLabel();
064: jLabel2 = new javax.swing.JLabel();
065: jLabel3 = new javax.swing.JLabel();
066: attenuationXTF = new javax.swing.JTextField();
067: attenuationYTF = new javax.swing.JTextField();
068: attenuationZTF = new javax.swing.JTextField();
069:
070: setLayout(new java.awt.GridBagLayout());
071: java.awt.GridBagConstraints gridBagConstraints1;
072:
073: lightEnableCB.setText("enabled");
074: lightEnableCB
075: .addActionListener(new java.awt.event.ActionListener() {
076: public void actionPerformed(
077: java.awt.event.ActionEvent evt) {
078: lightEnableCBActionPerformed(evt);
079: }
080: });
081:
082: gridBagConstraints1 = new java.awt.GridBagConstraints();
083: gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
084: add(lightEnableCB, gridBagConstraints1);
085:
086: colorB.setText("Color ...");
087: colorB.addActionListener(new java.awt.event.ActionListener() {
088: public void actionPerformed(java.awt.event.ActionEvent evt) {
089: selectColor(evt);
090: }
091: });
092:
093: gridBagConstraints1 = new java.awt.GridBagConstraints();
094: gridBagConstraints1.gridx = 0;
095: gridBagConstraints1.gridy = 1;
096: gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
097: add(colorB, gridBagConstraints1);
098:
099: positionPanel.setLayout(new java.awt.GridBagLayout());
100: java.awt.GridBagConstraints gridBagConstraints2;
101:
102: positionPanel.setBorder(new javax.swing.border.TitledBorder(
103: new javax.swing.border.EtchedBorder(), "Position"));
104: xLabel.setText("X");
105: gridBagConstraints2 = new java.awt.GridBagConstraints();
106: gridBagConstraints2.insets = new java.awt.Insets(0, 0, 0, 2);
107: positionPanel.add(xLabel, gridBagConstraints2);
108:
109: yLabel.setText("Y");
110: gridBagConstraints2 = new java.awt.GridBagConstraints();
111: gridBagConstraints2.gridx = 0;
112: gridBagConstraints2.gridy = 1;
113: gridBagConstraints2.insets = new java.awt.Insets(0, 0, 0, 2);
114: positionPanel.add(yLabel, gridBagConstraints2);
115:
116: zLabel.setText("Z");
117: gridBagConstraints2 = new java.awt.GridBagConstraints();
118: gridBagConstraints2.gridx = 0;
119: gridBagConstraints2.gridy = 2;
120: gridBagConstraints2.insets = new java.awt.Insets(0, 0, 0, 2);
121: positionPanel.add(zLabel, gridBagConstraints2);
122:
123: xTF.setText("jTextField1");
124: gridBagConstraints2 = new java.awt.GridBagConstraints();
125: gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
126: positionPanel.add(xTF, gridBagConstraints2);
127:
128: zTF.setText("jTextField3");
129: gridBagConstraints2 = new java.awt.GridBagConstraints();
130: gridBagConstraints2.gridx = 1;
131: gridBagConstraints2.gridy = 2;
132: gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
133: positionPanel.add(zTF, gridBagConstraints2);
134:
135: yTF.setText("jTextField2");
136: gridBagConstraints2 = new java.awt.GridBagConstraints();
137: gridBagConstraints2.gridx = 1;
138: gridBagConstraints2.gridy = 1;
139: gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
140: positionPanel.add(yTF, gridBagConstraints2);
141:
142: gridBagConstraints1 = new java.awt.GridBagConstraints();
143: gridBagConstraints1.gridx = 0;
144: gridBagConstraints1.gridy = 2;
145: gridBagConstraints1.gridwidth = 2;
146: add(positionPanel, gridBagConstraints1);
147:
148: colorPanel.setBackground(java.awt.Color.red);
149: gridBagConstraints1 = new java.awt.GridBagConstraints();
150: gridBagConstraints1.gridx = 1;
151: gridBagConstraints1.gridy = 1;
152: gridBagConstraints1.gridwidth = 2;
153: gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
154: add(colorPanel, gridBagConstraints1);
155:
156: attenuationPanel.setLayout(new java.awt.GridBagLayout());
157: java.awt.GridBagConstraints gridBagConstraints3;
158:
159: attenuationPanel.setBorder(new javax.swing.border.TitledBorder(
160: new javax.swing.border.EtchedBorder(), "Attenuation"));
161: jLabel1.setText("X");
162: gridBagConstraints3 = new java.awt.GridBagConstraints();
163: gridBagConstraints3.insets = new java.awt.Insets(0, 0, 0, 2);
164: attenuationPanel.add(jLabel1, gridBagConstraints3);
165:
166: jLabel2.setText("Y");
167: gridBagConstraints3 = new java.awt.GridBagConstraints();
168: gridBagConstraints3.gridx = 0;
169: gridBagConstraints3.gridy = 1;
170: gridBagConstraints3.insets = new java.awt.Insets(0, 0, 0, 2);
171: attenuationPanel.add(jLabel2, gridBagConstraints3);
172:
173: jLabel3.setText("Z");
174: gridBagConstraints3 = new java.awt.GridBagConstraints();
175: gridBagConstraints3.gridx = 0;
176: gridBagConstraints3.gridy = 2;
177: gridBagConstraints3.insets = new java.awt.Insets(0, 0, 0, 2);
178: attenuationPanel.add(jLabel3, gridBagConstraints3);
179:
180: attenuationXTF.setText("jTextField1");
181: gridBagConstraints3 = new java.awt.GridBagConstraints();
182: gridBagConstraints3.fill = java.awt.GridBagConstraints.HORIZONTAL;
183: attenuationPanel.add(attenuationXTF, gridBagConstraints3);
184:
185: attenuationYTF.setText("jTextField3");
186: gridBagConstraints3 = new java.awt.GridBagConstraints();
187: gridBagConstraints3.gridx = 1;
188: gridBagConstraints3.gridy = 2;
189: gridBagConstraints3.fill = java.awt.GridBagConstraints.HORIZONTAL;
190: attenuationPanel.add(attenuationYTF, gridBagConstraints3);
191:
192: attenuationZTF.setText("jTextField2");
193: gridBagConstraints3 = new java.awt.GridBagConstraints();
194: gridBagConstraints3.gridx = 1;
195: gridBagConstraints3.gridy = 1;
196: gridBagConstraints3.fill = java.awt.GridBagConstraints.HORIZONTAL;
197: attenuationPanel.add(attenuationZTF, gridBagConstraints3);
198:
199: gridBagConstraints1 = new java.awt.GridBagConstraints();
200: gridBagConstraints1.gridx = 1;
201: gridBagConstraints1.gridy = 2;
202: gridBagConstraints1.gridwidth = 2;
203: gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
204: add(attenuationPanel, gridBagConstraints1);
205:
206: }//GEN-END:initComponents
207:
208: private void lightEnableCBActionPerformed(
209: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lightEnableCBActionPerformed
210: // Add your handling code here:
211: setUpdateRequired(true);
212: ((PointLight) node.getJ3dNode()).setEnable(lightEnableCB
213: .isSelected());
214: }//GEN-LAST:event_lightEnableCBActionPerformed
215:
216: // TODO Handle focuslost and carriage return in text fields like DirectionalLight
217:
218: private void selectColor(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectColor
219: // Add your handling code here:
220: PointLight light = (PointLight) node.getJ3dNode();
221:
222: setUpdateRequired(true);
223: Color3f color = new Color3f();
224: light.getColor(color);
225: Color c = org.jdesktop.j3dedit.scenegrapheditor.WindowManager
226: .getManager().chooseColor(
227: new Color(color.x, color.y, color.z));
228:
229: colorPanel.setBackground(c);
230: if (c.getRed() != 0)
231: color.x = (float) c.getRed() / 255.0f;
232: if (c.getGreen() != 0)
233: color.y = (float) c.getGreen() / 255.0f;
234: if (c.getBlue() != 0)
235: color.z = (float) c.getBlue() / 255.0f;
236: light.setColor(color);
237:
238: }//GEN-LAST:event_selectColor
239:
240: public void setControls() {
241: PointLight light = (PointLight) node.getJ3dNode();
242:
243: lightEnableCB.setSelected(light.getEnable());
244:
245: Color3f color = new Color3f();
246: light.getColor(color);
247: colorPanel.setBackground(new Color(color.x, color.y, color.z));
248:
249: light.getPosition(origPosition);
250: xTF.setText(Float.toString(origPosition.x));
251: yTF.setText(Float.toString(origPosition.y));
252: zTF.setText(Float.toString(origPosition.z));
253:
254: origEnabled = light.getEnable();
255: origColor = color;
256: }
257:
258: public void applyChanges() {
259: setControls();
260: setUpdateRequired(false);
261: }
262:
263: public void resetChanges() {
264: PointLight light = (PointLight) node.getJ3dNode();
265: light.setEnable(origEnabled);
266: light.setPosition(origPosition);
267: light.setColor(origColor);
268: setUpdateRequired(false);
269: }
270:
271: protected void setReadCapabilityBits(javax.media.j3d.Node node) {
272: PointLight light = (PointLight) node;
273:
274: light.setCapability(PointLight.ALLOW_COLOR_READ);
275: light.setCapability(PointLight.ALLOW_STATE_READ);
276: light.setCapability(PointLight.ALLOW_POSITION_READ);
277: }
278:
279: protected void setReadWriteCapabilityBits(javax.media.j3d.Node node) {
280: PointLight light = (PointLight) node;
281:
282: light.setCapability(PointLight.ALLOW_COLOR_READ);
283: light.setCapability(PointLight.ALLOW_STATE_READ);
284: light.setCapability(PointLight.ALLOW_POSITION_READ);
285: light.setCapability(PointLight.ALLOW_COLOR_WRITE);
286: light.setCapability(PointLight.ALLOW_STATE_WRITE);
287: light.setCapability(PointLight.ALLOW_POSITION_WRITE);
288: }
289:
290: // Variables declaration - do not modify//GEN-BEGIN:variables
291: private javax.swing.JCheckBox lightEnableCB;
292: private javax.swing.JButton colorB;
293: private javax.swing.JPanel positionPanel;
294: private javax.swing.JLabel xLabel;
295: private javax.swing.JLabel yLabel;
296: private javax.swing.JLabel zLabel;
297: private javax.swing.JTextField xTF;
298: private javax.swing.JTextField zTF;
299: private javax.swing.JTextField yTF;
300: private javax.swing.JPanel colorPanel;
301: private javax.swing.JPanel attenuationPanel;
302: private javax.swing.JLabel jLabel1;
303: private javax.swing.JLabel jLabel2;
304: private javax.swing.JLabel jLabel3;
305: private javax.swing.JTextField attenuationXTF;
306: private javax.swing.JTextField attenuationYTF;
307: private javax.swing.JTextField attenuationZTF;
308: // End of variables declaration//GEN-END:variables
309:
310: }
|