~ubuntu-branches/debian/stretch/insubstantial/stretch

« back to all changes in this revision

Viewing changes to substance/src/main/java/org/pushingpixels/substance/internal/contrib/randelshofer/quaqua/colorchooser/SwatchesChooser.java

  • Committer: Package Import Robot
  • Author(s): Felix Natter
  • Date: 2016-01-18 20:58:45 UTC
  • Revision ID: package-import@ubuntu.com-20160118205845-crbmrkda61qsi5qa
Tags: upstream-7.3+dfsg2
ImportĀ upstreamĀ versionĀ 7.3+dfsg2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * @(#)SwatchesChooser.java  1.1  2006-04-23
 
3
 *
 
4
 * Copyright (c) 2005-2006 Werner Randelshofer
 
5
 * Staldenmattweg 2, Immensee, CH-6405, Switzerland.
 
6
 * All rights reserved.
 
7
 *
 
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.
 
13
 */
 
14
 
 
15
package org.pushingpixels.substance.internal.contrib.randelshofer.quaqua.colorchooser;
 
16
 
 
17
import java.awt.*;
 
18
import java.awt.event.*;
 
19
import javax.swing.*;
 
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.*;
 
25
 
 
26
import org.pushingpixels.substance.internal.contrib.randelshofer.quaqua.*;
 
27
import org.pushingpixels.substance.internal.contrib.randelshofer.quaqua.util.*;
 
28
 
 
29
/**
 
30
 * SwatchesChooser.
 
31
 *
 
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.
 
37
 */
 
38
public class SwatchesChooser
 
39
extends AbstractColorChooserPanel
 
40
implements UIResource {
 
41
    private SwatchPanel swatchPanel;
 
42
    
 
43
    
 
44
    /** Creates new form. */
 
45
    public SwatchesChooser() {
 
46
        initComponents();
 
47
        swatchPanel = new SwatchPanel();
 
48
        initColors();
 
49
        scrollPane.setViewportView(swatchPanel);
 
50
    }
 
51
    
 
52
    protected void initColors() {
 
53
        int[] rawValues = initRawValues();
 
54
        int numColors = rawValues.length / 3;
 
55
        
 
56
        Color[] colors = new Color[numColors];
 
57
        for (int i = 0; i < numColors ; i++) {
 
58
            int x = i % 31;
 
59
            int y = i / 31;
 
60
            colors[x * 9 + y % 9] = new Color( rawValues[(i*3)], rawValues[(i*3)+1], rawValues[(i*3)+2] );
 
61
        }
 
62
        swatchPanel.setColors(colors);
 
63
        swatchPanel.setNumSwatches(9, 31);
 
64
        swatchPanel.addMouseListener(new MouseAdapter() {
 
65
            @Override
 
66
            public void mouseReleased(MouseEvent e) {
 
67
                Color c = swatchPanel.getColorForLocation(e.getX(), e.getY());
 
68
                if (c != null) {
 
69
                    setColorToModel(c);
 
70
                    }
 
71
            }
 
72
        });
 
73
    }
 
74
    
 
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.
 
79
     */
 
80
    private void initComponents() {//GEN-BEGIN:initComponents
 
81
        scrollPane = new javax.swing.JScrollPane();
 
82
 
 
83
        setLayout(new java.awt.BorderLayout());
 
84
 
 
85
        add(scrollPane, java.awt.BorderLayout.CENTER);
 
86
 
 
87
    }//GEN-END:initComponents
 
88
    
 
89
    @Override
 
90
    protected void buildChooser() {
 
91
    }
 
92
    
 
93
    @Override
 
94
    public String getDisplayName() {
 
95
        return UIManager.getString("ColorChooser.colorSwatches");
 
96
    }
 
97
    
 
98
    @Override
 
99
    public Icon getLargeDisplayIcon() {
 
100
        return UIManager.getIcon("ColorChooser.colorSwatchesIcon");
 
101
    }
 
102
    
 
103
    @Override
 
104
    public Icon getSmallDisplayIcon() {
 
105
        return getLargeDisplayIcon();
 
106
    }
 
107
    
 
108
    public void setColorToModel(Color color) {
 
109
        getColorSelectionModel().setSelectedColor(color);
 
110
    }
 
111
    
 
112
    @Override
 
113
    public void updateChooser() {
 
114
    }
 
115
    
 
116
    // Variables declaration - do not modify//GEN-BEGIN:variables
 
117
    private javax.swing.JScrollPane scrollPane;
 
118
    // End of variables declaration//GEN-END:variables
 
119
    
 
120
    private int[] initRawValues() {
 
121
        int[] rawValues = {
 
122
            255, 255, 255, // first row.
 
123
            204, 255, 255,
 
124
            204, 204, 255,
 
125
            204, 204, 255,
 
126
            204, 204, 255,
 
127
            204, 204, 255,
 
128
            204, 204, 255,
 
129
            204, 204, 255,
 
130
            204, 204, 255,
 
131
            204, 204, 255,
 
132
            204, 204, 255,
 
133
            255, 204, 255,
 
134
            255, 204, 204,
 
135
            255, 204, 204,
 
136
            255, 204, 204,
 
137
            255, 204, 204,
 
138
            255, 204, 204,
 
139
            255, 204, 204,
 
140
            255, 204, 204,
 
141
            255, 204, 204,
 
142
            255, 204, 204,
 
143
            255, 255, 204,
 
144
            204, 255, 204,
 
145
            204, 255, 204,
 
146
            204, 255, 204,
 
147
            204, 255, 204,
 
148
            204, 255, 204,
 
149
            204, 255, 204,
 
150
            204, 255, 204,
 
151
            204, 255, 204,
 
152
            204, 255, 204,
 
153
            204, 204, 204,  // second row.
 
154
            153, 255, 255,
 
155
            153, 204, 255,
 
156
            153, 153, 255,
 
157
            153, 153, 255,
 
158
            153, 153, 255,
 
159
            153, 153, 255,
 
160
            153, 153, 255,
 
161
            153, 153, 255,
 
162
            153, 153, 255,
 
163
            204, 153, 255,
 
164
            255, 153, 255,
 
165
            255, 153, 204,
 
166
            255, 153, 153,
 
167
            255, 153, 153,
 
168
            255, 153, 153,
 
169
            255, 153, 153,
 
170
            255, 153, 153,
 
171
            255, 153, 153,
 
172
            255, 153, 153,
 
173
            255, 204, 153,
 
174
            255, 255, 153,
 
175
            204, 255, 153,
 
176
            153, 255, 153,
 
177
            153, 255, 153,
 
178
            153, 255, 153,
 
179
            153, 255, 153,
 
180
            153, 255, 153,
 
181
            153, 255, 153,
 
182
            153, 255, 153,
 
183
            153, 255, 204,
 
184
            204, 204, 204,  // third row
 
185
            102, 255, 255,
 
186
            102, 204, 255,
 
187
            102, 153, 255,
 
188
            102, 102, 255,
 
189
            102, 102, 255,
 
190
            102, 102, 255,
 
191
            102, 102, 255,
 
192
            102, 102, 255,
 
193
            153, 102, 255,
 
194
            204, 102, 255,
 
195
            255, 102, 255,
 
196
            255, 102, 204,
 
197
            255, 102, 153,
 
198
            255, 102, 102,
 
199
            255, 102, 102,
 
200
            255, 102, 102,
 
201
            255, 102, 102,
 
202
            255, 102, 102,
 
203
            255, 153, 102,
 
204
            255, 204, 102,
 
205
            255, 255, 102,
 
206
            204, 255, 102,
 
207
            153, 255, 102,
 
208
            102, 255, 102,
 
209
            102, 255, 102,
 
210
            102, 255, 102,
 
211
            102, 255, 102,
 
212
            102, 255, 102,
 
213
            102, 255, 153,
 
214
            102, 255, 204,
 
215
            153, 153, 153, // fourth row
 
216
            51, 255, 255,
 
217
            51, 204, 255,
 
218
            51, 153, 255,
 
219
            51, 102, 255,
 
220
            51, 51, 255,
 
221
            51, 51, 255,
 
222
            51, 51, 255,
 
223
            102, 51, 255,
 
224
            153, 51, 255,
 
225
            204, 51, 255,
 
226
            255, 51, 255,
 
227
            255, 51, 204,
 
228
            255, 51, 153,
 
229
            255, 51, 102,
 
230
            255, 51, 51,
 
231
            255, 51, 51,
 
232
            255, 51, 51,
 
233
            255, 102, 51,
 
234
            255, 153, 51,
 
235
            255, 204, 51,
 
236
            255, 255, 51,
 
237
            204, 255, 51,
 
238
            153, 244, 51,
 
239
            102, 255, 51,
 
240
            51, 255, 51,
 
241
            51, 255, 51,
 
242
            51, 255, 51,
 
243
            51, 255, 102,
 
244
            51, 255, 153,
 
245
            51, 255, 204,
 
246
            153, 153, 153, // Fifth row
 
247
            0, 255, 255,
 
248
            0, 204, 255,
 
249
            0, 153, 255,
 
250
            0, 102, 255,
 
251
            0, 51, 255,
 
252
            0, 0, 255,
 
253
            51, 0, 255,
 
254
            102, 0, 255,
 
255
            153, 0, 255,
 
256
            204, 0, 255,
 
257
            255, 0, 255,
 
258
            255, 0, 204,
 
259
            255, 0, 153,
 
260
            255, 0, 102,
 
261
            255, 0, 51,
 
262
            255, 0 , 0,
 
263
            255, 51, 0,
 
264
            255, 102, 0,
 
265
            255, 153, 0,
 
266
            255, 204, 0,
 
267
            255, 255, 0,
 
268
            204, 255, 0,
 
269
            153, 255, 0,
 
270
            102, 255, 0,
 
271
            51, 255, 0,
 
272
            0, 255, 0,
 
273
            0, 255, 51,
 
274
            0, 255, 102,
 
275
            0, 255, 153,
 
276
            0, 255, 204,
 
277
            102, 102, 102, // sixth row
 
278
            0, 204, 204,
 
279
            0, 204, 204,
 
280
            0, 153, 204,
 
281
            0, 102, 204,
 
282
            0, 51, 204,
 
283
            0, 0, 204,
 
284
            51, 0, 204,
 
285
            102, 0, 204,
 
286
            153, 0, 204,
 
287
            204, 0, 204,
 
288
            204, 0, 204,
 
289
            204, 0, 204,
 
290
            204, 0, 153,
 
291
            204, 0, 102,
 
292
            204, 0, 51,
 
293
            204, 0, 0,
 
294
            204, 51, 0,
 
295
            204, 102, 0,
 
296
            204, 153, 0,
 
297
            204, 204, 0,
 
298
            204, 204, 0,
 
299
            204, 204, 0,
 
300
            153, 204, 0,
 
301
            102, 204, 0,
 
302
            51, 204, 0,
 
303
            0, 204, 0,
 
304
            0, 204, 51,
 
305
            0, 204, 102,
 
306
            0, 204, 153,
 
307
            0, 204, 204,
 
308
            102, 102, 102, // seventh row
 
309
            0, 153, 153,
 
310
            0, 153, 153,
 
311
            0, 153, 153,
 
312
            0, 102, 153,
 
313
            0, 51, 153,
 
314
            0, 0, 153,
 
315
            51, 0, 153,
 
316
            102, 0, 153,
 
317
            153, 0, 153,
 
318
            153, 0, 153,
 
319
            153, 0, 153,
 
320
            153, 0, 153,
 
321
            153, 0, 153,
 
322
            153, 0, 102,
 
323
            153, 0, 51,
 
324
            153, 0, 0,
 
325
            153, 51, 0,
 
326
            153, 102, 0,
 
327
            153, 153, 0,
 
328
            153, 153, 0,
 
329
            153, 153, 0,
 
330
            153, 153, 0,
 
331
            153, 153, 0,
 
332
            102, 153, 0,
 
333
            51, 153, 0,
 
334
            0, 153, 0,
 
335
            0, 153, 51,
 
336
            0, 153, 102,
 
337
            0, 153, 153,
 
338
            0, 153, 153,
 
339
            51, 51, 51, // eigth row
 
340
            0, 102, 102,
 
341
            0, 102, 102,
 
342
            0, 102, 102,
 
343
            0, 102, 102,
 
344
            0, 51, 102,
 
345
            0, 0, 102,
 
346
            51, 0, 102,
 
347
            102, 0, 102,
 
348
            102, 0, 102,
 
349
            102, 0, 102,
 
350
            102, 0, 102,
 
351
            102, 0, 102,
 
352
            102, 0, 102,
 
353
            102, 0, 102,
 
354
            102, 0, 51,
 
355
            102, 0, 0,
 
356
            102, 51, 0,
 
357
            102, 102, 0,
 
358
            102, 102, 0,
 
359
            102, 102, 0,
 
360
            102, 102, 0,
 
361
            102, 102, 0,
 
362
            102, 102, 0,
 
363
            102, 102, 0,
 
364
            51, 102, 0,
 
365
            0, 102, 0,
 
366
            0, 102, 51,
 
367
            0, 102, 102,
 
368
            0, 102, 102,
 
369
            0, 102, 102,
 
370
            0, 0, 0, // ninth row
 
371
            0, 51, 51,
 
372
            0, 51, 51,
 
373
            0, 51, 51,
 
374
            0, 51, 51,
 
375
            0, 51, 51,
 
376
            0, 0, 51,
 
377
            51, 0, 51,
 
378
            51, 0, 51,
 
379
            51, 0, 51,
 
380
            51, 0, 51,
 
381
            51, 0, 51,
 
382
            51, 0, 51,
 
383
            51, 0, 51,
 
384
            51, 0, 51,
 
385
            51, 0, 51,
 
386
            51, 0, 0,
 
387
            51, 51, 0,
 
388
            51, 51, 0,
 
389
            51, 51, 0,
 
390
            51, 51, 0,
 
391
            51, 51, 0,
 
392
            51, 51, 0,
 
393
            51, 51, 0,
 
394
            51, 51, 0,
 
395
            0, 51, 0,
 
396
            0, 51, 51,
 
397
            0, 51, 51,
 
398
            0, 51, 51,
 
399
            0, 51, 51,
 
400
            51, 51, 51 };
 
401
            return rawValues;
 
402
    }
 
403
}