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-2015 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.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28 import java.lang.reflect.InvocationTargetException;
29 import javax.swing.AbstractButton;
30 import javax.swing.JButton;
31 import javax.swing.JFrame;
32 import javax.swing.JPanel;
33 import javax.swing.JSplitPane;
34 import javax.swing.SwingUtilities;
35 import org.jetbrains.annotations.NotNull;
36 
44 
48  private static final int MIN_SIZE = 2;
49 
54  }
55 
62  public static void main(@NotNull final String[] args) throws InterruptedException, InvocationTargetException {
63  SwingUtilities.invokeAndWait(new Runnable() {
64 
65  @Override
66  public void run() {
67  final JPanel green = newPanel(MIN_SIZE, MIN_SIZE, Color.GREEN);
68  final JPanel blue = newPanel(MIN_SIZE, MIN_SIZE, Color.BLUE);
69  final JPanel yellow = newPanel(MIN_SIZE, MIN_SIZE, Color.YELLOW);
70  final JPanel orange = newPanel(MIN_SIZE, MIN_SIZE, Color.ORANGE);
71  final GSplitPane splitPane1 = new GSplitPane(JSplitPane.HORIZONTAL_SPLIT, green, blue, "TEST_GREEN_BLUE", 70);
72  splitPane1.setResizeWeight(0.5);
73  final GSplitPane splitPane2 = new GSplitPane(JSplitPane.VERTICAL_SPLIT, splitPane1, yellow, "TEST_GREEN_BLUE_YELLOW", 40);
74  final GSplitPane splitPane3 = new GSplitPane(JSplitPane.HORIZONTAL_SPLIT, orange, splitPane2, "TEST_ORANGE_GREEN_BLUE_YELLOW", 30);
75  final AbstractButton button = new JButton("save divider locations and quit");
76  final Window frame = new JFrame();
77  button.addActionListener(new ActionListener() {
78 
79  @Override
80  public void actionPerformed(@NotNull final ActionEvent e) {
81  splitPane1.saveLocation();
82  splitPane2.saveLocation();
83  splitPane3.saveLocation();
84  frame.setVisible(false);
85  System.exit(0);
86  }
87  });
88  frame.setLayout(new BorderLayout());
89  frame.add(button, BorderLayout.SOUTH);
90  frame.add(splitPane3);
91  frame.pack();
92  frame.setSize(new Dimension(800, 600));
93  frame.setLocationRelativeTo(null);
94  frame.setVisible(true);
95  }
96  });
97  }
98 
106  private static JPanel newPanel(final int width, final int height, @NotNull final Color color) {
107  final JPanel panel = new JPanel();
108  panel.setMinimumSize(new Dimension(width, height));
109  panel.setOpaque(true);
110  panel.setBackground(color);
111  return panel;
112  }
113 
114 }
A JSplitPane that keeps its size even upon ancestor layout changes and is restored upon editor restar...
Definition: GSplitPane.java:50
static final int MIN_SIZE
The minimal size of components.
GSplitPaneTestApplication()
Private constructor to prevent instantiation.
Simple application for testing GSplitPane behavior.
void saveLocation()
Saves the current divider location into the preferences.
static JPanel newPanel(final int width, final int height, @NotNull final Color color)
Creates a new colored area.
static void main(@NotNull final String[] args)
The entry point of the application.