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