better positioning of dialog on the screen
[instantlauncher.git] / src / main / java / eu / svjatoslav / instantlauncher / MainFrame.java
1 package eu.svjatoslav.instantlauncher;
2
3 import java.awt.BorderLayout;
4 import java.awt.Dimension;
5 import java.awt.event.WindowEvent;
6 import java.awt.event.WindowListener;
7
8 import javax.swing.JFrame;
9
10 import eu.svjatoslav.instantlauncher.menu.MultiLevelMenu;
11
12 public class MainFrame {
13
14     private JFrame frame;
15
16     private boolean isShowing;
17
18     public static final Dimension CONTENT_PANEL_SIZE = new Dimension(1100, 850);
19
20     private final InstantLauncher instantLauncher;
21
22     public MainFrame(final InstantLauncher instantLauncher) {
23         this.instantLauncher = instantLauncher;
24     }
25
26     private void buildContentPane() {
27
28         final MultiLevelMenu multiLevelMenu = new MultiLevelMenu(instantLauncher);
29         frame.getContentPane().add(multiLevelMenu.buildContentPanel(), BorderLayout.CENTER);
30
31     }
32
33     public void show() {
34
35         if (!isShowing) {
36             // initialize frame
37             frame = new JFrame("InstantLauncher");
38
39             buildContentPane();
40
41             // registor window listener
42             final FrameWindowListener windowListener = new FrameWindowListener();
43             frame.addWindowListener(windowListener);
44
45             // maximize window
46             frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
47             frame.setVisible(true);
48
49             isShowing = true;
50         }
51
52     }
53
54     public static class FrameWindowListener implements WindowListener {
55
56         @Override
57         public void windowActivated(final WindowEvent e) {
58         }
59
60         @Override
61         public void windowClosed(final WindowEvent e) {
62         }
63
64         @Override
65         public void windowClosing(final WindowEvent e) {
66             InstantLauncher.exitProgram();
67         }
68
69         @Override
70         public void windowDeactivated(final WindowEvent e) {
71         }
72
73         @Override
74         public void windowDeiconified(final WindowEvent e) {
75         }
76
77         @Override
78         public void windowIconified(final WindowEvent e) {
79         }
80
81         @Override
82         public void windowOpened(final WindowEvent e) {
83         }
84
85     }
86
87 }