| StatusBar.java |
1 /**
2 * Distribution License:
3 * BibleDesktop is free software; you can redistribute it and/or modify it under
4 * the terms of the GNU General Public License, version 2 as published by
5 * the Free Software Foundation. This program is distributed in the hope
6 * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8 * See the GNU General Public License for more details.
9 *
10 * The License is available on the internet at:
11 * http://www.gnu.org/copyleft/gpl.html
12 * or by writing to:
13 * Free Software Foundation, Inc.
14 * 59 Temple Place - Suite 330
15 * Boston, MA 02111-1307, USA
16 *
17 * Copyright: 2005
18 * The copyright to this program is held by it's authors.
19 *
20 * ID: $Id: StatusBar.java 2091 2011-03-07 04:15:31Z dmsmith $
21 */
22 package org.crosswire.bibledesktop.desktop;
23
24 import java.awt.Font;
25 import java.awt.GridBagConstraints;
26 import java.awt.GridBagLayout;
27 import java.awt.Insets;
28 import java.awt.event.MouseEvent;
29 import java.awt.event.MouseListener;
30
31 import javax.swing.AbstractButton;
32 import javax.swing.Action;
33 import javax.swing.BorderFactory;
34 import javax.swing.JComponent;
35 import javax.swing.JLabel;
36 import javax.swing.JSeparator;
37 import javax.swing.SwingConstants;
38
39 import org.crosswire.bibledesktop.BDMsg;
40 import org.crosswire.bibledesktop.display.URIEvent;
41 import org.crosswire.bibledesktop.display.URIEventListener;
42 import org.crosswire.common.progress.swing.JobsProgressBar;
43 import org.crosswire.common.swing.GuiUtil;
44 import org.crosswire.common.util.OSType;
45
46 /**
47 * The status bar provides useful info to the user as to the current state of
48 * the program.
49 * <p>
50 * We need to think about the stuff to put in here:
51 * <ul>
52 * <li>A status message. This changes with what the user is pointing at, so is
53 * very similar to tool-tips. Although they are commonly more instructional.
54 * <li>A set of panels that tell you the time/if CAPS is presses and so on
55 * </ul>
56 *
57 * @see gnu.gpl.License for license details.<br>
58 * The copyright to this program is held by it's authors.
59 * @author Joe Walker [joe at eireneh dot com]
60 */
61 public class StatusBar extends JComponent implements MouseListener, URIEventListener {
62 /**
63 * Create a new StatusBar
64 */
65 public StatusBar() {
66 initialize();
67 }
68
69 /**
70 * Init the GUI
71 */
72 private void initialize() {
73 // TRANSLATOR: This is the text in the status bar when there is nothing else to say.
74 labelMessage.setText(BDMsg.gettext("Ready ..."));
75
76 Font font = panelProgress.getFont();
77 panelProgress.setFont(font.deriveFont(6.0F));
78
79 /*
80 Dimension dim = panelProgress.getPreferredSize();
81 dim.height = labelMessage.getSize().height;
82 panelProgress.setPreferredSize(dim);
83 */
84
85 this.setBorder(BorderFactory.createEtchedBorder());
86 this.setLayout(new GridBagLayout());
87
88 JSeparator separator = new JSeparator(SwingConstants.VERTICAL);
89
90 // Right pad the last entry so that it stays away from the corner.
91 // On the Mac, the "grow" handle is in the corner of the app.
92 int finalPadX = 0;
93 int finalPadY = 0;
94 if (OSType.MAC.equals(OSType.getOSType())) {
95 finalPadX = 20;
96 finalPadY = 5;
97 }
98 this.add(labelMessage, new GridBagConstraints(0, 0, 1, 1, 0.3, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL,
99 new Insets(0, 0, 0, 0), 0, 0));
100 this.add(separator,
101 new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_END, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0), 0, 0));
102 this.add(panelProgress, new GridBagConstraints(2, 0, 1, 1, 0.7, 0.0, GridBagConstraints.LINE_END, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0),
103 finalPadX, finalPadY));
104 GuiUtil.applyDefaultOrientation(this);
105 }
106
107 /* (non-Javadoc)
108 * @see org.crosswire.bibledesktop.display.URIEventListener#activateURI(org.crosswire.bibledesktop.display.URIEvent)
109 */
110 public void activateURI(URIEvent ev) {
111 // We don't care about activate events
112 }
113
114 /* (non-Javadoc)
115 * @see org.crosswire.bibledesktop.display.URIEventListener#enterURI(org.crosswire.bibledesktop.display.URIEvent)
116 */
117 public void enterURI(URIEvent ev) {
118 String protocol = ev.getScheme();
119 String uri = ev.getURI();
120 if (protocol.length() == 0) {
121 labelMessage.setText(uri);
122 } else {
123 labelMessage.setText(protocol + "://" + uri);
124 }
125 }
126
127 /* (non-Javadoc)
128 * @see org.crosswire.bibledesktop.display.URIEventListener#leaveURI(org.crosswire.bibledesktop.display.URIEvent)
129 */
130 public void leaveURI(URIEvent ev) {
131 // TRANSLATOR: This is the text in the status bar when there is nothing else to say.
132 labelMessage.setText(BDMsg.gettext("Ready ..."));
133 }
134
135 /**
136 * Sets the text to display
137 *
138 * @param txt
139 * The text
140 */
141 public void setText(String txt) {
142 if (txt == null) {
143 // TRANSLATOR: This is the text in the status bar when there is nothing else to say.
144 labelMessage.setText(BDMsg.gettext("Ready ..."));
145 } else {
146 labelMessage.setText(txt);
147 }
148 }
149
150 /**
151 * Catches status signals and displays new text
152 *
153 * @param signal
154 * The signal with the status text
155 */
156 // public void channel(final StatusSignal signal)
157 // {
158 // SwingUtilities.invokeLater(new Runnable()
159 // {
160 // public void run()
161 // {
162 // labelMessage.setText(signal.getMessage());
163 // }
164 // });
165 // }
166 /**
167 * When the mouse points at something that has registered with us to be
168 * shown on the statusbar
169 *
170 * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
171 */
172 public void mouseEntered(MouseEvent ev) {
173 if (ev.getSource() instanceof AbstractButton) {
174 AbstractButton button = (AbstractButton) ev.getSource();
175 Action action = button.getAction();
176
177 if (action != null) {
178 Object value = action.getValue(Action.SHORT_DESCRIPTION);
179
180 if (value != null) {
181 labelMessage.setText(value.toString());
182 }
183 }
184 }
185 }
186
187 /**
188 * When the mouse no longer points at something that has registered with us
189 *
190 * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
191 */
192 public void mouseExited(MouseEvent ev) {
193 // TRANSLATOR: This is the text in the status bar when there is nothing else to say.
194 labelMessage.setText(BDMsg.gettext("Ready ..."));
195 }
196
197 /**
198 * Invoked when the mouse has been clicked on a component. Ignored
199 *
200 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
201 */
202 public void mouseClicked(MouseEvent ev) {
203 }
204
205 /**
206 * Invoked when a mouse button has been pressed on a component. Ignored
207 *
208 * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
209 */
210 public void mousePressed(MouseEvent ev) {
211 }
212
213 /**
214 * Invoked when a mouse button has been released on a component. Ignored
215 *
216 * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
217 */
218 public void mouseReleased(MouseEvent ev) {
219 }
220
221 /**
222 * Where the progress bars go
223 */
224 private JobsProgressBar panelProgress = new JobsProgressBar(true);
225
226 /**
227 * Where the help messages go
228 */
229 protected JLabel labelMessage = new JLabel();
230
231 /**
232 * Serialization ID
233 */
234 private static final long serialVersionUID = 3546920264718955568L;
235 }
236