package bluej.groupwork.actions;
import bluej.Config;
import bluej.pkgmgr.PkgMgrFrame;
import bluej.pkgmgr.Project;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.control.ButtonBase;
import javafx.scene.control.MenuItem;
import javafx.scene.control.Tooltip;
| An abstract class for team actions.
|
| This is similar to FXAbstractAction but is different in that each button or menu item is not
| constructed here, but is instead adapted with an explicit reference to either the PkgMgrFrame
| or Project (see useButton, useMenuItem methods).
|
| @author fisker
|
public abstract class TeamAction
{
private final StringProperty name = new SimpleStringProperty();
private final BooleanProperty disabled = new SimpleBooleanProperty(false);
protected String shortDescription;
| Constructor for a team action which shows a dialog. An ellipsis
| is added to the action text.
|
| @param label The key for action text
| @param showsDialog True if an ellipsis should be appended
|
public TeamAction(String label, boolean showsDialog)
{
setName(Config.getString(label), showsDialog);
}
| Changes the name of the action.
| @param name
|
public void setName(String name, boolean showsDialog)
{
this.name.set(showsDialog && !name.endsWith("...") ? (name + "...") : name);
}
public void setEnabled(boolean enabled)
{
disabled.set(!enabled);
}
public boolean isDisabled()
{
return disabled.get();
}
public BooleanProperty disabledProperty()
{
return disabled;
}
public void setShortDescription(String shortDescription)
{
this.shortDescription = shortDescription;
}
| Sets the given button, which is associated with a PkgMgrFrame, to activate this action on
| click, and use this action's title and disabled state.
|
public void useButton(PkgMgrFrame pmf, ButtonBase button)
{
button.textProperty().unbind();
button.textProperty().bind(name);
button.disableProperty().unbind();
button.disableProperty().bind(disabled);
button.setOnAction(e -> actionPerformed(pmf));
if (shortDescription != null)
{
Tooltip.install(button, new Tooltip(shortDescription));
}
}
| Sets the given button to activate this action on click, and use this action's title and
| disabled state.
|
public void useButton(Project project, ButtonBase button)
{
button.textProperty().unbind();
button.textProperty().bind(name);
button.disableProperty().unbind();
button.disableProperty().bind(disabled);
button.setOnAction(e -> actionPerformed(project));
if (shortDescription != null)
{
Tooltip.install(button, new Tooltip(shortDescription));
}
}
| Sets the given menu item to activate this action,
| and use this action's title and disabled state
|
public void useMenuItem(PkgMgrFrame pmf, MenuItem menuItem)
{
menuItem.textProperty().unbind();
menuItem.textProperty().bind(name);
menuItem.disableProperty().unbind();
menuItem.disableProperty().bind(disabled);
menuItem.setOnAction(e -> actionPerformed(pmf));
}
| The action was attached to a button not associated with a PkgMgrFrame.
|
protected void actionPerformed(Project project)
{
}
| The action was attached to a button or menu item associated with a PkgMgrFrame.
|
protected void actionPerformed(PkgMgrFrame pmf)
{
actionPerformed(pmf.getProject());
}
}
top,
use,
map,
abstract class TeamAction
. TeamAction
. setName
. setEnabled
. isDisabled
. disabledProperty
. setShortDescription
. useButton
. useButton
. useMenuItem
. actionPerformed
. actionPerformed
122 neLoCode
+ 20 LoComm