From 4c2dee60330e8620f9c6da8d8fad1afc2641eef1 Mon Sep 17 00:00:00 2001 From: vito Date: Thu, 14 Dec 2023 14:36:23 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-99485=20Storybook=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=B8=BB=E9=A2=98=E5=8F=8ADPI=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/gui/storybook/Storybook.java | 117 +++++++++++++++++- .../{ => components}/ButtonStoryBoard.java | 3 +- .../components/EastRegionContainer.java | 19 +++ .../ToggleButtonStoryBoard.java | 3 +- .../UIHeadGroupStoryBoard.java | 5 +- 5 files changed, 141 insertions(+), 6 deletions(-) rename designer-base/src/test/java/com/fr/design/gui/storybook/{ => components}/ButtonStoryBoard.java (90%) create mode 100644 designer-base/src/test/java/com/fr/design/gui/storybook/components/EastRegionContainer.java rename designer-base/src/test/java/com/fr/design/gui/storybook/{ => components}/ToggleButtonStoryBoard.java (89%) rename designer-base/src/test/java/com/fr/design/gui/storybook/{ => components}/UIHeadGroupStoryBoard.java (93%) diff --git a/designer-base/src/test/java/com/fr/design/gui/storybook/Storybook.java b/designer-base/src/test/java/com/fr/design/gui/storybook/Storybook.java index e6621cddca..4094163384 100644 --- a/designer-base/src/test/java/com/fr/design/gui/storybook/Storybook.java +++ b/designer-base/src/test/java/com/fr/design/gui/storybook/Storybook.java @@ -2,17 +2,34 @@ package com.fr.design.gui.storybook; import com.fanruan.gui.UiInspector; import com.fine.theme.light.ui.laf.FineLightLaf; +import com.formdev.flatlaf.FlatDarkLaf; +import com.formdev.flatlaf.FlatLaf; +import com.formdev.flatlaf.FlatLightLaf; +import com.formdev.flatlaf.extras.FlatAnimatedLafChange; import com.formdev.flatlaf.util.ScaledEmptyBorder; +import com.fr.design.gui.UILookAndFeel; +import com.fr.design.gui.storybook.components.ButtonStoryBoard; +import com.fr.design.gui.storybook.components.EastRegionContainer; +import com.fr.design.gui.storybook.components.ToggleButtonStoryBoard; +import com.fr.design.gui.storybook.components.UIHeadGroupStoryBoard; import javax.swing.DefaultListCellRenderer; import javax.swing.JFrame; import javax.swing.JList; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JScrollPane; +import javax.swing.KeyStroke; +import javax.swing.LookAndFeel; import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import javax.swing.UnsupportedLookAndFeelException; import java.awt.BorderLayout; -import java.awt.CardLayout; import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.KeyEvent; import java.util.ArrayList; import static com.fine.swing.ui.layout.Layouts.cell; @@ -29,12 +46,12 @@ import static com.fine.theme.utils.FineUIScale.scale; */ public class Storybook { - CardLayout cardLayout; JPanel cards; public void start() { FineLightLaf.setup(); JFrame jf = new JFrame("Story Book"); + jf.setJMenuBar(initMenu()); jf.add(row( cell(new JList<>(components())).with(it -> { it.setBorder(new ScaledEmptyBorder(10, 10, 10, 10)); @@ -74,9 +91,105 @@ public class Storybook { components.add(new StoryBookComponent("Button", new ButtonStoryBoard())); components.add(new StoryBookComponent("HeadGroup", new UIHeadGroupStoryBoard())); components.add(new StoryBookComponent("ToggleButton", new ToggleButtonStoryBoard())); + components.add(new StoryBookComponent("EastRegionContainer", new EastRegionContainer())); return components.toArray(new StoryBookComponent[0]); } + /** + * 应用主题 + */ + private void applyLookAndFeel(LookAndFeel lookAndFeel) { + FlatAnimatedLafChange.showSnapshot(); + try { + UIManager.setLookAndFeel(lookAndFeel); + } catch (UnsupportedLookAndFeelException e) { + throw new RuntimeException(e); + } + FlatLaf.updateUI(); + FlatAnimatedLafChange.hideSnapshotWithAnimation(); + } + + /** + * 应用DPI + */ + private void applyDPI(float dpi) { + System.setProperty("flatlaf.uiScale", String.valueOf(dpi)); + FlatAnimatedLafChange.showSnapshot(); + FineLightLaf.setup(); + FlatLaf.updateUI(); + FlatAnimatedLafChange.hideSnapshotWithAnimation(); + } + + /** + * 添加外观和缩放 + * + * @return 菜单 + */ + private JMenuBar initMenu() { + JMenuBar menuBar = new JMenuBar(); + + JMenu menu = new JMenu("外观"); + menu.setMnemonic(KeyEvent.VK_A); + menuBar.add(menu); + + JMenuItem menuItem = new JMenuItem("Fine New UI", + KeyEvent.VK_T); + menuItem.setAccelerator(KeyStroke.getKeyStroke( + KeyEvent.VK_1, ActionEvent.ALT_MASK)); + menuItem.addActionListener(e -> applyLookAndFeel(new FineLightLaf())); + menu.add(menuItem); + + menuItem = new JMenuItem("Flat Dark", + KeyEvent.VK_T); + menuItem.setAccelerator(KeyStroke.getKeyStroke( + KeyEvent.VK_2, ActionEvent.ALT_MASK)); + menuItem.addActionListener(e -> applyLookAndFeel(new FlatDarkLaf())); + menu.add(menuItem); + + menuItem = new JMenuItem("Flat Light", KeyEvent.VK_T); + menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3, ActionEvent.ALT_MASK)); + menuItem.addActionListener(e -> applyLookAndFeel(new FlatLightLaf())); + menu.add(menuItem); + + + menuItem = new JMenuItem("FR11", + KeyEvent.VK_T); + menuItem.setAccelerator(KeyStroke.getKeyStroke( + KeyEvent.VK_4, ActionEvent.ALT_MASK)); + menuItem.addActionListener(e -> applyLookAndFeel(new UILookAndFeel())); + menu.add(menuItem); + + menu = new JMenu("缩放"); + menu.setMnemonic(KeyEvent.VK_A); + menuBar.add(menu); + + menuItem = new JMenuItem("100%(96dpi)", + KeyEvent.VK_Y); + menuItem.setAccelerator(KeyStroke.getKeyStroke( + KeyEvent.VK_1, ActionEvent.META_MASK)); + menuItem.addActionListener(e -> applyDPI(1.0f)); + + menu.add(menuItem); + menuItem = new JMenuItem("150%(144dpi)", + KeyEvent.VK_Y); + menuItem.setAccelerator(KeyStroke.getKeyStroke( + KeyEvent.VK_2, ActionEvent.META_MASK)); + menuItem.addActionListener(e -> applyDPI(1.5f)); + menu.add(menuItem); + + menu.add(menuItem); + menuItem = new JMenuItem("200%(192dpi)", + KeyEvent.VK_Y); + menuItem.setAccelerator(KeyStroke.getKeyStroke( + KeyEvent.VK_3, ActionEvent.META_MASK)); + menuItem.addActionListener(e -> applyDPI(2.0f)); + menu.add(menuItem); + + + return menuBar; + + } + public static void main(String... args) { SwingUtilities.invokeLater(() -> new Storybook().start()); diff --git a/designer-base/src/test/java/com/fr/design/gui/storybook/ButtonStoryBoard.java b/designer-base/src/test/java/com/fr/design/gui/storybook/components/ButtonStoryBoard.java similarity index 90% rename from designer-base/src/test/java/com/fr/design/gui/storybook/ButtonStoryBoard.java rename to designer-base/src/test/java/com/fr/design/gui/storybook/components/ButtonStoryBoard.java index 17646a18dc..86937b0441 100644 --- a/designer-base/src/test/java/com/fr/design/gui/storybook/ButtonStoryBoard.java +++ b/designer-base/src/test/java/com/fr/design/gui/storybook/components/ButtonStoryBoard.java @@ -1,7 +1,8 @@ -package com.fr.design.gui.storybook; +package com.fr.design.gui.storybook.components; import com.fine.theme.icon.LazyIcon; import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.storybook.StoryBoard; import javax.swing.JButton; diff --git a/designer-base/src/test/java/com/fr/design/gui/storybook/components/EastRegionContainer.java b/designer-base/src/test/java/com/fr/design/gui/storybook/components/EastRegionContainer.java new file mode 100644 index 0000000000..267df28e0d --- /dev/null +++ b/designer-base/src/test/java/com/fr/design/gui/storybook/components/EastRegionContainer.java @@ -0,0 +1,19 @@ +package com.fr.design.gui.storybook.components; + +import com.fr.design.gui.storybook.StoryBoard; +import com.fr.design.mainframe.EastRegionContainerPane; + +/** + * 东区 + * + * @author vito + * @since 11.0 + * Created on 2023/11/28 + */ +public class EastRegionContainer extends StoryBoard { + + public EastRegionContainer() { + super("东区工具栏"); + add(EastRegionContainerPane.getInstance()); + } +} diff --git a/designer-base/src/test/java/com/fr/design/gui/storybook/ToggleButtonStoryBoard.java b/designer-base/src/test/java/com/fr/design/gui/storybook/components/ToggleButtonStoryBoard.java similarity index 89% rename from designer-base/src/test/java/com/fr/design/gui/storybook/ToggleButtonStoryBoard.java rename to designer-base/src/test/java/com/fr/design/gui/storybook/components/ToggleButtonStoryBoard.java index 8ef89bc40a..b60be87e66 100644 --- a/designer-base/src/test/java/com/fr/design/gui/storybook/ToggleButtonStoryBoard.java +++ b/designer-base/src/test/java/com/fr/design/gui/storybook/components/ToggleButtonStoryBoard.java @@ -1,6 +1,7 @@ -package com.fr.design.gui.storybook; +package com.fr.design.gui.storybook.components; import com.fine.theme.icon.LazyIcon; +import com.fr.design.gui.storybook.StoryBoard; import javax.swing.JToggleButton; diff --git a/designer-base/src/test/java/com/fr/design/gui/storybook/UIHeadGroupStoryBoard.java b/designer-base/src/test/java/com/fr/design/gui/storybook/components/UIHeadGroupStoryBoard.java similarity index 93% rename from designer-base/src/test/java/com/fr/design/gui/storybook/UIHeadGroupStoryBoard.java rename to designer-base/src/test/java/com/fr/design/gui/storybook/components/UIHeadGroupStoryBoard.java index 887c59e9e4..fb827881b4 100644 --- a/designer-base/src/test/java/com/fr/design/gui/storybook/UIHeadGroupStoryBoard.java +++ b/designer-base/src/test/java/com/fr/design/gui/storybook/components/UIHeadGroupStoryBoard.java @@ -1,9 +1,10 @@ -package com.fr.design.gui.storybook; +package com.fr.design.gui.storybook.components; import com.fine.theme.icon.LazyIcon; import com.fr.design.gui.ibutton.UIHead; import com.fr.design.gui.ibutton.UIHeadGroup; import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.storybook.StoryBoard; import java.util.ArrayList; import java.util.List; @@ -18,7 +19,7 @@ import static com.fine.swing.ui.layout.Layouts.flex; * @since 11.0 * Created on 2023/11/27 */ -class UIHeadGroupStoryBoard extends StoryBoard { +public class UIHeadGroupStoryBoard extends StoryBoard { public UIHeadGroupStoryBoard() { super("属性面板&导入数据集tab");