2
* @(#)SwatchesChooser.java 1.1 2006-04-23
4
* Copyright (c) 2005-2006 Werner Randelshofer
5
* Staldenmattweg 2, Immensee, CH-6405, Switzerland.
8
* This software is the confidential and proprietary information of
9
* Werner Randelshofer. ("Confidential Information"). You shall not
10
* disclose such Confidential Information and shall use it only in
11
* accordance with the terms of the license agreement you entered into
12
* with Werner Randelshofer.
15
package org.pushingpixels.substance.internal.contrib.randelshofer.quaqua.colorchooser;
18
import java.awt.event.*;
20
import javax.swing.text.*;
21
import javax.swing.event.*;
22
import javax.swing.border.*;
23
import javax.swing.colorchooser.*;
24
import javax.swing.plaf.*;
26
import org.pushingpixels.substance.internal.contrib.randelshofer.quaqua.*;
27
import org.pushingpixels.substance.internal.contrib.randelshofer.quaqua.util.*;
32
* @author Werner Randelshofer
33
* @version 1.3 2006-04-23 Retrieve labels directly from UIManager.
34
* <br>1.0.2 2005-11-07 Get "Labels" ResourceBundle fro UIManager.
35
* <br>1.0.1 2005-09-11 Get icon from UIManager.
36
* <br>1.0 30 March 2005 Created.
38
public class SwatchesChooser
39
extends AbstractColorChooserPanel
40
implements UIResource {
41
private SwatchPanel swatchPanel;
44
/** Creates new form. */
45
public SwatchesChooser() {
47
swatchPanel = new SwatchPanel();
49
scrollPane.setViewportView(swatchPanel);
52
protected void initColors() {
53
int[] rawValues = initRawValues();
54
int numColors = rawValues.length / 3;
56
Color[] colors = new Color[numColors];
57
for (int i = 0; i < numColors ; i++) {
60
colors[x * 9 + y % 9] = new Color( rawValues[(i*3)], rawValues[(i*3)+1], rawValues[(i*3)+2] );
62
swatchPanel.setColors(colors);
63
swatchPanel.setNumSwatches(9, 31);
64
swatchPanel.addMouseListener(new MouseAdapter() {
66
public void mouseReleased(MouseEvent e) {
67
Color c = swatchPanel.getColorForLocation(e.getX(), e.getY());
75
/** This method is called from within the constructor to
76
* initialize the form.
77
* WARNING: Do NOT modify this code. The content of this method is
78
* always regenerated by the Form Editor.
80
private void initComponents() {//GEN-BEGIN:initComponents
81
scrollPane = new javax.swing.JScrollPane();
83
setLayout(new java.awt.BorderLayout());
85
add(scrollPane, java.awt.BorderLayout.CENTER);
87
}//GEN-END:initComponents
90
protected void buildChooser() {
94
public String getDisplayName() {
95
return UIManager.getString("ColorChooser.colorSwatches");
99
public Icon getLargeDisplayIcon() {
100
return UIManager.getIcon("ColorChooser.colorSwatchesIcon");
104
public Icon getSmallDisplayIcon() {
105
return getLargeDisplayIcon();
108
public void setColorToModel(Color color) {
109
getColorSelectionModel().setSelectedColor(color);
113
public void updateChooser() {
116
// Variables declaration - do not modify//GEN-BEGIN:variables
117
private javax.swing.JScrollPane scrollPane;
118
// End of variables declaration//GEN-END:variables
120
private int[] initRawValues() {
122
255, 255, 255, // first row.
153
204, 204, 204, // second row.
184
204, 204, 204, // third row
215
153, 153, 153, // fourth row
246
153, 153, 153, // Fifth row
277
102, 102, 102, // sixth row
308
102, 102, 102, // seventh row
339
51, 51, 51, // eigth row
370
0, 0, 0, // ninth row