20 package net.sf.gridarta.gui.misc;
22 import java.awt.BorderLayout;
23 import java.awt.Component;
24 import java.awt.Rectangle;
25 import java.awt.Toolkit;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28 import java.awt.event.WindowAdapter;
29 import java.awt.event.WindowEvent;
30 import java.awt.geom.RectangularShape;
31 import java.util.prefs.Preferences;
32 import javax.swing.ImageIcon;
33 import javax.swing.JFrame;
34 import javax.swing.JOptionPane;
35 import javax.swing.WindowConstants;
44 import org.jetbrains.annotations.NotNull;
45 import org.jetbrains.annotations.Nullable;
68 private static final String
WINDOW_X =
"MainWindow.x";
73 private static final String
WINDOW_Y =
"MainWindow.y";
105 public MainView(@NotNull
final JFrame frame, @NotNull
final ActionListener exitAction, @NotNull
final Component mapDesktop, @Nullable
final ImageIcon icon, @NotNull
final Exiter exiter) {
107 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
108 frame.addWindowListener(
new WindowAdapter() {
111 public void windowClosing(
final WindowEvent e) {
112 exitAction.actionPerformed(
new ActionEvent(e.getSource(), 0, null));
116 frame.setIconImage(icon.getImage());
122 public void preExitNotify() {
127 public void appExitNotify() {
128 final Rectangle bounds = frame.getBounds();
129 PREFERENCES.putInt(WINDOW_X, bounds.x);
130 PREFERENCES.putInt(WINDOW_Y, bounds.y);
131 PREFERENCES.putInt(WINDOW_WIDTH, bounds.width);
132 PREFERENCES.putInt(WINDOW_HEIGHT, bounds.height);
133 PREFERENCES.putInt(WINDOW_STATE, frame.getExtendedState());
137 public void waitExitNotify() {
142 exiter.addExiterListener(exiterListener);
145 final RectangularShape screen = frame.getGraphicsConfiguration().getBounds();
146 final int defaultWidth = (int) (0.9 * screen.getWidth());
147 final int defaultHeight = (int) (0.9 * screen.getHeight());
150 frame.add(tabbedPanel, BorderLayout.CENTER);
153 frame.setBounds(PREFERENCES.getInt(WINDOW_X, (
int) (screen.getX() + (screen.getWidth() - (double) defaultWidth) / 2.0)), PREFERENCES.getInt(WINDOW_Y, (
int) (screen.getY() + (screen.getHeight() - (double) defaultHeight) / 2.0)), PREFERENCES.getInt(WINDOW_WIDTH, defaultWidth), PREFERENCES.getInt(WINDOW_HEIGHT, defaultHeight));
154 frame.setExtendedState(PREFERENCES.getInt(WINDOW_STATE, frame.getExtendedState()));
166 public void severityChanged(@NotNull
final Severity severity) {
171 tab.addTabListener(tabListener);
185 return tabbedPanel.
getActiveTab(location, alternativeLocation);
195 tab.getButton().setForeground(severity.getColor());
202 Toolkit.getDefaultToolkit().beep();
203 JOptionPane.showMessageDialog(frame, t.getMessage(),
"Error", JOptionPane.WARNING_MESSAGE);
void addTab(@NotNull final Tab tab)
Adds a tab.
Graphical User Interface of Gridarta.
Interface for listeners interested in Tab related events.
A tab in a TabbedPanel component.
final Component frame
The main window of the editor.
Main window of the level editor.
Base package of all Gridarta classes.
Tab getActiveTab(@NotNull final Location location, final boolean alternativeLocation)
Returns the active Tab on a given Location of the main view.
Interface for listeners interested in Exiter related events.
MainView(@NotNull final JFrame frame, @NotNull final ActionListener exitAction, @NotNull final Component mapDesktop, @Nullable final ImageIcon icon, @NotNull final Exiter exiter)
Constructs the main view and registers the given main controller.
static final String WINDOW_Y
The key used to store the main windows y-coordinate to INI file.
Interface used as preferences location.
A Component that always displays another component and optionally a number of tabs around it...
static final String WINDOW_X
The key used to store the main windows x-coordinate to INI file.
Tab getActiveTab(@NotNull final Location location, final boolean alternativeLocation)
Returns the active Tab on a given Location of the main view.
static final String WINDOW_HEIGHT
The key used to store the main windows height to INI file.
Severity levels for colors of tabs.
static void setSeverity(@NotNull final Tab tab, @NotNull final Severity severity)
Sets a Tab's Severity.
static final Preferences PREFERENCES
Preferences.
final TabbedPanel tabbedPanel
The TabbedPanel that displays frame and all open tabs.
void handleThrowable(final Throwable t)
This implementation displays the exception in a modal message dialog.
void addTab(@NotNull final Tab tab)
Adds a tab.
static final String WINDOW_STATE
The key used to store the main window state in the preferences.
static final String WINDOW_WIDTH
The key used to store the main windows width to INI file.