2 * jSite2 - StatusBar.java -
3 * Copyright © 2008 David Roden
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 package net.pterodactylus.util.swing;
22 import java.awt.BorderLayout;
23 import java.awt.Component;
24 import java.awt.GridBagConstraints;
25 import java.awt.GridBagLayout;
26 import java.awt.Insets;
27 import java.util.ArrayList;
28 import java.util.List;
30 import javax.swing.JFrame;
31 import javax.swing.JLabel;
32 import javax.swing.JPanel;
33 import javax.swing.border.EtchedBorder;
36 * Status bar component that can be added to the {@link BorderLayout#SOUTH} area
37 * of a {@link JFrame}’s {@link JFrame#getContentPane() content pane}.
39 * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
41 /* TODO - make it possible to add further components. */
42 public class StatusBar extends JPanel {
45 private GridBagLayout layout = new GridBagLayout();
48 private JLabel statusLabel = new JLabel();
50 /** Addition components. */
51 private List<Component> sideComponents = new ArrayList<Component>();
54 * Creates a new status bar.
58 statusLabel.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
59 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));
63 * Sets the text of the label.
66 * The text of the label
68 public void setText(String text) {
69 statusLabel.setText(text);
73 * Adds a side component to the right side of the status bar, pushing all
74 * previously added side components to the left.
77 * The component to add
79 public void addSideComponent(Component component) {
80 sideComponents.add(component);
81 int newIndex = sideComponents.size();
82 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));
87 * Returns the number of side components.
89 * @return The number of side components
91 public int getSideComponentCount() {
92 return sideComponents.size();
96 * Returns all side components in order.
98 * @return All side components
100 public List<Component> getSideComponents() {
101 return sideComponents;
105 * Removes the side component with the given index.
107 * @param sideComponentIndex
108 * The index of the side component to remove
110 public void removeSideComponent(int sideComponentIndex) {
111 Component sideComponent = sideComponents.remove(sideComponentIndex);
112 remove(sideComponent);
117 * Removes the given side component.
119 * @param sideComponent
120 * The side component to remove
122 public void removeSideComponent(Component sideComponent) {
123 sideComponents.remove(sideComponent);
124 remove(sideComponent);