From 64d20988730289d95110882fa0db5352117ccd9b Mon Sep 17 00:00:00 2001 From: weisj Date: Tue, 14 Apr 2020 14:58:42 +0200 Subject: [PATCH] Updated demos. --- core/src/test/java/UIDemo.java | 4 ++-- core/src/test/java/icon/RotatableIconDemo.java | 5 ++--- core/src/test/java/ui/ComponentDemo.java | 12 +++++++++++- core/src/test/java/ui/DemoPanel.java | 10 +++++++--- core/src/test/java/ui/DemoResources.java | 8 ++++++-- core/src/test/java/ui/button/ButtonDemo.java | 4 ++-- core/src/test/java/ui/button/ToggleButtonDemo.java | 4 ++-- core/src/test/java/ui/label/LabelDemo.java | 4 ++-- core/src/test/java/ui/popupMenu/PopupMenuDemo.java | 4 ++-- .../java/ui/scrollPane/OverlayScrollPaneDemo.java | 2 +- core/src/test/java/ui/scrollPane/ScrollPaneDemo.java | 11 ++++------- core/src/test/java/ui/tabFrame/TabFrameDemo.java | 2 +- 12 files changed, 42 insertions(+), 28 deletions(-) diff --git a/core/src/test/java/UIDemo.java b/core/src/test/java/UIDemo.java index 039f5bd4..3a8206f3 100644 --- a/core/src/test/java/UIDemo.java +++ b/core/src/test/java/UIDemo.java @@ -2,13 +2,13 @@ import com.github.weisj.darklaf.LafManager; import com.github.weisj.darklaf.components.text.SearchTextField; import com.github.weisj.darklaf.components.text.SearchTextFieldWithHistory; import com.github.weisj.darklaf.components.tristate.TristateCheckBox; -import com.github.weisj.darklaf.icons.IconLoader; import com.github.weisj.darklaf.theme.HighContrastDarkTheme; import com.github.weisj.darklaf.ui.button.DarkButtonUI; import com.github.weisj.darklaf.ui.slider.DarkSliderUI; import org.jdesktop.swingx.JXStatusBar; import org.jdesktop.swingx.JXTaskPane; import org.jdesktop.swingx.JXTaskPaneContainer; +import ui.DemoResources; import javax.swing.*; import java.awt.*; @@ -45,7 +45,7 @@ public final class UIDemo { UIDemo.class.getClassLoader().getResource("mima.png") )); - Icon folderIcon = IconLoader.get().getIcon("files/folder.svg", 19, 19, true); + Icon folderIcon = DemoResources.FOLDER_ICON; JPanel panel = new JPanel(new GridLayout(3, 4)); JPanel content = new JPanel(new BorderLayout()); diff --git a/core/src/test/java/icon/RotatableIconDemo.java b/core/src/test/java/icon/RotatableIconDemo.java index cc1e24fa..ebf89cd8 100644 --- a/core/src/test/java/icon/RotatableIconDemo.java +++ b/core/src/test/java/icon/RotatableIconDemo.java @@ -23,10 +23,10 @@ */ package icon; -import com.github.weisj.darklaf.icons.IconLoader; import com.github.weisj.darklaf.icons.RotatableIcon; import ui.ComponentDemo; import ui.DemoPanel; +import ui.DemoResources; import javax.swing.*; @@ -38,8 +38,7 @@ public class RotatableIconDemo implements ComponentDemo { @Override public JComponent createComponent() { - RotatableIcon folderIcon = new RotatableIcon( - IconLoader.get().getIcon("files/folder.svg", 19, 19, true)); + RotatableIcon folderIcon = new RotatableIcon(DemoResources.FOLDER_ICON); JLabel label = new JLabel(folderIcon); SwingUtilities.invokeLater(() -> { Timer timer = new Timer(1000, e -> { diff --git a/core/src/test/java/ui/ComponentDemo.java b/core/src/test/java/ui/ComponentDemo.java index bb714d72..80b5444f 100644 --- a/core/src/test/java/ui/ComponentDemo.java +++ b/core/src/test/java/ui/ComponentDemo.java @@ -55,7 +55,17 @@ public interface ComponentDemo { frame.setContentPane(demo.createComponent()); frame.setJMenuBar(demo.createMenuBar()); frame.pack(); - if (dimension != null) frame.setSize(dimension); + if (dimension == null) { + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + Dimension dim = new Dimension(screenSize.width / 2, + screenSize.height / 2); + Dimension targetSize = frame.getSize(); + targetSize.width = Math.min(targetSize.width, dim.width); + targetSize.height = Math.min(targetSize.height, dim.height); + frame.setSize(targetSize); + } else { + frame.setSize(dimension); + } frame.setVisible(true); frame.setLocationRelativeTo(null); }); diff --git a/core/src/test/java/ui/DemoPanel.java b/core/src/test/java/ui/DemoPanel.java index f4c7bb8c..153076be 100644 --- a/core/src/test/java/ui/DemoPanel.java +++ b/core/src/test/java/ui/DemoPanel.java @@ -44,10 +44,14 @@ public class DemoPanel extends JPanel { public DemoPanel(final JComponent component, final LayoutManager layoutManager, final int hGap) { super(new BorderLayout()); JPanel contentHolder = new JPanel(new BorderLayout()); - contentHolder.add(Box.createVerticalStrut(hGap), BorderLayout.NORTH); - contentHolder.add(Box.createVerticalStrut(hGap), BorderLayout.SOUTH); JPanel content = new JPanel(layoutManager); - content.add(component); + if (layoutManager instanceof BorderLayout) { + content.add(component, BorderLayout.CENTER); + } else { + contentHolder.add(Box.createVerticalStrut(hGap), BorderLayout.NORTH); + contentHolder.add(Box.createVerticalStrut(hGap), BorderLayout.SOUTH); + content.add(component); + } contentHolder.add(content, BorderLayout.CENTER); add(contentHolder, BorderLayout.CENTER); diff --git a/core/src/test/java/ui/DemoResources.java b/core/src/test/java/ui/DemoResources.java index 53eff195..b8220da3 100644 --- a/core/src/test/java/ui/DemoResources.java +++ b/core/src/test/java/ui/DemoResources.java @@ -23,14 +23,17 @@ */ package ui; +import com.github.weisj.darklaf.icons.IconLoader; + +import javax.swing.*; + public class DemoResources { public static final String LOREM_IPSUM = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. In tempor quis nibh a semper. Nullam\n" + " auctor, erat non viverra commodo, libero orci aliquam quam, ac interdum nunc est sed\n " + "ligula. Aliquam vel velit non dolor accumsan blandit id eu metus. Aenean iaculis urna in\n " + "placerat aliquam. Aliquam dui quam, bibendum sed magna in, cursus ornare est. Quisque\n " - + "tempor nunc quis nunc tempor convallis. Vestibulum tristique luctus ante, ac hendrerit dui\n" - + ".\n\n" + + "tempor nunc quis nunc tempor convallis. Vestibulum tristique luctus ante, ac hendrerit dui.\n\n" + "Donec ut maximus augue. Nam eleifend maximus scelerisque. Duis varius accumsan est, non\n " + "aliquam dolor. Aenean iaculis nibh in aliquam viverra. Sed laoreet, urna ut facilisis\n " + "convallis, arcu turpis vestibulum augue, id convallis tellus metus nec orci. Lorem ipsum\n " @@ -49,4 +52,5 @@ public class DemoResources { + "elementum ligula at, porta turpis. Praesent feugiat dolor diam, at facilisis metus gravida\n" + " non. Aliquam quis pellentesque nibh. Sed vestibulum porttitor nisi. In vitae malesuada\n " + "sapien."; + public static Icon FOLDER_ICON = IconLoader.get().getIcon("files/folder.svg", 19, 19, true); } diff --git a/core/src/test/java/ui/button/ButtonDemo.java b/core/src/test/java/ui/button/ButtonDemo.java index 89261c44..79160af2 100644 --- a/core/src/test/java/ui/button/ButtonDemo.java +++ b/core/src/test/java/ui/button/ButtonDemo.java @@ -23,11 +23,11 @@ */ package ui.button; -import com.github.weisj.darklaf.icons.IconLoader; import com.github.weisj.darklaf.ui.button.DarkButtonUI; import com.github.weisj.darklaf.util.AlignmentExt; import ui.ComponentDemo; import ui.DemoPanel; +import ui.DemoResources; import ui.QuickColorChooser; import javax.swing.*; @@ -41,7 +41,7 @@ public class ButtonDemo implements ComponentDemo { @Override public JComponent createComponent() { - Icon icon = IconLoader.get().getIcon("files/folder.svg", 19, 19, true); + Icon icon = DemoResources.FOLDER_ICON; JButton button = new JButton("Test Button", icon); DemoPanel panel = new DemoPanel(button); JPanel controlPanel = panel.addControls(); diff --git a/core/src/test/java/ui/button/ToggleButtonDemo.java b/core/src/test/java/ui/button/ToggleButtonDemo.java index 0a2640db..2d19b3de 100644 --- a/core/src/test/java/ui/button/ToggleButtonDemo.java +++ b/core/src/test/java/ui/button/ToggleButtonDemo.java @@ -23,11 +23,11 @@ */ package ui.button; -import com.github.weisj.darklaf.icons.IconLoader; import com.github.weisj.darklaf.ui.togglebutton.DarkToggleButtonUI; import com.github.weisj.darklaf.ui.togglebutton.ToggleButtonConstants; import ui.ComponentDemo; import ui.DemoPanel; +import ui.DemoResources; import javax.swing.*; import java.awt.*; @@ -40,7 +40,7 @@ public class ToggleButtonDemo implements ComponentDemo { @Override public JComponent createComponent() { - Icon icon = IconLoader.get().getIcon("files/folder.svg", 19, 19, true); + Icon icon = DemoResources.FOLDER_ICON; JToggleButton button = new JToggleButton("Test ToggleButton", icon); DemoPanel panel = new DemoPanel(button); diff --git a/core/src/test/java/ui/label/LabelDemo.java b/core/src/test/java/ui/label/LabelDemo.java index ddaa0fe7..5ee8c92c 100644 --- a/core/src/test/java/ui/label/LabelDemo.java +++ b/core/src/test/java/ui/label/LabelDemo.java @@ -23,9 +23,9 @@ */ package ui.label; -import com.github.weisj.darklaf.icons.IconLoader; import ui.ComponentDemo; import ui.DemoPanel; +import ui.DemoResources; import javax.swing.*; import java.awt.*; @@ -38,7 +38,7 @@ public class LabelDemo implements ComponentDemo { @Override public JComponent createComponent() { - Icon icon = IconLoader.get().getIcon("files/folder.svg", 19, 19, true); + Icon icon = DemoResources.FOLDER_ICON; JLabel label = new JLabel("Test Label", icon, JLabel.LEFT); DemoPanel panel = new DemoPanel(label); diff --git a/core/src/test/java/ui/popupMenu/PopupMenuDemo.java b/core/src/test/java/ui/popupMenu/PopupMenuDemo.java index 7bc6e629..85017358 100644 --- a/core/src/test/java/ui/popupMenu/PopupMenuDemo.java +++ b/core/src/test/java/ui/popupMenu/PopupMenuDemo.java @@ -23,8 +23,8 @@ */ package ui.popupMenu; -import com.github.weisj.darklaf.icons.IconLoader; import ui.ComponentDemo; +import ui.DemoResources; import javax.swing.*; import java.awt.*; @@ -39,7 +39,7 @@ public class PopupMenuDemo implements ComponentDemo { public JComponent createComponent() { JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); - Icon icon = IconLoader.get().getIcon("files/folder.svg", 19, 19, true); + Icon icon = DemoResources.FOLDER_ICON; panel.add(new JLabel("Right click anywhere to open menu.") {{ setInheritsPopupMenu(true); }}); diff --git a/core/src/test/java/ui/scrollPane/OverlayScrollPaneDemo.java b/core/src/test/java/ui/scrollPane/OverlayScrollPaneDemo.java index 057492f9..3be6d952 100644 --- a/core/src/test/java/ui/scrollPane/OverlayScrollPaneDemo.java +++ b/core/src/test/java/ui/scrollPane/OverlayScrollPaneDemo.java @@ -35,7 +35,7 @@ import java.awt.*; public class OverlayScrollPaneDemo implements ComponentDemo { public static void main(final String[] args) { - ComponentDemo.showDemo(new OverlayScrollPaneDemo(), new Dimension(500, 1000)); + ComponentDemo.showDemo(new OverlayScrollPaneDemo()); } @Override diff --git a/core/src/test/java/ui/scrollPane/ScrollPaneDemo.java b/core/src/test/java/ui/scrollPane/ScrollPaneDemo.java index 8b02f1bf..fd701808 100644 --- a/core/src/test/java/ui/scrollPane/ScrollPaneDemo.java +++ b/core/src/test/java/ui/scrollPane/ScrollPaneDemo.java @@ -23,6 +23,7 @@ */ package ui.scrollPane; +import com.github.weisj.darklaf.util.StringUtil; import ui.ComponentDemo; import ui.DemoPanel; import ui.DemoResources; @@ -43,19 +44,15 @@ public final class ScrollPaneDemo implements ComponentDemo { @Override public JComponent createComponent() { - JScrollPane scrollPane = new JScrollPane(); - scrollPane.setViewportView(new JPanel() {{ - add(new JTextArea() {{ - setText(DemoResources.LOREM_IPSUM); - }}); + JScrollPane scrollPane = new JScrollPane(new JTextArea() {{ + setText(StringUtil.repeat(DemoResources.LOREM_IPSUM, 10)); }}); JPanel upperLeft = new SolidColorComponent(Color.RED, 20, 20); JPanel upperRight = new SolidColorComponent(Color.RED, 20, 20); JPanel lowerLeft = new SolidColorComponent(Color.RED, 20, 20); JPanel lowerRight = new SolidColorComponent(Color.RED, 20, 20); - DemoPanel panel = new DemoPanel(scrollPane); - + DemoPanel panel = new DemoPanel(scrollPane, new BorderLayout(), 10); JPanel controlPanel = panel.addControls(); controlPanel.add(new JCheckBox("LeftToRight") {{ diff --git a/core/src/test/java/ui/tabFrame/TabFrameDemo.java b/core/src/test/java/ui/tabFrame/TabFrameDemo.java index c8e6ef78..f58f996c 100644 --- a/core/src/test/java/ui/tabFrame/TabFrameDemo.java +++ b/core/src/test/java/ui/tabFrame/TabFrameDemo.java @@ -64,7 +64,7 @@ public class TabFrameDemo implements ComponentDemo { @Override public JComponent createComponent() { - Icon folderIcon = IconLoader.get().getIcon("files/folder.svg", 19, 19, true); + Icon folderIcon = DemoResources.FOLDER_ICON; JTabFrame tabFrame = new JTabFrame(); for (Alignment o : Alignment.values()) { if (o != Alignment.CENTER) {