Display pipeline in main window.
[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.BorderFactory;
24 import javax.swing.JFrame;
25 import javax.swing.JTabbedPane;
26 import javax.swing.WindowConstants;
27
28 import net.pterodactylus.sonitus.data.Controlled;
29 import net.pterodactylus.sonitus.data.Controller;
30 import net.pterodactylus.sonitus.data.Pipeline;
31 import net.pterodactylus.sonitus.main.Version;
32
33 import com.google.common.eventbus.EventBus;
34
35 /**
36  * Sonitus main window.
37  *
38  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
39  */
40 public class MainWindow extends JFrame {
41
42         /** The event bus. */
43         private final EventBus eventBus;
44
45         /** The pipeline to display. */
46         private final Pipeline pipeline;
47
48         /** The tabbed pane displaying all controlled components. */
49         private final JTabbedPane tabbedPane = new JTabbedPane();
50
51         /**
52          * Creates a new main window.
53          *
54          * @param eventBus
55          *              The event bus
56          * @param pipeline
57          *              The pipeline to display
58          */
59         public MainWindow(EventBus eventBus, Pipeline pipeline) {
60                 super(String.format("Sonitus %s", Version.version()));
61                 this.eventBus = eventBus;
62                 this.pipeline = pipeline;
63                 tabbedPane.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
64                 tabbedPane.add("Pipeline", new PipelinePanel(pipeline));
65                 getContentPane().add(tabbedPane, BorderLayout.CENTER);
66                 setSize(new Dimension(800, 450));
67
68                 /* FIXME - shut everything down properly. */
69                 setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
70         }
71
72         //
73         // ACTIONS
74         //
75
76         /**
77          * Adds the given controlled to this main window.
78          *
79          * @param controlled
80          *              The controlled to add
81          */
82         public void addControllers(Controlled controlled) {
83                 List<Controller<?>> controllers = controlled.controllers();
84                 ControlledPane controlledPane = new ControlledPane(eventBus, controlled);
85                 tabbedPane.addTab(controlled.name(), controlledPane);
86         }
87
88 }