67c350a5b97daa14c8b8d78f4645a601abb15a03
[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     private final InstantLauncher instantLauncher;
13     private JFrame frame;
14     private boolean isShowing;
15
16     public MainFrame(final InstantLauncher instantLauncher) {
17         this.instantLauncher = instantLauncher;
18     }
19
20     private void buildContentPane() {
21
22         final MultiLevelMenu multiLevelMenu = new MultiLevelMenu(instantLauncher);
23         frame.getContentPane().add(multiLevelMenu.buildContentPanel(), BorderLayout.CENTER);
24
25     }
26
27     public void show() {
28
29         if (!isShowing) {
30             // initialize frame
31             frame = new JFrame("InstantLauncher");
32
33             buildContentPane();
34
35             // registor window listener
36             final FrameWindowListener windowListener = new FrameWindowListener();
37             frame.addWindowListener(windowListener);
38
39             // maximize window
40             frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
41             frame.setVisible(true);
42
43             isShowing = true;
44         }
45
46     }
47
48     private static class FrameWindowListener implements WindowListener {
49
50         @Override
51         public void windowActivated(final WindowEvent e) {
52         }
53
54         @Override
55         public void windowClosed(final WindowEvent e) {
56         }
57
58         @Override
59         public void windowClosing(final WindowEvent e) {
60             InstantLauncher.exitProgram();
61         }
62
63         @Override
64         public void windowDeactivated(final WindowEvent e) {
65         }
66
67         @Override
68         public void windowDeiconified(final WindowEvent e) {
69         }
70
71         @Override
72         public void windowIconified(final WindowEvent e) {
73         }
74
75         @Override
76         public void windowOpened(final WindowEvent e) {
77         }
78
79     }
80
81 }