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