Browse Source

ct

feature/big-screen
neil 4 years ago
parent
commit
3cad18d7c5
  1. 94
      designer-base/src/main/java/com/fr/design/style/color/CustomChooserPanel.java

94
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 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 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 HSPINNER_VALUE = 360f;
private static final float SSPINNER_VALUE = 100f; 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_EIGHT = 255;
private static final int BINARY_FOR_FOUR = 16; private static final int BINARY_FOR_FOUR = 16;
@ -314,14 +314,14 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
* @param p The point where the MouseEvent occurred. * @param p The point where the MouseEvent occurred.
*/ */
private void updateH(Point p) { private void updateH(Point p) {
double s = (IMG_WIDTH - p.x * 1D) / IMG_WIDTH; float s = (IMG_WIDTH - p.x * 1f) / IMG_WIDTH;
double b = (IMG_HEIGHT - p.y * 1D) / IMG_HEIGHT; float b = (IMG_HEIGHT - p.y * 1f) / IMG_HEIGHT;
// Avoid two changes to the model by changing internalChange to true. // Avoid two changes to the model by changing internalChange to true.
internalChange = true; internalChange = true;
sSpinner.setValue(new Integer((int) (s * S_MAX))); sSpinner.setValue(new Integer((int) (s * S_MAX)));
internalChange = false; internalChange = false;
bSpinner.setValue(new Integer((int) (b * L_MAX))); bSpinner.setValue(new Integer((int) (b * B_MAX)));
revalidate(); revalidate();
} }
@ -332,13 +332,13 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
* @param p The point where the MouseEvent occurred. * @param p The point where the MouseEvent occurred.
*/ */
private void updateS(Point p) { private void updateS(Point p) {
double h = p.x * 1D / IMG_WIDTH; float h = p.x * 1f / IMG_WIDTH;
double b = (IMG_HEIGHT - p.y * 1D) / IMG_HEIGHT; float b = (IMG_HEIGHT - p.y * 1f) / IMG_HEIGHT;
internalChange = true; internalChange = true;
hSpinner.setValue(new Integer((int) (h * H_MAX))); hSpinner.setValue(new Integer((int) (h * H_MAX)));
internalChange = false; internalChange = false;
bSpinner.setValue(new Integer((int) (b * L_MAX))); bSpinner.setValue(new Integer((int) (b * B_MAX)));
revalidate(); revalidate();
} }
@ -349,8 +349,8 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
* @param p The point where the MouseEvent occurred. * @param p The point where the MouseEvent occurred.
*/ */
private void updateB(Point p) { private void updateB(Point p) {
double h = p.x * 1D / IMG_WIDTH; float h = p.x * 1f / IMG_WIDTH;
double s = (IMG_HEIGHT - p.y * 1D) / IMG_HEIGHT; float s = (IMG_HEIGHT - p.y * 1f) / IMG_HEIGHT;
internalChange = true; internalChange = true;
hSpinner.setValue(new Integer((int) (h * H_MAX))); hSpinner.setValue(new Integer((int) (h * H_MAX)));
@ -431,7 +431,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
} }
/** /**
* hsl 监听 * hsb 监听
*/ */
class ImageScrollListener implements ChangeListener { class ImageScrollListener implements ChangeListener {
/** /**
@ -506,7 +506,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
null); null);
internalChange = true; internalChange = true;
adjustHSLValue(hsbVals); adjustHSBValue(hsbVals);
internalChange = false; internalChange = false;
@ -521,11 +521,11 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
updateHexFields(); updateHexFields();
} }
private void adjustHSLValue(float[] hsbVals) { private void adjustHSBValue(float[] hsbVals) {
if (!spinnerTrigger) { if (!spinnerTrigger) {
hSpinner.setValue(new Integer((int) ((double) hsbVals[0] * HSPINNER_VALUE))); hSpinner.setValue(new Integer((int) (hsbVals[0] * HSPINNER_VALUE)));
sSpinner.setValue(new Integer((int) ((double) hsbVals[1] * SSPINNER_VALUE))); sSpinner.setValue(new Integer((int) (hsbVals[1] * SSPINNER_VALUE)));
bSpinner.setValue(new Integer((int) ((double) hsbVals[2] * LSPINNER_VALUE))); bSpinner.setValue(new Integer((int) (hsbVals[2] * BSPINNER_VALUE)));
} }
switch (locked) { switch (locked) {
case HLOCKED: case HLOCKED:
@ -534,9 +534,9 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
} }
if (!handlingMouse) { if (!handlingMouse) {
gradientPoint.x = (int) ((1 gradientPoint.x = (int) ((1
- ((Number) sSpinner.getValue()).intValue() / (double) SSPINNER_VALUE) * IMG_WIDTH); - ((Number) sSpinner.getValue()).intValue() / SSPINNER_VALUE) * IMG_WIDTH);
gradientPoint.y = (int) ((1 gradientPoint.y = (int) ((1
- ((Number) bSpinner.getValue()).intValue() / (double) LSPINNER_VALUE) * IMG_HEIGHT); - ((Number) bSpinner.getValue()).intValue() / BSPINNER_VALUE) * IMG_HEIGHT);
} }
break; break;
case SLOCKED: case SLOCKED:
@ -544,9 +544,9 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
slider.setValue(((Number) sSpinner.getValue()).intValue()); slider.setValue(((Number) sSpinner.getValue()).intValue());
} }
if (!handlingMouse) { if (!handlingMouse) {
gradientPoint.x = (int) (((Number) hSpinner.getValue()).intValue() / (double) HSPINNER_VALUE * IMG_WIDTH); gradientPoint.x = (int) (((Number) hSpinner.getValue()).intValue() / HSPINNER_VALUE * IMG_WIDTH);
gradientPoint.y = (int) ((1 gradientPoint.y = (int) ((1
- ((Number) bSpinner.getValue()).intValue() / (double) LSPINNER_VALUE) * IMG_HEIGHT); - ((Number) bSpinner.getValue()).intValue() / BSPINNER_VALUE) * IMG_HEIGHT);
} }
break; break;
case BLOCKED: case BLOCKED:
@ -554,18 +554,18 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
slider.setValue(((Number) bSpinner.getValue()).intValue()); slider.setValue(((Number) bSpinner.getValue()).intValue());
} }
if (!handlingMouse) { if (!handlingMouse) {
gradientPoint.x = (int) (((Number) hSpinner.getValue()).intValue() / (double) HSPINNER_VALUE * IMG_WIDTH); gradientPoint.x = (int) (((Number) hSpinner.getValue()).intValue() / HSPINNER_VALUE * IMG_WIDTH);
gradientPoint.y = (int) ((1 gradientPoint.y = (int) ((1
- ((Number) sSpinner.getValue()).intValue() / (double) SSPINNER_VALUE) * IMG_HEIGHT); - ((Number) sSpinner.getValue()).intValue() / SSPINNER_VALUE) * IMG_HEIGHT);
} }
break; break;
} }
} }
private void updateImageAndTrack() { private void updateImageAndTrack() {
float h = (float) (((Number) hSpinner.getValue()).intValue() / (double) HSPINNER_VALUE); float h = ((Number) hSpinner.getValue()).intValue() / HSPINNER_VALUE;
float s = (float) (((Number) sSpinner.getValue()).intValue() / (double) SSPINNER_VALUE); float s = ((Number) sSpinner.getValue()).intValue() / SSPINNER_VALUE;
float b = (float) (((Number) bSpinner.getValue()).intValue() / (double) LSPINNER_VALUE); float b = ((Number) bSpinner.getValue()).intValue() / BSPINNER_VALUE;
spinnerTrigger = true; spinnerTrigger = true;
getColorSelectionModel().setSelectedColor(new Color(Color.HSBtoRGB(h, s, b))); getColorSelectionModel().setSelectedColor(new Color(Color.HSBtoRGB(h, s, b)));
@ -691,11 +691,11 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
container.add(label); container.add(label);
container.add(mainPanel); container.add(mainPanel);
// hsl和rgb面板 // hsb和rgb面板
JPanel hslAndRgbPanel = new JPanel(); JPanel hsbAndRgbPanel = new JPanel();
hslAndRgbPanel.setLayout(new BorderLayout(0, 16)); hsbAndRgbPanel.setLayout(new BorderLayout(0, 16));
hslAndRgbPanel.add(initialHSLPanel(), BorderLayout.CENTER); hsbAndRgbPanel.add(initialHSBPanel(), BorderLayout.CENTER);
hslAndRgbPanel.add(initialRGBPanel(), BorderLayout.SOUTH); hsbAndRgbPanel.add(initialRGBPanel(), BorderLayout.SOUTH);
// 十六进制面板 // 十六进制面板
JPanel hexPanel = new JPanel(); JPanel hexPanel = new JPanel();
@ -703,7 +703,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
hexPanel.add(new UILabel("#")); hexPanel.add(new UILabel("#"));
hexPanel.add(field); hexPanel.add(field);
mainPanel.add(hslAndRgbPanel, BorderLayout.CENTER); mainPanel.add(hsbAndRgbPanel, BorderLayout.CENTER);
mainPanel.add(hexPanel, BorderLayout.SOUTH); mainPanel.add(hexPanel, BorderLayout.SOUTH);
JPanel rightPane = new JPanel(new BorderLayout()); JPanel rightPane = new JPanel(new BorderLayout());
@ -719,11 +719,11 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
return container; return container;
} }
//初始化HSL部分 //初始化HSB部分
private JPanel initialHSLPanel() { private JPanel initialHSBPanel() {
hRadio = new UIRadioButton("H"); hRadio = new UIRadioButton("H");
sRadio = new UIRadioButton("S"); sRadio = new UIRadioButton("S");
bRadio = new UIRadioButton("L"); bRadio = new UIRadioButton("B");
ButtonGroup group = new ButtonGroup(); ButtonGroup group = new ButtonGroup();
group.add(hRadio); group.add(hRadio);
group.add(sRadio); group.add(sRadio);
@ -748,27 +748,27 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
sSpinner.addChangeListener(scroll); sSpinner.addChangeListener(scroll);
bSpinner.addChangeListener(scroll); bSpinner.addChangeListener(scroll);
JPanel hslPanel = new JPanel(); JPanel hsbPanel = new JPanel();
hslPanel.setLayout(new GridLayout(3, 0, 0, 5)); hsbPanel.setLayout(new GridLayout(3, 0, 0, 5));
JPanel hPanel = new JPanel(); JPanel hPanel = new JPanel();
hPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 0)); hPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 0));
hPanel.add(hRadio); hPanel.add(hRadio);
hPanel.add(hSpinner); hPanel.add(hSpinner);
hslPanel.add(hPanel); hsbPanel.add(hPanel);
JPanel sPanel = new JPanel(); JPanel sPanel = new JPanel();
sPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 0)); sPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 0));
sPanel.add(sRadio); sPanel.add(sRadio);
sPanel.add(sSpinner); sPanel.add(sSpinner);
hslPanel.add(sPanel); hsbPanel.add(sPanel);
JPanel lPanel = new JPanel(); JPanel lPanel = new JPanel();
lPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 0)); lPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 0));
lPanel.add(bRadio); lPanel.add(bRadio);
lPanel.add(bSpinner); lPanel.add(bSpinner);
hslPanel.add(lPanel); hsbPanel.add(lPanel);
return hslPanel; return hsbPanel;
} }
private JPanel initialRGBPanel() { private JPanel initialRGBPanel() {
@ -837,12 +837,12 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
private void updateHLockImage() { private void updateHLockImage() {
int index = 0; int index = 0;
int[] pix = new int[IMG_WIDTH * IMG_HEIGHT]; int[] pix = new int[IMG_WIDTH * IMG_HEIGHT];
float hValue = (float)(((Number) hSpinner.getValue()).intValue() / (double) HSPINNER_VALUE ); float hValue = ((Number) hSpinner.getValue()).intValue() / HSPINNER_VALUE;
for (int j = 0; j < IMG_HEIGHT; j++) { for (int j = 0; j < IMG_HEIGHT; j++) {
for (int i = 0; i < IMG_WIDTH; i++) { for (int i = 0; i < IMG_WIDTH; i++) {
pix[index++] = Color.HSBtoRGB(hValue, (float) ((IMG_WIDTH - i * 1D) / IMG_WIDTH), pix[index++] = Color.HSBtoRGB(hValue, (IMG_WIDTH - i * 1f) / IMG_WIDTH,
(float) ((IMG_HEIGHT - j * 1D) / IMG_HEIGHT)) | (BINARY_FOR_EIGHT << TWENTY_FOUR); (IMG_HEIGHT - j * 1f) / IMG_HEIGHT) | (BINARY_FOR_EIGHT << TWENTY_FOUR);
} }
} }
@ -856,7 +856,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
*/ */
private void updateBLockImage() { private void updateBLockImage() {
int[] pix = new int[IMG_WIDTH * IMG_HEIGHT]; 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; int index = 0;
for (int j = 0; j < IMG_HEIGHT; j++) { 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]; int[] trackPix = new int[TRACK_WIDTH * IMG_HEIGHT];
float hValue = ((Number) hSpinner.getValue()).intValue() / HSPINNER_VALUE; 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; int trackIndex = 0;
for (int j = 0; j < IMG_HEIGHT; j++) { for (int j = 0; j < IMG_HEIGHT; j++) {
@ -1076,4 +1076,4 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
public void colorSetted(ColorCell cc) { public void colorSetted(ColorCell cc) {
} }
} }
Loading…
Cancel
Save