From d39c62bb0271412aaa9445b2ba7596b0fabb394a Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 26 May 2013 15:11:05 +0200 Subject: [PATCH] Improve layout. --- .../pterodactylus/sonitus/gui/ControlledPane.java | 23 +++++++++++++++------- .../net/pterodactylus/sonitus/gui/FaderPanel.java | 12 +++-------- .../net/pterodactylus/sonitus/gui/SwitchPanel.java | 7 +------ 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/main/java/net/pterodactylus/sonitus/gui/ControlledPane.java b/src/main/java/net/pterodactylus/sonitus/gui/ControlledPane.java index 010fa3a..76fb8d0 100644 --- a/src/main/java/net/pterodactylus/sonitus/gui/ControlledPane.java +++ b/src/main/java/net/pterodactylus/sonitus/gui/ControlledPane.java @@ -17,8 +17,12 @@ package net.pterodactylus.sonitus.gui; -import javax.swing.Box; -import javax.swing.BoxLayout; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import javax.swing.BorderFactory; +import javax.swing.JLabel; +import javax.swing.JPanel; import net.pterodactylus.sonitus.data.Controlled; import net.pterodactylus.sonitus.data.Controller; @@ -31,7 +35,7 @@ import net.pterodactylus.sonitus.data.controller.Switch; * * @author David ‘Bombe’ Roden */ -public class ControlledPane extends Box { +public class ControlledPane extends JPanel { /** * Creates a new controlled pane. @@ -40,15 +44,20 @@ public class ControlledPane extends Box { * The controlled whose controllers to display */ public ControlledPane(Controlled controlled) { - super(BoxLayout.Y_AXIS); + super(new GridBagLayout()); + setBorder(BorderFactory.createEmptyBorder(6, 12, 12, 12)); + + int controllerIndex = 0; for (Controller controller : controlled.controllers()) { + add(new JLabel(controller.name()), new GridBagConstraints(0, controllerIndex, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(6, 0, 0, 6), 0, 0)); if (controller instanceof Fader) { - add(new FaderPanel((Fader) controller)); + add(new FaderPanel((Fader) controller), new GridBagConstraints(1, controllerIndex, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(6, 0, 0, 0), 0, 0)); } else if (controller instanceof Switch) { - add(new SwitchPanel((Switch) controller)); + add(new SwitchPanel((Switch) controller), new GridBagConstraints(1, controllerIndex, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(6, 0, 0, 0), 0, 0)); } + ++controllerIndex; } - add(Box.createGlue()); + add(new JPanel(), new GridBagConstraints(0, controllerIndex, 2, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(6, 0, 0, 0), 0, 0)); } } diff --git a/src/main/java/net/pterodactylus/sonitus/gui/FaderPanel.java b/src/main/java/net/pterodactylus/sonitus/gui/FaderPanel.java index b37fec6..cb4102c 100644 --- a/src/main/java/net/pterodactylus/sonitus/gui/FaderPanel.java +++ b/src/main/java/net/pterodactylus/sonitus/gui/FaderPanel.java @@ -20,7 +20,6 @@ package net.pterodactylus.sonitus.gui; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; -import javax.swing.BorderFactory; import javax.swing.DefaultBoundedRangeModel; import javax.swing.JLabel; import javax.swing.JPanel; @@ -45,15 +44,10 @@ public class FaderPanel extends JPanel { */ public FaderPanel(final Fader fader) { super(new GridBagLayout()); - setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); - - /* create label. */ - JLabel label = new JLabel(fader.name()); - add(label, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); /* create fader labels. */ - add(new JLabel("-∞"), new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0)); - add(new JLabel("0"), new GridBagConstraints(3, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0)); + add(new JLabel("-∞"), new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0)); + add(new JLabel("0"), new GridBagConstraints(2, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 6, 0, 0), 0, 0)); /* create fader. */ JSlider slider = new JSlider(new DefaultBoundedRangeModel((int) (fader.value() * Integer.MAX_VALUE), 0, 0, Integer.MAX_VALUE)); @@ -64,7 +58,7 @@ public class FaderPanel extends JPanel { fader.value(((JSlider) changeEvent.getSource()).getValue() / (double) Integer.MAX_VALUE); } }); - add(slider, new GridBagConstraints(2, 0, 1, 1, 1, 1, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); + add(slider, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); } } diff --git a/src/main/java/net/pterodactylus/sonitus/gui/SwitchPanel.java b/src/main/java/net/pterodactylus/sonitus/gui/SwitchPanel.java index 5ffd8a2..e3350a7 100644 --- a/src/main/java/net/pterodactylus/sonitus/gui/SwitchPanel.java +++ b/src/main/java/net/pterodactylus/sonitus/gui/SwitchPanel.java @@ -44,11 +44,6 @@ public class SwitchPanel extends JPanel { */ public SwitchPanel(final Switch switchController) { super(new GridBagLayout()); - setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); - - /* create label. */ - JLabel label = new JLabel(switchController.name()); - add(label, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); /* create checkbox. */ JCheckBox checkBox = new JCheckBox(); @@ -59,7 +54,7 @@ public class SwitchPanel extends JPanel { switchController.value(((JCheckBox) actionEvent.getSource()).isSelected()); } }); - add(checkBox, new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); + add(checkBox, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); } } -- 2.7.4