92 lines
2.3 KiB
Java
92 lines
2.3 KiB
Java
package de.synolo.app.qs;
|
|
|
|
import de.synolo.app.qs.editor.EditorCanvas;
|
|
import de.synolo.app.qs.editor.EditorItem;
|
|
import de.synolo.app.qs.editor.EditorLayer;
|
|
import de.synolo.app.qs.editor.ItemFactory;
|
|
import de.synolo.app.qs.editor.ItemNode;
|
|
import de.synolo.lib.fw.app.AbstractApplication;
|
|
import javafx.scene.Scene;
|
|
import javafx.scene.canvas.GraphicsContext;
|
|
import javafx.scene.control.Button;
|
|
import javafx.scene.control.TextArea;
|
|
import javafx.scene.layout.AnchorPane;
|
|
import javafx.scene.layout.BorderPane;
|
|
import javafx.scene.paint.Color;
|
|
import javafx.stage.Modality;
|
|
import javafx.stage.Stage;
|
|
import javafx.stage.StageStyle;
|
|
|
|
public class QSApplication extends AbstractApplication<QSContext>{
|
|
|
|
public static void main(String[] args) {
|
|
launch(args);
|
|
}
|
|
|
|
@Override
|
|
protected QSContext initContext() {
|
|
return new QSContext();
|
|
}
|
|
|
|
@Override
|
|
protected void buildApplication(Stage primaryStage) throws Exception {
|
|
EditorCanvas cnv = new EditorCanvas();
|
|
Scene scene = new Scene(cnv);
|
|
primaryStage.setScene(scene);
|
|
|
|
EditorLayer layer = new EditorLayer(cnv, "My Layer", true, false);
|
|
|
|
cnv.getLayers().add(layer);
|
|
|
|
RectangleFactory factory = new RectangleFactory();
|
|
cnv.getControl().setItemFactory(factory);
|
|
|
|
cnv.getLayerSelectionModel().select(0);
|
|
|
|
System.out.println(cnv.getLayerSelectionModel().getSelectedItems());
|
|
|
|
|
|
primaryStage.show();
|
|
|
|
}
|
|
|
|
private static class RectangleFactory implements ItemFactory {
|
|
|
|
@Override
|
|
public EditorItem createItem() {
|
|
return new EditorItem() {
|
|
|
|
@Override
|
|
protected void paintShape(GraphicsContext gc) {
|
|
System.out.println("xy: " + getX() + " " + getY());
|
|
gc.setFill(Color.BEIGE);
|
|
gc.fillRect(getX(), getY(), getWidth(), getHeight());
|
|
|
|
}
|
|
|
|
@Override
|
|
public ItemNode nextNode(double x, double y) {
|
|
if(this.nodes.isEmpty()) {
|
|
System.out.println(x + " " + y);
|
|
ItemNode node = new ItemNode(x, y);
|
|
this.nodes.add(node);
|
|
this.xProperty.bind(node.xProperty());
|
|
this.yProperty.bind(node.yPropert());
|
|
|
|
node = new ItemNode(x, y);
|
|
this.nodes.add(node);
|
|
this.widthProperty.bind(node.xProperty().subtract(this.xProperty));
|
|
this.heightProperty.bind(node.yPropert().subtract(this.yProperty));
|
|
|
|
return node;
|
|
}else {
|
|
return null;
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
}
|
|
|
|
}
|