X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsonitus%2Fgui%2FMainWindow.java;h=aa358c3a58c304f952f7dc0ba942e10bae090228;hb=fa5196e029c48636f0c318311244395cfae49953;hp=cdd077697a5091e0ef8d7104a2dda1bb32a6cbe5;hpb=09f8bd2297dc864e24baa67c65be97104e00c320;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 cdd0776..aa358c3 100644 --- a/src/main/java/net/pterodactylus/sonitus/gui/MainWindow.java +++ b/src/main/java/net/pterodactylus/sonitus/gui/MainWindow.java @@ -18,16 +18,26 @@ 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.ControlledComponent; +import net.pterodactylus.sonitus.data.Pipeline; +import net.pterodactylus.sonitus.gui.PipelinePanel.ComponentHoverListener; import net.pterodactylus.sonitus.main.Version; +import com.google.common.base.Optional; +import com.google.common.collect.Maps; + /** * Sonitus main window. * @@ -35,36 +45,70 @@ import net.pterodactylus.sonitus.main.Version; */ public class MainWindow extends JFrame { + /** The pipeline to display. */ + private final Pipeline pipeline; + /** The tabbed pane displaying all controlled components. */ private final JTabbedPane tabbedPane = new JTabbedPane(); - /** Creates a new main window. */ - public MainWindow() { - super(String.format("Sonitus %s", Version.version())); - getContentPane().add(tabbedPane, BorderLayout.CENTER); - setSize(new Dimension(800, 450)); + /** The info panel card layout. */ + private final CardLayout infoPanelCardLayout = new CardLayout(); - /* FIXME - shut everything down properly. */ - setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); - } + /** The info panel. */ + private final JPanel infoPanel = new JPanel(infoPanelCardLayout); - // - // ACTIONS - // + /** The mapping from controlled components to info panels. */ + private final Map controlledInfoPanels = Maps.newHashMap(); /** - * Adds the given controlled to this main window. + * Creates a new main window. * - * @param controlled - * The controlled to add + * @param pipeline + * The pipeline to display */ - public void addControllers(Controlled controlled) { - List> controllers = controlled.controllers(); - if (controllers.isEmpty()) { - return; + public MainWindow(Pipeline pipeline) { + super(String.format("Sonitus %s", Version.version())); + this.pipeline = pipeline; + tabbedPane.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); + final JPanel pipelineInfoPanel = new JPanel(new BorderLayout(12, 12)); + PipelinePanel pipelinePanel = new PipelinePanel(pipeline); + pipelinePanel.addComponentHoverListener(new ComponentHoverListener() { + + @Override + public void componentEntered(ControlledComponent controlledComponent) { + infoPanelCardLayout.show(infoPanel, controlledComponent.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)); + + /* create info panels for all components. */ + for (ControlledComponent controlledComponent : pipeline) { + ComponentInfoPanel componentInfoPanel = new ComponentInfoPanel(controlledComponent); + infoPanel.add(componentInfoPanel, controlledComponent.name()); + controlledInfoPanels.put(controlledComponent, componentInfoPanel); } - ControlledPane controlledPane = new ControlledPane(controlled); - tabbedPane.addTab(controlled.name(), controlledPane); + + Timer timer = new Timer(250, new ActionListener() { + + @Override + public void actionPerformed(ActionEvent actionEvent) { + /* update all info panels. */ + for (ControlledComponent controlled : MainWindow.this.pipeline) { + ComponentInfoPanel componentInfoPanel = controlledInfoPanels.get(controlled); + componentInfoPanel.input(MainWindow.this.pipeline.trafficCounter(controlled).input()); + componentInfoPanel.output(MainWindow.this.pipeline.trafficCounter(controlled).output()); + componentInfoPanel.format(Optional.of(controlled.metadata().format())); + } + } + }); + timer.start(); + + /* FIXME - shut everything down properly. */ + setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } }