001 /**
002 * ========================================
003 * JFreeReport : a free Java report library
004 * ========================================
005 *
006 * Project Info: http://reporting.pentaho.org/
007 *
008 * (C) Copyright 2000-2007, by Object Refinery Limited, Pentaho Corporation and Contributors.
009 *
010 * This library is free software; you can redistribute it and/or modify it under the terms
011 * of the GNU Lesser General Public License as published by the Free Software Foundation;
012 * either version 2.1 of the License, or (at your option) any later version.
013 *
014 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016 * See the GNU Lesser General Public License for more details.
017 *
018 * You should have received a copy of the GNU Lesser General Public License along with this
019 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020 * Boston, MA 02111-1307, USA.
021 *
022 * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023 * in the United States and other countries.]
024 *
025 * ------------
026 * $Id: JStatusBar.java,v 1.5 2007/04/01 18:49:30 taqua Exp $
027 * ------------
028 * (C) Copyright 2000-2005, by Object Refinery Limited.
029 * (C) Copyright 2005-2007, by Pentaho Corporation.
030 */
031 package org.jfree.report.modules.gui.swing.common;
032
033 import java.awt.BorderLayout;
034 import java.awt.Dimension;
035 import java.awt.IllegalComponentStateException;
036 import java.util.Locale;
037 import javax.swing.BorderFactory;
038 import javax.swing.Icon;
039 import javax.swing.JComponent;
040 import javax.swing.JLabel;
041 import javax.swing.JPanel;
042 import javax.swing.UIManager;
043
044 import org.jfree.report.modules.gui.common.DefaultIconTheme;
045 import org.jfree.report.modules.gui.common.IconTheme;
046
047 public class JStatusBar extends JComponent
048 {
049 public static final int TYPE_ERROR = 3;
050 public static final int TYPE_WARNING = 2;
051 public static final int TYPE_INFORMATION = 1;
052 public static final int TYPE_NONE = 0;
053
054 private JComponent otherComponents;
055 private JLabel statusHolder;
056 private IconTheme iconTheme;
057 private int statusType;
058
059 public JStatusBar()
060 {
061 this(new DefaultIconTheme());
062 }
063
064 public JStatusBar (final IconTheme theme)
065 {
066 setLayout(new BorderLayout());
067 setBorder(BorderFactory.createMatteBorder
068 (1, 0, 0, 0, UIManager.getDefaults().getColor("controlShadow")));
069 statusHolder = new JLabel(" ");
070 statusHolder.setMinimumSize(new Dimension(0, 20));
071 add(statusHolder, BorderLayout.CENTER);
072
073 otherComponents = new JPanel();
074 add(otherComponents, BorderLayout.EAST);
075 this.iconTheme = theme;
076 }
077
078 protected IconTheme getIconTheme()
079 {
080 return iconTheme;
081 }
082
083 public void setIconTheme(final IconTheme iconTheme)
084 {
085 IconTheme oldTheme = this.iconTheme;
086 this.iconTheme = iconTheme;
087 firePropertyChange("iconTheme", oldTheme, iconTheme);
088
089 if (iconTheme == null)
090 {
091 statusHolder.setIcon(null);
092 }
093 else
094 {
095 updateTypeIcon(getStatusType());
096 }
097 }
098
099 public JComponent getExtensionArea ()
100 {
101 return otherComponents;
102 }
103
104 public int getStatusType()
105 {
106 return statusType;
107 }
108
109 public String getStatusText()
110 {
111 return statusHolder.getText();
112 }
113
114 public void setStatusText (String text)
115 {
116 final String oldText = statusHolder.getText();
117 this.statusHolder.setText(text);
118 firePropertyChange("statusText", oldText, text);
119 }
120
121 public void setStatusType (int type)
122 {
123 int oldType = statusType;
124 this.statusType = type;
125 firePropertyChange("statusType", oldType, type);
126 updateTypeIcon(type);
127 }
128
129 public void setStatus (final int type, final String text)
130 {
131 this.statusType = type;
132 updateTypeIcon(type);
133 statusHolder.setText(text);
134 }
135
136 private void updateTypeIcon(final int type)
137 {
138 if (iconTheme != null)
139 {
140 if (type == TYPE_ERROR)
141 {
142 final Icon res = getIconTheme().getSmallIcon(getLocale(), "statusbar.errorIcon");
143 statusHolder.setIcon(res);
144 }
145 else if (type == TYPE_WARNING)
146 {
147 final Icon res = getIconTheme().getSmallIcon(getLocale(), "statusbar.warningIcon");
148 statusHolder.setIcon(res);
149 }
150 else if (type == TYPE_INFORMATION)
151 {
152 final Icon res = getIconTheme().getSmallIcon(getLocale(), "statusbar.informationIcon");
153 statusHolder.setIcon(res);
154 }
155 else
156 {
157 final Icon res = getIconTheme().getSmallIcon(getLocale(), "statusbar.otherIcon");
158 statusHolder.setIcon(res);
159 }
160 }
161 }
162
163 public void clear ()
164 {
165 setStatus(TYPE_NONE, " ");
166 }
167
168 /**
169 * Gets the locale of this component.
170 *
171 * @return this component's locale; if this component does not have a locale,
172 * the locale of its parent is returned
173 * @throws java.awt.IllegalComponentStateException
174 * if the <code>Component</code> does not have its own locale and has
175 * not yet been added to a containment hierarchy such that the locale
176 * can be determined from the containing parent
177 * @see #setLocale
178 * @since JDK1.1
179 */
180 public Locale getLocale()
181 {
182 try
183 {
184 return super.getLocale();
185 }
186 catch(IllegalComponentStateException ice)
187 {
188 return Locale.getDefault();
189 }
190 }
191 }