1 | package genius.gui;
|
---|
2 |
|
---|
3 | import java.awt.BorderLayout;
|
---|
4 | import java.awt.Component;
|
---|
5 | import java.awt.Dimension;
|
---|
6 | import java.awt.Frame;
|
---|
7 | import java.awt.Toolkit;
|
---|
8 | import java.awt.event.MouseEvent;
|
---|
9 |
|
---|
10 | import javax.swing.JFrame;
|
---|
11 | import javax.swing.JMenu;
|
---|
12 | import javax.swing.JMenuBar;
|
---|
13 | import javax.swing.JScrollPane;
|
---|
14 | import javax.swing.JSplitPane;
|
---|
15 | import javax.swing.JTabbedPane;
|
---|
16 |
|
---|
17 | import genius.gui.actions.AboutAction;
|
---|
18 | import genius.gui.actions.OpenManual;
|
---|
19 | import genius.gui.actions.Session;
|
---|
20 | import genius.gui.actions.Tournament;
|
---|
21 | import genius.gui.boaframework.BOARepositoryUI;
|
---|
22 | import genius.gui.boaparties.BoaPartiesPanel;
|
---|
23 | import genius.gui.domainrepository.DomainRepositoryUI;
|
---|
24 | import genius.gui.panels.tab.CloseTabbedPane;
|
---|
25 | import genius.gui.repository.PartyRepositoryUI;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * main application and main GUI panel.
|
---|
29 | *
|
---|
30 | */
|
---|
31 | @SuppressWarnings("serial")
|
---|
32 | public class MainPanel extends JFrame implements GeniusAppInterface {
|
---|
33 |
|
---|
34 | private JTabbedPane repoArea = new JTabbedPane();
|
---|
35 | private CloseTabbedPane editArea = new CloseTabbedPane();
|
---|
36 |
|
---|
37 | public MainPanel() {
|
---|
38 | setLayout(new BorderLayout());
|
---|
39 |
|
---|
40 | // Fit nicely on smaller and bigger screens
|
---|
41 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
---|
42 | int prefx = 1280;
|
---|
43 | int prefy = 1024;
|
---|
44 | if (screenSize.getWidth() >= prefx && screenSize.getHeight() >= prefy)
|
---|
45 | setPreferredSize(new Dimension(prefx, prefy));
|
---|
46 | else
|
---|
47 | setMinimumSize(new Dimension(600, 400));
|
---|
48 |
|
---|
49 | String version = getClass().getPackage().getImplementationVersion();
|
---|
50 | if (version != null) // if the version is defined in the MANIFEST file,
|
---|
51 | // e.g. Genius is in a .jar
|
---|
52 | setTitle("GENIUS " + version);
|
---|
53 | else
|
---|
54 | setTitle("GENIUS");
|
---|
55 | JSplitPane splitpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
|
---|
56 | repoArea, editArea);
|
---|
57 | splitpane.setDividerLocation(300);
|
---|
58 |
|
---|
59 | add(splitpane, BorderLayout.CENTER);
|
---|
60 | repoArea.addTab("Domains",
|
---|
61 | new JScrollPane(new DomainRepositoryUI(this)));
|
---|
62 | repoArea.addTab("BOA Components",
|
---|
63 | new JScrollPane(new BOARepositoryUI(this)));
|
---|
64 | repoArea.addTab("Parties", new PartyRepositoryUI());
|
---|
65 | repoArea.addTab("Boa Parties", new BoaPartiesPanel());
|
---|
66 |
|
---|
67 | setJMenuBar(new MenuBar(this));
|
---|
68 |
|
---|
69 | editArea.addCloseListener((MouseEvent e, int overTabIndex) -> editArea
|
---|
70 | .remove(overTabIndex));
|
---|
71 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
---|
72 | }
|
---|
73 |
|
---|
74 | /**
|
---|
75 | * For testing
|
---|
76 | */
|
---|
77 | public static void main(String[] args) {
|
---|
78 | MainPanel mainpanel = new MainPanel();
|
---|
79 |
|
---|
80 | mainpanel.pack();
|
---|
81 | mainpanel.setVisible(true);
|
---|
82 |
|
---|
83 | }
|
---|
84 |
|
---|
85 | @Override
|
---|
86 | public void addTab(String title, Component comp) {
|
---|
87 | editArea.addTab(title, comp);
|
---|
88 | editArea.setSelectedComponent(comp);
|
---|
89 | }
|
---|
90 |
|
---|
91 | @Override
|
---|
92 | public Frame getMainFrame() {
|
---|
93 | return this;
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | @SuppressWarnings("serial")
|
---|
98 | class MenuBar extends JMenuBar {
|
---|
99 | private JMenu startMenu = new JMenu();
|
---|
100 | private JMenu helpMenu = new JMenu();
|
---|
101 |
|
---|
102 | public MenuBar(GeniusAppInterface mainPanel) {
|
---|
103 | startMenu.setText("Start");
|
---|
104 | startMenu.add(new Session(mainPanel));
|
---|
105 | startMenu.add(new Tournament(mainPanel));
|
---|
106 |
|
---|
107 | add(startMenu);
|
---|
108 |
|
---|
109 | helpMenu.setText("Help");
|
---|
110 | helpMenu.add(new OpenManual());
|
---|
111 | helpMenu.add(new AboutAction());
|
---|
112 | add(helpMenu);
|
---|
113 | }
|
---|
114 | } |
---|