001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package examples.colorpicker;
043:
044: /** This class is an entry point of the color picker sample application.
045: * It creates and shows the main application frame.
046: */
047: public class ColorPicker extends javax.swing.JFrame {
048:
049: /** Color Picker constructor.
050: * It initializes all GUI components.
051: */
052: public ColorPicker() {
053: initComponents();
054: pack();
055: }
056:
057: /** This method is called from within the constructor to
058: * initialize the form.
059: * WARNING: Do NOT modify this code. The content of this method is
060: * always regenerated by the FormEditor.
061: */
062: private void initComponents() {//GEN-BEGIN:initComponents
063: sliderPanel = new javax.swing.JPanel();
064: redSlider = new javax.swing.JSlider();
065: greenSlider = new javax.swing.JSlider();
066: blueSlider = new javax.swing.JSlider();
067: colorPreviewPanel = new javax.swing.JPanel();
068: colorPreview1 = new examples.colorpicker.ColorPreview();
069:
070: addWindowListener(new java.awt.event.WindowAdapter() {
071: public void windowClosing(java.awt.event.WindowEvent evt) {
072: exitForm(evt);
073: }
074: });
075:
076: sliderPanel.setLayout(new javax.swing.BoxLayout(sliderPanel,
077: javax.swing.BoxLayout.Y_AXIS));
078:
079: redSlider.setMaximum(255);
080: redSlider.setBorder(new javax.swing.border.TitledBorder(
081: new javax.swing.border.EtchedBorder(null,
082: new java.awt.Color(134, 134, 134)), "Red"));
083: redSlider
084: .addChangeListener(new javax.swing.event.ChangeListener() {
085: public void stateChanged(
086: javax.swing.event.ChangeEvent evt) {
087: redSliderStateChanged(evt);
088: }
089: });
090:
091: sliderPanel.add(redSlider);
092: redSlider.getAccessibleContext()
093: .setAccessibleName("Red Slider");
094: redSlider.getAccessibleContext().setAccessibleDescription(
095: "Red slider.");
096:
097: greenSlider.setMaximum(255);
098: greenSlider.setBorder(new javax.swing.border.TitledBorder(
099: new javax.swing.border.EtchedBorder(null,
100: new java.awt.Color(134, 134, 134)), "Green"));
101: greenSlider
102: .addChangeListener(new javax.swing.event.ChangeListener() {
103: public void stateChanged(
104: javax.swing.event.ChangeEvent evt) {
105: greenSliderStateChanged(evt);
106: }
107: });
108:
109: sliderPanel.add(greenSlider);
110: greenSlider.getAccessibleContext().setAccessibleName(
111: "Green Slider");
112: greenSlider.getAccessibleContext().setAccessibleDescription(
113: "Green slider.");
114:
115: blueSlider.setMaximum(255);
116: blueSlider.setBorder(new javax.swing.border.TitledBorder(
117: new javax.swing.border.EtchedBorder(null,
118: new java.awt.Color(134, 134, 134)), "Blue"));
119: blueSlider
120: .addChangeListener(new javax.swing.event.ChangeListener() {
121: public void stateChanged(
122: javax.swing.event.ChangeEvent evt) {
123: blueSliderStateChanged(evt);
124: }
125: });
126:
127: sliderPanel.add(blueSlider);
128: blueSlider.getAccessibleContext().setAccessibleName(
129: "Blue Slider");
130: blueSlider.getAccessibleContext().setAccessibleDescription(
131: "Blue slider.");
132:
133: getContentPane().add(sliderPanel, java.awt.BorderLayout.NORTH);
134:
135: colorPreviewPanel.setLayout(new java.awt.BorderLayout());
136:
137: colorPreviewPanel
138: .setBorder(new javax.swing.border.TitledBorder(
139: new javax.swing.border.EtchedBorder(null,
140: new java.awt.Color(134, 134, 134)),
141: "Color Preview"));
142: colorPreviewPanel.add(colorPreview1,
143: java.awt.BorderLayout.CENTER);
144: colorPreview1.getAccessibleContext().setAccessibleName(
145: "Color Preview Component");
146: colorPreview1.getAccessibleContext().setAccessibleDescription(
147: "Color preview component.");
148:
149: getContentPane().add(colorPreviewPanel,
150: java.awt.BorderLayout.CENTER);
151: colorPreviewPanel.getAccessibleContext().setAccessibleName(
152: "Color Preview Panel");
153: colorPreviewPanel.getAccessibleContext()
154: .setAccessibleDescription("Color preview panel.");
155:
156: }//GEN-END:initComponents
157:
158: /** This method is called when blue slider position is changed.
159: * It sets the current blue color value.
160: * @param evt ChangeEvent instance passed from stateChanged event.
161: */
162: private void blueSliderStateChanged(
163: javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_blueSliderStateChanged
164: colorPreview1.setBlue(blueSlider.getValue());
165: }//GEN-LAST:event_blueSliderStateChanged
166:
167: /** This method is called when green slider position is changed.
168: * It sets the current green color value.
169: * @param evt ChangeEvent instance passed from stateChanged event.
170: */
171: private void greenSliderStateChanged(
172: javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_greenSliderStateChanged
173: colorPreview1.setGreen(greenSlider.getValue());
174: }//GEN-LAST:event_greenSliderStateChanged
175:
176: /** This method is called when red slider position is changed.
177: * It sets the current red color value.
178: * @param evt ChangeEvent instance passed from stateChanged event.
179: */
180: private void redSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_redSliderStateChanged
181: colorPreview1.setRed(redSlider.getValue());
182: }//GEN-LAST:event_redSliderStateChanged
183:
184: /** This method is called when the application frame is closed.
185: * @param evt WindowEvent instance passed from windowClosing event.
186: */
187: private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
188: System.exit(0);
189: }//GEN-LAST:event_exitForm
190:
191: // Variables declaration - do not modify//GEN-BEGIN:variables
192: private javax.swing.JSlider blueSlider;
193: private examples.colorpicker.ColorPreview colorPreview1;
194: private javax.swing.JPanel colorPreviewPanel;
195: private javax.swing.JSlider greenSlider;
196: private javax.swing.JSlider redSlider;
197: private javax.swing.JPanel sliderPanel;
198:
199: // End of variables declaration//GEN-END:variables
200:
201: /** Starts the application.
202: * @param args Application arguments.
203: */
204: public static void main(java.lang.String[] args) {
205: new ColorPicker().show();
206: }
207:
208: }
|