package greenfoot.guifx.classes;
import bluej.utility.javafx.JavaFXUtil;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Paint;
import threadchecker.OnThread;
import threadchecker.Tag;
| The display of a single class in Greenfoot's class diagram.
|
| Note that due to anticipated re-use of this item in the right-hand class diagram,
| and the import-class dialog and maybe other places too, this class itself only
| handles display and selection. All other functionality (e.g. context menus)
| is done externally as it is not used in all instances of ClassDisplay.
|
@OnThread(Tag.FXPlatform)
public class ClassDisplay
extends StackPane{
private final String fullyQualifiedName;
private final BorderPane stripePane;
private final Label contentLabel;
| @param displayName The class name to display (without package)
| @param image The image, if any (can be null)
| @param selectionManager The selection manager. The constructor will add this
| class to the selection manager.
|
public ClassDisplay(String displayName, String fullyQualifiedName, Image image, ClassDisplaySelectionManager selectionManager)
{
this.fullyQualifiedName = fullyQualifiedName;
getStyleClass().add("class-display");
setSnapToPixel(true);
contentLabel = new Label(displayName);
BorderPane content = new BorderPane(contentLabel);
setImage(image);
JavaFXUtil.addStyleClass(content, "class-display-content");
stripePane = new BorderPane();
getChildren().addAll(stripePane, content);
selectionManager.addClassDisplay(this);
addEventHandler(MouseEvent.MOUSE_CLICKED, e -> {
if (e.getButton() == MouseButton.PRIMARY && e.getClickCount() == 1)
{
selectionManager.select(this);
e.consume();
}
});
}
| Sets the graphical selected state of this class display
|
public void setSelected(boolean selected)
{
JavaFXUtil.setPseudoclass("gf-selected", selected, this);
}
| Gets the qualified name of the class
|
public String getQualifiedName()
{
return fullyQualifiedName;
}
| Sets the image to the left of the class name
|
public void setImage(Image image)
{
if (image == null)
{
contentLabel.setGraphic(null);
}
else
{
ImageView imageView = new ImageView(image);
imageView.setFitHeight(Math.min(image.getHeight(), 16));
imageView.setFitWidth(Math.min(image.getWidth(), 16));
imageView.setPreserveRatio(true);
contentLabel.setGraphic(imageView);
}
}
| Sets the stripe pattern of this class (use Color.TRANSPARENT to mean none)
|
public void setStripePattern(Paint stripeFill)
{
stripePane.setBackground(new Background(new BackgroundFill(stripeFill, null, null)));
}
}
top,
use,
map,
class ClassDisplay
. ClassDisplay
. setSelected
. getQualifiedName
. setImage
. setStripePattern
112 neLoCode
+ 13 LoComm