1 package net.pterodactylus.util.swing;
4 import java.awt.BorderLayout;
5 import java.awt.Component;
6 import java.awt.GridBagConstraints;
7 import java.awt.GridBagLayout;
8 import java.awt.Insets;
9 import java.util.ArrayList;
10 import java.util.List;
12 import javax.swing.JFrame;
13 import javax.swing.JLabel;
14 import javax.swing.JPanel;
15 import javax.swing.border.EtchedBorder;
18 * Status bar component that can be added to the {@link BorderLayout#SOUTH} area
19 * of a {@link JFrame}’s {@link JFrame#getContentPane() content pane}.
21 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
23 /* TODO - make it possible to add further components. */
24 public class StatusBar extends JPanel {
27 private GridBagLayout layout = new GridBagLayout();
30 private JLabel statusLabel = new JLabel();
32 /** Addition components. */
33 private List<Component> sideComponents = new ArrayList<Component>();
36 * Creates a new status bar.
40 statusLabel.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
41 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));
45 * Sets the text of the label.
48 * The text of the label
50 public void setText(String text) {
51 statusLabel.setText(text);
55 * Adds a side component to the right side of the status bar, pushing all
56 * previously added side components to the left.
59 * The component to add
61 public void addSideComponent(Component component) {
62 sideComponents.add(component);
63 int newIndex = sideComponents.size();
64 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));
69 * Returns the number of side components.
71 * @return The number of side components
73 public int getSideComponentCount() {
74 return sideComponents.size();
78 * Returns all side components in order.
80 * @return All side components
82 public List<Component> getSideComponents() {
83 return sideComponents;
87 * Removes the side component with the given index.
89 * @param sideComponentIndex
90 * The index of the side component to remove
92 public void removeSideComponent(int sideComponentIndex) {
93 Component sideComponent = sideComponents.remove(sideComponentIndex);
94 remove(sideComponent);
99 * Removes the given side component.
101 * @param sideComponent
102 * The side component to remove
104 public void removeSideComponent(Component sideComponent) {
105 sideComponents.remove(sideComponent);
106 remove(sideComponent);