Browse Source

REPORT-23627 设计器颜色设置自定义页面中RGB和HSL互相转换有问题

feature/big-screen
Joe.Jiang 5 years ago
parent
commit
b7d2d199ec
  1. 58
      designer-base/src/main/java/com/fr/design/style/color/CustomChooserPanel.java

58
designer-base/src/main/java/com/fr/design/style/color/CustomChooserPanel.java

@ -142,13 +142,13 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
*/
private static final UILabel B = new UILabel("B");
private static final int H_MAX = 365;
private static final int H_MAX = 360;
private static final int S_MAX = 100;
private static final int L_MAX = 100;
private static final int B_MAX = 100;
private static final float HSPINNER_VALUE = 360f;
private static final float SSPINNER_VALUE = 100f;
private static final float LSPINNER_VALUE = 100f;
private static final float BSPINNER_VALUE = 100f;
private static final int BINARY_FOR_EIGHT = 255;
private static final int BINARY_FOR_FOUR = 16;
@ -321,7 +321,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
internalChange = true;
sSpinner.setValue(new Integer((int) (s * S_MAX)));
internalChange = false;
bSpinner.setValue(new Integer((int) (b * L_MAX)));
bSpinner.setValue(new Integer((int) (b * B_MAX)));
revalidate();
}
@ -338,7 +338,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
internalChange = true;
hSpinner.setValue(new Integer((int) (h * H_MAX)));
internalChange = false;
bSpinner.setValue(new Integer((int) (b * L_MAX)));
bSpinner.setValue(new Integer((int) (b * B_MAX)));
revalidate();
}
@ -431,7 +431,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
}
/**
* hsl 监听
* hsb 监听
*/
class ImageScrollListener implements ChangeListener {
/**
@ -506,7 +506,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
null);
internalChange = true;
adjustHSLValue(hsbVals);
adjustHSBValue(hsbVals);
internalChange = false;
@ -521,11 +521,11 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
updateHexFields();
}
private void adjustHSLValue(float[] hsbVals) {
private void adjustHSBValue(float[] hsbVals) {
if (!spinnerTrigger) {
hSpinner.setValue(new Integer((int) (hsbVals[0] * HSPINNER_VALUE)));
sSpinner.setValue(new Integer((int) (hsbVals[1] * SSPINNER_VALUE)));
bSpinner.setValue(new Integer((int) (hsbVals[2] * LSPINNER_VALUE)));
bSpinner.setValue(new Integer((int) (hsbVals[2] * BSPINNER_VALUE)));
}
switch (locked) {
case HLOCKED:
@ -536,7 +536,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
gradientPoint.x = (int) ((1
- ((Number) sSpinner.getValue()).intValue() / SSPINNER_VALUE) * IMG_WIDTH);
gradientPoint.y = (int) ((1
- ((Number) bSpinner.getValue()).intValue() / LSPINNER_VALUE) * IMG_HEIGHT);
- ((Number) bSpinner.getValue()).intValue() / BSPINNER_VALUE) * IMG_HEIGHT);
}
break;
case SLOCKED:
@ -546,7 +546,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
if (!handlingMouse) {
gradientPoint.x = (int) (((Number) hSpinner.getValue()).intValue() / HSPINNER_VALUE * IMG_WIDTH);
gradientPoint.y = (int) ((1
- ((Number) bSpinner.getValue()).intValue() / LSPINNER_VALUE) * IMG_HEIGHT);
- ((Number) bSpinner.getValue()).intValue() / BSPINNER_VALUE) * IMG_HEIGHT);
}
break;
case BLOCKED:
@ -565,7 +565,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
private void updateImageAndTrack() {
float h = ((Number) hSpinner.getValue()).intValue() / HSPINNER_VALUE;
float s = ((Number) sSpinner.getValue()).intValue() / SSPINNER_VALUE;
float b = ((Number) bSpinner.getValue()).intValue() / LSPINNER_VALUE;
float b = ((Number) bSpinner.getValue()).intValue() / BSPINNER_VALUE;
spinnerTrigger = true;
getColorSelectionModel().setSelectedColor(new Color(Color.HSBtoRGB(h, s, b)));
@ -691,11 +691,11 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
container.add(label);
container.add(mainPanel);
// hsl和rgb面板
JPanel hslAndRgbPanel = new JPanel();
hslAndRgbPanel.setLayout(new BorderLayout(0, 16));
hslAndRgbPanel.add(initialHSLPanel(), BorderLayout.CENTER);
hslAndRgbPanel.add(initialRGBPanel(), BorderLayout.SOUTH);
// hsb和rgb面板
JPanel hsbAndRgbPanel = new JPanel();
hsbAndRgbPanel.setLayout(new BorderLayout(0, 16));
hsbAndRgbPanel.add(initialHSBPanel(), BorderLayout.CENTER);
hsbAndRgbPanel.add(initialRGBPanel(), BorderLayout.SOUTH);
// 十六进制面板
JPanel hexPanel = new JPanel();
@ -703,7 +703,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
hexPanel.add(new UILabel("#"));
hexPanel.add(field);
mainPanel.add(hslAndRgbPanel, BorderLayout.CENTER);
mainPanel.add(hsbAndRgbPanel, BorderLayout.CENTER);
mainPanel.add(hexPanel, BorderLayout.SOUTH);
JPanel rightPane = new JPanel(new BorderLayout());
@ -719,11 +719,11 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
return container;
}
//初始化HSL部分
private JPanel initialHSLPanel() {
//初始化HSB部分
private JPanel initialHSBPanel() {
hRadio = new UIRadioButton("H");
sRadio = new UIRadioButton("S");
bRadio = new UIRadioButton("L");
bRadio = new UIRadioButton("B");
ButtonGroup group = new ButtonGroup();
group.add(hRadio);
group.add(sRadio);
@ -748,27 +748,27 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
sSpinner.addChangeListener(scroll);
bSpinner.addChangeListener(scroll);
JPanel hslPanel = new JPanel();
hslPanel.setLayout(new GridLayout(3, 0, 0, 5));
JPanel hsbPanel = new JPanel();
hsbPanel.setLayout(new GridLayout(3, 0, 0, 5));
JPanel hPanel = new JPanel();
hPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 0));
hPanel.add(hRadio);
hPanel.add(hSpinner);
hslPanel.add(hPanel);
hsbPanel.add(hPanel);
JPanel sPanel = new JPanel();
sPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 0));
sPanel.add(sRadio);
sPanel.add(sSpinner);
hslPanel.add(sPanel);
hsbPanel.add(sPanel);
JPanel lPanel = new JPanel();
lPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 0));
lPanel.add(bRadio);
lPanel.add(bSpinner);
hslPanel.add(lPanel);
return hslPanel;
hsbPanel.add(lPanel);
return hsbPanel;
}
private JPanel initialRGBPanel() {
@ -856,7 +856,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
*/
private void updateBLockImage() {
int[] pix = new int[IMG_WIDTH * IMG_HEIGHT];
float bValue = ((Number) bSpinner.getValue()).intValue() / LSPINNER_VALUE;
float bValue = ((Number) bSpinner.getValue()).intValue() / BSPINNER_VALUE;
int index = 0;
for (int j = 0; j < IMG_HEIGHT; j++) {
@ -1028,7 +1028,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
int[] trackPix = new int[TRACK_WIDTH * IMG_HEIGHT];
float hValue = ((Number) hSpinner.getValue()).intValue() / HSPINNER_VALUE;
float bValue = ((Number) bSpinner.getValue()).intValue() / LSPINNER_VALUE;
float bValue = ((Number) bSpinner.getValue()).intValue() / BSPINNER_VALUE;
int trackIndex = 0;
for (int j = 0; j < IMG_HEIGHT; j++) {

Loading…
Cancel
Save