package MyPaint;
import java.io.Serializable;
import java.util.Date;
import javafx.event.EventHandler;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Ellipse;
import javafx.scene.shape.Line;
import javafx.scene.shape.Polygon;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.Shape;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
interface Copy{
public Shape deepCopy(double x, double y);
public Shape deepCopy(double... points);
public double getPosX();
public double getPosY();
public double getArea();
public double getPerimeter();
public double[] getPos();
public String getID();
public double getwidth();
public double getheight();
public String getLineColor();
public String getFillColor();
public double getLineWidth();
public Shape reply();
public void changeAttr(double lineWidth, Paint lineColor, Paint fillColor);
}
class MyStraitLine extends Line implements Serializable, Copy{
protected Date createDate;
protected double[] pos;
protected double lineWidth;
protected String lineColor;
protected String fillColor;
public MyStraitLine(double startX, double startY, double endX, double endY,
double lineWidth, Paint lineColor, Paint fillColor) {
super(startX, startY, endX, endY);
this.setStrokeWidth(lineWidth);
this.setStroke(lineColor);
this.setFill(fillColor);
this.pos = new double[] {startX, startY, endX, endY};
this.createDate = new Date();
this.lineWidth = lineWidth;
this.lineColor = (lineColor==null?"":((Color)lineColor).toString() );
this.fillColor = (fillColor==null?"":((Color)fillColor).toString() );
}
@Override
public Shape deepCopy(double x, double y) {
// TODO Auto-generated method stub
double offsetX = x-this.pos[0];
double offsetY = y-this.pos[1];
MyStraitLine newCircle = new MyStraitLine(x,y,this.pos[2]+offsetX, this.pos[3]+offsetY,
this.getStrokeWidth(), this.getStroke(), this.getFill());
return newCircle;
}
@Override
public Shape deepCopy(double... points) {
// TODO Auto-generated method stub
return this.deepCopy(points[0], points[1]);
}
@Override
public double getPosX() {
// TODO Auto-generated method stub
return this.pos[0];
}
@Override
public double getPosY() {
// TODO Auto-generated method stub
return this.pos[1];
}
@Override
public double[] getPos() {
// TODO Auto-generated method stub
return this.pos;
}
@Override
public String getID() {
// TODO Auto-generated method stub
return "MyStraitLine@"+this.createDate.getTime();
}
@Override
public double getwidth() {
// TODO Auto-generated method stub
return 0;
}
@Override
public double getheight() {
// TODO Auto-generated method stub
return 0;
}
@Override
public String getLineColor() {
// TODO Auto-generated method stub
return this.lineColor;
}
@Override
public String getFillColor() {
// TODO Auto-generated method stub
return this.fillColor;
}
@Override
public double getLineWidth() {
// TODO Auto-generated method stub
return this.lineWidth;
}
@Override
public Shape reply() {
// TODO Auto-generated method stub
Paint fill = this.fillColor.equals("")?null:Color.valueOf(this.fillColor);
Paint lineColor = this.lineColor.equals("")?null:Color.valueOf(this.lineColor);
MyStraitLine newShape = new MyStraitLine(this.getPosX(), this.getPosY(), this.pos[2], this.pos[3],
this.lineWidth, lineColor, fill);
newShape.createDate = this.createDate;
return newShape;
}
public String toString() {
return this.getID()+"[ pos=[startX="+(int)this.getPosX()+","
+ " StartY="+(int)this.getPosY()+", endX="+(int)this.pos[2]+", endY="+(int)this.pos[3]+"] length="+(int)this.getPerimeter()+
", strokeWidth="+(int)this.lineWidth+", stroke="+this.lineColor+", fill="+this.fillColor+"]";
}
@Override
public double getArea() {
// TODO Auto-generated method stub
return 0;
}
@Override
public double getPerimeter() {
// TODO Auto-generated method stub
return Math.sqrt((this.pos[0]-this.pos[2])*(this.pos[0]-this.pos[2]) + (this.pos[1]-this.pos[3])*(this.pos[1]-this.pos[3]));
}
@Override
public void changeAttr(double lineWidth, Paint lineColor, Paint fillColor) {
// TODO Auto-generated method stub
this.setStrokeWidth(lineWidth);
this.setStroke(lineColor);
this.setFill(fillColor);
this.lineWidth = lineWidth;
this.lineColor = (lineColor==null?"":((Color)lineColor).toString() );
this.fillColor = (fillColor==null?"":((Color)fillColor).toString() );
}
}
class MyRectangle extends Rectangle implements Serializable, Copy{
/**
*
*/
private static final long serialVersionUID = -8577986604588650981L;
protected Date createDate;
protected double[] pos;
protected double width, height, lineWidth;
protected String lineColor;
protected String fillColor;
public MyRectangle(double x, double y, double width, double height, double lineWidth, Paint lineColor, Paint fillColor) {
super(x,y,width,height);
this.setFill(fillColor);
this.setStrokeWidth(lineWidth);
this.setStroke(lineColor);
this.pos = new double[] {x,y};
this.createDate = new Date();
this.width = width;
this.height = height;
this.lineWidth = lineWidth;
this.lineColor = (lineColor==null?"":((Color)lineColor).toString() );
this.fillColor = (fillColor==null?"":((Color)fillColor).toString() );
}
public double[] getPos() {
return this.pos;
}
public double getPosX() {
return this.pos[0];
}
public double getPosY() {
return this.pos[1];
}
public double getArea() {
return (int)this.getWidth() * (int)this.getHeight();
}
public double getPerimeter() {
return ( (int)this.getWidth() + (int)this.getHeight() ) * 2;
}
public Date getDate() {
return this.createDate;
}
//使用创建时的秒数来唯一标记形状
public String getID() {
return "MyRectangle@"+this.createDate.getTime();
}
public MyRectangle deepCopy(double x, double y) {
MyRectangle newRect = new MyRectangle(x, y, this.getWidth(), this.getHeight(),
this.getStrokeWidth(), this.getStroke(), this.getFill());
return newRect;
}
@Override
public Shape deepCopy(double... points) {
// TODO Auto-generated method stub
return this.deepCopy(points[0], points[1]);
}
public Shape reply() {
Paint fill = this.fillColor.equals("")?null:Color.valueOf(this.fillColor);
Paint lineColor = this.lineColor.equals("")?null:Color.valueOf(this.lineColor);
MyRectangle newShape = new MyRectangle(this.getPosX(), this.getPosY(), this.getwidth(), this.getheight(),
this.lineWidth, lineColor, fill);
newShape.createDate = this.createDate;
return newShape;
}
public String toString() {
return
this.getID()+"[ pos=[x="+(int)this.getPosX()+", y="+(int)this.getPosY()+"] width="+(int)this.width+", height="+(int)this.height+
", area="+(int)this.getArea()+", perimeter="+(int)this.getPerimeter()+
", strokeWidth="+(int)this.lineWidth+", stroke="+this.lineColor+", fill="+this.fillColor+"]";
}
@Override
public String getLineColor() {
// TODO Auto-generated method stub
return this.lineColor;
}
@Override
public String getFillColor() {
// TODO Auto-generated method stub
return this.fillColor;
}
@Override
public double getLineWidth() {
// TODO Auto-generated method stub
return this.lineWidth;
}
@Override
public double getwidth() {
// TODO Auto-generated method stub
return this.width;
}
//@Override
public double getheight() {
// TODO Auto-generated method stub
return this.height;
}
@Override
public void changeAttr(double lineWidth, Paint lineColor, Paint fillColor) {
// TODO Auto-generated method