001: /*
002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/nodeeditors/panels/AmbientLightPanel.java,v 1.1 2005/04/20 22:21:02 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.AmbientLight;
021: import javax.vecmath.Color3f;
022: import java.awt.Color;
023: import org.jdesktop.j3dedit.scenegrapheditor.nodeeditors.NodeEditorPanel;
024:
025: /**
026: * @author Paul Byrne
027: * @version 1.7, 01/18/02
028: */
029: public class AmbientLightPanel extends NodeEditorPanel {
030:
031: private boolean origEnabled;
032: private Color3f origColor;
033:
034: /** Creates new form DirectionalLightPanel */
035: public AmbientLightPanel() {
036: super ();
037: frameTitle = "Ambient Light";
038: initComponents();
039: }
040:
041: /** This method is called from within the constructor to
042: * initialize the form.
043: * WARNING: Do NOT modify this code. The content of this method is
044: * always regenerated by the FormEditor.
045: */
046: private void initComponents() {//GEN-BEGIN:initComponents
047: lightEnableCB = new javax.swing.JCheckBox();
048: colorB = new javax.swing.JButton();
049: colorPanel = new javax.swing.JPanel();
050:
051: setLayout(new java.awt.GridBagLayout());
052: java.awt.GridBagConstraints gridBagConstraints1;
053:
054: lightEnableCB.setText("enabled");
055: lightEnableCB
056: .addActionListener(new java.awt.event.ActionListener() {
057: public void actionPerformed(
058: java.awt.event.ActionEvent evt) {
059: lightEnableCBActionPerformed(evt);
060: }
061: });
062:
063: gridBagConstraints1 = new java.awt.GridBagConstraints();
064: gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
065: add(lightEnableCB, gridBagConstraints1);
066:
067: colorB.setText("Color ...");
068: colorB.addActionListener(new java.awt.event.ActionListener() {
069: public void actionPerformed(java.awt.event.ActionEvent evt) {
070: selectColor(evt);
071: }
072: });
073:
074: gridBagConstraints1 = new java.awt.GridBagConstraints();
075: gridBagConstraints1.gridx = 0;
076: gridBagConstraints1.gridy = 1;
077: gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
078: add(colorB, gridBagConstraints1);
079:
080: colorPanel.setBackground(java.awt.Color.red);
081: colorPanel.setPreferredSize(new java.awt.Dimension(50, 10));
082: colorPanel.setMinimumSize(new java.awt.Dimension(50, 10));
083: gridBagConstraints1 = new java.awt.GridBagConstraints();
084: gridBagConstraints1.gridx = 1;
085: gridBagConstraints1.gridy = 1;
086: gridBagConstraints1.gridwidth = 2;
087: gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
088: add(colorPanel, gridBagConstraints1);
089:
090: }//GEN-END:initComponents
091:
092: private void lightEnableCBActionPerformed(
093: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_lightEnableCBActionPerformed
094: // Add your handling code here:
095: setUpdateRequired(true);
096: ((AmbientLight) node.getJ3dNode()).setEnable(lightEnableCB
097: .isSelected());
098: }//GEN-LAST:event_lightEnableCBActionPerformed
099:
100: private void selectColor(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectColor
101: // Add your handling code here:
102: AmbientLight light = (AmbientLight) node.getJ3dNode();
103:
104: setUpdateRequired(true);
105: Color3f color = new Color3f();
106: light.getColor(color);
107: Color c = org.jdesktop.j3dedit.scenegrapheditor.WindowManager
108: .getManager().chooseColor(
109: new Color(color.x, color.y, color.z));
110:
111: if (c == null)
112: return;
113:
114: colorPanel.setBackground(c);
115: if (c.getRed() != 0)
116: color.x = (float) c.getRed() / 255.0f;
117: if (c.getGreen() != 0)
118: color.y = (float) c.getGreen() / 255.0f;
119: if (c.getBlue() != 0)
120: color.z = (float) c.getBlue() / 255.0f;
121: light.setColor(color);
122:
123: }//GEN-LAST:event_selectColor
124:
125: public void setControls() {
126: AmbientLight light = (AmbientLight) node.getJ3dNode();
127:
128: lightEnableCB.setSelected(light.getEnable());
129:
130: Color3f color = new Color3f();
131: light.getColor(color);
132: colorPanel.setBackground(new Color(color.x, color.y, color.z));
133:
134: origEnabled = light.getEnable();
135: origColor = color;
136: }
137:
138: public void applyChanges() {
139: setControls();
140: setUpdateRequired(false);
141: }
142:
143: public void resetChanges() {
144: AmbientLight light = (AmbientLight) node.getJ3dNode();
145: light.setEnable(origEnabled);
146: light.setColor(origColor);
147: setUpdateRequired(false);
148: }
149:
150: protected void setReadCapabilityBits(javax.media.j3d.Node node) {
151: AmbientLight light = (AmbientLight) node;
152:
153: light.setCapability(AmbientLight.ALLOW_COLOR_READ);
154: light.setCapability(AmbientLight.ALLOW_STATE_READ);
155: }
156:
157: protected void setReadWriteCapabilityBits(javax.media.j3d.Node node) {
158: AmbientLight light = (AmbientLight) node;
159:
160: light.setCapability(AmbientLight.ALLOW_COLOR_READ);
161: light.setCapability(AmbientLight.ALLOW_COLOR_WRITE);
162: light.setCapability(AmbientLight.ALLOW_STATE_READ);
163: light.setCapability(AmbientLight.ALLOW_STATE_WRITE);
164: }
165:
166: // Variables declaration - do not modify//GEN-BEGIN:variables
167: private javax.swing.JCheckBox lightEnableCB;
168: private javax.swing.JButton colorB;
169: private javax.swing.JPanel colorPanel;
170: // End of variables declaration//GEN-END:variables
171:
172: }
|