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..bd31f513e1 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); } @@ -101,6 +99,7 @@ public class UIButtonGroup extends Column implements GlobalNameObserver, UIOb }; initButton(labelButton, index); } + setBorder(new FineRoundBorder()); initLayout(getCols()); } @@ -109,7 +108,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 +140,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) { @@ -177,6 +176,7 @@ public class UIButtonGroup extends Column implements GlobalNameObserver, UIOb }; initButton(labelButton, index); } + setBorder(new FineRoundBorder()); initLayout(getCols()); } @@ -194,13 +194,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 +217,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 +273,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; }