From c60f62842b1c97fb08668a65b3b7885b11395078 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 27 May 2013 06:28:37 +0200 Subject: [PATCH] Add border around controller panel. --- .../pterodactylus/sonitus/gui/ControlledPane.java | 35 ++++++++++++++++++---- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/pterodactylus/sonitus/gui/ControlledPane.java b/src/main/java/net/pterodactylus/sonitus/gui/ControlledPane.java index 19b9fac..9a679f1 100644 --- a/src/main/java/net/pterodactylus/sonitus/gui/ControlledPane.java +++ b/src/main/java/net/pterodactylus/sonitus/gui/ControlledPane.java @@ -17,10 +17,15 @@ package net.pterodactylus.sonitus.gui; +import static javax.swing.BorderFactory.createEtchedBorder; +import static javax.swing.BorderFactory.createTitledBorder; + import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; @@ -48,19 +53,39 @@ public class ControlledPane extends JPanel { super(new GridBagLayout()); setBorder(BorderFactory.createEmptyBorder(6, 12, 12, 12)); + add(createControllerPanel(controlled), new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(6, 0, 0, 0), 0, 0)); + add(Box.createVerticalGlue(), new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(6, 0, 0, 0), 0, 0)); + } + + // + // PRIVATE METHODS + // + + /** + * Creates the controller panel for the given component. + * + * @param controlled + * The component whose controllers to display + * @return The created controller panel + */ + private JComponent createControllerPanel(Controlled controlled) { + JPanel controllerPanel = new JPanel(new GridBagLayout()); + controllerPanel.setBorder(createTitledBorder(createEtchedBorder(), "Controller")); + 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)); + controllerPanel.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), new GridBagConstraints(1, controllerIndex, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(6, 0, 0, 0), 0, 0)); + controllerPanel.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), new GridBagConstraints(1, controllerIndex, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(6, 0, 0, 0), 0, 0)); + controllerPanel.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)); } else if (controller instanceof Knob) { - add(new KnobPanel((Knob) controller), new GridBagConstraints(1, controllerIndex, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(6, 0, 0, 0), 0, 0)); + controllerPanel.add(new KnobPanel((Knob) 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(new JPanel(), new GridBagConstraints(0, controllerIndex, 2, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(6, 0, 0, 0), 0, 0)); + + return controllerPanel; } } -- 2.7.4