001: /*
002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/nodeeditors/panels/SpotLightPanel.java,v 1.1 2005/04/20 22:21:10 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.SpotLight;
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 SpotLightPanel extends NodeEditorPanel {
031:
032: private Point3f origPosition = new Point3f();
033: private boolean origEnabled;
034: private Color3f origColor;
035:
036: /** Creates new form SpotLightPanel */
037: public SpotLightPanel() {
038: super ();
039: frameTitle = "Spot Light";
040: initComponents();
041:
042: System.out
043: .println("TODO - Test SpotLightPanel, 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: directionPanel = new javax.swing.JPanel();
070: jLabel4 = new javax.swing.JLabel();
071: jLabel5 = new javax.swing.JLabel();
072: jLabel6 = new javax.swing.JLabel();
073: jTextField1 = new javax.swing.JTextField();
074: jTextField2 = new javax.swing.JTextField();
075: jTextField3 = new javax.swing.JTextField();
076:
077: setLayout(new java.awt.GridBagLayout());
078: java.awt.GridBagConstraints gridBagConstraints1;
079:
080: lightEnableCB.setText("enabled");
081: lightEnableCB
082: .addActionListener(new java.awt.event.ActionListener() {
083: public void actionPerformed(
084: java.awt.event.ActionEvent evt) {
085: lightEnableCBActionPerformed(evt);
086: }
087: });
088:
089: gridBagConstraints1 = new java.awt.GridBagConstraints();
090: gridBagConstraints1.gridx = 0;
091: gridBagConstraints1.gridy = 0;
092: gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
093: add(lightEnableCB, gridBagConstraints1);
094:
095: colorB.setText("Color ...");
096: colorB.addActionListener(new java.awt.event.ActionListener() {
097: public void actionPerformed(java.awt.event.ActionEvent evt) {
098: selectColor(evt);
099: }
100: });
101:
102: gridBagConstraints1 = new java.awt.GridBagConstraints();
103: gridBagConstraints1.gridx = 0;
104: gridBagConstraints1.gridy = 1;
105: gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
106: add(colorB, gridBagConstraints1);
107:
108: positionPanel.setLayout(new java.awt.GridBagLayout());
109: java.awt.GridBagConstraints gridBagConstraints2;
110:
111: positionPanel.setBorder(new javax.swing.border.TitledBorder(
112: new javax.swing.border.EtchedBorder(), "Position"));
113: xLabel.setText("X");
114: gridBagConstraints2 = new java.awt.GridBagConstraints();
115: gridBagConstraints2.insets = new java.awt.Insets(0, 0, 0, 2);
116: positionPanel.add(xLabel, gridBagConstraints2);
117:
118: yLabel.setText("Y");
119: gridBagConstraints2 = new java.awt.GridBagConstraints();
120: gridBagConstraints2.gridx = 0;
121: gridBagConstraints2.gridy = 1;
122: gridBagConstraints2.insets = new java.awt.Insets(0, 0, 0, 2);
123: positionPanel.add(yLabel, gridBagConstraints2);
124:
125: zLabel.setText("Z");
126: gridBagConstraints2 = new java.awt.GridBagConstraints();
127: gridBagConstraints2.gridx = 0;
128: gridBagConstraints2.gridy = 2;
129: gridBagConstraints2.insets = new java.awt.Insets(0, 0, 0, 2);
130: positionPanel.add(zLabel, gridBagConstraints2);
131:
132: xTF.setText("jTextField1");
133: gridBagConstraints2 = new java.awt.GridBagConstraints();
134: gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
135: positionPanel.add(xTF, gridBagConstraints2);
136:
137: zTF.setText("jTextField3");
138: gridBagConstraints2 = new java.awt.GridBagConstraints();
139: gridBagConstraints2.gridx = 1;
140: gridBagConstraints2.gridy = 2;
141: gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
142: positionPanel.add(zTF, gridBagConstraints2);
143:
144: yTF.setText("jTextField2");
145: gridBagConstraints2 = new java.awt.GridBagConstraints();
146: gridBagConstraints2.gridx = 1;
147: gridBagConstraints2.gridy = 1;
148: gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
149: positionPanel.add(yTF, gridBagConstraints2);
150:
151: gridBagConstraints1 = new java.awt.GridBagConstraints();
152: gridBagConstraints1.gridx = 0;
153: gridBagConstraints1.gridy = 2;
154: gridBagConstraints1.gridwidth = 2;
155: add(positionPanel, gridBagConstraints1);
156:
157: colorPanel.setBackground(java.awt.Color.red);
158: gridBagConstraints1 = new java.awt.GridBagConstraints();
159: gridBagConstraints1.gridx = 1;
160: gridBagConstraints1.gridy = 1;
161: gridBagConstraints1.gridwidth = 2;
162: gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
163: add(colorPanel, gridBagConstraints1);
164:
165: attenuationPanel.setLayout(new java.awt.GridBagLayout());
166: java.awt.GridBagConstraints gridBagConstraints3;
167:
168: attenuationPanel.setBorder(new javax.swing.border.TitledBorder(
169: new javax.swing.border.EtchedBorder(), "Attenuation"));
170: jLabel1.setText("X");
171: gridBagConstraints3 = new java.awt.GridBagConstraints();
172: gridBagConstraints3.insets = new java.awt.Insets(0, 0, 0, 2);
173: attenuationPanel.add(jLabel1, gridBagConstraints3);
174:
175: jLabel2.setText("Y");
176: gridBagConstraints3 = new java.awt.GridBagConstraints();
177: gridBagConstraints3.gridx = 0;
178: gridBagConstraints3.gridy = 1;
179: gridBagConstraints3.insets = new java.awt.Insets(0, 0, 0, 2);
180: attenuationPanel.add(jLabel2, gridBagConstraints3);
181:
182: jLabel3.setText("Z");
183: gridBagConstraints3 = new java.awt.GridBagConstraints();
184: gridBagConstraints3.gridx = 0;
185: gridBagConstraints3.gridy = 2;
186: gridBagConstraints3.insets = new java.awt.Insets(0, 0, 0, 2);
187: attenuationPanel.add(jLabel3, gridBagConstraints3);
188:
189: attenuationXTF.setText("jTextField1");
190: gridBagConstraints3 = new java.awt.GridBagConstraints();
191: gridBagConstraints3.fill = java.awt.GridBagConstraints.HORIZONTAL;
192: attenuationPanel.add(attenuationXTF, gridBagConstraints3);
193:
194: attenuationYTF.setText("jTextField3");
195: gridBagConstraints3 = new java.awt.GridBagConstraints();
196: gridBagConstraints3.gridx = 1;
197: gridBagConstraints3.gridy = 2;
198: gridBagConstraints3.fill = java.awt.GridBagConstraints.HORIZONTAL;
199: attenuationPanel.add(attenuationYTF, gridBagConstraints3);
200:
201: attenuationZTF.setText("jTextField2");
202: gridBagConstraints3 = new java.awt.GridBagConstraints();
203: gridBagConstraints3.gridx = 1;
204: gridBagConstraints3.gridy = 1;
205: gridBagConstraints3.fill = java.awt.GridBagConstraints.HORIZONTAL;
206: attenuationPanel.add(attenuationZTF, gridBagConstraints3);
207:
208: gridBagConstraints1 = new java.awt.GridBagConstraints();
209: gridBagConstraints1.gridx = 1;
210: gridBagConstraints1.gridy = 2;
211: gridBagConstraints1.gridwidth = 2;
212: gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
213: add(attenuationPanel, gridBagConstraints1);
214:
215: directionPanel.setLayout(new java.awt.GridBagLayout());
216: java.awt.GridBagConstraints gridBagConstraints4;
217:
218: directionPanel.setBorder(new javax.swing.border.TitledBorder(
219: new javax.swing.border.EtchedBorder(), "Direction"));
220: jLabel4.setText("X");
221: gridBagConstraints4 = new java.awt.GridBagConstraints();
222: gridBagConstraints4.insets = new java.awt.Insets(0, 0, 0, 2);
223: directionPanel.add(jLabel4, gridBagConstraints4);
224:
225: jLabel5.setText("Y");
226: gridBagConstraints4 = new java.awt.GridBagConstraints();
227: gridBagConstraints4.gridx = 0;
228: gridBagConstraints4.gridy = 1;
229: gridBagConstraints4.insets = new java.awt.Insets(0, 0, 0, 2);
230: directionPanel.add(jLabel5, gridBagConstraints4);
231:
232: jLabel6.setText("Z");
233: gridBagConstraints4 = new java.awt.GridBagConstraints();
234: gridBagConstraints4.gridx = 0;
235: gridBagConstraints4.gridy = 2;
236: gridBagConstraints4.insets = new java.awt.Insets(0, 0, 0, 2);
237: directionPanel.add(jLabel6, gridBagConstraints4);
238:
239: jTextField1.setText("jTextField1");
240: gridBagConstraints4 = new java.awt.GridBagConstraints();
241: gridBagConstraints4.fill = java.awt.GridBagConstraints.HORIZONTAL;
242: directionPanel.add(jTextField1, gridBagConstraints4);
243:
244: jTextField2.setText("jTextField3");
245: gridBagConstraints4 = new java.awt.GridBagConstraints();
246: gridBagConstraints4.gridx = 1;
247: gridBagConstraints4.gridy = 2;
248: gridBagConstraints4.fill = java.awt.GridBagConstraints.HORIZONTAL;
249: directionPanel.add(jTextField2, gridBagConstraints4);
250:
251: jTextField3.setText("jTextField2");
252: gridBagConstraints4 = new java.awt.GridBagConstraints();
253: gridBagConstraints4.gridx = 1;
254: gridBagConstraints4.gridy = 1;
255: gridBagConstraints4.fill = java.awt.GridBagConstraints.HORIZONTAL;
256: directionPanel.add(jTextField3, gridBagConstraints4);
257:
258: gridBagConstraints1 = new java.awt.GridBagConstraints();
259: gridBagConstraints1.gridx = 1;
260: gridBagConstraints1.gridy = 2;
261: gridBagConstraints1.gridwidth = 2;
262: gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
263: add(directionPanel, gridBagConstraints1);
264:
265: }//GEN-END:initComponents
266:
267: private void lightEnableCBActionPerformed(
268: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lightEnableCBActionPerformed
269: // Add your handling code here:
270: setUpdateRequired(true);
271: ((SpotLight) node.getJ3dNode()).setEnable(lightEnableCB
272: .isSelected());
273: }//GEN-LAST:event_lightEnableCBActionPerformed
274:
275: private void selectColor(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectColor
276: // Add your handling code here:
277: SpotLight light = (SpotLight) node.getJ3dNode();
278:
279: setUpdateRequired(true);
280: Color3f color = new Color3f();
281: light.getColor(color);
282: Color c = org.jdesktop.j3dedit.scenegrapheditor.WindowManager
283: .getManager().chooseColor(
284: new Color(color.x, color.y, color.z));
285:
286: colorPanel.setBackground(c);
287: if (c.getRed() != 0)
288: color.x = (float) c.getRed() / 255.0f;
289: if (c.getGreen() != 0)
290: color.y = (float) c.getGreen() / 255.0f;
291: if (c.getBlue() != 0)
292: color.z = (float) c.getBlue() / 255.0f;
293: light.setColor(color);
294:
295: }//GEN-LAST:event_selectColor
296:
297: public void setControls() {
298: SpotLight light = (SpotLight) node.getJ3dNode();
299:
300: lightEnableCB.setSelected(light.getEnable());
301:
302: Color3f color = new Color3f();
303: light.getColor(color);
304: colorPanel.setBackground(new Color(color.x, color.y, color.z));
305:
306: light.getPosition(origPosition);
307: xTF.setText(Float.toString(origPosition.x));
308: yTF.setText(Float.toString(origPosition.y));
309: zTF.setText(Float.toString(origPosition.z));
310:
311: origEnabled = light.getEnable();
312: origColor = color;
313: }
314:
315: public void applyChanges() {
316: setControls();
317: setUpdateRequired(false);
318: }
319:
320: public void resetChanges() {
321: SpotLight light = (SpotLight) node.getJ3dNode();
322: light.setEnable(origEnabled);
323: light.setPosition(origPosition);
324: light.setColor(origColor);
325: setUpdateRequired(false);
326: }
327:
328: protected void setReadCapabilityBits(javax.media.j3d.Node node) {
329: SpotLight light = (SpotLight) node;
330:
331: light.setCapability(SpotLight.ALLOW_COLOR_READ);
332: light.setCapability(SpotLight.ALLOW_STATE_READ);
333: light.setCapability(SpotLight.ALLOW_POSITION_READ);
334: }
335:
336: protected void setReadWriteCapabilityBits(javax.media.j3d.Node node) {
337: SpotLight light = (SpotLight) node;
338:
339: light.setCapability(SpotLight.ALLOW_COLOR_READ);
340: light.setCapability(SpotLight.ALLOW_STATE_READ);
341: light.setCapability(SpotLight.ALLOW_POSITION_READ);
342: light.setCapability(SpotLight.ALLOW_COLOR_WRITE);
343: light.setCapability(SpotLight.ALLOW_STATE_WRITE);
344: light.setCapability(SpotLight.ALLOW_POSITION_WRITE);
345: }
346:
347: // Variables declaration - do not modify//GEN-BEGIN:variables
348: private javax.swing.JCheckBox lightEnableCB;
349: private javax.swing.JButton colorB;
350: private javax.swing.JPanel positionPanel;
351: private javax.swing.JLabel xLabel;
352: private javax.swing.JLabel yLabel;
353: private javax.swing.JLabel zLabel;
354: private javax.swing.JTextField xTF;
355: private javax.swing.JTextField zTF;
356: private javax.swing.JTextField yTF;
357: private javax.swing.JPanel colorPanel;
358: private javax.swing.JPanel attenuationPanel;
359: private javax.swing.JLabel jLabel1;
360: private javax.swing.JLabel jLabel2;
361: private javax.swing.JLabel jLabel3;
362: private javax.swing.JTextField attenuationXTF;
363: private javax.swing.JTextField attenuationYTF;
364: private javax.swing.JTextField attenuationZTF;
365: private javax.swing.JPanel directionPanel;
366: private javax.swing.JLabel jLabel4;
367: private javax.swing.JLabel jLabel5;
368: private javax.swing.JLabel jLabel6;
369: private javax.swing.JTextField jTextField1;
370: private javax.swing.JTextField jTextField2;
371: private javax.swing.JTextField jTextField3;
372: // End of variables declaration//GEN-END:variables
373:
374: }
|