Browse Source

Pull request #13471: REPORT-99485 工具栏ButtonGroup样式调整

Merge in DESIGN/design from ~VITO/c-design:newui to newui

* commit 'd4e12822223e4bc064b1ff0043440a4140c34a30':
  REPORT-99485 工具栏ButtonGroup样式调整
newui
vito-刘恒霖 1 year ago
parent
commit
c6a0d4c8c0
  1. 10
      designer-base/src/main/java/com/fine/theme/light/ui/FineButtonGroupUI.java
  2. 11
      designer-base/src/main/java/com/fine/theme/light/ui/FineRoundBorder.java
  3. 15
      designer-base/src/main/java/com/fine/theme/utils/FineUIStyle.java
  4. 25
      designer-base/src/main/java/com/fr/design/gui/ibutton/UIButtonGroup.java
  5. 8
      designer-base/src/main/resources/com/fine/theme/light/ui/laf/FineLightLaf.properties
  6. 14
      designer-base/src/test/java/com/fr/design/gui/storybook/components/ButtonGroupStoryBoard.java
  7. 6
      designer-realize/src/main/java/com/fr/design/actions/ButtonGroupAction.java
  8. 7
      designer-realize/src/main/java/com/fr/design/actions/cell/style/AlignmentAction.java

10
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,10 +27,13 @@ public class FineButtonGroupUI extends PanelUI {
}
@Override
public void installUI(JComponent c) {
super.installUI(c);
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) {

11
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();
}
}

15
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";
}

25
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<T> extends Column implements GlobalNameObserver, UIObserver {
private static final String UI_CLASS_ID = "ButtonGroupUI";
@ -51,6 +54,8 @@ public class UIButtonGroup<T> 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<T> 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<T> 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<T> extends Column implements GlobalNameObserver, UIOb
/**
* 计算按钮位于整个按钮组件中的位置
*
* @param index 按钮序号
* @return 按钮位置详见 {@link com.fine.theme.utils.FineClientProperties}
*/
@ -256,13 +267,21 @@ public class UIButtonGroup<T> 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);

8
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

14
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<Object> 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"))

6
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<Integer> createToolBarComponent() {
if(group == null) {
group = new UIButtonGroup<Integer>(iconArray, valueArray);
group = new UIButtonGroup<Integer>(iconArray, valueArray, true);
group.addActionListener(this);
}
return group;

7
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;
}

Loading…
Cancel
Save