package net.pterodactylus.sonitus.gui;
import java.awt.BorderLayout;
+import java.awt.CardLayout;
import java.awt.Dimension;
-import java.util.List;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
+import javax.swing.JPanel;
import javax.swing.JTabbedPane;
+import javax.swing.Timer;
import javax.swing.WindowConstants;
-import net.pterodactylus.sonitus.data.Controlled;
-import net.pterodactylus.sonitus.data.Controller;
+import net.pterodactylus.sonitus.data.Filter;
import net.pterodactylus.sonitus.data.Pipeline;
+import net.pterodactylus.sonitus.gui.PipelinePanel.FilterSelectionListener;
import net.pterodactylus.sonitus.main.Version;
-import com.google.common.eventbus.EventBus;
+import com.google.common.base.Optional;
+import com.google.common.collect.Maps;
/**
* Sonitus main window.
*/
public class MainWindow extends JFrame {
- /** The event bus. */
- private final EventBus eventBus;
-
/** The pipeline to display. */
private final Pipeline pipeline;
- /** The tabbed pane displaying all controlled components. */
+ /** The tabbed pane displaying all pipelines. */
private final JTabbedPane tabbedPane = new JTabbedPane();
+ /** The info panel card layout. */
+ private final CardLayout infoPanelCardLayout = new CardLayout();
+
+ /** The info panel. */
+ private final JPanel infoPanel = new JPanel(infoPanelCardLayout);
+
+ /** The mapping from filters to info panels. */
+ private final Map<Filter, FilterInfoPanel> filterInfoPanels = Maps.newHashMap();
+
/**
* Creates a new main window.
*
- * @param eventBus
- * The event bus
* @param pipeline
* The pipeline to display
*/
- public MainWindow(EventBus eventBus, Pipeline pipeline) {
+ public MainWindow(Pipeline pipeline) {
super(String.format("Sonitus %s", Version.version()));
- this.eventBus = eventBus;
this.pipeline = pipeline;
tabbedPane.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
- tabbedPane.add("Pipeline", new PipelinePanel(pipeline));
+ final JPanel pipelineInfoPanel = new JPanel(new BorderLayout(12, 12));
+ PipelinePanel pipelinePanel = new PipelinePanel(pipeline);
+ pipelinePanel.addFilterSelectionListener(new FilterSelectionListener() {
+
+ @Override
+ public void filterSelected(Filter filter) {
+ infoPanelCardLayout.show(infoPanel, filter.name());
+ }
+ });
+ pipelineInfoPanel.add(pipelinePanel, BorderLayout.CENTER);
+ pipelineInfoPanel.add(infoPanel, BorderLayout.EAST);
+ tabbedPane.add("Pipeline", pipelineInfoPanel);
getContentPane().add(tabbedPane, BorderLayout.CENTER);
setSize(new Dimension(800, 450));
- /* FIXME - shut everything down properly. */
- setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
- }
+ /* create info panels for all filters. */
+ for (Filter fliter : pipeline) {
+ FilterInfoPanel filterInfoPanel = new FilterInfoPanel(fliter);
+ infoPanel.add(filterInfoPanel, fliter.name());
+ filterInfoPanels.put(fliter, filterInfoPanel);
+ }
- //
- // ACTIONS
- //
+ Timer timer = new Timer(250, new ActionListener() {
- /**
- * Adds the given controlled to this main window.
- *
- * @param controlled
- * The controlled to add
- */
- public void addControllers(Controlled controlled) {
- List<Controller<?>> controllers = controlled.controllers();
- ControlledPane controlledPane = new ControlledPane(eventBus, controlled);
- tabbedPane.addTab(controlled.name(), controlledPane);
+ @Override
+ public void actionPerformed(ActionEvent actionEvent) {
+ /* update all info panels. */
+ for (Filter filter : MainWindow.this.pipeline) {
+ FilterInfoPanel filterInfoPanel = filterInfoPanels.get(filter);
+ filterInfoPanel.input(MainWindow.this.pipeline.trafficCounter(filter).input());
+ filterInfoPanel.output(MainWindow.this.pipeline.trafficCounter(filter).output());
+ filterInfoPanel.format(Optional.of(filter.metadata().format()));
+ }
+ }
+ });
+ timer.start();
+
+ /* FIXME - shut everything down properly. */
+ setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
}