From dd8b4361efb9d53fccaf52584ca684d84f54204a Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 24 May 2008 18:43:06 +0200 Subject: [PATCH] add side components --- src/net/pterodactylus/util/swing/StatusBar.java | 61 ++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/src/net/pterodactylus/util/swing/StatusBar.java b/src/net/pterodactylus/util/swing/StatusBar.java index ebfaec2..f4dc146 100644 --- a/src/net/pterodactylus/util/swing/StatusBar.java +++ b/src/net/pterodactylus/util/swing/StatusBar.java @@ -20,9 +20,12 @@ package net.pterodactylus.util.swing; import java.awt.BorderLayout; +import java.awt.Component; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; +import java.util.ArrayList; +import java.util.List; import javax.swing.JFrame; import javax.swing.JLabel; @@ -45,13 +48,16 @@ public class StatusBar extends JPanel { /** The label. */ private JLabel statusLabel = new JLabel(); + /** Addition components. */ + private List sideComponents = new ArrayList(); + /** * Creates a new status bar. */ public StatusBar() { setLayout(layout); statusLabel.setBorder(new EtchedBorder(EtchedBorder.LOWERED)); - add(statusLabel, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); + add(statusLabel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); } /** @@ -64,4 +70,57 @@ public class StatusBar extends JPanel { statusLabel.setText(text); } + /** + * Adds a side component to the right side of the status bar, pushing all + * previously added side components to the left. + * + * @param component + * The component to add + */ + public void addSideComponent(Component component) { + sideComponents.add(component); + int newIndex = sideComponents.size(); + add(component, new GridBagConstraints(newIndex, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 2, 0, 0), 0, 0)); + } + + /** + * Returns the number of side components. + * + * @return The number of side components + */ + public int getSideComponentCount() { + return sideComponents.size(); + } + + /** + * Returns all side components in order. + * + * @return All side components + */ + public List getSideComponents() { + return sideComponents; + } + + /** + * Removes the side component with the given index. + * + * @param sideComponentIndex + * The index of the side component to remove + */ + public void removeSideComponent(int sideComponentIndex) { + Component sideComponent = sideComponents.remove(sideComponentIndex); + remove(sideComponent); + } + + /** + * Removes the given side component. + * + * @param sideComponent + * The side component to remove + */ + public void removeSideComponent(Component sideComponent) { + sideComponents.remove(sideComponent); + remove(sideComponent); + } + } -- 2.7.4