Gridarta Editor
GSplitPaneTestApplication.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.gui.utils;
21 
22 import java.awt.BorderLayout;
23 import java.awt.Color;
24 import java.awt.Dimension;
25 import java.awt.Window;
26 import java.lang.reflect.InvocationTargetException;
27 import javax.swing.AbstractButton;
28 import javax.swing.JButton;
29 import javax.swing.JFrame;
30 import javax.swing.JPanel;
31 import javax.swing.JSplitPane;
32 import javax.swing.SwingUtilities;
33 import org.jetbrains.annotations.NotNull;
34 
42 
46  private static final int MIN_SIZE = 2;
47 
52  }
53 
60  public static void main(@NotNull final String @NotNull [] args) throws InterruptedException, InvocationTargetException {
61  SwingUtilities.invokeAndWait(() -> {
62  final JPanel green = newPanel(MIN_SIZE, MIN_SIZE, Color.GREEN);
63  final JPanel blue = newPanel(MIN_SIZE, MIN_SIZE, Color.BLUE);
64  final JPanel yellow = newPanel(MIN_SIZE, MIN_SIZE, Color.YELLOW);
65  final JPanel orange = newPanel(MIN_SIZE, MIN_SIZE, Color.ORANGE);
66  final GSplitPane splitPane1 = new GSplitPane(JSplitPane.HORIZONTAL_SPLIT, green, blue, "TEST_GREEN_BLUE", 70);
67  splitPane1.setResizeWeight(0.5);
68  final GSplitPane splitPane2 = new GSplitPane(JSplitPane.VERTICAL_SPLIT, splitPane1, yellow, "TEST_GREEN_BLUE_YELLOW", 40);
69  final GSplitPane splitPane3 = new GSplitPane(JSplitPane.HORIZONTAL_SPLIT, orange, splitPane2, "TEST_ORANGE_GREEN_BLUE_YELLOW", 30);
70  final AbstractButton button = new JButton("save divider locations and quit");
71  final Window frame = new JFrame();
72  button.addActionListener(e -> {
73  splitPane1.saveLocation();
74  splitPane2.saveLocation();
75  splitPane3.saveLocation();
76  frame.setVisible(false);
77  System.exit(0);
78  });
79  frame.setLayout(new BorderLayout());
80  frame.add(button, BorderLayout.SOUTH);
81  frame.add(splitPane3);
82  frame.pack();
83  frame.setSize(new Dimension(800, 600));
84  frame.setLocationRelativeTo(null);
85  frame.setVisible(true);
86  });
87  }
88 
96  private static JPanel newPanel(final int width, final int height, @NotNull final Color color) {
97  final JPanel panel = new JPanel();
98  panel.setMinimumSize(new Dimension(width, height));
99  panel.setOpaque(true);
100  panel.setBackground(color);
101  return panel;
102  }
103 
104 }
net.sf.gridarta.gui.utils.GSplitPaneTestApplication
Simple application for testing GSplitPane behavior.
Definition: GSplitPaneTestApplication.java:41
net.sf.gridarta.gui.utils.GSplitPane.saveLocation
void saveLocation()
Saves the current divider location into the preferences.
Definition: GSplitPane.java:201
net.sf.gridarta.gui.utils.GSplitPaneTestApplication.main
static void main(@NotNull final String @NotNull[] args)
The entry point of the application.
Definition: GSplitPaneTestApplication.java:60
net.sf.gridarta.gui.utils.GSplitPaneTestApplication.MIN_SIZE
static final int MIN_SIZE
The minimal size of components.
Definition: GSplitPaneTestApplication.java:46
net.sf.gridarta.gui.utils.GSplitPaneTestApplication.GSplitPaneTestApplication
GSplitPaneTestApplication()
Private constructor to prevent instantiation.
Definition: GSplitPaneTestApplication.java:51
net.sf.gridarta.gui.utils.GSplitPaneTestApplication.newPanel
static JPanel newPanel(final int width, final int height, @NotNull final Color color)
Creates a new colored area.
Definition: GSplitPaneTestApplication.java:96
net.sf.gridarta.gui.utils.GSplitPane
A JSplitPane that keeps its size even upon ancestor layout changes and is restored upon editor restar...
Definition: GSplitPane.java:50