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