From a4e936a433ebd5611bc8f8db585dd58083d99fa5 Mon Sep 17 00:00:00 2001 From: hades Date: Wed, 9 Oct 2019 16:12:02 +0800 Subject: [PATCH 1/2] =?UTF-8?q?REPORT-21486=20=E8=AE=BE=E8=AE=A1=E5=99=A8?= =?UTF-8?q?=20=E5=8F=96=E8=89=B2=E5=99=A8=20=E5=8F=8C=E5=B1=8F=E6=83=85?= =?UTF-8?q?=E5=86=B5=E4=B8=8B=20=E5=9C=A8=E4=BA=A4=E6=8D=A2=E5=B1=8F?= =?UTF-8?q?=E5=B9=95=E4=BD=8D=E7=BD=AE=E5=90=8E=20=E4=BB=8D=E6=9C=89?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E4=BA=8C=E9=97=AE=E9=A2=98=20&&=20REPORT-222?= =?UTF-8?q?14=20=E7=A6=81=E6=AD=A2=E4=BF=AE=E6=94=B9=E6=8E=A7=E4=BB=B6js?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/style/color/ColorPicker.java | 96 +++++++++++-------- .../com/fr/design/utils/gui/GUICoreUtils.java | 26 ++--- .../properties/EventPropertyTable.java | 1 + 3 files changed, 68 insertions(+), 55 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/style/color/ColorPicker.java b/designer-base/src/main/java/com/fr/design/style/color/ColorPicker.java index d8816c3e3f..6c1808fc05 100644 --- a/designer-base/src/main/java/com/fr/design/style/color/ColorPicker.java +++ b/designer-base/src/main/java/com/fr/design/style/color/ColorPicker.java @@ -4,7 +4,8 @@ package com.fr.design.style.color; * Created by plough on 2016/12/22. */ -import com.fr.base.BaseUtils; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.general.IOUtils; import com.fr.log.FineLoggerFactory; import javax.swing.*; @@ -19,8 +20,7 @@ import java.awt.image.BufferedImage; /** * 取色框 */ -public class ColorPicker extends JDialog implements ActionListener -{ +public class ColorPicker extends JDialog implements ActionListener { private Container container = getContentPane(); // 主容器 private int setCoordinateX; // 取色框x坐标 private int setCoordinateY; // 取色框y坐标 @@ -42,8 +42,7 @@ public class ColorPicker extends JDialog implements ActionListener /** * 构造函数,创建一个取色框窗体 */ - public ColorPicker(ColorSelectable colorSelectable, Boolean setColorRealTime) - { + public ColorPicker(ColorSelectable colorSelectable, Boolean setColorRealTime) { setUndecorated(true); // 去掉窗体边缘 setResizable(false); Shape shape = new Ellipse2D.Double(0, 0, colorPickerSize, colorPickerSize); @@ -77,7 +76,6 @@ public class ColorPicker extends JDialog implements ActionListener } colorPickerPanel.captureScreen(); } -// System.out.println(KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow()); } /** @@ -94,11 +92,33 @@ public class ColorPicker extends JDialog implements ActionListener public void updateLocation() { mousePos = MouseInfo.getPointerInfo().getLocation(); - setCoordinateX = mousePos.x - getSize().width/2; - setCoordinateY = mousePos.y- getSize().height/2; + updateCoordinate(); + setLocation(setCoordinateX, setCoordinateY); + updateMousePos(); + updateCoordinate(); colorPickerPanel.setMagnifierLocation(setCoordinateX, setCoordinateY); - setLocation(setCoordinateX, setCoordinateY); + + } + + private void updateCoordinate() { + setCoordinateX = mousePos.x - getSize().width / 2; + setCoordinateY = mousePos.y - getSize().height / 2; + } + + /** + * 兼容多屏下鼠标位置的计算 + */ + private void updateMousePos() { + Rectangle bounds = GUICoreUtils.getRectScreen(); + mousePos.x -= bounds.x; + mousePos.y -= bounds.y; + if (mousePos.x < 0) { + mousePos.x *= -1; + } + if (mousePos.y < 0) { + mousePos.y *= -1; + } } /** @@ -106,8 +126,7 @@ public class ColorPicker extends JDialog implements ActionListener * * @param colorPickerSize 取色框尺寸 */ - public void updateSize(int colorPickerSize) - { + public void updateSize(int colorPickerSize) { colorPickerPanel.setColorPickerSize(colorPickerSize); setSize(colorPickerSize, colorPickerSize); validate(); // 更新所有子控件 @@ -124,20 +143,19 @@ public class ColorPicker extends JDialog implements ActionListener // 隐藏鼠标光标 public void hideCursor() { Image imageCursor = Toolkit.getDefaultToolkit().getImage(""); - Cursor cu = Toolkit.getDefaultToolkit().createCustomCursor(imageCursor, new Point(0,0), "cursor"); + Cursor cu = Toolkit.getDefaultToolkit().createCustomCursor(imageCursor, new Point(0, 0), "cursor"); setCursor(cu); } - private class MouseFunctions extends MouseAdapter - { + private class MouseFunctions extends MouseAdapter { + @Override public void mousePressed(MouseEvent e) { - pickComplete(e.getButton() == e.BUTTON1); // 左键确定 + pickComplete(e.getButton() == MouseEvent.BUTTON1); // 左键确定 } } } -class ColorPickerPanel extends JPanel -{ +class ColorPickerPanel extends JPanel { private BufferedImage screenImage; private Image colorPickerFrame; // 取色框的边框图案 private int colorPickerSize; // 取色框尺寸 @@ -154,11 +172,11 @@ class ColorPickerPanel extends JPanel /** * 带参数的构造函数 - * @param scaleFactor 放大倍数 + * + * @param scaleFactor 放大倍数 */ - public ColorPickerPanel(int scaleFactor) - { - colorPickerFrame = BaseUtils.readImage("/com/fr/design/images/gui/colorPicker/colorPickerFrame.png"); + public ColorPickerPanel(int scaleFactor) { + colorPickerFrame = IOUtils.readImage("/com/fr/design/images/gui/colorPicker/colorPickerFrame.png"); this.scaleFactor = scaleFactor; captureScreen(); } @@ -169,25 +187,20 @@ class ColorPickerPanel extends JPanel public void captureScreen() { try { robot = new Robot(); - } - catch (AWTException e) { + } catch (AWTException e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); } // 截屏幕 - Rectangle rectangle = new Rectangle(0, 0, 0, 0); - for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) { - rectangle = rectangle.union(gd.getDefaultConfiguration().getBounds()); - } - screenImage = robot.createScreenCapture(rectangle); + screenImage = robot.createScreenCapture(GUICoreUtils.getRectScreen()); } /** * 设置取色框的位置 - * @param locationX x坐标 - * @param locationY y坐标 + * + * @param locationX x坐标 + * @param locationY y坐标 */ - public void setMagnifierLocation(int locationX, int locationY) - { + public void setMagnifierLocation(int locationX, int locationY) { this.locationX = locationX; this.locationY = locationY; repaint(); // 注意重画控件 @@ -201,17 +214,16 @@ class ColorPickerPanel extends JPanel return new Color(R, G, B); } - public void setColorPickerSize(int colorPickerSize) - { + public void setColorPickerSize(int colorPickerSize) { this.colorPickerSize = colorPickerSize; } - public void paintComponent(Graphics g) - { + @Override + public void paintComponent(Graphics 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( screenImage, // 要画的图片 @@ -219,10 +231,10 @@ class ColorPickerPanel extends JPanel 0, // 目标矩形的第一个角的y坐标 colorPickerSize, // 目标矩形的第二个角的x坐标 colorPickerSize, // 目标矩形的第二个角的y坐标 - locationX + (int)((colorPickerSize - pixelCount) * 0.5) + 1, // 源矩形的第一个角的x坐标 - locationY + (int)((colorPickerSize - pixelCount) * 0.5) + 1, // 源矩形的第一个角的y坐标 - locationX + (int)((colorPickerSize + pixelCount) * 0.5) + 1, // 源矩形的第二个角的x坐标 - locationY + (int)((colorPickerSize + pixelCount) * 0.5) + 1, // 源矩形的第二个角的y坐标 + locationX + (int) ((colorPickerSize - pixelCount) * 0.5) + 1, // 源矩形的第一个角的x坐标 + locationY + (int) ((colorPickerSize - pixelCount) * 0.5) + 1, // 源矩形的第一个角的y坐标 + locationX + (int) ((colorPickerSize + pixelCount) * 0.5) + 1, // 源矩形的第二个角的x坐标 + locationY + (int) ((colorPickerSize + pixelCount) * 0.5) + 1, // 源矩形的第二个角的y坐标 this ); g2d.drawImage(colorPickerFrame, 0, 0, this); diff --git a/designer-base/src/main/java/com/fr/design/utils/gui/GUICoreUtils.java b/designer-base/src/main/java/com/fr/design/utils/gui/GUICoreUtils.java index c8c0561c90..fdc0d0f0c7 100644 --- a/designer-base/src/main/java/com/fr/design/utils/gui/GUICoreUtils.java +++ b/designer-base/src/main/java/com/fr/design/utils/gui/GUICoreUtils.java @@ -60,19 +60,7 @@ import javax.swing.border.TitledBorder; import javax.swing.event.ChangeListener; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Component; -import java.awt.Cursor; -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.Font; -import java.awt.GridLayout; -import java.awt.Image; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.Toolkit; -import java.awt.Window; +import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; @@ -962,4 +950,16 @@ public final class GUICoreUtils { } return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, 0, 10); } + + /** + * 获取当前所有显示器设备的总长总宽 + * @return + */ + public static Rectangle getRectScreen() { + Rectangle rectangle = new Rectangle(0, 0, 0, 0); + for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) { + rectangle = rectangle.union(gd.getDefaultConfiguration().getBounds()); + } + return rectangle; + } } diff --git a/designer-form/src/main/java/com/fr/design/designer/properties/EventPropertyTable.java b/designer-form/src/main/java/com/fr/design/designer/properties/EventPropertyTable.java index 1592b0fd01..ec953b9da3 100644 --- a/designer-form/src/main/java/com/fr/design/designer/properties/EventPropertyTable.java +++ b/designer-form/src/main/java/com/fr/design/designer/properties/EventPropertyTable.java @@ -28,6 +28,7 @@ public class EventPropertyTable extends UIListControlPane { public EventPropertyTable(FormDesigner designer) { super(); + this.setNameListEditable(false); this.designer = designer; } From 514844ae5f9f767f7ecfb9b83492104c7ec58524 Mon Sep 17 00:00:00 2001 From: hades Date: Wed, 9 Oct 2019 16:16:04 +0800 Subject: [PATCH 2/2] update --- .../com/fr/design/utils/gui/GUICoreUtils.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/designer-base/src/main/java/com/fr/design/utils/gui/GUICoreUtils.java b/designer-base/src/main/java/com/fr/design/utils/gui/GUICoreUtils.java index fdc0d0f0c7..22107bf8ad 100644 --- a/designer-base/src/main/java/com/fr/design/utils/gui/GUICoreUtils.java +++ b/designer-base/src/main/java/com/fr/design/utils/gui/GUICoreUtils.java @@ -60,12 +60,26 @@ import javax.swing.border.TitledBorder; import javax.swing.event.ChangeListener; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; -import java.awt.*; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Component; +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.GridLayout; +import java.awt.Image; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Toolkit; +import java.awt.Window; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.image.BufferedImage; import java.awt.image.ImageObserver; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; import java.util.ArrayList; import java.util.Arrays; import java.util.List;