< prev index next >
src/java.desktop/share/classes/javax/swing/colorchooser/ColorPanel.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 28,48 ****
import java.awt.Color;
import java.awt.ContainerOrderFocusTraversalPolicy;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
! import java.awt.event.ActionEvent;
! import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.EmptyBorder;
import javax.swing.JSpinner.DefaultEditor;
@SuppressWarnings("serial") // Superclass is not serializable across versions
! final class ColorPanel extends JPanel implements ActionListener {
private final SlidingSpinner[] spinners = new SlidingSpinner[5];
private final float[] values = new float[this.spinners.length];
private final ColorModel model;
--- 28,49 ----
import java.awt.Color;
import java.awt.ContainerOrderFocusTraversalPolicy;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
! import java.awt.event.ItemEvent;
! import java.awt.event.ItemListener;
import javax.swing.ButtonGroup;
+ import javax.swing.DefaultButtonModel;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.EmptyBorder;
import javax.swing.JSpinner.DefaultEditor;
@SuppressWarnings("serial") // Superclass is not serializable across versions
! final class ColorPanel extends JPanel implements ItemListener {
private final SlidingSpinner[] spinners = new SlidingSpinner[5];
private final float[] values = new float[this.spinners.length];
private final ColorModel model;
*** 71,81 ****
gbc.insets.top = 5;
}
add(button, gbc);
group.add(button);
button.setActionCommand(Integer.toString(i));
! button.addActionListener(this);
this.spinners[i] = new SlidingSpinner(this, button);
}
else {
JLabel label = new JLabel();
add(label, gbc);
--- 72,82 ----
gbc.insets.top = 5;
}
add(button, gbc);
group.add(button);
button.setActionCommand(Integer.toString(i));
! button.getModel().addItemListener(this);
this.spinners[i] = new SlidingSpinner(this, button);
}
else {
JLabel label = new JLabel();
add(label, gbc);
*** 104,123 ****
setFocusable(false);
this.model = model;
}
! public void actionPerformed(ActionEvent event) {
try {
! this.z = Integer.parseInt(event.getActionCommand());
this.y = (this.z != 2) ? 2 : 1;
this.x = (this.z != 0) ? 0 : 1;
getParent().repaint();
}
catch (NumberFormatException exception) {
}
}
void buildPanel() {
int count = this.model.getCount();
this.spinners[4].setVisible(count > 4);
for (int i = 0; i < count; i++) {
--- 105,130 ----
setFocusable(false);
this.model = model;
}
! @Override
! public void itemStateChanged(ItemEvent e) {
! if(e.getStateChange() == ItemEvent.SELECTED) {
! if (e.getSource() instanceof DefaultButtonModel) {
! DefaultButtonModel model = (DefaultButtonModel) e.getSource();
try {
! this.z = Integer.parseInt(model.getActionCommand());
this.y = (this.z != 2) ? 2 : 1;
this.x = (this.z != 0) ? 0 : 1;
getParent().repaint();
}
catch (NumberFormatException exception) {
}
}
+ }
+ }
void buildPanel() {
int count = this.model.getCount();
this.spinners[4].setVisible(count > 4);
for (int i = 0; i < count; i++) {
< prev index next >