Added license and copyright notice.
[instantlauncher.git] / src / main / java / eu / svjatoslav / instantlauncher / MainFrame.java
1 /*
2  * Instantlauncher. Copyright ©2012-2019, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of version 3 of the GNU Lesser General Public License
6  * or later as published by the Free Software Foundation.
7  */
8
9 package eu.svjatoslav.instantlauncher;
10
11 import eu.svjatoslav.instantlauncher.menu.MultiLevelMenu;
12
13 import javax.swing.*;
14 import java.awt.*;
15 import java.awt.event.WindowEvent;
16 import java.awt.event.WindowListener;
17
18 class MainFrame {
19
20     private final InstantLauncher instantLauncher;
21     private JFrame frame;
22     private boolean isShowing;
23
24     public MainFrame(final InstantLauncher instantLauncher) {
25         this.instantLauncher = instantLauncher;
26     }
27
28     private void buildContentPane() {
29
30         final MultiLevelMenu multiLevelMenu = new MultiLevelMenu(instantLauncher);
31         frame.getContentPane().add(multiLevelMenu.buildContentPanel(), BorderLayout.CENTER);
32
33     }
34
35     public void show() {
36
37         if (!isShowing) {
38             // initialize frame
39             frame = new JFrame("InstantLauncher");
40
41             buildContentPane();
42
43             // registor window listener
44             final FrameWindowListener windowListener = new FrameWindowListener();
45             frame.addWindowListener(windowListener);
46
47             // maximize window
48             frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
49             frame.setVisible(true);
50
51             isShowing = true;
52         }
53
54     }
55
56     private static class FrameWindowListener implements WindowListener {
57
58         @Override
59         public void windowActivated(final WindowEvent e) {
60         }
61
62         @Override
63         public void windowClosed(final WindowEvent e) {
64         }
65
66         @Override
67         public void windowClosing(final WindowEvent e) {
68             InstantLauncher.exitProgram();
69         }
70
71         @Override
72         public void windowDeactivated(final WindowEvent e) {
73         }
74
75         @Override
76         public void windowDeiconified(final WindowEvent e) {
77         }
78
79         @Override
80         public void windowIconified(final WindowEvent e) {
81         }
82
83         @Override
84         public void windowOpened(final WindowEvent e) {
85         }
86
87     }
88
89 }