[Aprog]
[aprog.git] / Aprog / src / net / sourceforge / aprog / af / AFMainFrame.java
blob9b7bf259fd1d36e5d8cf5df533f962c6a7cff84d
1 /*
2 * The MIT License
3 *
4 * Copyright 2010 Codist Monk.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
25 package net.sourceforge.aprog.af;
27 import static net.sourceforge.aprog.af.AFConstants.Variables.*;
28 import static net.sourceforge.aprog.af.AFTools.*;
29 import static net.sourceforge.aprog.swing.SwingTools.*;
31 import java.awt.Component;
32 import java.awt.event.WindowListener;
33 import java.io.IOException;
34 import java.util.logging.Level;
36 import javax.imageio.ImageIO;
37 import javax.swing.JFrame;
38 import javax.swing.JMenuBar;
39 import javax.swing.WindowConstants;
41 import net.sourceforge.aprog.context.Context;
42 import net.sourceforge.aprog.tools.Tools;
44 /**
46 * @author codistmonk (creation 2010-09-16)
48 public final class AFMainFrame extends JFrame {
50 private final Context context;
52 /**
54 * @param context
55 * <br>Not null
56 * <br>Shared
58 private AFMainFrame(final Context context) {
59 super(context.get(APPLICATION_NAME).toString());
60 this.context = context;
62 try {
63 this.setIconImage(ImageIO.read(Tools.getResourceAsStream(context.get(APPLICATION_ICON_PATH).toString())));
64 } catch (final IOException exception) {
65 Tools.getLoggerForThisMethod().log(Level.WARNING, null, exception);
69 /**
71 * @return
72 * <br>Not null
73 * <br>Shared
75 public final Context getContext() {
76 return this.context;
79 private static final long serialVersionUID = -3668377952583428013L;
81 /**
83 * @param context
84 * <br>Not null
85 * <br>Shared
86 * @return
87 * <br>Not null
88 * <br>New
90 public static final AFMainFrame newMainFrame(final Context context) {
91 checkAWT();
93 final AFMainFrame result = new AFMainFrame(context);
95 context.set(MAIN_FRAME, result);
97 result.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
99 result.addWindowListener(newListener(WindowListener.class, "windowClosing",
100 AFTools.class, "perform", context, ACTIONS_QUIT));
102 result.setJMenuBar((JMenuBar) context.get(MAIN_MENU_BAR));
104 result.add((Component) context.get(MAIN_PANEL));
106 return packAndCenter(result);