Browse Source

REPORT-1096 自定义界面的颜色随鼠标位置动态变化;修改取色框的UI

master
plough 8 years ago
parent
commit
b828b89a46
  1. 0
      designer_base/src/com/fr/design/images/gui/colorPicker/colorPicker16.png
  2. 0
      designer_base/src/com/fr/design/images/gui/colorPicker/colorPicker18.png
  3. BIN
      designer_base/src/com/fr/design/images/gui/colorPicker/colorPickerFrame.png
  4. 43
      designer_base/src/com/fr/design/style/color/ColorPicker.java
  5. 16
      designer_base/src/com/fr/design/style/color/CustomChooserPanel.java
  6. 14
      designer_base/src/com/fr/design/style/color/NewColorSelectPane.java
  7. 19
      designer_base/src/com/fr/design/style/color/PickColorButton.java

0
designer_base/src/com/fr/design/images/gui/colorSelectPane/colorPicker16.png → designer_base/src/com/fr/design/images/gui/colorPicker/colorPicker16.png

Before

Width:  |  Height:  |  Size: 332 B

After

Width:  |  Height:  |  Size: 332 B

0
designer_base/src/com/fr/design/images/gui/colorSelectPane/colorPicker18.png → designer_base/src/com/fr/design/images/gui/colorPicker/colorPicker18.png

Before

Width:  |  Height:  |  Size: 432 B

After

Width:  |  Height:  |  Size: 432 B

BIN
designer_base/src/com/fr/design/images/gui/colorPicker/colorPickerFrame.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

43
designer_base/src/com/fr/design/style/color/ColorPicker.java

@ -5,6 +5,8 @@ package com.fr.design.style.color;
*/ */
//import com.fr.design.dialog.UIDialog; //import com.fr.design.dialog.UIDialog;
import com.fr.base.BaseUtils;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.awt.geom.Ellipse2D; import java.awt.geom.Ellipse2D;
@ -32,14 +34,9 @@ public class ColorPicker extends JDialog implements ActionListener
private Boolean setColorRealTime; // 实时设定颜色值 private Boolean setColorRealTime; // 实时设定颜色值
// private UIDialog modalDialog; // 对上层模态对话框的引用
/** /**
* 构造函数创建一个取色框窗体 * 构造函数创建一个取色框窗体
*/ */
public ColorPicker(ColorSelectable colorSelectable) {
this(colorSelectable, false);
}
public ColorPicker(ColorSelectable colorSelectable, Boolean setColorRealTime) public ColorPicker(ColorSelectable colorSelectable, Boolean setColorRealTime)
{ {
setUndecorated(true); // 去掉窗体边缘 setUndecorated(true); // 去掉窗体边缘
@ -60,17 +57,7 @@ public class ColorPicker extends JDialog implements ActionListener
public void start() { public void start() {
timer = new Timer(1000/FPS, this); timer = new Timer(1000/FPS, this);
timer.start(); timer.start();
// if (!this.hasFocus()) { hideCursor();
// // 此时的焦点应该在模态对话框上
// modalDialog = (UIDialog)KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
// System.out.println("1 modalDialog is modal? " + modalDialog.isModal());
// modalDialog.setModal(false);
// System.out.println("2 modalDialog is modal? " + modalDialog.isModal());
// System.out.println("1 has focus? " + this.hasFocus());
// modalDialog.transferFocus();
// System.out.println("2 has focus? " + this.hasFocus());
// System.out.println("current focus: " + KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow());
// }
} }
/** /**
@ -80,10 +67,9 @@ public class ColorPicker extends JDialog implements ActionListener
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
updateLocation(); updateLocation();
colorToSet = colorPickerPanel.getPixelColor(mousePos); colorToSet = colorPickerPanel.getPixelColor(mousePos);
if (setColorRealTime) { if (setColorRealTime && !colorSelectable.getColor().equals(colorToSet)) {
colorSelectable.setColor(colorToSet); colorSelectable.setColor(colorToSet);
} }
// System.out.println("hasFocus? " + this.hasFocus());
} }
public void updateLocation() { public void updateLocation() {
@ -110,19 +96,13 @@ public class ColorPicker extends JDialog implements ActionListener
public void pickComplete() { public void pickComplete() {
timer.stop(); timer.stop();
colorSelectable.setColor(colorToSet); colorSelectable.setColor(colorToSet);
// if (modalDialog != null) {
// modalDialog.setModal(true);
// }
this.dispose(); this.dispose();
} }
// 隐藏鼠标光标 // 隐藏鼠标光标
public void hideCursor() { public void hideCursor() {
Image imageCursor = Toolkit.getDefaultToolkit().getImage(""); Image imageCursor = Toolkit.getDefaultToolkit().getImage("");
// Image img = new BufferedImage()
Cursor cu = Toolkit.getDefaultToolkit().createCustomCursor(imageCursor, new Point(0,0), "cursor"); Cursor cu = Toolkit.getDefaultToolkit().createCustomCursor(imageCursor, new Point(0,0), "cursor");
// setCursor(Toolkit.getDefaultToolkit().createCustomCursor(
// imageCursor, new Point(16, 16), "stick"));
setCursor(cu); setCursor(cu);
} }
@ -139,6 +119,7 @@ public class ColorPicker extends JDialog implements ActionListener
class ColorPickerPanel extends JPanel class ColorPickerPanel extends JPanel
{ {
private BufferedImage screenImage; private BufferedImage screenImage;
private Image colorPickerFrame; // 取色框的边框图案
private int colorPickerSize; // 取色框尺寸 private int colorPickerSize; // 取色框尺寸
private int locationX; // 取色框 x 坐标 private int locationX; // 取色框 x 坐标
private int locationY; // 取色框 y 坐标 private int locationY; // 取色框 y 坐标
@ -162,6 +143,7 @@ class ColorPickerPanel extends JPanel
screenImage = robot.createScreenCapture(new Rectangle(0, 0, Toolkit screenImage = robot.createScreenCapture(new Rectangle(0, 0, Toolkit
.getDefaultToolkit().getScreenSize().width, Toolkit .getDefaultToolkit().getScreenSize().width, Toolkit
.getDefaultToolkit().getScreenSize().height)); .getDefaultToolkit().getScreenSize().height));
colorPickerFrame = BaseUtils.readImage("/com/fr/design/images/gui/colorPicker/colorPickerFrame.png");
this.scaleFactor = scaleFactor; this.scaleFactor = scaleFactor;
} }
@ -194,6 +176,7 @@ class ColorPickerPanel extends JPanel
{ {
Graphics2D g2d = (Graphics2D) g; Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
double pixelCount = (double)colorPickerSize / scaleFactor; // 取色器一条边上的放大后的像素点个数(可以是小数) double pixelCount = (double)colorPickerSize / scaleFactor; // 取色器一条边上的放大后的像素点个数(可以是小数)
// 关键处理代码 // 关键处理代码
g2d.drawImage( g2d.drawImage(
@ -209,16 +192,6 @@ class ColorPickerPanel extends JPanel
this this
); );
g2d.setColor(Color.white); g2d.drawImage(colorPickerFrame, 0, 0, this);
g2d.drawOval(1, 1, 188, 188);
g2d.drawOval(2, 2, 186, 186);
g2d.setColor(Color.black);
g2d.drawOval(0, 0, 190, 190);
g2d.drawOval(3, 3, 184, 184);
g2d.setColor(Color.white);
g2d.drawRect(86, 86, 18, 18);
g2d.setColor(Color.black);
g2d.drawRect(87, 87, 16, 16);
} }
} }

16
designer_base/src/com/fr/design/style/color/CustomChooserPanel.java

@ -710,13 +710,7 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
hexPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 8, 0)); hexPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 8, 0));
hexPanel.add(new UILabel("#")); hexPanel.add(new UILabel("#"));
hexPanel.add(field); hexPanel.add(field);
PickColorButton pickColorButton = new PickColorButton(PickColorButton.IconType.ICON18); PickColorButton pickColorButton = new PickColorButton(this, PickColorButton.IconType.ICON18, true);
pickColorButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
doPickColor();
}
});
hexPanel.add(pickColorButton); hexPanel.add(pickColorButton);
mainPanel.add(hslAndRgbPanel, BorderLayout.CENTER); mainPanel.add(hslAndRgbPanel, BorderLayout.CENTER);
@ -1082,12 +1076,4 @@ class CustomChooserPanel extends AbstractColorChooserPanel implements ColorSelec
public void colorSetted(ColorCell cc) { public void colorSetted(ColorCell cc) {
} }
/**
* 打开取色框开始取色
*/
public void doPickColor() {
ColorPicker colorPicker = new ColorPicker(this, true);
colorPicker.start();
}
} }

14
designer_base/src/com/fr/design/style/color/NewColorSelectPane.java

@ -87,13 +87,8 @@ public class NewColorSelectPane extends BasicPane implements ColorSelectable {
centerPane.add(row1Pane); centerPane.add(row1Pane);
// 取色按钮 // 取色按钮
PickColorButton pickColorButton = new PickColorButton(PickColorButton.IconType.ICON18); PickColorButton pickColorButton = new PickColorButton(this, PickColorButton.IconType.ICON18);
pickColorButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
doPickColor();
}
});
row1Pane.add(pickColorButton, BorderLayout.WEST); row1Pane.add(pickColorButton, BorderLayout.WEST);
// 最近使用 // 最近使用
@ -222,9 +217,6 @@ public class NewColorSelectPane extends BasicPane implements ColorSelectable {
usedColorPane.updateUsedColor(); usedColorPane.updateUsedColor();
} }
public void doPickColor() {
ColorPicker colorPicker = new ColorPicker(this);
colorPicker.start();
}
} }

19
designer_base/src/com/fr/design/style/color/PickColorButton.java

@ -4,23 +4,36 @@ import com.fr.base.BaseUtils;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/** /**
* Created by plough on 2016/12/22. * Created by plough on 2016/12/22.
*/ */
public class PickColorButton extends UIButton { public class PickColorButton extends UIButton {
public PickColorButton(final ColorSelectable colorSelectable, IconType iconType){
this(colorSelectable, iconType, false);
}
public PickColorButton(IconType iconType) { public PickColorButton(final ColorSelectable colorSelectable, IconType iconType, final Boolean setColorRealTime) {
super(); super();
if (iconType == IconType.ICON16) { if (iconType == IconType.ICON16) {
this.setIcon(BaseUtils.readIcon("/com/fr/design/images/gui/colorSelectPane/colorPicker16.png")); this.setIcon(BaseUtils.readIcon("/com/fr/design/images/gui/colorPicker/colorPicker16.png"));
this.setPreferredSize(new Dimension(16, 16)); this.setPreferredSize(new Dimension(16, 16));
} else { } else {
this.setIcon(BaseUtils.readIcon("/com/fr/design/images/gui/colorSelectPane/colorPicker18.png")); this.setIcon(BaseUtils.readIcon("/com/fr/design/images/gui/colorPicker/colorPicker18.png"));
this.setPreferredSize(new Dimension(18, 18)); this.setPreferredSize(new Dimension(18, 18));
} }
this.setCursor(new Cursor(Cursor.HAND_CURSOR)); this.setCursor(new Cursor(Cursor.HAND_CURSOR));
this.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ColorPicker colorPicker = new ColorPicker(colorSelectable, setColorRealTime);
colorPicker.start();
}
});
} }
// 取色器按钮使用的图标 // 取色器按钮使用的图标

Loading…
Cancel
Save