|
|
@ -5,6 +5,7 @@ package com.fr.design.style.color; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
import com.fr.base.BaseUtils; |
|
|
|
import com.fr.base.BaseUtils; |
|
|
|
|
|
|
|
import com.fr.general.FRLogger; |
|
|
|
|
|
|
|
|
|
|
|
import java.awt.*; |
|
|
|
import java.awt.*; |
|
|
|
import java.awt.event.*; |
|
|
|
import java.awt.event.*; |
|
|
@ -49,7 +50,10 @@ public class ColorPicker extends JDialog implements ActionListener |
|
|
|
updateSize(colorPickerSize); |
|
|
|
updateSize(colorPickerSize); |
|
|
|
this.colorSelectable = colorSelectable; |
|
|
|
this.colorSelectable = colorSelectable; |
|
|
|
this.setColorRealTime = setColorRealTime; |
|
|
|
this.setColorRealTime = setColorRealTime; |
|
|
|
|
|
|
|
start(); |
|
|
|
|
|
|
|
this.setModal(true); |
|
|
|
this.setAlwaysOnTop(true); |
|
|
|
this.setAlwaysOnTop(true); |
|
|
|
|
|
|
|
updateLocation(); |
|
|
|
this.setVisible(true); |
|
|
|
this.setVisible(true); |
|
|
|
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); |
|
|
|
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); |
|
|
|
} |
|
|
|
} |
|
|
@ -58,6 +62,18 @@ public class ColorPicker extends JDialog implements ActionListener |
|
|
|
timer = new Timer(timeCycle, this); |
|
|
|
timer = new Timer(timeCycle, this); |
|
|
|
timer.start(); |
|
|
|
timer.start(); |
|
|
|
hideCursor(); |
|
|
|
hideCursor(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果要求实时变化,确保先关闭弹窗,再截屏
|
|
|
|
|
|
|
|
// 主要针对"图案"选项卡中的"前景"、"背景"
|
|
|
|
|
|
|
|
if (this.setColorRealTime) { |
|
|
|
|
|
|
|
colorSelectable.setColor(Color.WHITE); // setColor 可以关闭弹窗
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
Thread.sleep(100); // 等待弹窗关闭
|
|
|
|
|
|
|
|
} catch (InterruptedException e) { |
|
|
|
|
|
|
|
FRLogger.getLogger().error(e.getMessage()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
colorPickerPanel.captureScreen(); |
|
|
|
|
|
|
|
} |
|
|
|
// System.out.println(KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow());
|
|
|
|
// System.out.println(KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow());
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -68,7 +84,7 @@ 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 && !colorSelectable.getColor().equals(colorToSet)) { |
|
|
|
if (setColorRealTime && (colorSelectable.getColor() == null || !colorSelectable.getColor().equals(colorToSet))) { |
|
|
|
colorSelectable.setColor(colorToSet); |
|
|
|
colorSelectable.setColor(colorToSet); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -94,9 +110,11 @@ public class ColorPicker extends JDialog implements ActionListener |
|
|
|
validate(); // 更新所有子控件
|
|
|
|
validate(); // 更新所有子控件
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void pickComplete() { |
|
|
|
public void pickComplete(Boolean setColor) { |
|
|
|
timer.stop(); |
|
|
|
timer.stop(); |
|
|
|
colorSelectable.setColor(colorToSet); |
|
|
|
if (setColor) { |
|
|
|
|
|
|
|
colorSelectable.setColor(colorToSet); |
|
|
|
|
|
|
|
} |
|
|
|
this.dispose(); |
|
|
|
this.dispose(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -111,7 +129,11 @@ public class ColorPicker extends JDialog implements ActionListener |
|
|
|
{ |
|
|
|
{ |
|
|
|
public void mousePressed(MouseEvent e) |
|
|
|
public void mousePressed(MouseEvent e) |
|
|
|
{ |
|
|
|
{ |
|
|
|
pickComplete(); |
|
|
|
if (e.getButton() == e.BUTTON1) { // 左键确定
|
|
|
|
|
|
|
|
pickComplete(true); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
pickComplete(false); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -138,6 +160,15 @@ class ColorPickerPanel extends JPanel |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public ColorPickerPanel(int scaleFactor) |
|
|
|
public ColorPickerPanel(int scaleFactor) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
colorPickerFrame = BaseUtils.readImage("/com/fr/design/images/gui/colorPicker/colorPickerFrame.png"); |
|
|
|
|
|
|
|
this.scaleFactor = scaleFactor; |
|
|
|
|
|
|
|
captureScreen(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 截屏 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public void captureScreen() { |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
robot = new Robot(); |
|
|
|
robot = new Robot(); |
|
|
@ -149,8 +180,6 @@ 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; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|