Jskad/source/org/thdl/util/StatusBar.java
dchandler 7198f23361 I really hesitate to commit this because I'm not sure what it brings to the
table exactly and I fear that it makes the ACIP->Tibetan converter code
a lot uglier.  The TODO(DLC)[EWTS->Tibetan] comments littered throughout
are part of the ugliness; they point to the ugliness.  If each were addressed,
cleanliness could perhaps be achieved.

I've largely forgotten exactly what this change does, but it attempts to
improve EWTS->Tibetan conversion.  The lexer is probably really, really
primitive.  I concentrate here on converting a single tsheg bar rather than
a whole document.

Eclipse was used during part of my journey here and some imports were
reorganized merely because I could.  :)

(Eclipse was needed when the usual ant build failed to run a new test
EWTSTest.  And I wanted its debugger.)

Next steps: end-to-end EWTS tests should bring many problems to light.  Fix
those.  Triage all the TODO comments.

I don't know that I'll ever really trust the implementation.  The tests are
valuable, though.  A clean implementation of EWTS->Tibetan in Jython
might hold enough interest for me; I'd like to learn Python.
2005-06-20 06:18:00 +00:00

106 lines
3.4 KiB
Java

/*
The contents of this file are subject to the THDL Open Community License
Version 1.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License on the THDL web site
(http://www.thdl.org/).
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific terms governing rights and limitations under the
License.
The Initial Developer of this software is the Tibetan and Himalayan Digital
Library (THDL). Portions created by the THDL are Copyright 2001 THDL.
All Rights Reserved.
Contributor(s): ______________________________________.
*/
package org.thdl.util;
import java.util.Stack;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
/** A StatusBar can be added to a component, typically to the bottom
of it, in order to show the user the status of the program. There
are methods to change the status, and there are actually a LIFO
stack of status messages if you wish to use them. */
public class StatusBar extends JPanel {
/** The current status is the String on top of the stack. */
private Stack statuses;
private JLabel label;
/** Creates a status bar. */
public StatusBar() {
super();
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
statuses = new Stack();
label = new JLabel("Visit 'http://www.thdl.org/'.");
label.setHorizontalAlignment(SwingConstants.LEFT);
add(label);
}
/** Creates a status bar with the initial message msg. */
public StatusBar(String msg) {
this();
pushStatus(msg);
}
/** Sets the status to msg, replacing the current status message. */
public void replaceStatus(String msg) throws NullPointerException {
if (msg == null)
throw new NullPointerException();
if (!statuses.empty())
statuses.pop();
statuses.push(msg);
updateLabel();
}
/** Sets the status to msg, leaving the previous status on the
stack. */
public void pushStatus(String msg) throws NullPointerException {
if (msg == null)
throw new NullPointerException();
statuses.push(msg);
updateLabel();
}
/** Removes the current status message. If the stack is then
empty, the message will be the empty string. Otherwise, the
message will be the message then topmost on the stack.
@throws NullPointerException if msg is null
*/
public void popStatus() {
if (!statuses.empty()) {
statuses.pop();
updateLabel();
}
}
/** Returns the String currently displayed in the status bar. */
public String currentStatus() {
return getMsgOnTopOfStack();
}
/** Returns the status message on top of the stack, or "" if the
stack is empty. */
private String getMsgOnTopOfStack() {
if (statuses.empty())
return "";
else
return (String)statuses.peek();
}
/** Sets the displayed text to what's on top of the stack, or ""
if the stack is empty. */
private void updateLabel() {
label.setText(" " + // FIXME: nasty hack to make everything show up
getMsgOnTopOfStack());
}
}