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 2035abf493..dc65b33e81 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,8 +1,11 @@ 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} @@ -24,9 +27,12 @@ public class FineButtonGroupUI extends PanelUI { } @Override - public void installUI(JComponent c) { - super.installUI(c); - c.setBorder(new FineRoundBorder()); + public void update(Graphics g, JComponent c) { + UIButtonGroup group = (UIButtonGroup) c; + if (!group.isInToolbar()) { + c.setBorder(new FineRoundBorder()); + } + super.update(g, c); } @Override diff --git a/designer-base/src/main/java/com/fine/theme/light/ui/FineRoundBorder.java b/designer-base/src/main/java/com/fine/theme/light/ui/FineRoundBorder.java index 3fe2129049..9538079996 100644 --- a/designer-base/src/main/java/com/fine/theme/light/ui/FineRoundBorder.java +++ b/designer-base/src/main/java/com/fine/theme/light/ui/FineRoundBorder.java @@ -8,6 +8,7 @@ import com.fr.design.event.HoverAware; import java.awt.Color; import java.awt.Component; import java.awt.Paint; +import java.util.StringJoiner; /** @@ -49,4 +50,14 @@ public class FineRoundBorder extends FlatRoundBorder { return highlightBorderColor; } + + @Override + public String toString() { + return new StringJoiner(", ", FineRoundBorder.class.getSimpleName() + "[", "]") + .add("borderColor=" + borderColor) + .add("arc=" + arc) + .add("roundRect=" + roundRect) + .add("borderWidth=" + borderWidth) + .toString(); + } } diff --git a/designer-base/src/main/java/com/fine/theme/utils/FineUIStyle.java b/designer-base/src/main/java/com/fine/theme/utils/FineUIStyle.java new file mode 100644 index 0000000000..35f489399e --- /dev/null +++ b/designer-base/src/main/java/com/fine/theme/utils/FineUIStyle.java @@ -0,0 +1,15 @@ +package com.fine.theme.utils; + +/** + * UI样式工具 + * + * @author vito + * @since 11.0 + * Created on 2024/1/4 + */ +public interface FineUIStyle { + + String IN_TOOLBAR_GROUP = "inToolbarGroup"; + + +} 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 4f5dadba45..ad2ca580e4 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 @@ -4,6 +4,7 @@ import com.fine.swing.ui.layout.Column; import com.fine.swing.ui.layout.Row; import com.fine.swing.ui.layout.Spacer; import com.fine.theme.light.ui.FineRoundBorder; +import com.fine.theme.utils.FineClientProperties; import com.fine.theme.utils.FineUIScale; import com.fine.theme.utils.FineUIUtils; import com.fr.design.event.GlobalNameListener; @@ -26,9 +27,9 @@ import java.util.Arrays; import java.util.List; import static com.fine.swing.ui.layout.Layouts.cell; -import static com.fine.theme.utils.FineClientProperties.BUTTON_TYPE_GROUP; -import static com.fine.theme.utils.FineClientProperties.BUTTON_TYPE; import static com.fine.theme.utils.FineClientProperties.BUTTON_GROUP_POSITION; +import static com.fine.theme.utils.FineClientProperties.BUTTON_TYPE; +import static com.fine.theme.utils.FineClientProperties.BUTTON_TYPE_GROUP; import static com.fine.theme.utils.FineClientProperties.GROUP_BUTTON_POSITION_INNER; import static com.fine.theme.utils.FineClientProperties.GROUP_BUTTON_POSITION_LEFT; import static com.fine.theme.utils.FineClientProperties.GROUP_BUTTON_POSITION_LEFT_BOTTOM; @@ -36,6 +37,8 @@ import static com.fine.theme.utils.FineClientProperties.GROUP_BUTTON_POSITION_LE import static com.fine.theme.utils.FineClientProperties.GROUP_BUTTON_POSITION_RIGHT; import static com.fine.theme.utils.FineClientProperties.GROUP_BUTTON_POSITION_RIGHT_BOTTOM; import static com.fine.theme.utils.FineClientProperties.GROUP_BUTTON_POSITION_RIGHT_TOP; +import static com.fine.theme.utils.FineUIStyle.IN_TOOLBAR_GROUP; +import static com.formdev.flatlaf.FlatClientProperties.BUTTON_TYPE_TOOLBAR_BUTTON; public class UIButtonGroup extends Column implements GlobalNameObserver, UIObserver { private static final String UI_CLASS_ID = "ButtonGroupUI"; @@ -51,6 +54,8 @@ 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); } @@ -100,6 +105,11 @@ public class UIButtonGroup extends Column implements GlobalNameObserver, UIOb } public UIButtonGroup(Icon[][] iconArray, T[] objects) { + this(iconArray, objects, false); + } + + public UIButtonGroup(Icon[][] iconArray, T[] objects, boolean inToolbar) { + this.inToolbar = inToolbar; if (!ArrayUtils.isEmpty(objects) && iconArray.length == objects.length) { this.objectList = Arrays.asList(objects); } @@ -192,7 +202,7 @@ public class UIButtonGroup extends Column implements GlobalNameObserver, UIOb for (int j = 0; j < col; j++) { rowContainer.add(cell(labelButtonList.get(currentIndex)).weight(1.0)); currentIndex++; - if (j != col - 1) { + if (j != col - 1 && !inToolbar) { rowContainer.add(createDivider()); } } @@ -219,6 +229,7 @@ public class UIButtonGroup extends Column implements GlobalNameObserver, UIOb /** * 计算按钮位于整个按钮组件中的位置 + * * @param index 按钮序号 * @return 按钮位置,详见 {@link com.fine.theme.utils.FineClientProperties} */ @@ -256,13 +267,21 @@ public class UIButtonGroup extends Column implements GlobalNameObserver, UIOb public void setForToolBarButtonGroup(boolean isToolBarComponent) { if (isToolBarComponent) { + inToolbar = true; for (UIToggleButton uiToggleButton : labelButtonList) { + uiToggleButton.putClientProperty(BUTTON_TYPE, BUTTON_TYPE_TOOLBAR_BUTTON); + FineClientProperties.setStyle(uiToggleButton, IN_TOOLBAR_GROUP); uiToggleButton.set4ToolbarButton(); + uiToggleButton.setBorderPainted(false); } } repaint(); } + public boolean isInToolbar() { + return inToolbar; + } + @Override public void setEnabled(boolean enabled) { super.setEnabled(enabled); diff --git a/designer-base/src/main/resources/com/fine/theme/light/ui/laf/FineLightLaf.properties b/designer-base/src/main/resources/com/fine/theme/light/ui/laf/FineLightLaf.properties index 4d5851c4b3..aaec48dfaa 100644 --- a/designer-base/src/main/resources/com/fine/theme/light/ui/laf/FineLightLaf.properties +++ b/designer-base/src/main/resources/com/fine/theme/light/ui/laf/FineLightLaf.properties @@ -1229,10 +1229,10 @@ CellOtherSetPane.height=$Component.defaultHeight background : #fff [style]Button.inToolbarLeft = \ - margin : 4,4,4,0 + margin : 3,3,3,3 [style]Button.inToolbarRight = \ - margin : 1,1,1,1 + margin : 0,0,0,0 [style]ToolBar.topTools = \ background: #fff @@ -1247,6 +1247,10 @@ CellOtherSetPane.height=$Component.defaultHeight foreground: $text.white;\ opaque: true +[style]ToggleButton.inToolbarGroup = \ + margin : 4,4,4,4; \ + background : #fff + #---- clearButton ---- # for clear/cancel button in text fields 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 72fa9228a6..46ede30053 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 @@ -4,11 +4,13 @@ import com.fine.theme.icon.LazyIcon; import com.fr.design.gui.ibutton.UIButtonGroup; import com.fr.design.gui.ibutton.UITabGroup; import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itoolbar.UIToolbar; import com.fr.design.gui.storybook.Story; import com.fr.design.gui.storybook.StoryBoard; import com.fr.stable.ArrayUtils; import javax.swing.Icon; +import java.awt.Component; import static com.fine.swing.ui.layout.Layouts.cell; import static com.fine.swing.ui.layout.Layouts.flex; @@ -41,10 +43,20 @@ public class ButtonGroupStoryBoard extends StoryBoard { cell(new UITabGroup(fiveTextArray())), cell(new UILabel("多行按钮-奇数场景-7按钮")).with(this::h3), cell(new UITabGroup(sevenTextArray())), + cell(new UILabel("单行按钮-工具栏")).with(this::h3), + cell(getToolbar()), flex() ); } + private static Component getToolbar(){ + UIToolbar toolbar = new UIToolbar(); + UIButtonGroup objectUIButtonGroup = new UIButtonGroup<>(iconArrayWithWhite(),null,true); + objectUIButtonGroup.setForToolBarButtonGroup(true); + toolbar.add(objectUIButtonGroup); + return toolbar; + } + private static Icon[] iconArray() { return ArrayUtils.toArray( new LazyIcon("edit"), @@ -53,7 +65,7 @@ public class ButtonGroupStoryBoard extends StoryBoard { ); } - private Icon[][] iconArrayWithWhite() { + private static Icon[][] iconArrayWithWhite() { return ArrayUtils.toArray( ArrayUtils.toArray(new LazyIcon("edit"), new LazyIcon("copy")), ArrayUtils.toArray(new LazyIcon("preview"), new LazyIcon("save")) 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 a0197fec96..5381fb3a3f 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 @@ -1,10 +1,10 @@ package com.fr.design.actions; -import javax.swing.Icon; - import com.fr.design.gui.ibutton.UIButtonGroup; import com.fr.design.mainframe.ElementCasePane; +import javax.swing.Icon; + public abstract class ButtonGroupAction extends ElementCaseAction{ protected Icon[][] iconArray; protected Integer[] valueArray; @@ -48,7 +48,7 @@ public abstract class ButtonGroupAction extends ElementCaseAction{ @Override public UIButtonGroup createToolBarComponent() { if(group == null) { - group = new UIButtonGroup(iconArray, valueArray); + 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 4a87155c26..9147b3d653 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 @@ -6,7 +6,6 @@ import com.fr.base.Style; import com.fr.base.chart.BaseChartCollection; import com.fr.design.actions.ButtonGroupAction; import com.fr.design.actions.utils.ReportActionUtils; -import com.fr.design.constants.UIConstants; import com.fr.design.gui.ibutton.UIButtonGroup; import com.fr.design.mainframe.ElementCasePane; import com.fr.grid.selection.FloatSelection; @@ -109,12 +108,6 @@ public class AlignmentAction extends ButtonGroupAction implements StyleActionInt 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")}); } - for (int i = 0; i < 3; i++) { - if (group != null) { - group.getButton(i).setRoundBorder(true, UIConstants.ARC); - group.getButton(i).setBorderPainted(true); - } - } return group; }