249 setSelectedColor(color);
250 recentSwatchPanel.requestFocusInWindow();
251 }
252 }
253 }
254
255 class MainSwatchListener extends MouseAdapter implements Serializable {
256 public void mousePressed(MouseEvent e) {
257 if (isEnabled()) {
258 Color color = swatchPanel.getColorForLocation(e.getX(), e.getY());
259 setSelectedColor(color);
260 swatchPanel.setSelectedColorFromLocation(e.getX(), e.getY());
261 recentSwatchPanel.setMostRecentColor(color);
262 swatchPanel.requestFocusInWindow();
263 }
264 }
265 }
266
267 }
268
269
270
271 class SwatchPanel extends JPanel {
272
273 protected Color[] colors;
274 protected Dimension swatchSize;
275 protected Dimension numSwatches;
276 protected Dimension gap;
277
278 private int selRow;
279 private int selCol;
280
281 public SwatchPanel() {
282 initValues();
283 initColors();
284 setToolTipText(""); // register for events
285 setOpaque(true);
286 setBackground(Color.white);
287 setFocusable(true);
288 setInheritsPopupMenu(true);
289
290 addFocusListener(new FocusAdapter() {
421 public Color getColorForLocation( int x, int y ) {
422 int column;
423 if (!this.getComponentOrientation().isLeftToRight()) {
424 column = numSwatches.width - x / (swatchSize.width + gap.width) - 1;
425 } else {
426 column = x / (swatchSize.width + gap.width);
427 }
428 int row = y / (swatchSize.height + gap.height);
429 return getColorForCell(column, row);
430 }
431
432 private Color getColorForCell( int column, int row) {
433 return colors[ (row * numSwatches.width) + column ]; // (STEVE) - change data orientation here
434 }
435
436
437
438
439 }
440
441 class RecentSwatchPanel extends SwatchPanel {
442 protected void initValues() {
443 swatchSize = UIManager.getDimension("ColorChooser.swatchesRecentSwatchSize", getLocale());
444 numSwatches = new Dimension( 5, 7 );
445 gap = new Dimension(1, 1);
446 }
447
448
449 protected void initColors() {
450 Color defaultRecentColor = UIManager.getColor("ColorChooser.swatchesDefaultRecentColor", getLocale());
451 int numColors = numSwatches.width * numSwatches.height;
452
453 colors = new Color[numColors];
454 for (int i = 0; i < numColors ; i++) {
455 colors[i] = defaultRecentColor;
456 }
457 }
458
459 public void setMostRecentColor(Color c) {
460
461 System.arraycopy( colors, 0, colors, 1, colors.length-1);
462 colors[0] = c;
463 repaint();
464 }
465
466 }
467
468 class MainSwatchPanel extends SwatchPanel {
469
470
471 protected void initValues() {
472 swatchSize = UIManager.getDimension("ColorChooser.swatchesSwatchSize", getLocale());
473 numSwatches = new Dimension( 31, 9 );
474 gap = new Dimension(1, 1);
475 }
476
477 protected void initColors() {
478 int[] rawValues = initRawValues();
479 int numColors = rawValues.length / 3;
480
481 colors = new Color[numColors];
482 for (int i = 0; i < numColors ; i++) {
483 colors[i] = new Color( rawValues[(i*3)], rawValues[(i*3)+1], rawValues[(i*3)+2] );
484 }
485 }
486
487 private int[] initRawValues() {
|
249 setSelectedColor(color);
250 recentSwatchPanel.requestFocusInWindow();
251 }
252 }
253 }
254
255 class MainSwatchListener extends MouseAdapter implements Serializable {
256 public void mousePressed(MouseEvent e) {
257 if (isEnabled()) {
258 Color color = swatchPanel.getColorForLocation(e.getX(), e.getY());
259 setSelectedColor(color);
260 swatchPanel.setSelectedColorFromLocation(e.getX(), e.getY());
261 recentSwatchPanel.setMostRecentColor(color);
262 swatchPanel.requestFocusInWindow();
263 }
264 }
265 }
266
267 }
268
269 @SuppressWarnings("serial") // Same-version serialization only
270 class SwatchPanel extends JPanel {
271
272 protected Color[] colors;
273 protected Dimension swatchSize;
274 protected Dimension numSwatches;
275 protected Dimension gap;
276
277 private int selRow;
278 private int selCol;
279
280 public SwatchPanel() {
281 initValues();
282 initColors();
283 setToolTipText(""); // register for events
284 setOpaque(true);
285 setBackground(Color.white);
286 setFocusable(true);
287 setInheritsPopupMenu(true);
288
289 addFocusListener(new FocusAdapter() {
420 public Color getColorForLocation( int x, int y ) {
421 int column;
422 if (!this.getComponentOrientation().isLeftToRight()) {
423 column = numSwatches.width - x / (swatchSize.width + gap.width) - 1;
424 } else {
425 column = x / (swatchSize.width + gap.width);
426 }
427 int row = y / (swatchSize.height + gap.height);
428 return getColorForCell(column, row);
429 }
430
431 private Color getColorForCell( int column, int row) {
432 return colors[ (row * numSwatches.width) + column ]; // (STEVE) - change data orientation here
433 }
434
435
436
437
438 }
439
440 @SuppressWarnings("serial") // Superclass is not serializable across versions
441 class RecentSwatchPanel extends SwatchPanel {
442 protected void initValues() {
443 swatchSize = UIManager.getDimension("ColorChooser.swatchesRecentSwatchSize", getLocale());
444 numSwatches = new Dimension( 5, 7 );
445 gap = new Dimension(1, 1);
446 }
447
448
449 protected void initColors() {
450 Color defaultRecentColor = UIManager.getColor("ColorChooser.swatchesDefaultRecentColor", getLocale());
451 int numColors = numSwatches.width * numSwatches.height;
452
453 colors = new Color[numColors];
454 for (int i = 0; i < numColors ; i++) {
455 colors[i] = defaultRecentColor;
456 }
457 }
458
459 public void setMostRecentColor(Color c) {
460
461 System.arraycopy( colors, 0, colors, 1, colors.length-1);
462 colors[0] = c;
463 repaint();
464 }
465
466 }
467
468 @SuppressWarnings("serial") // Superclass is not serializable across versions
469 class MainSwatchPanel extends SwatchPanel {
470
471
472 protected void initValues() {
473 swatchSize = UIManager.getDimension("ColorChooser.swatchesSwatchSize", getLocale());
474 numSwatches = new Dimension( 31, 9 );
475 gap = new Dimension(1, 1);
476 }
477
478 protected void initColors() {
479 int[] rawValues = initRawValues();
480 int numColors = rawValues.length / 3;
481
482 colors = new Color[numColors];
483 for (int i = 0; i < numColors ; i++) {
484 colors[i] = new Color( rawValues[(i*3)], rawValues[(i*3)+1], rawValues[(i*3)+2] );
485 }
486 }
487
488 private int[] initRawValues() {
|