package bluej.editor.moe;
import bluej.Config;
import bluej.prefmgr.PrefMgr;
import bluej.utility.javafx.JavaFXUtil;
import javafx.scene.control.Label;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.VBox;
import threadchecker.OnThread;
import threadchecker.Tag;
| Status label for the Moe editor.
|
| @author Michael Kolling
|
@OnThread(Tag.FXPlatform)
public final class StatusLabel
extends VBox{
public static enum Status
{
READONLY("editor.state.readOnly"),
SAVED("editor.state.saved"),
CHANGED("editor.state.changed");
private final String displayText;
private Status(String displayKey)
{
this.displayText = Config.getString(displayKey);
}
public String getDisplayText()
{
return displayText;
}
}
private final Label statusLabel;
private final Label errorLabel;
private Status state;
private int errorCount = 0;
public StatusLabel(Status initialState, MoeEditor editor, MoeErrorManager errorManager)
{
JavaFXUtil.addStyleClass(this, "moe-status-label-wrapper");
styleProperty().bind(PrefMgr.getEditorFontCSS(false));
state = initialState;
statusLabel = new Label();
errorLabel = new Label();
JavaFXUtil.addStyleClass(errorLabel, "error-count-label");
getChildren().setAll(statusLabel, errorLabel);
updateLabel();
errorManager.listenForErrorChange(errs -> {
errorCount = errs.size();
updateLabel();
});
setOnMouseClicked(e -> {
if (e.getButton() == MouseButton.PRIMARY)
{
if (errorCount > 0)
{
editor.compileOrShowNextError();
}
e.consume();
}
});
}
public boolean isSaved()
{
return (state != Status.CHANGED);
}
public boolean isChanged()
{
return (state == Status.CHANGED);
}
public boolean isReadOnly()
{
return (state == Status.READONLY);
}
public void setState(Status newState)
{
state = newState;
updateLabel();
}
private void updateLabel()
{
statusLabel.setText(state.getDisplayText().replace("\n", ""));
if (errorCount > 0)
{
errorLabel.setText("Errors: " + errorCount);
}
else
{
errorLabel.setText("");
}
JavaFXUtil.setPseudoclass("bj-status-error", errorCount > 0, this);
}
}
. - StatusLabel
. Status
. getDisplayText
. StatusLabel
. isSaved
. isChanged
. isReadOnly
. setState
. updateLabel
122 neLoCode
+ 2 LoComm