Browse Source

REPORT-99485 Storybook添加主题及DPI切换

newui
vito 12 months ago
parent
commit
4c2dee6033
  1. 117
      designer-base/src/test/java/com/fr/design/gui/storybook/Storybook.java
  2. 3
      designer-base/src/test/java/com/fr/design/gui/storybook/components/ButtonStoryBoard.java
  3. 19
      designer-base/src/test/java/com/fr/design/gui/storybook/components/EastRegionContainer.java
  4. 3
      designer-base/src/test/java/com/fr/design/gui/storybook/components/ToggleButtonStoryBoard.java
  5. 5
      designer-base/src/test/java/com/fr/design/gui/storybook/components/UIHeadGroupStoryBoard.java

117
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());

3
designer-base/src/test/java/com/fr/design/gui/storybook/ButtonStoryBoard.java → 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;

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

3
designer-base/src/test/java/com/fr/design/gui/storybook/ToggleButtonStoryBoard.java → 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;

5
designer-base/src/test/java/com/fr/design/gui/storybook/UIHeadGroupStoryBoard.java → 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");
Loading…
Cancel
Save