From 09cc08ab53b474ff075cbba62d6ee3c21fad8838 Mon Sep 17 00:00:00 2001 From: vito Date: Wed, 17 Jan 2024 11:24:32 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-99485=20=E4=BF=AE=E5=A4=8DUIButtonGroup?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E5=AF=BC=E8=87=B4=E6=97=A0=E9=99=90=E7=BB=98?= =?UTF-8?q?=E5=88=B6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../theme/light/ui/FineButtonGroupUI.java | 12 -------- .../fr/design/gui/ibutton/UIButtonGroup.java | 30 ++++++++++--------- .../components/ButtonGroupStoryBoard.java | 11 ++++--- .../fr/design/actions/ButtonGroupAction.java | 2 +- .../actions/cell/style/AlignmentAction.java | 8 +++-- 5 files changed, 28 insertions(+), 35 deletions(-) diff --git a/designer-base/src/main/java/com/fine/theme/light/ui/FineButtonGroupUI.java b/designer-base/src/main/java/com/fine/theme/light/ui/FineButtonGroupUI.java index dc65b33e81..bf59dda3a5 100644 --- a/designer-base/src/main/java/com/fine/theme/light/ui/FineButtonGroupUI.java +++ b/designer-base/src/main/java/com/fine/theme/light/ui/FineButtonGroupUI.java @@ -1,11 +1,8 @@ package com.fine.theme.light.ui; -import com.fr.design.gui.ibutton.UIButtonGroup; - import javax.swing.JComponent; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.PanelUI; -import java.awt.Graphics; /** * 按钮组UI,应用于 {@link com.fr.design.gui.ibutton.UIButtonGroup} @@ -26,15 +23,6 @@ public class FineButtonGroupUI extends PanelUI { return new FineButtonGroupUI(); } - @Override - public void update(Graphics g, JComponent c) { - UIButtonGroup group = (UIButtonGroup) c; - if (!group.isInToolbar()) { - c.setBorder(new FineRoundBorder()); - } - super.update(g, c); - } - @Override public void uninstallUI(JComponent c) { super.uninstallUI(c); diff --git a/designer-base/src/main/java/com/fr/design/gui/ibutton/UIButtonGroup.java b/designer-base/src/main/java/com/fr/design/gui/ibutton/UIButtonGroup.java index 7505eeb773..39dbc8a803 100644 --- a/designer-base/src/main/java/com/fr/design/gui/ibutton/UIButtonGroup.java +++ b/designer-base/src/main/java/com/fr/design/gui/ibutton/UIButtonGroup.java @@ -54,8 +54,6 @@ public class UIButtonGroup extends Column implements GlobalNameObserver, UIOb private UIObserverListener uiObserverListener; private boolean autoFireStateChanged = true; - private boolean inToolbar = false; - public UIButtonGroup(String[] textArray) { this(textArray, null); } @@ -109,7 +107,6 @@ public class UIButtonGroup extends Column implements GlobalNameObserver, UIOb } public UIButtonGroup(Icon[][] iconArray, T[] objects, boolean inToolbar) { - this.inToolbar = inToolbar; if (!ArrayUtils.isEmpty(objects) && iconArray.length == objects.length) { this.objectList = Arrays.asList(objects); } @@ -142,7 +139,8 @@ public class UIButtonGroup extends Column implements GlobalNameObserver, UIOb }; initButton(labelButton, index); } - initLayout(getCols()); + setForToolBarButtonGroup(inToolbar); + initLayout(getCols(), inToolbar); } public UIButtonGroup(String[] textArray, T[] objects) { @@ -194,13 +192,17 @@ public class UIButtonGroup extends Column implements GlobalNameObserver, UIOb return new int[]{totalButtonSize}; } - protected void initLayout(int[] cols) { + private void initLayout(int[] cols) { + initLayout(cols, false); + } + + protected void initLayout(int[] cols, boolean inToolbar) { int currentIndex = 0; for (int row = 0; row < cols.length; row++) { int col = cols[row]; Row rowContainer = new Row(); for (int j = 0; j < col; j++) { - rowContainer.add(cell(labelButtonList.get(currentIndex)).weight(1.0)); + rowContainer.add(cell(getLabelButtonList().get(currentIndex)).weight(1.0)); currentIndex++; if (j != col - 1 && !inToolbar) { rowContainer.add(createDivider()); @@ -213,6 +215,10 @@ public class UIButtonGroup extends Column implements GlobalNameObserver, UIOb } } + private List getLabelButtonList() { + return labelButtonList; + } + private Spacer createDivider() { Spacer spacer = new Spacer(FineUIScale.scale(1)); spacer.setBorder(new LineBorder(FineUIUtils.getUIColor("defaultBorderColor", "Component.borderColor"))); @@ -265,20 +271,16 @@ public class UIButtonGroup extends Column implements GlobalNameObserver, UIOb isClick = changeFlag; } - public void setForToolBarButtonGroup(boolean isToolBarComponent) { - if (isToolBarComponent) { - inToolbar = true; + private void setForToolBarButtonGroup(boolean inToolbar) { + if (inToolbar) { for (UIToggleButton button : labelButtonList) { button.putClientProperty(BUTTON_TYPE, BUTTON_TYPE_TOOLBAR_BUTTON); FineUIStyle.setStyle(button, IN_TOOLBAR_GROUP); button.setBorderPainted(false); } + } else { + setBorder(new FineRoundBorder()); } - repaint(); - } - - public boolean isInToolbar() { - return inToolbar; } @Override diff --git a/designer-base/src/test/java/com/fr/design/gui/storybook/components/ButtonGroupStoryBoard.java b/designer-base/src/test/java/com/fr/design/gui/storybook/components/ButtonGroupStoryBoard.java index 3c84e3371c..2b259dbe84 100644 --- a/designer-base/src/test/java/com/fr/design/gui/storybook/components/ButtonGroupStoryBoard.java +++ b/designer-base/src/test/java/com/fr/design/gui/storybook/components/ButtonGroupStoryBoard.java @@ -61,10 +61,9 @@ public class ButtonGroupStoryBoard extends StoryBoard { ArrayUtils.toArray(new LazyIcon("preview"), new LazyIcon("save")) )); - private static Component getToolbar(){ + private static Component getToolbar() { UIToolbar toolbar = new UIToolbar(); - UIButtonGroup objectUIButtonGroup = new UIButtonGroup<>(iconArrayWithWhite(),null,true); - objectUIButtonGroup.setForToolBarButtonGroup(true); + UIButtonGroup objectUIButtonGroup = new UIButtonGroup<>(iconArrayWithWhite(), null, true); toolbar.add(objectUIButtonGroup); return toolbar; } @@ -77,15 +76,15 @@ public class ButtonGroupStoryBoard extends StoryBoard { return iconArrayWithWhite.getValue(); } - private String[] fiveTextArray() { + private String[] fiveTextArray() { return ArrayUtils.toArray("按钮1", "按钮2", "按钮3", "按钮4", "按钮5"); } - private String[] sevenTextArray() { + private String[] sevenTextArray() { return ArrayUtils.toArray("按钮1", "按钮2", "按钮3", "按钮4", "按钮5", "按钮6", "按钮7"); } - private String[] sixTextArray() { + private String[] sixTextArray() { return ArrayUtils.toArray("按钮1", "按钮2", "按钮3", "按钮4", "按钮5", "按钮6"); } diff --git a/designer-realize/src/main/java/com/fr/design/actions/ButtonGroupAction.java b/designer-realize/src/main/java/com/fr/design/actions/ButtonGroupAction.java index 5381fb3a3f..ca15794bdd 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/ButtonGroupAction.java +++ b/designer-realize/src/main/java/com/fr/design/actions/ButtonGroupAction.java @@ -48,7 +48,7 @@ public abstract class ButtonGroupAction extends ElementCaseAction{ @Override public UIButtonGroup createToolBarComponent() { if(group == null) { - group = new UIButtonGroup(iconArray, valueArray, true); + group = new UIButtonGroup<>(iconArray, valueArray, true); group.addActionListener(this); } return group; diff --git a/designer-realize/src/main/java/com/fr/design/actions/cell/style/AlignmentAction.java b/designer-realize/src/main/java/com/fr/design/actions/cell/style/AlignmentAction.java index 9147b3d653..5bbd54a716 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/cell/style/AlignmentAction.java +++ b/designer-realize/src/main/java/com/fr/design/actions/cell/style/AlignmentAction.java @@ -16,6 +16,8 @@ import com.fr.stable.Constants; import javax.swing.Icon; +import static com.fr.design.i18n.Toolkit.i18nText; + public class AlignmentAction extends ButtonGroupAction implements StyleActionInterface { @@ -105,8 +107,10 @@ public class AlignmentAction extends ButtonGroupAction implements StyleActionInt public UIButtonGroup createToolBarComponent() { UIButtonGroup group = super.createToolBarComponent(); if (group != null) { - group.setForToolBarButtonGroup(true); - group.setAllToolTips(new String[]{com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_StyleAlignment_Left"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Center"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_StyleAlignment_Right")}); + group.setAllToolTips(new String[]{ + i18nText("Fine-Design_Basic_StyleAlignment_Left"), + i18nText("Fine-Design_Form_Center"), + i18nText("Fine-Design_Basic_StyleAlignment_Right")}); } return group; }