0cc3b135c6fda52c2ec5b5e7f759ee9e48576351
[sonitus.git] / src / main / java / net / pterodactylus / sonitus / gui / MainWindow.java
1 /*
2  * Sonitus - MainWindow.java - Copyright © 2013 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.sonitus.gui;
19
20 import java.awt.BorderLayout;
21 import java.awt.Dimension;
22 import java.util.List;
23 import javax.swing.JFrame;
24 import javax.swing.JTabbedPane;
25 import javax.swing.WindowConstants;
26
27 import net.pterodactylus.sonitus.data.Controlled;
28 import net.pterodactylus.sonitus.data.Controller;
29 import net.pterodactylus.sonitus.main.Version;
30
31 /**
32  * Sonitus main window.
33  *
34  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
35  */
36 public class MainWindow extends JFrame {
37
38         /** The tabbed pane displaying all controlled components. */
39         private final JTabbedPane tabbedPane = new JTabbedPane();
40
41         /** Creates a new main window. */
42         public MainWindow() {
43                 super(String.format("Sonitus %s", Version.version()));
44                 getContentPane().add(tabbedPane, BorderLayout.CENTER);
45                 setSize(new Dimension(800, 450));
46
47                 /* FIXME - shut everything down properly. */
48                 setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
49         }
50
51         //
52         // ACTIONS
53         //
54
55         /**
56          * Adds the given controlled to this main window.
57          *
58          * @param controlled
59          *              The controlled to add
60          */
61         public void addControllers(Controlled controlled) {
62                 List<Controller<?>> controllers = controlled.controllers();
63                 if (controllers.isEmpty()) {
64                         return;
65                 }
66                 ControlledPane controlledPane = new ControlledPane(controlled);
67                 tabbedPane.addTab(controlled.toString(), controlledPane);
68         }
69
70 }