java-app-qs/src/main/java/de/synolo/app/qs/editor/EditorItem.java

83 lines
2.6 KiB
Java

package de.synolo.app.qs.editor;
import java.util.ArrayList;
import java.util.List;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
public abstract class EditorItem {
private StringProperty nameProperty = new SimpleStringProperty("");
private BooleanProperty selectedProperty = new SimpleBooleanProperty(false);
protected DoubleProperty xProperty = new SimpleDoubleProperty(),
yProperty = new SimpleDoubleProperty(),
widthProperty = new SimpleDoubleProperty(),
heightProperty = new SimpleDoubleProperty();
protected List<ItemNode> nodes = new ArrayList<>();
public EditorItem() {
}
public StringProperty nameProperty() { return this.nameProperty; }
public String getName() { return this.nameProperty.get(); }
public void setName(String name) { this.nameProperty.set(name); }
public BooleanProperty selectedProperty() { return this.selectedProperty; }
public boolean isSelected() { return this.selectedProperty.get(); }
public void setSelected(boolean selected) { this.selectedProperty.set(selected); }
public DoubleProperty xProperty() { return this.xProperty; }
public double getX() { return this.xProperty.get(); }
public void setX(double x) { this.xProperty.set(x); }
public DoubleProperty yProperty() { return this.yProperty; }
public double getY() { return this.yProperty.get(); }
public void setY(double y) { this.yProperty.set(y); }
public DoubleProperty widthProperty() { return this.widthProperty; }
public double getWidth() { return this.widthProperty.get(); }
public void setWidth(double width) { this.widthProperty.set(width); }
public DoubleProperty heightProperty() { return this.heightProperty; }
public double getHeight() { return this.heightProperty.get(); }
public void setHeight(double height) { this.heightProperty.set(height); }
public boolean containsPoint(double x, double y) {
double tx = getX(),
ty = getY(),
width = getWidth(),
height = getHeight();
return x >= tx && x <= tx + width
&& y >= ty && ty <= ty + height;
}
public void paint(GraphicsContext gc) {
paintShape(gc);
if(isSelected()) {
gc.setFill(Color.YELLOW);
for(ItemNode node : this.nodes) {
gc.fillRect(node.getX()-10, node.getY()-10, 20, 20);
}
}
}
protected abstract void paintShape(GraphicsContext gc);
public abstract ItemNode nextNode(double x, double y);
}