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>
42 /* TODO - make it possible to add further components. */
43 public class StatusBar extends JPanel {
46 private GridBagLayout layout = new GridBagLayout();
49 private JLabel statusLabel = new JLabel();
51 /** Addition components. */
52 private List<Component> sideComponents = new ArrayList<Component>();
55 * Creates a new status bar.
59 statusLabel.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
60 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 * Sets the text of the label.
67 * The text of the label
69 public void setText(String text) {
70 statusLabel.setText(text);
74 * Adds a side component to the right side of the status bar, pushing all
75 * previously added side components to the left.
78 * The component to add
80 public void addSideComponent(Component component) {
81 sideComponents.add(component);
82 int newIndex = sideComponents.size();
83 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);
116 * Removes the given side component.
118 * @param sideComponent
119 * The side component to remove
121 public void removeSideComponent(Component sideComponent) {
122 sideComponents.remove(sideComponent);
123 remove(sideComponent);