X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsonitus%2Fgui%2FMainWindow.java;h=85a49fbbab15f9dae3cb902cfa44effa48a734bc;hb=633a841142f978235ed9f745b6ba16c278963e62;hp=3077950167252e737f32bb1e59e0a76238f3c77b;hpb=2f8bbcf8e8ea4779c5e8ced8e4221ab58e790b93;p=sonitus.git diff --git a/src/main/java/net/pterodactylus/sonitus/gui/MainWindow.java b/src/main/java/net/pterodactylus/sonitus/gui/MainWindow.java index 3077950..85a49fb 100644 --- a/src/main/java/net/pterodactylus/sonitus/gui/MainWindow.java +++ b/src/main/java/net/pterodactylus/sonitus/gui/MainWindow.java @@ -18,19 +18,25 @@ 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. @@ -39,50 +45,70 @@ import com.google.common.eventbus.EventBus; */ 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 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> 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); } }