Browse Source

Migrated InternalFrameDemo to ComponentDemo.

pull/188/head
weisj 5 years ago
parent
commit
3e76332df9
  1. 1
      core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java
  2. 15
      core/src/test/java/ui/ComponentDemo.java
  3. 4
      core/src/test/java/ui/internalFrame/DemoFrame.java
  4. 73
      core/src/test/java/ui/internalFrame/InternalFrameDemo.java
  5. 7
      core/src/test/java/ui/tabFrame/TabFrameDemo.java

1
core/src/main/java/com/github/weisj/darklaf/ui/rootpane/DarkRootPaneUI.java

@ -35,7 +35,6 @@ import javax.swing.plaf.basic.BasicRootPaneUI;
import com.github.weisj.darklaf.platform.DecorationsHandler; import com.github.weisj.darklaf.platform.DecorationsHandler;
import com.github.weisj.darklaf.platform.decorations.CustomTitlePane; import com.github.weisj.darklaf.platform.decorations.CustomTitlePane;
import com.github.weisj.darklaf.ui.DarkPopupFactory;
import com.github.weisj.darklaf.util.DarkUIUtil; import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyKey; import com.github.weisj.darklaf.util.PropertyKey;
import com.github.weisj.darklaf.util.PropertyUtil; import com.github.weisj.darklaf.util.PropertyUtil;

15
core/src/test/java/ui/ComponentDemo.java

@ -52,18 +52,10 @@ public interface ComponentDemo {
JComponent createComponent(); JComponent createComponent();
static void showDemo(final ComponentDemo demo) { static void showDemo(final ComponentDemo demo) {
showDemo(demo, null); showDemo(demo, false);
} }
static void showDemo(final ComponentDemo demo, final boolean asDialog) { static void showDemo(final ComponentDemo demo, final boolean asDialog) {
showDemo(demo, null, asDialog);
}
static void showDemo(final ComponentDemo demo, final Dimension dimension) {
showDemo(demo, dimension, false);
}
static void showDemo(final ComponentDemo demo, final Dimension dimension, final boolean asDialog) {
LafManager.enabledPreferenceChangeReporting(false); LafManager.enabledPreferenceChangeReporting(false);
System.setProperty("apple.laf.useScreenMenuBar", "true"); System.setProperty("apple.laf.useScreenMenuBar", "true");
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
@ -92,6 +84,7 @@ public interface ComponentDemo {
if (image != null) window.setIconImage(image); if (image != null) window.setIconImage(image);
window.pack(); window.pack();
Dimension dimension = demo.getDisplayDimension();
if (dimension == null) { if (dimension == null) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension dim = new Dimension(screenSize.width / 2, Dimension dim = new Dimension(screenSize.width / 2,
@ -108,6 +101,10 @@ public interface ComponentDemo {
}); });
} }
default Dimension getDisplayDimension() {
return null;
}
default Image getIconImage() { default Image getIconImage() {
return null; return null;
} }

4
core/src/test/java/ui/internalFrame/DemoInternalFrame.java → core/src/test/java/ui/internalFrame/DemoFrame.java

@ -26,11 +26,11 @@ package ui.internalFrame;
import javax.swing.*; import javax.swing.*;
public class DemoInternalFrame extends JInternalFrame { public class DemoFrame extends JInternalFrame {
private static final int xOffset = 30, yOffset = 30; private static final int xOffset = 30, yOffset = 30;
private static int openFrameCount = 0; private static int openFrameCount = 0;
public DemoInternalFrame() { public DemoFrame() {
super("Document #" + (++openFrameCount), true, true, true, true); super("Document #" + (++openFrameCount), true, true, true, true);
setSize(300, 300); setSize(300, 300);
setLocation(xOffset * openFrameCount, yOffset * openFrameCount); setLocation(xOffset * openFrameCount, yOffset * openFrameCount);

73
core/src/test/java/ui/internalFrame/InternalFrameDemo.java

@ -36,28 +36,26 @@ import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder; import javax.swing.border.EmptyBorder;
import ui.ComponentDemo; import ui.ComponentDemo;
import ui.DemoPanel;
import com.github.weisj.darklaf.LafManager;
import com.github.weisj.darklaf.components.border.DarkBorders; import com.github.weisj.darklaf.components.border.DarkBorders;
/* public class InternalFrameDemo implements ActionListener, ComponentDemo {
* internalFrame.InternalFrameDemo.java requires:
* internalFrame.MyInternalFrame.java
*/
public class InternalFrameDemo extends JFrame implements ActionListener {
private final JDesktopPane desktop;
private InternalFrameDemo() { private JDesktopPane desktop;
super("InternalFrameDemo");
// Make the big window be indented 50 pixels from each edge public static void main(final String[] args) {
// of the screen. ComponentDemo.showDemo(new InternalFrameDemo());
int inset = 50; }
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(inset, inset, screenSize.width - inset * 2, screenSize.height - inset * 2);
desktop = new JDesktopPane(); @Override
public Dimension getDisplayDimension() {
return new Dimension(1000, 500);
}
@Override
public JComponent createComponent() {
desktop = new JDesktopPane();
JPanel panel = new JPanel(); JPanel panel = new JPanel();
panel.setBorder(new CompoundBorder(new EmptyBorder(20, 20, 20, 20), panel.setBorder(new CompoundBorder(new EmptyBorder(20, 20, 20, 20),
DarkBorders.createLineBorder(1, 1, 1, 1))); DarkBorders.createLineBorder(1, 1, 1, 1)));
@ -65,19 +63,15 @@ public class InternalFrameDemo extends JFrame implements ActionListener {
panel.add(desktop, BorderLayout.CENTER); panel.add(desktop, BorderLayout.CENTER);
createFrame(); createFrame();
setContentPane(panel);
setJMenuBar(createMenuBar());
// Make dragging a little faster but perhaps uglier. // Make dragging a little faster but perhaps uglier.
desktop.setDragMode(JDesktopPane.LIVE_DRAG_MODE); desktop.setDragMode(JDesktopPane.LIVE_DRAG_MODE);
return new DemoPanel(desktop, new BorderLayout(), 10);
} }
public static void main(final String[] args) { @Override
SwingUtilities.invokeLater(InternalFrameDemo::createAndShowGUI); public JMenuBar createMenuBar() {
} JMenuBar menuBar = ComponentDemo.getDefaultMenuBar();
private JMenuBar createMenuBar() {
JMenuBar menuBar = new JMenuBar();
// Set up the lone menu. // Set up the lone menu.
JMenu menu = new JMenu("Document"); JMenu menu = new JMenu("Document");
@ -92,34 +86,17 @@ public class InternalFrameDemo extends JFrame implements ActionListener {
menuItem.addActionListener(this); menuItem.addActionListener(this);
menu.add(menuItem); menu.add(menuItem);
// Set up the second menu item.
menuItem = new JMenuItem("Quit");
menuItem.setMnemonic(KeyEvent.VK_Q);
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.ALT_DOWN_MASK));
menuItem.setActionCommand("quit");
menuItem.addActionListener(this);
menu.add(menuItem);
return menuBar; return menuBar;
} }
/** @Override
* Create the GUI and show it. For thread safety, this method should be invoked from the event-dispatching thread. public String getTitle() {
*/ return "Internal Frame Demo";
private static void createAndShowGUI() {
LafManager.install(ComponentDemo.getTheme());
// Create and set up the window.
InternalFrameDemo frame = new InternalFrameDemo();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Display the window.
frame.setVisible(true);
} }
// Create a new internal frame. // Create a new internal frame.
private void createFrame() { private void createFrame() {
DemoInternalFrame frame = new DemoInternalFrame(); DemoFrame frame = new DemoFrame();
frame.setVisible(true); frame.setVisible(true);
desktop.add(frame); desktop.add(frame);
try { try {
@ -131,14 +108,6 @@ public class InternalFrameDemo extends JFrame implements ActionListener {
public void actionPerformed(final ActionEvent e) { public void actionPerformed(final ActionEvent e) {
if ("new".equals(e.getActionCommand())) { if ("new".equals(e.getActionCommand())) {
createFrame(); createFrame();
} else {
quit();
}
} }
// Quit the application.
private void quit() {
System.exit(0);
} }
} }

7
core/src/test/java/ui/tabFrame/TabFrameDemo.java

@ -44,7 +44,12 @@ import com.github.weisj.darklaf.util.StringUtil;
public class TabFrameDemo implements ComponentDemo { public class TabFrameDemo implements ComponentDemo {
public static void main(final String[] args) { public static void main(final String[] args) {
ComponentDemo.showDemo(new TabFrameDemo(), new Dimension(1000, 500)); ComponentDemo.showDemo(new TabFrameDemo());
}
@Override
public Dimension getDisplayDimension() {
return new Dimension(1000, 500);
} }
private static Component createTextArea() { private static Component createTextArea() {

Loading…
Cancel
Save