duh il y a 7 ans
Parent
commit
7e5f9b6f97

+ 326 - 0
src/main/java/com/hb/project4/tools/CatchTool.java

@@ -0,0 +1,326 @@
+package com.hb.project4.tools;
+
+import java.awt.Color;
+import java.awt.Cursor;
+import java.awt.Graphics;
+import java.awt.Point;
+import java.awt.event.MouseEvent;
+import java.util.ArrayList;
+
+import javax.swing.undo.UndoableEdit;
+
+import com.hb.project4.drawPanel.DrawJPanel;
+import com.hb.project4.shapes.HotPointShape;
+import com.hb.project4.shapes.SuperShape;
+
+public class CatchTool extends SuperTool {
+
+	private boolean canselectFlag = false;
+
+	private Point[] hotP;
+
+	private int index = 0;
+
+	private SuperShape newShape = null; // 探测的新图形
+
+	private SuperShape opShape; // 操作图形
+
+	private SuperShape oldShape = null;// 探测同一图形
+
+	boolean dragged = false; // 是否在拖动状态
+
+	boolean isChangedShape = false; // 形状是否改变了
+
+	HotPointShape hotShape = new HotPointShape();
+
+	Point bg = new Point(0, 0); // 操作图形的原开始点
+
+	Point ed = new Point(0, 0); // 操作图形的原结束点
+
+	int position = 0; // 探测图形的位置
+
+	public CatchTool(DrawJPanel j) {
+
+		super(j);
+		newShape = null;
+		opShape = null;
+		oldShape = null;
+		// TODO Auto-generated constructor stub
+	}
+
+	/**
+	 * 根据移动点,来判断是否抓到了图形
+	 * 
+	 * @param p
+	 * @return
+	 */
+	public SuperShape catchShape(Point p) {
+		this.setNewShape(null);
+		ArrayList shapeList = this.getJPanel().getCurrentShapes();
+		SuperShape tempShape = null;
+		SuperShape returnShape = null;
+		for (int i = shapeList.size() - 1; i > -1; i--) {
+			tempShape = (SuperShape) shapeList.get(i);
+			if (tempShape.checkOnShape(p) != 0) {
+				returnShape = tempShape;
+				return returnShape;
+			}
+		}
+		return returnShape;
+	}
+
+	@Override
+	public void mouseClickedAction(MouseEvent mouseEvent) {
+
+	}
+
+	/**
+	 * 根据鼠标的拖动,来重画相应的图形
+	 */
+	@Override
+	public void mouseDraggedAction(MouseEvent mouseEvent) {
+		Graphics g = this.getJPanel().getGraphics();
+//		g.setColor(this.getJPanel().getLinecolor());
+		g.setXORMode(Color.WHITE);
+		if (opShape != null) {
+//			g.setColor(this.opShape.getClor());
+			this.setNewDragPoint(mouseEvent.getPoint());
+			if (this.position == -1) {// 点在边缘平移
+
+				opShape.draw(g);// 擦去原图形和热点
+
+				int wide = this.getNewDragPoint().x - this.getOldDragPoint().x;
+				int lengh = this.getNewDragPoint().y - this.getOldDragPoint().y;
+				Point tuo = new Point(wide, lengh);
+				this.opShape.setBegin(new Point(wide + bg.x, lengh + bg.y));
+				this.opShape.setEnd(new Point(wide + ed.x, lengh + ed.y));
+
+				opShape.draw(g);// 画出现有图形和热点
+
+				isChangedShape = true;
+
+			} else if (this.position == 0) {
+			} else {
+				opShape.draw(g);// 擦去原图形和热点
+
+				this.opShape.setHotPoint(position, this.getNewDragPoint());
+
+				opShape.draw(g);// 画出现有图形和热点
+
+				isChangedShape = true;
+			}
+
+		}
+	}
+
+	/**
+	 * 鼠标探测图形,显示相应的热点
+	 */
+	@Override
+	public void mouseMovedAction(MouseEvent mouseEvent) {
+		if (!this.dragged) {
+			Graphics g = this.getJPanel().getGraphics();
+//			g.setColor(Color.BLACK);
+			g.setXORMode(Color.WHITE);
+
+			Point movePoint = mouseEvent.getPoint();
+
+			this.newShape = this.catchShape(movePoint);
+			if (newShape != null) { // 鼠标监测到图形时变换
+				if (newShape.checkOnShape(movePoint) != -1
+						&& newShape.checkOnShape(movePoint) != 0) {
+					this
+							.getJPanel()
+							.setCursor(
+									Cursor
+											.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
+				} else if (newShape.checkOnShape(movePoint) == -1) {
+					this.getJPanel().setCursor(
+							Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
+				}
+			} else {
+				this.getJPanel().setCursor(
+						Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+			}
+
+			if (newShape != null) {
+
+				if (oldShape == null) { // 触到第一个图形,画出其热点
+					if (opShape == null) {
+						this.canselectFlag = true;
+						oldShape = newShape;
+						hotShape.setHotPoints(this.oldShape.getHotPoints());
+						hotShape.draw(g);
+					} else {
+						if (opShape != newShape) {
+							this.canselectFlag = true;
+							oldShape = newShape;
+							hotShape.setHotPoints(this.oldShape.getHotPoints());
+							hotShape.draw(g);
+						}
+					}
+				}
+				if (newShape != oldShape && oldShape != null) { // 当原图形和现图形不同时,再画一次老图形热点
+					this.canselectFlag = true;
+					if (oldShape != opShape) {
+						hotShape.setHotPoints(this.oldShape.getHotPoints());
+						hotShape.draw(g);
+					}
+					if (newShape != opShape) {
+						oldShape = newShape;
+						hotShape.setHotPoints(this.oldShape.getHotPoints()); // 显示新图形热点,
+						hotShape.draw(g);
+					}
+				}
+			} else {
+				this.canselectFlag = false;
+				if (oldShape != null && oldShape != opShape) {
+					hotShape.setHotPoints(this.oldShape.getHotPoints());// 当原图形不空时,再画一次老图形热点
+					hotShape.draw(g);
+					oldShape = null;
+				}
+			}
+		}
+	}
+
+	/**
+	 * 鼠标按下,拖动修改图形的前置条件,或者选择要操作的图形
+	 */
+	@Override
+	public void mousePressedAction(MouseEvent mouseEvent) {
+		Point pressPoint = mouseEvent.getPoint();
+		this.setOldDragPoint(pressPoint);
+		this.setBeginPoint(pressPoint);
+		if (opShape != null && opShape.checkOnShape(pressPoint) != 0) {
+			this.dragged = true;
+		}
+		Graphics g = this.getJPanel().getGraphics();
+//		g.setColor(this.getJPanel().getLinecolor());
+		if (opShape != null && opShape.checkOnShape(pressPoint) == 0 && canselectFlag==false) {
+			this.opShape.setSelect(false);
+			this.opShape = null;
+			this.oldShape=null;
+		}
+		if (opShape != null) {
+			position = this.opShape.checkOnShape(pressPoint);
+			// System.out.println("position"+position);
+		}
+		if (canselectFlag) {
+
+			if (opShape == null) { // 操作图形为空时把触到的图形赋给操作图形
+
+				this.opShape = this.oldShape;
+
+				this.setOperateShape(opShape);
+
+				this.opShape.setSelect(true);
+				position = this.opShape.checkOnShape(pressPoint);
+			}
+			if (opShape != oldShape) {
+				if (opShape != null) { // 再画一次原操作图形的热点
+					this.opShape.setSelect(false);
+				}
+				this.opShape = this.oldShape;
+				this.setOperateShape(opShape);
+				this.opShape.setSelect(true);
+				position = this.opShape.checkOnShape(pressPoint);
+			}
+		}
+
+		if (opShape != null) {
+			bg = this.opShape.getBegin();
+			ed = this.opShape.getEnd();
+		}
+		this.getJPanel().repaint();
+
+	}
+
+	@Override
+	public void mouseReleasedAction(MouseEvent mouseEvent) {
+		// px
+		if (isChangedShape) {
+			this.opShape.setSelect(false);
+			this.getJPanel().saveHistory();
+			this.opShape.setSelect(true);
+			isChangedShape = false;
+		}
+		// px
+		this.dragged = false;
+		this.canselectFlag = false;
+		this.bg = null;
+		this.ed = null;
+		position = 0;
+		this.getJPanel().repaint();
+		this.setOldDragPoint(null);
+
+	}
+	
+	public void removeCatchShape(){
+		this.getJPanel().getCurrentShapes().remove(opShape);
+		this.getJPanel().saveHistory();
+		this.getJPanel().repaint();
+	}
+	
+	public void changeColor(Color co){
+		this.opShape.setClor(co);
+		this.getJPanel().saveHistory();
+		this.getJPanel().repaint();
+	}
+
+	public Point[] getHotP() {
+		return hotP;
+	}
+
+	public void setHotP(Point[] hotP) {
+		this.hotP = hotP;
+	}
+
+	public int getIndex() {
+		return index;
+	}
+
+	public void setIndex(int index) {
+		this.index = index;
+	}
+
+	public boolean isCanSelectFlag() {
+		return canselectFlag;
+	}
+
+	public void setCanSelectFlag(boolean selectFlag) {
+		this.canselectFlag = selectFlag;
+	}
+
+	public HotPointShape getHotShape() {
+		return hotShape;
+	}
+
+	public void setHotShape(HotPointShape hotShape) {
+		this.hotShape = hotShape;
+	}
+
+	public SuperShape getOldShape() {
+		return oldShape;
+	}
+
+	public void setOldShape(SuperShape oldShape) {
+		this.oldShape = oldShape;
+	}
+
+	public SuperShape getOpShape() {
+		return opShape;
+	}
+
+	public void setOpShape(SuperShape opShape) {
+		this.opShape = opShape;
+	}
+
+	public SuperShape getNewShape() {
+		return newShape;
+	}
+
+	public void setNewShape(SuperShape newShape) {
+		this.newShape = newShape;
+	}
+
+}

+ 85 - 0
src/main/java/com/hb/project4/tools/LineTool.java

@@ -0,0 +1,85 @@
+package com.hb.project4.tools;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Point;
+import java.awt.event.MouseEvent;
+import java.util.ArrayList;
+
+import com.hb.project4.drawPanel.DrawJPanel;
+import com.hb.project4.shapes.LineShape;
+import com.hb.project4.shapes.SuperShape;
+
+public class LineTool extends SuperTool {
+
+	public LineTool(DrawJPanel j) {
+		super(j);
+		// TODO Auto-generated constructor stub
+	}
+
+	@Override
+	public void mouseClickedAction(MouseEvent mouseEvent) {
+
+	}
+
+	@Override
+	public void mouseDraggedAction(MouseEvent mouseEvent) {
+		this.setNewDragPoint(mouseEvent.getPoint());
+		this.setOldDragPoint(this.getNewDragPoint());
+//		this.setNewDragPoint(null);
+
+		Graphics g = this.getJPanel().getGraphics();
+		g.setColor(this.getJPanel().getLinecolor());
+		g.setXORMode(Color.WHITE);
+
+		if (this.getOperateShape().getEnd() != null) {
+			this.getOperateShape().draw(g);
+		}
+		this.getOperateShape().setEnd(this.getNewDragPoint());
+		this.getOperateShape().draw(g);
+
+	}
+
+	@Override
+	public void mouseMovedAction(MouseEvent mouseEvent) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void mousePressedAction(MouseEvent mouseEvent) {
+		this.setBeginPoint(mouseEvent.getPoint());
+
+		this.setOldDragPoint(this.getBeginPoint());
+		this.setOldMovePoint(this.getBeginPoint());
+
+		this.setOperateShape(new LineShape());
+		this.getOperateShape().setClor(this.getJPanel().getLinecolor());
+		this.getOperateShape().setBegin(this.getBeginPoint());
+
+	}
+
+	@Override
+	public void mouseReleasedAction(MouseEvent mouseEvent) {
+		Graphics g = this.getJPanel().getGraphics();
+		g.setColor(this.getJPanel().getLinecolor());
+//		g.setXORMode(Color.WHITE);
+		this.setEndPoint(mouseEvent.getPoint());
+		if (this.getOldMovePoint() != null) {
+			this.getOperateShape().setEnd(this.getOldMovePoint());
+			this.getOperateShape().draw(g);
+		}
+		this.getOperateShape().setEnd(this.getEndPoint());
+		this.getOperateShape().draw(g);
+		this.getJPanel().getCurrentShapes().add(this.getOperateShape());
+
+		// add new Shapes to historyShapes
+		this.getJPanel().saveHistory();
+		
+		this.getJPanel().repaint();
+		this.setBeginPoint(null);
+		this.setEndPoint(null);
+
+	}
+
+}

+ 89 - 0
src/main/java/com/hb/project4/tools/OpenTool.java

@@ -0,0 +1,89 @@
+package com.hb.project4.tools;
+
+import java.awt.Graphics;
+import java.awt.event.MouseEvent;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.util.ArrayList;
+
+import javax.swing.JOptionPane;
+
+import com.hb.project4.drawPanel.DrawJPanel;
+import com.hb.project4.shapes.LineShape;
+import com.hb.project4.shapes.RectangleShape;
+import com.hb.project4.shapes.SuperShape;
+/**
+ * 该类用于读取文件中保存的图形
+ * @author 杨鹏飞
+ * 时间:2008.08.04
+ */
+public class OpenTool extends SuperTool {
+	private ArrayList<SuperShape> shapeArray;
+	private ArrayList<ShapePropertyTool> shapePropArray;//保存文件属性的数组
+	
+	public OpenTool(DrawJPanel j) {
+		super(j);
+		shapeArray = new ArrayList<SuperShape>();
+		shapePropArray = new ArrayList<ShapePropertyTool>();
+	}
+	/**
+	 * 该方法读取文件file中的图形
+	 * @param file 保存图形的文件
+	 * @return 返回从文件file中返回的图形数组ArrayList<SuperShape> 
+	 */
+	public ArrayList<SuperShape> openFile(File file){
+		try {
+			ObjectInputStream in = new ObjectInputStream(new FileInputStream(
+					file));
+			try {
+				shapePropArray =(ArrayList<ShapePropertyTool>) in.readObject();
+				for(ShapePropertyTool r:shapePropArray){
+					String className = r.getClassName();
+					try {
+						ReMakeTool reMakedShape = (ReMakeTool)Class.forName(className).newInstance();
+						shapeArray.add(reMakedShape.propertyToShape(r));
+					} catch (InstantiationException e) {
+						e.printStackTrace();
+					} catch (IllegalAccessException e) {
+						e.printStackTrace();
+					}
+				}
+			} catch (ClassNotFoundException e) {
+				e.printStackTrace();
+			}
+		} catch (FileNotFoundException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			JOptionPane.showMessageDialog(null, "文件错误!");
+		}
+		return shapeArray;
+	}
+
+	@Override
+	public void mouseClickedAction(MouseEvent mouseEvent) {
+		// TODO Auto-generated method stub
+	}
+
+	@Override
+	public void mouseDraggedAction(MouseEvent mouseEvent) {
+		// TODO Auto-generated method stub
+	}
+
+	@Override
+	public void mouseMovedAction(MouseEvent mouseEvent) {
+		// TODO Auto-generated method stub
+	}
+
+	@Override
+	public void mousePressedAction(MouseEvent mouseEvent) {
+		// TODO Auto-generated method stub
+	}
+
+	@Override
+	public void mouseReleasedAction(MouseEvent mouseEvent) {
+		// TODO Auto-generated method stub
+	}
+}

+ 70 - 0
src/main/java/com/hb/project4/tools/SaveTool.java

@@ -0,0 +1,70 @@
+package com.hb.project4.tools;
+
+import java.awt.Color;
+import java.awt.event.ActionEvent;
+import java.awt.event.MouseEvent;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+
+import com.hb.project4.drawPanel.DrawJPanel;
+import com.hb.project4.shapes.SuperShape;
+/**
+ * 该类用于保存当前画板中的图形
+ * @author Administrator
+ *时间:2008.08.04
+ */
+public class SaveTool extends SuperTool {
+	private ArrayList<ShapePropertyTool> pictureTempArray;
+	public SaveTool(DrawJPanel j) 
+	{
+		super(j);	
+		pictureTempArray = new ArrayList<ShapePropertyTool>();
+	}
+	
+	@Override
+	public void mouseClickedAction(MouseEvent mouseEvent) {
+		// TODO Auto-generated method stub		
+	}
+
+	@Override
+	public void mouseDraggedAction(MouseEvent mouseEvent) {
+		// TODO Auto-generated method stub		
+	}
+
+	@Override
+	public void mouseMovedAction(MouseEvent mouseEvent) {
+		// TODO Auto-generated method stub		
+	}
+
+	@Override
+	public void mousePressedAction(MouseEvent mouseEvent) {
+		// TODO Auto-generated method stub		
+	}
+
+	@Override
+	public void mouseReleasedAction(MouseEvent mouseEvent) {
+		// TODO Auto-generated method stub		
+	}
+	/**
+	 * 该方法用于保存shapeArray中的图形到文件file中
+	 * @param shapeArray要保存的图形的数组
+	 * @param file保存到的文件夹
+	 */
+	public void save(ArrayList<SuperShape> shapeArray, File file) {
+		for (SuperShape r : shapeArray)
+			pictureTempArray.add(new ShapePropertyTool(r));
+		try {
+			ObjectOutputStream out = new ObjectOutputStream(
+					new FileOutputStream(file));
+			out.writeObject(pictureTempArray);
+			out.flush();
+			out.close();
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		pictureTempArray.clear();//必须有!
+	}
+}

+ 17 - 0
src/main/java/config/RoomConfig.java

@@ -6,5 +6,22 @@ package config;
  * @email duh@elab-plus.com
  **/
 public class RoomConfig extends RectangleConfig {
+    private int x;
+    private int y;
 
+    public int getX() {
+        return x;
+    }
+
+    public void setX(int x) {
+        this.x = x;
+    }
+
+    public int getY() {
+        return y;
+    }
+
+    public void setY(int y) {
+        this.y = y;
+    }
 }

+ 27 - 18
src/main/java/controller/MyFrame.java

@@ -6,6 +6,7 @@ import view.Axis;
 import view.AxisBorder;
 
 import javax.imageio.ImageIO;
+import javax.swing.*;
 import java.awt.*;
 import java.awt.image.BufferedImage;
 import java.io.File;
@@ -20,26 +21,34 @@ import static utils.AxisUtils.drawAxis;
  * @create 2018/7/17 15:06
  * @email duh@elab-plus.com
  **/
-public class MyFrame {
-    public static void main(String[] args) throws Exception {
-        TemplateConfig template = YmlUtils.readYml();
-        int width = template.getRoom().getWidth();
-        int height = template.getRoom().getLength();
+public class MyFrame extends JFrame {
+    public static final String TITLE = "Java图形绘制";
+    public static TemplateConfig template = YmlUtils.readYml();
 
-        AxisBorder axisBorder = new AxisBorder(60, 60, 40, 40, 0xffffff);
-        BufferedImage bufferedImage = new BufferedImage(width+axisBorder.getLeft() + axisBorder.getRight(),
-                height + axisBorder.getTop() +axisBorder.getBottom(), BufferedImage.TYPE_INT_RGB);
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
+    public MyFrame() {
+        initFrame();
+    }
 
-        Graphics2D g = bufferedImage.createGraphics();
-        Date startDate = sdf.parse("20140318120000");
-        Date endDate = sdf.parse("20140320120000");
-        Axis xAxis = new Axis(0x000000, 2, "长", "datetime", 0, 0, 5, startDate, endDate, "");
-        Axis yAxis = new Axis(0x000000, 2, "宽", "value", 30, 0, 5, null, null, "");
-        drawAxis(axisBorder, xAxis, yAxis, width, height, g);
+    private void initFrame() {
+        // 设置 窗口标题 和 窗口大小
+        setTitle(TITLE);
+        setSize(template.getRoom().getWidth(), template.getRoom().getLength());
+        // 设置窗口关闭按钮的默认操作(点击关闭时退出进程)
+        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+        // 把窗口位置设置到屏幕的中心
+        setLocationRelativeTo(null);
+        // 设置窗口的内容面板
+        MyPanel panel = new MyPanel(this, template);
+        setContentPane(panel);
+    }
 
-        //导出图片
-        String pathname = "E:\\config\\test.jpg";
-        ImageIO.write(bufferedImage, "jpg", new File(pathname));
+    public static void main(String[] args) throws Exception {
+        EventQueue.invokeLater(new Runnable() {
+            @Override
+            public void run() {
+                MyFrame frame = new MyFrame();
+                frame.setVisible(true);
+            }
+        });
     }
 }

+ 211 - 0
src/main/java/controller/MyPanel.java

@@ -0,0 +1,211 @@
+package controller;
+
+import config.TemplateConfig;
+import model.Room;
+import model.XS;
+
+import javax.swing.*;
+import java.awt.*;
+import java.io.File;
+
+/**
+ * @author duh
+ * @create 2018/7/17 16:01
+ * @email duh@elab-plus.com
+ **/
+public class MyPanel extends JPanel{
+    private MyFrame frame;
+    private TemplateConfig templateConfig;
+
+    public MyPanel(MyFrame frame, TemplateConfig templateConfig) {
+        super();
+        this.frame = frame;
+        this.templateConfig = templateConfig;
+    }
+
+    @Override
+    protected void paintComponent(Graphics g) {
+        super.paintComponent(g);
+//        drawLine(g);
+//        drawRect(g);
+        drawImage(g);
+//        drawArc(g);
+//        drawRoom(g);
+//        drawTemplate(g);
+    }
+    private void drawRoom(Graphics g){
+        Room room = new Room(templateConfig.getRoom());
+        room.drawSelf(g);
+        drawXS(g,room);
+    }
+    private void drawXS(Graphics g,Room room){
+        XS xs = new XS(room);
+        xs.setConfig(templateConfig.getXS());
+        xs.drawSelf(g);
+    }
+    /**
+     * 1. 线段 / 折线
+     */
+    private void drawLine(Graphics g) {
+        frame.setTitle("1. 线段 / 折线");
+
+        // 创建 Graphics 的副本, 需要改变 Graphics 的参数,
+        // 这里必须使用副本, 避免影响到 Graphics 原有的设置
+        Graphics2D g2d = (Graphics2D) g.create();
+
+        // 抗锯齿
+        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+        // 设置画笔颜色
+        g2d.setColor(Color.RED);
+
+        // 1. 两点绘制线段: 点(20, 50), 点(200, 50)
+        g2d.drawLine(50, 50, 200, 50);
+
+        // 2. 多点绘制折线: 点(50, 100), 点(100, 130), 点(150, 70), 点(200, 100)
+        int[] xPoints = new int[] { 50, 100, 150, 200 };
+        int[] yPoints = new int[] { 100, 120, 80, 100 };
+        int nPoints = 4;
+        g2d.drawPolyline(xPoints, yPoints, nPoints);
+
+        // 3. 两点绘制线段(设置线宽为5px): 点(50, 150), 点(200, 150)
+        BasicStroke bs1 = new BasicStroke(5);       // 笔画的轮廓(画笔宽度/线宽为5px)
+        g2d.setStroke(bs1);
+        g2d.drawLine(50, 150, 200, 150);
+
+        // 4. 绘制虚线: 将虚线分为若干段( 实线段 和 空白段 都认为是一段), 实线段 和 空白段 交替绘制,
+        //             绘制的每一段(包括 实线段 和 空白段)的 长度 从 dash 虚线模式数组中取值(从首
+        //             元素开始循环取值), 下面数组即表示每段长度分别为: 5px, 10px, 5px, 10px, ...
+        float[] dash = new float[] { 5, 10 };
+        BasicStroke bs2 = new BasicStroke(
+                1,                      // 画笔宽度/线宽
+                BasicStroke.CAP_SQUARE,
+                BasicStroke.JOIN_MITER,
+                10.0f,
+                dash,                   // 虚线模式数组
+                0.0f
+        );
+        g2d.setStroke(bs2);
+        g2d.drawLine(50, 200, 200, 200);
+
+        // 自己创建的副本用完要销毁掉
+        g2d.dispose();
+    }
+
+    /**
+     * 2. 矩形 / 多边形
+     */
+    private void drawRect(Graphics g) {
+        frame.setTitle("2. 矩形 / 多边形");
+        Graphics2D g2d = (Graphics2D) g.create();
+
+        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+        g2d.setColor(Color.GRAY);
+
+        // 1. 绘制一个矩形: 起点(30, 20), 宽80, 高100
+        g2d.drawRect(30, 20, 80, 100);
+
+        // 2. 填充一个矩形
+        g2d.fillRect(140, 20, 80, 100);
+
+        // 3. 绘制一个圆角矩形: 起点(30, 150), 宽80, 高100, 圆角宽30, 圆角高30
+        g2d.drawRoundRect(30, 150, 80, 100, 30, 30);
+
+        // 4. 绘制一个多边形(收尾相连): 点(140, 150), 点(180, 250), 点(220, 200)
+        int[] xPoints = new int[] { 140, 180, 220};
+        int[] yPoints = new int[] { 150,  250, 200};
+        int nPoints = 3;
+        g2d.drawPolygon(xPoints, yPoints, nPoints);
+
+        g2d.dispose();
+    }
+
+    /**
+     * 3. 圆弧 / 扇形
+     */
+    private void drawArc(Graphics g) {
+        frame.setTitle("3. 圆弧 / 扇形");
+        Graphics2D g2d = (Graphics2D) g.create();
+
+        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+        g2d.setColor(Color.RED);
+
+        // 1. 绘制一条圆弧: 椭圆的外切矩形 左上角坐标为(0, 0), 宽100, 高100,
+        //                弧的开始角度为0度, 需要绘制的角度数为-90度,
+        //                椭圆右边水平线为0度, 逆时针为正角度, 顺时针为负角度
+        g2d.drawArc(0, 0, 100, 100, 0, -90);
+
+        // 2. 绘制一个圆: 圆的外切矩形 左上角坐标为(120, 20), 宽高为100
+        g2d.drawArc(120, 20, 100, 100, 0, 360);
+
+        g2d.setColor(Color.GRAY);
+
+        // 3. 填充一个扇形
+        g2d.fillArc(80, 150, 100, 100, 90, 270);
+
+        g2d.dispose();
+    }
+
+    /**
+     * 4. 椭圆 (实际上通过绘制360度的圆弧/扇形也能达到绘制圆/椭圆的效果)
+     */
+    private void drawOval(Graphics g) {
+        frame.setTitle("4. 椭圆");
+        Graphics2D g2d = (Graphics2D) g.create();
+
+        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+        g2d.setColor(Color.RED);
+
+        // 1. 绘制一个圆: 圆的外切矩形 左上角坐标为(0, 0), 宽高为100
+        g2d.drawOval(0, 0, 100, 100);
+
+        g2d.setColor(Color.GRAY);
+
+        // 2. 填充一个椭圆
+        g2d.fillOval(120, 100, 100, 150);
+
+        g2d.dispose();
+    }
+
+    /**
+     * 5. 图片
+     */
+    private void drawImage(Graphics g) {
+        frame.setTitle("5. 图片");
+        Graphics2D g2d = (Graphics2D) g.create();
+
+        // 从本地读取一张图片
+        String filepath = "xs.png";
+        File file = new File(filepath);
+        System.out.println(file.getAbsolutePath());
+        Image image = Toolkit.getDefaultToolkit().getImage(filepath);
+
+        // 绘制图片(如果宽高传的不是图片原本的宽高, 则图片将会适当缩放绘制)
+        g2d.drawImage(image, 50, 50, image.getWidth(this), image.getHeight(this), this);
+
+        g2d.dispose();
+    }
+
+    /**
+     * 6. 文本
+     */
+    private void drawString(Graphics g) {
+        frame.setTitle("6. 文本");
+        Graphics2D g2d = (Graphics2D) g.create();
+
+        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+
+        // 设置字体样式, null 表示使用默认字体, Font.PLAIN 为普通样式, 大小为 25px
+        g2d.setFont(new Font(null, Font.PLAIN, 25));
+
+        // 绘制文本, 其中坐标参数指的是文本绘制后的 左下角 的位置
+        // 首次绘制需要初始化字体, 可能需要较耗时
+        g2d.drawString("Hello World!", 20, 60);
+        g2d.drawString("你好, 世界!", 20, 120);
+
+        g2d.dispose();
+    }
+
+    private void drawTemplate(Graphics g) {
+
+    }
+}

BIN
src/main/java/controller/xs.png


BIN
src/main/java/icon/paintbox.JPG


BIN
src/main/java/icon/五角星.JPG


BIN
src/main/java/icon/五边形.JPG


BIN
src/main/java/icon/删除.JPG


BIN
src/main/java/icon/圆.JPG


BIN
src/main/java/icon/抓取.JPG


BIN
src/main/java/icon/撒消.JPG


BIN
src/main/java/icon/椭圆.JPG


BIN
src/main/java/icon/正三角形.JPG


BIN
src/main/java/icon/正方形.JPG


BIN
src/main/java/icon/直线.JPG


BIN
src/main/java/icon/矩形.JPG


BIN
src/main/java/icon/重做.JPG


+ 50 - 0
src/main/java/model/Room.java

@@ -0,0 +1,50 @@
+package model;
+
+import config.RoomConfig;
+
+import java.awt.*;
+
+/**
+ * @author duh
+ * @create 2018/7/17 16:19
+ * @email duh@elab-plus.com
+ **/
+public class Room extends Template{
+    private int length;
+    private int width;
+    public Room(){
+
+    }
+    public Room(RoomConfig config) {
+        this.length = config.getLength();
+        this.width = config.getWidth();
+        this.x = config.getX();
+        this.y = config.getY();
+    }
+
+    @Override
+    public void drawSelf(Graphics g) {
+        Graphics2D g2d = (Graphics2D) g.create();
+        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+        g2d.setColor(Color.GRAY);
+
+        // 1. 绘制一个矩形: 起点(30, 20), 宽80, 高100
+        g2d.drawRect(x, y, width, length);
+    }
+
+    public int getLength() {
+        return length;
+    }
+
+    public void setLength(int length) {
+        this.length = length;
+    }
+
+    public int getWidth() {
+        return width;
+    }
+
+    public void setWidth(int width) {
+        this.width = width;
+    }
+}

+ 4 - 1
src/main/java/model/Template.java

@@ -1,11 +1,13 @@
 package model;
 
+import java.awt.*;
+
 /**
  * @author duh
  * @create 2018/7/17 15:00
  * @email duh@elab-plus.com
  **/
-public class Template {
+public abstract class Template {
     protected String name;
     //x坐标
     protected int x;
@@ -45,4 +47,5 @@ public class Template {
     public void setScale(int scale) {
         this.scale = scale;
     }
+    abstract void drawSelf(Graphics g);
 }

+ 36 - 0
src/main/java/model/XS.java

@@ -1,13 +1,49 @@
 package model;
 
+import config.XSConfig;
+
+import java.awt.*;
+
 /**
  * @author duh
  * @create 2018/7/17 15:00
  * @email duh@elab-plus.com
  **/
 public class XS extends Template{
+    private Room room;
+    private XSConfig config;
     public XS(){
         setName("XS");
     }
 
+    public XS(Room room) {
+        this.room = room;
+    }
+
+    @Override
+    public void drawSelf(Graphics g) {
+        Graphics2D g2d = (Graphics2D) g.create();
+        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+        g2d.setColor(Color.GRAY);
+        // 1. 绘制一个矩形: 起点(30, 20), 宽80, 高100
+        g2d.drawRect(x, y, config.getWidth(), config.getLength());
+        g2d.drawOval(x, y, config.getWidth(), config.getLength());
+        g2d.drawOval(x+10, y+10, config.getWidth()-10, config.getLength()-10);
+    }
+
+    public Room getRoom() {
+        return room;
+    }
+
+    public void setRoom(Room room) {
+        this.room = room;
+    }
+
+    public XSConfig getConfig() {
+        return config;
+    }
+
+    public void setConfig(XSConfig config) {
+        this.config = config;
+    }
 }

+ 0 - 33
src/main/java/utils/AxisUtils.java

@@ -17,41 +17,8 @@ import java.util.Date;
  * @create 2018/7/17 15:03
  * @email duh@elab-plus.com
  **/
-/**
- * Copyright (c) 2014, alax
- * All Rights Reserved.
- */
-
-
-/**
- *
- * @author   	 alax_app@yeah.net
- * @Date	 	 2014-3-19 上午12:30:20
- *
- */
 public class AxisUtils {
 
-
-    public static void main(String[] args) throws Exception {
-        int width = 1000;
-        int height = 400;
-        AxisBorder axisBorder = new AxisBorder(60, 60, 40, 40, 0xffffff);
-        BufferedImage bufferedImage = new BufferedImage(width+axisBorder.getLeft() + axisBorder.getRight(),
-                height + axisBorder.getTop() +axisBorder.getBottom(), BufferedImage.TYPE_INT_RGB);
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
-
-        Graphics2D g = bufferedImage.createGraphics();
-        Date startDate = sdf.parse("20140318120000");
-        Date endDate = sdf.parse("20140320120000");
-        Axis xAxis = new Axis(0x000000, 2, "时间", "datetime", 0, 0, 5, startDate, endDate, "");
-        Axis yAxis = new Axis(0x000000, 2, "高度", "value", 30, 0, 5, null, null, "");
-        drawAxis(axisBorder, xAxis, yAxis, width, height, g);
-
-        //导出图片
-        String pathname = "E:\\config\\test.jpg";
-        ImageIO.write(bufferedImage, "jpg", new File(pathname));
-
-    }
     public static void drawAxis(AxisBorder border ,Axis xaxis, Axis yaxis, int width, int height, Graphics2D g){
         //抗锯齿 字体更平滑
         g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

+ 44 - 4
src/main/resources/template.yml

@@ -1,8 +1,48 @@
 room:
- length: 1000
- width: 550
+  length: 550
+  width: 1000
+  #相对于整个画面接入点
+  x: 550
+  y: 500
+#门
+door:
+  x: 100
+  y: 0
+  positon: 1
+  radis: 280
+  doorShadow:
+    radis: 100
+    #与x轴夹角
+    xDir: 30
+    #与x轴夹角
+    yDir: 30
+#洗漱台
 XS:
   length: 1000
   width: 550
-  shadowPoint: 0.5,1
-  radis: 800
+  shadow:
+    x: 550
+    y: 500
+    width: 1000
+    direct: 0
+    radis: 800
+#浴盆
+YP:
+  length: 1500
+  width: 800
+  shadow:
+    x: 550
+    y: 500
+    width: 650
+    direct: 90
+    radis: 800
+#马桶
+MT:
+  length: 700
+  width: 850
+  shadow:
+    x: 700
+    y: 400
+    width: 800
+    direct: 0
+    radis: 500

BIN
src/main/resources/xs.png


BIN
xs.png