package drawingBoard;
import javafx.beans.property.*;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.event.EventType;
import javafx.geometry.Orientation;
import javafx.scene.Cursor;
import javafx.scene.Group;
import javafx.scene.control.*;
import javafx.scene.effect.Bloom;
import javafx.scene.effect.InnerShadow;
import javafx.scene.effect.Light;
import javafx.scene.effect.Lighting;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.*;
import javafx.scene.text.Font;
import java.util.*;
public class PropertyBar extends Pane
{
MainPane fa;
private Label name = new Label("PROPERTY");
private ArrayList<ArrayList<Property>> objectProperty = new ArrayList<>();
private LinkedList<Shape> selected = new LinkedList<>();
private Shape nowShape;
private ScrollBar scrollBar = new ScrollBar();
private Group layout = new Group();
public ArrayList<ArrayList<Property>> getObjectProperty()
{
return objectProperty;
}
public Label getName()
{
return name;
}
public PropertyBar(MainPane fa)
{
scrollBar.setOrientation(Orientation.VERTICAL);
scrollBar.setPrefWidth(20);
scrollBar.layoutXProperty().bind(prefWidthProperty().subtract(scrollBar.getPrefWidth()));
scrollBar.prefHeightProperty().bind(heightProperty());
getChildren().add(scrollBar);
scrollBar.valueProperty().addListener((value, pre, now)->
{
layout.setLayoutY(-now.doubleValue());
});
setOnScroll(event ->
{
scrollBar.setValue(scrollBar.getValue()-event.getDeltaY());
});
setPrefWidth(250);
this.fa=fa;
setStyle("-fx-background-color: #ffffff");
Light.Point light = new Light.Point();
light.setColor(Color.BLACK);
light.xProperty().bind(widthProperty().divide(2));
light.yProperty().bind(heightProperty().divide(2));
light.setZ(300);
Lighting lighting = new Lighting();
lighting.setLight(light);
lighting.setSurfaceScale(50.0);
name.setFont(Font.font("Arial Black", 30));
name.setTextFill(Color.BLACK);
name.setLayoutX(40);
Group group = new Group(name);
group.setEffect(new Bloom(0.1));
layout.getChildren().add(group);
getChildren().add(layout);
}
public void initBind()
{
DragToSuit dragToSuit = new DragToSuit(Main.getChangeCursor());
this.setOnMouseEntered(dragToSuit);
this.setOnMouseExited(dragToSuit);
this.setOnMouseMoved(dragToSuit);
this.setOnMouseDragged(dragToSuit);
this.setOnMousePressed(dragToSuit);
this.setOnMouseReleased(dragToSuit);
}
public class DragToSuit implements EventHandler<MouseEvent>
{
private ChangeCursor changeCursor;
private boolean pressed = false;
public DragToSuit(ChangeCursor changeCursor)
{
this.changeCursor = changeCursor;
}
@Override
public void handle(MouseEvent event)
{
if(event.getEventType().equals(MouseEvent.MOUSE_ENTERED))
{
if(event.getX()<10)
{
Main.getScene().setCursor(Cursor.E_RESIZE);
}
}
else if(event.getEventType().equals(MouseEvent.MOUSE_EXITED))
{
Main.getScene().setCursor(changeCursor.future);
}
else if(event.getEventType().equals(MouseEvent.MOUSE_MOVED))
{
if(!pressed)
{
if (event.getX() >= 10)
{
Main.getScene().setCursor(changeCursor.future);
} else
{
Main.getScene().setCursor(Cursor.E_RESIZE);
}
}
}
else if(event.getEventType().equals(MouseEvent.MOUSE_PRESSED))
{
if(event.getX()<10)
{
pressed = true;
setPrefWidth(getWidth()-event.getX());
}
}
else if(event.getEventType().equals(MouseEvent.MOUSE_DRAGGED))
{
if(pressed)
{
setPrefWidth(getWidth()-event.getX());
}
}
else if(event.getEventType().equals(MouseEvent.MOUSE_RELEASED))
{
pressed = false;
}
}
}
public void setName(String name)
{
this.name.setText(name);
}
public void update(Shape shape)
{
delete(shape);
add(shape);
}
public void add(Shape shape)
{
add(shape, fa.getMyCenter().getObject().getChildren().indexOf(shape));
}
public void add(Shape shape, int index)
{
objectProperty.add(new ArrayList<>());
ArrayList<Property> now = objectProperty.get(index);
if(shape instanceof Line)//startX startY endX endY strokeWidth Color blendMode
{
Line line = (Line)shape;
now.add(shape.layoutXProperty());
now.add(shape.layoutYProperty());
now.add(line.startXProperty());
now.add(line.startYProperty());
now.add(line.endXProperty());
now.add(line.endYProperty());
now.add(line.strokeProperty());
now.add(line.rotateProperty());
now.add(line.strokeWidthProperty());
double x=line.endYProperty().getValue()-line.startYProperty().getValue();
double y=line.endXProperty().getValue()-line.startYProperty().getValue();
double width=line.strokeWidthProperty().doubleValue();
double length=Math.sqrt(x*x+y*y)*width;
Property area=new SimpleDoubleProperty(length);
Property perimeter=new SimpleDoubleProperty(2*(width+length));
now.add(area);
now.add(perimeter);
}
else if(shape instanceof CubicCurve)
{
CubicCurve curve = (CubicCurve)shape;
now.add(shape.layoutXProperty());
now.add(shape.layoutYProperty());
now.add(curve.startXProperty());
now.add(curve.startYProperty());
now.add(curve.endXProperty());
now.add(curve.endYProperty());
now.add(curve.controlX1Property());
now.add(curve.controlY1Property());
now.add(curve.controlX2Property());
now.add(curve.controlY2Property());
now.add(curve.strokeProperty());
now.add(curve.fillProperty());
now.add(curve.rotateProperty());
now.add(curve.strokeWidthProperty());
}
else if(shape instanceof Ellipse)
{
Ellipse ellipse = (Ellipse)shape;
now.add(shape.layoutXProperty());
now.add(shape.layoutYProperty());
now.add(ellipse.centerXProperty());
now.add(ellipse.centerYProperty());
now.add(ellipse.radiusXProperty());
now.add(ellipse.radiusYProperty());
now.add(ellipse.strokeProperty());
now.add(ellipse.fillProperty());
now.add(ellipse.rotateProperty());
now.add(ellipse.strokeWidthProperty());
if(ellipse.getRadiusX()==ellipse.getRadiusY()){
//System.out.println(ellipse.radiusXProperty());
SimpleDoubleProperty simpleDoubleProperty = new SimpleDoubleProperty(2 * Math.P
评论0