From 4cf400fa9e6a9c6c8b1d058a3fa508155ae29d3e Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 28 May 2013 13:00:29 +0200 Subject: [PATCH] Draw components correctly in case of filters without sinks. --- .../pterodactylus/sonitus/gui/PipelinePanel.java | 43 ++++++++++++---------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/main/java/net/pterodactylus/sonitus/gui/PipelinePanel.java b/src/main/java/net/pterodactylus/sonitus/gui/PipelinePanel.java index dc9a901..42ddf9e 100644 --- a/src/main/java/net/pterodactylus/sonitus/gui/PipelinePanel.java +++ b/src/main/java/net/pterodactylus/sonitus/gui/PipelinePanel.java @@ -29,21 +29,18 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.Collection; import java.util.EventListener; -import java.util.List; +import java.util.logging.Logger; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.event.EventListenerList; import net.pterodactylus.sonitus.data.ControlledComponent; -import net.pterodactylus.sonitus.data.Filter; import net.pterodactylus.sonitus.data.Metadata; import net.pterodactylus.sonitus.data.MetadataListener; import net.pterodactylus.sonitus.data.Pipeline; import net.pterodactylus.sonitus.data.Sink; import net.pterodactylus.sonitus.data.Source; -import com.google.common.collect.Lists; - /** * {@link JPanel} that displays all components of a {@link Pipeline}. * @@ -51,6 +48,9 @@ import com.google.common.collect.Lists; */ public class PipelinePanel extends JPanel { + /** The logger. */ + private static final Logger logger = Logger.getLogger(PipelinePanel.class.getName()); + /** The pipeline being displayed. */ private final Pipeline pipeline; @@ -94,18 +94,19 @@ public class PipelinePanel extends JPanel { /* count all sinks. */ int sinkCount = 0; - List sources = Lists.newArrayList(pipeline.source()); - while (!sources.isEmpty()) { - Collection sinks = pipeline.sinks(sources.remove(0)); - for (Sink sink : sinks) { - /* only count real sinks, everything else is filter. */ - if (sink instanceof Filter) { - sources.add((Filter) sink); - } else { - sinkCount++; - } + for (ControlledComponent component : pipeline.components()) { + if (!(component instanceof Source)) { + logger.finest(String.format("%s is not a Source, skipping.", component.name())); + sinkCount++; + continue; + } + Collection sinks = pipeline.sinks((Source) component); + logger.finest(String.format("%s has %d sinks: %s", component.name(), sinks.size(), sinks)); + if (sinks.isEmpty()) { + sinkCount++; } } + System.out.println(sinkCount); /* get number of maximum horizontal grid cells. */ int gridCellCount = 1; @@ -153,12 +154,14 @@ public class PipelinePanel extends JPanel { /* iterate over the component’s sinks. */ Collection sinks = pipeline.sinks((Source) controlledComponent); - int sinkWidth = width / sinks.size(); - int sinkIndex = 0; - for (Sink connectedSink : sinks) { - /* distribute all sinks evenly below this source. */ - addControlled(connectedSink, level + 1, position + sinkIndex * sinkWidth, sinkWidth, controlledComponent); - sinkIndex++; + if (!sinks.isEmpty()) { + int sinkWidth = width / sinks.size(); + int sinkIndex = 0; + for (Sink connectedSink : sinks) { + /* distribute all sinks evenly below this source. */ + addControlled(connectedSink, level + 1, position + sinkIndex * sinkWidth, sinkWidth, controlledComponent); + sinkIndex++; + } } } -- 2.7.4