From f0be7e2883a6133b0256faa4149295d533ce33c0 Mon Sep 17 00:00:00 2001 From: obo Date: Thu, 8 Aug 2024 10:08:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E9=99=A4=E4=B8=A5=E9=87=8D=E8=AD=A6?= =?UTF-8?q?=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/fr/base/i18n/BidiUtils.java | 43 ++++++++++-- .../com/fr/design/gui/ilable/UILabel.java | 6 +- .../com/fr/design/gui/imenu/UIMenuItemUI.java | 26 ++++++-- .../mainframe/EastRegionContainerPane.java | 9 ++- .../style/color/NewColorSelectPane.java | 66 +++++++++++-------- .../com/fr/design/utils/LinkStrUtils.java | 1 - 6 files changed, 106 insertions(+), 45 deletions(-) diff --git a/designer-base/src/main/java/com/fr/base/i18n/BidiUtils.java b/designer-base/src/main/java/com/fr/base/i18n/BidiUtils.java index b11e6340da..63fefd550d 100644 --- a/designer-base/src/main/java/com/fr/base/i18n/BidiUtils.java +++ b/designer-base/src/main/java/com/fr/base/i18n/BidiUtils.java @@ -17,44 +17,73 @@ import java.util.Locale; */ public class BidiUtils { + /** + * 设计器国际化 + */ private static final Locale LOCALE = DesignerEnvManager.getEnvManager().getLanguage(); private BidiUtils() { } + /** + * 获取当前设计器语言的组件方向值 + */ public static ComponentOrientation getOrientationByLocale() { return ComponentOrientation.getOrientation(LOCALE); } + /** + * 把当前设计器国际化的组件方向应用到组件,影响子组件 + * + * @param component 组件 + * @return 组件对象 + * @param Component子类 + */ public static T applyOrientationByLocale(T component) { component.applyComponentOrientation(ComponentOrientation.getOrientation(LOCALE)); return component; } + /** + * 把当前设计器国际化的组件方向设置到组件,不影响子组件 + * + * @param component 组件 + * @return 组件对象 + * @param Component子类 + */ public static T setOrientationByLocale(T component) { component.setComponentOrientation(ComponentOrientation.getOrientation(LOCALE)); return component; } + /** + * 设置设计器国际化组件方向到多个组件,不影响子组件 + * + * @param components 组件数组 + */ public static void setOrientationByLocale(Component... components) { for (Component component : components) { component.setComponentOrientation(ComponentOrientation.getOrientation(LOCALE)); } } + /** + * 应用设计器国际化组件方向到多个组件,影响子组件 + * + * @param components 组件数组 + */ public static void applyOrientationByLocale(Component... components) { for (Component component : components) { component.applyComponentOrientation(ComponentOrientation.getOrientation(LOCALE)); } } + /** + * 判断当前设计器组件方向是否为rtl + */ public static boolean rtl() { return ComponentOrientation.getOrientation(LOCALE) == ComponentOrientation.RIGHT_TO_LEFT; } - - /** - * 拼接字符数组,有的组件名是多段字符串拼接起来的,如果是rtl的话需要反向拼接 - */ public static String concatenateStrings(String... strs) { StringBuilder result = new StringBuilder(); @@ -70,6 +99,12 @@ public class BidiUtils { return result.toString(); } + /** + * 根据组件方向调整titleBorder的标题位置 + * @param titledBorder + * @return + * @param + */ public static T applyTitledBorderJustification(T titledBorder) { titledBorder.setTitleJustification(BidiUtils.rtl() ? TitledBorder.RIGHT : TitledBorder.LEFT); return titledBorder; diff --git a/designer-base/src/main/java/com/fr/design/gui/ilable/UILabel.java b/designer-base/src/main/java/com/fr/design/gui/ilable/UILabel.java index f47ccfc8b7..1e7e0ff7c3 100644 --- a/designer-base/src/main/java/com/fr/design/gui/ilable/UILabel.java +++ b/designer-base/src/main/java/com/fr/design/gui/ilable/UILabel.java @@ -22,7 +22,7 @@ import java.awt.Dimension; */ public class UILabel extends JLabel implements UITextComponent { private static final int HTML_SHIFT_HEIGHT = 3; - + private static final String COLON = ":"; public UILabel(String text, Icon image, int horizontalAlignment) { super(text, image, horizontalAlignment); if (image != null && text != null) { @@ -84,8 +84,8 @@ public class UILabel extends JLabel implements UITextComponent { return; } String text = this.getText(); - if (StringUtils.isNotEmpty(text) && text.length() > 1 && text.charAt(text.length() - 1) == ':') { - text = ":" + text.substring(0, text.length() - 1); + if (StringUtils.isNotEmpty(text) && text.length() > 1 && StringUtils.equals(String.valueOf(text.charAt(text.length() - 1)), COLON)) { + text = COLON + text.substring(0, text.length() - 1); this.setText(text); } } diff --git a/designer-base/src/main/java/com/fr/design/gui/imenu/UIMenuItemUI.java b/designer-base/src/main/java/com/fr/design/gui/imenu/UIMenuItemUI.java index c5217331c0..14e5e64377 100644 --- a/designer-base/src/main/java/com/fr/design/gui/imenu/UIMenuItemUI.java +++ b/designer-base/src/main/java/com/fr/design/gui/imenu/UIMenuItemUI.java @@ -21,7 +21,11 @@ import java.awt.Rectangle; * created by Harrison on 2020/03/22 **/ public class UIMenuItemUI extends BasicMenuItemUI { - + + private static final int RTL_X = 5; + private static final int ICON_WIDTH = 30; + private static final int ARC = 7; + @Override protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) { if (menuItem.getIcon() == null) { @@ -35,20 +39,28 @@ public class UIMenuItemUI extends BasicMenuItemUI { g.setColor(UIConstants.NORMAL_BACKGROUND); g.fillRect(0, 0, menuWidth, menuHeight); - int bidiX = BidiUtils.rtl() ? 5 : 30; + int bidiX = BidiUtils.rtl() ? RTL_X : ICON_WIDTH; if (menuItem.isOpaque()) { - if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) { - GUIPaintUtils.fillPaint((Graphics2D) g, bidiX, 0, menuWidth - 30, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, 7); + if (itemArmedOrSelected(model, menuItem)) { + GUIPaintUtils.fillPaint((Graphics2D) g, bidiX, 0, menuWidth - ICON_WIDTH, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, ARC); } else { - GUIPaintUtils.fillPaint((Graphics2D) g, bidiX, 0, menuWidth - 30, menuHeight, true, Constants.NULL, menuItem.getBackground(), 7); + GUIPaintUtils.fillPaint((Graphics2D) g, bidiX, 0, menuWidth - ICON_WIDTH, menuHeight, true, Constants.NULL, menuItem.getBackground(), ARC); } g.setColor(oldColor); - } else if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) { - GUIPaintUtils.fillPaint((Graphics2D) g, bidiX, 0, menuWidth - 30, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, 7); + } else if (itemArmedOrSelected(model, menuItem)) { + GUIPaintUtils.fillPaint((Graphics2D) g, bidiX, 0, menuWidth - ICON_WIDTH, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, ARC); g.setColor(oldColor); } } + /** + * 按钮被触发,或菜单项被选中 + * 抽个方法 + */ + private boolean itemArmedOrSelected(ButtonModel model, JMenuItem menuItem) { + return model.isArmed() || (menuItem instanceof JMenu && model.isSelected()); + } + protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect, String text) { ButtonModel model = menuItem.getModel(); FontMetrics fm = SwingUtilities2.getFontMetrics(menuItem, g); diff --git a/designer-base/src/main/java/com/fr/design/mainframe/EastRegionContainerPane.java b/designer-base/src/main/java/com/fr/design/mainframe/EastRegionContainerPane.java index 8604fbbfa0..06e822f74c 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/EastRegionContainerPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/EastRegionContainerPane.java @@ -83,6 +83,7 @@ public class EastRegionContainerPane extends UIEastResizableContainer { private static final int CONTENT_WIDTH = CONTAINER_WIDTH - TAB_WIDTH; private static final int POPUP_TOOLPANE_HEIGHT = 27; private static final int ARROW_RANGE_START = CONTENT_WIDTH - 30; + private static final int ARROW_WIDTH = 30; // 弹出对话框高度 private static final int POPUP_MIN_HEIGHT = 145; private static final int POPUP_DEFAULT_HEIGHT = 356; @@ -1190,7 +1191,9 @@ public class EastRegionContainerPane extends UIEastResizableContainer { @Override public void mouseClicked(MouseEvent e) { - if ((BidiUtils.rtl() && e.getX() <= 30) || (!BidiUtils.rtl() && e.getX() >= ARROW_RANGE_START)) { + if (BidiUtils.rtl() && e.getX() <= ARROW_WIDTH) { + onPop(); + } else if (e.getX() >= ARROW_RANGE_START) { onPop(); } } @@ -1205,7 +1208,9 @@ public class EastRegionContainerPane extends UIEastResizableContainer { @Override public void mousePressed(MouseEvent e) { - if ((BidiUtils.rtl() && e.getX() > 30) || (!BidiUtils.rtl() && e.getX() < ARROW_RANGE_START)) { + if (BidiUtils.rtl() && e.getX() <= ARROW_WIDTH) { + mouseDownCompCoords = e.getPoint(); + } else if (e.getX() >= ARROW_RANGE_START) { mouseDownCompCoords = e.getPoint(); } } diff --git a/designer-base/src/main/java/com/fr/design/style/color/NewColorSelectPane.java b/designer-base/src/main/java/com/fr/design/style/color/NewColorSelectPane.java index fb1e77869a..7540e84338 100644 --- a/designer-base/src/main/java/com/fr/design/style/color/NewColorSelectPane.java +++ b/designer-base/src/main/java/com/fr/design/style/color/NewColorSelectPane.java @@ -155,7 +155,6 @@ public class NewColorSelectPane extends BasicPane implements ColorSelectable { JPanel themeColorPane = new JPanel(new BorderLayout(0, 5)); themeColorPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); themeColorPane.add(createColorSelectPaneLabel(Toolkit.i18nText("Fine-Design_Basic_Theme_Color")), BorderLayout.CENTER); - themeColorPane.add(menuColorPane, BorderLayout.SOUTH); menuColorPane.setLayout(new BorderLayout(0, 10)); @@ -164,22 +163,26 @@ public class NewColorSelectPane extends BasicPane implements ColorSelectable { menuColorPane.add(northPane, BorderLayout.NORTH); menuColorPane.add(centerPane, BorderLayout.CENTER); - Color[] colorArray = new Color[]{ - // 8列主题色 - Color.decode("#FFFFFF"), - Color.decode("#CCCCCC"), - Color.decode("#FFFFFF"), - Color.decode("#CCCCCC"), - Color.decode("#FFFFFF"), - Color.decode("#CCCCCC"), - Color.decode("#FFFFFF"), - Color.decode("#CCCCCC"), - - // 2列灰度色 - Color.decode("#000000"), - Color.decode("#FFFFFF"), - }; + Color[] colorArray = createColorArray(); + initThemeColorCellGrid(colorArray); + for (int i = 0; i < colorArray.length; i++) { + northPane.add(themeColorCellGrid[i][0]); + } + for (int i = 0; i < colorArray.length; i++) { + JPanel columnPane = new JPanel(new GridLayout(DEFAULT_DERIVE_COUNT - 1, 1, 0, 0)); + for (int j = 1; j < DEFAULT_DERIVE_COUNT; j++) { + columnPane.add(themeColorCellGrid[i][j]); + } + centerPane.add(columnPane); + } + refreshThemeMenuColorPane(); + return themeColorPane; + } + /** + * 初始化themeColorCellGrid + */ + private void initThemeColorCellGrid(Color[] colorArray) { if (themeColorCellGrid == null) { themeColorCellGrid = new ColorCell[colorArray.length][DEFAULT_DERIVE_COUNT]; for (int i = 0; i < colorArray.length; i++) { @@ -193,20 +196,27 @@ public class NewColorSelectPane extends BasicPane implements ColorSelectable { themeColorCellGrid[i] = colorCellColumn; } } + } - for (int i = 0; i < colorArray.length; i++) { - northPane.add(themeColorCellGrid[i][0]); - } - for (int i = 0; i < colorArray.length; i++) { - JPanel columnPane = new JPanel(new GridLayout(DEFAULT_DERIVE_COUNT - 1, 1, 0, 0)); - for (int j = 1; j < DEFAULT_DERIVE_COUNT; j++) { - columnPane.add(themeColorCellGrid[i][j]); - } - centerPane.add(columnPane); - } + /** + * 创建color数组对象,抽方法降复杂度 + */ + private Color[] createColorArray() { + return new Color[]{ + // 8列主题色 + Color.decode("#FFFFFF"), + Color.decode("#CCCCCC"), + Color.decode("#FFFFFF"), + Color.decode("#CCCCCC"), + Color.decode("#FFFFFF"), + Color.decode("#CCCCCC"), + Color.decode("#FFFFFF"), + Color.decode("#CCCCCC"), - refreshThemeMenuColorPane(); - return themeColorPane; + // 2列灰度色 + Color.decode("#000000"), + Color.decode("#FFFFFF"), + }; } private void refreshThemeMenuColorPane() { diff --git a/designer-base/src/main/java/com/fr/design/utils/LinkStrUtils.java b/designer-base/src/main/java/com/fr/design/utils/LinkStrUtils.java index bbee1f4643..666d17b84a 100644 --- a/designer-base/src/main/java/com/fr/design/utils/LinkStrUtils.java +++ b/designer-base/src/main/java/com/fr/design/utils/LinkStrUtils.java @@ -53,7 +53,6 @@ public class LinkStrUtils { StringBuilder style = new StringBuilder("font-family:" + font.getFamily() + ";"); style.append("font-weight:").append(font.isBold() ? "bold" : "normal").append(";"); - //style.append("margin-bottom:").append("5px").append(";"); style.append("font-size:").append(font.getSize()).append("pt;"); style.append("color:rgb(").append(fontColor.getRed()).append(",").append(fontColor.getGreen()).append(",").append(fontColor.getBlue()).append(");"); style.append("background-color: rgb(").append(backgroundColor.getRed()).append(",").append(backgroundColor.getGreen()).append(",").append(backgroundColor.getBlue()).append(");");