Browse Source

初步画图

duh 6 years ago
parent
commit
6e0a3804ce

+ 42 - 0
src/main/java/config/Config.java

@@ -0,0 +1,42 @@
+package config;
+
+import config.subConfig.DoorConfig;
+import config.subConfig.RoomConfig;
+import config.subConfig.TemplateConfig;
+
+import java.util.List;
+
+/**
+ * @author duh
+ * @create 2018/7/17 15:25
+ * @email duh@elab-plus.com
+ **/
+public class Config {
+    private RoomConfig room;
+    private DoorConfig door;
+    private List<TemplateConfig> templates;
+
+    public RoomConfig getRoom() {
+        return room;
+    }
+
+    public void setRoom(RoomConfig room) {
+        this.room = room;
+    }
+
+    public DoorConfig getDoor() {
+        return door;
+    }
+
+    public void setDoor(DoorConfig door) {
+        this.door = door;
+    }
+
+    public List<TemplateConfig> getTemplates() {
+        return templates;
+    }
+
+    public void setTemplates(List<TemplateConfig> templates) {
+        this.templates = templates;
+    }
+}

+ 0 - 27
src/main/java/config/RectangleConfig.java

@@ -1,27 +0,0 @@
-package config;
-
-/**
- * @author duh
- * @create 2018/7/17 15:28
- * @email duh@elab-plus.com
- **/
-public class RectangleConfig {
-    protected int length;
-    protected int width;
-
-    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;
-    }
-}

+ 0 - 27
src/main/java/config/TemplateConfig.java

@@ -1,27 +0,0 @@
-package config;
-
-/**
- * @author duh
- * @create 2018/7/17 15:25
- * @email duh@elab-plus.com
- **/
-public class TemplateConfig {
-    private RoomConfig room;
-    private XSConfig XS;
-
-    public RoomConfig getRoom() {
-        return room;
-    }
-
-    public void setRoom(RoomConfig room) {
-        this.room = room;
-    }
-
-    public XSConfig getXS() {
-        return XS;
-    }
-
-    public void setXS(XSConfig XS) {
-        this.XS = XS;
-    }
-}

+ 3 - 3
src/main/java/config/RoomConfig.java

@@ -1,11 +1,11 @@
-package config;
+package config.common;
 
 /**
  * @author duh
- * @create 2018/7/17 15:28
+ * @create 2018/7/17 20:26
  * @email duh@elab-plus.com
  **/
-public class RoomConfig extends RectangleConfig {
+public class TemplateInsert {
     private int x;
     private int y;
 

+ 66 - 0
src/main/java/config/subConfig/DoorConfig.java

@@ -0,0 +1,66 @@
+package config.subConfig;
+
+/**
+ * @author duh
+ * @create 2018/7/17 19:59
+ * @email duh@elab-plus.com
+ **/
+public class DoorConfig {
+    //相对room位置
+    private int x;
+    private int y;
+    //1 2 3 4,对应相应边
+    private int position;
+    //阴影半径长度
+    private int radis;
+    private int openDir;
+    private DoorShadowConfig doorShadow;
+
+    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;
+    }
+
+    public int getPosition() {
+        return position;
+    }
+
+    public void setPosition(int position) {
+        this.position = position;
+    }
+
+    public int getRadis() {
+        return radis;
+    }
+
+    public void setRadis(int radis) {
+        this.radis = radis;
+    }
+
+    public int getOpenDir() {
+        return openDir;
+    }
+
+    public void setOpenDir(int openDir) {
+        this.openDir = openDir;
+    }
+
+    public DoorShadowConfig getDoorShadow() {
+        return doorShadow;
+    }
+
+    public void setDoorShadow(DoorShadowConfig doorShadow) {
+        this.doorShadow = doorShadow;
+    }
+}

+ 36 - 0
src/main/java/config/subConfig/DoorShadowConfig.java

@@ -0,0 +1,36 @@
+package config.subConfig;
+
+/**
+ * @author duh
+ * @create 2018/7/17 20:02
+ * @email duh@elab-plus.com
+ **/
+public class DoorShadowConfig {
+    private int radis;
+    private int xDir;
+    private int yDir;
+
+    public int getRadis() {
+        return radis;
+    }
+
+    public void setRadis(int radis) {
+        this.radis = radis;
+    }
+
+    public int getxDir() {
+        return xDir;
+    }
+
+    public void setxDir(int xDir) {
+        this.xDir = xDir;
+    }
+
+    public int getyDir() {
+        return yDir;
+    }
+
+    public void setyDir(int yDir) {
+        this.yDir = yDir;
+    }
+}

+ 13 - 13
src/main/java/config/XSConfig.java

@@ -1,15 +1,15 @@
-package config;
+package config.subConfig;
 
 /**
  * @author duh
- * @create 2018/7/17 15:18
+ * @create 2018/7/17 15:28
  * @email duh@elab-plus.com
  **/
-public class XSConfig {
+public class RoomConfig {
     private int length;
     private int width;
-    private String shadowPoint;
-    private int radis;
+    private int x;
+    private int y;
 
     public int getLength() {
         return length;
@@ -27,19 +27,19 @@ public class XSConfig {
         this.width = width;
     }
 
-    public String getShadowPoint() {
-        return shadowPoint;
+    public int getX() {
+        return x;
     }
 
-    public void setShadowPoint(String shadowPoint) {
-        this.shadowPoint = shadowPoint;
+    public void setX(int x) {
+        this.x = x;
     }
 
-    public int getRadis() {
-        return radis;
+    public int getY() {
+        return y;
     }
 
-    public void setRadis(int radis) {
-        this.radis = radis;
+    public void setY(int y) {
+        this.y = y;
     }
 }

+ 47 - 0
src/main/java/config/subConfig/TemplateConfig.java

@@ -0,0 +1,47 @@
+package config.subConfig;
+
+import config.common.TemplateInsert;
+
+/**
+ * @author duh
+ * @create 2018/7/17 20:04
+ * @email duh@elab-plus.com
+ **/
+public class TemplateConfig extends TemplateInsert{
+    private String name;
+    private int length;
+    private int width;
+    private TemplateShadowConfig shadow;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    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;
+    }
+
+    public TemplateShadowConfig getShadow() {
+        return shadow;
+    }
+
+    public void setShadow(TemplateShadowConfig shadow) {
+        this.shadow = shadow;
+    }
+}

+ 54 - 0
src/main/java/config/subConfig/TemplateShadowConfig.java

@@ -0,0 +1,54 @@
+package config.subConfig;
+
+/**
+ * @author duh
+ * @create 2018/7/17 20:05
+ * @email duh@elab-plus.com
+ **/
+public class TemplateShadowConfig {
+    private int x;
+    private int y;
+    private int width;
+    private int direct;
+    private int radis;
+
+    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;
+    }
+
+    public int getWidth() {
+        return width;
+    }
+
+    public void setWidth(int width) {
+        this.width = width;
+    }
+
+    public int getDirect() {
+        return direct;
+    }
+
+    public void setDirect(int direct) {
+        this.direct = direct;
+    }
+
+    public int getRadis() {
+        return radis;
+    }
+
+    public void setRadis(int radis) {
+        this.radis = radis;
+    }
+}

+ 2 - 12
src/main/java/controller/MyFrame.java

@@ -1,20 +1,10 @@
 package controller;
 
-import config.TemplateConfig;
+import config.Config;
 import utils.YmlUtils;
-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;
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import static utils.AxisUtils.drawAxis;
 
 /**
  * @author duh
@@ -23,7 +13,7 @@ import static utils.AxisUtils.drawAxis;
  **/
 public class MyFrame extends JFrame {
     public static final String TITLE = "Java图形绘制";
-    public static TemplateConfig template = YmlUtils.readYml();
+    public static Config template = YmlUtils.readYml();
 
     public MyFrame() {
         initFrame();

+ 17 - 14
src/main/java/controller/MyPanel.java

@@ -1,12 +1,16 @@
 package controller;
 
-import config.TemplateConfig;
+import config.Config;
+import config.subConfig.RoomConfig;
+import config.subConfig.TemplateConfig;
 import model.Room;
 import model.XS;
+import utils.TemplateUtils;
 
 import javax.swing.*;
 import java.awt.*;
 import java.io.File;
+import java.util.List;
 
 /**
  * @author duh
@@ -15,9 +19,9 @@ import java.io.File;
  **/
 public class MyPanel extends JPanel{
     private MyFrame frame;
-    private TemplateConfig templateConfig;
+    private Config templateConfig;
 
-    public MyPanel(MyFrame frame, TemplateConfig templateConfig) {
+    public MyPanel(MyFrame frame, Config templateConfig) {
         super();
         this.frame = frame;
         this.templateConfig = templateConfig;
@@ -28,20 +32,21 @@ public class MyPanel extends JPanel{
         super.paintComponent(g);
 //        drawLine(g);
 //        drawRect(g);
-        drawImage(g);
+//        drawImage(g);
 //        drawArc(g);
-//        drawRoom(g);
-//        drawTemplate(g);
+        drawRoom(g);
+    }
+    private void drawTemplate(RoomConfig room, Graphics g) {
+        List<TemplateConfig> templateList = templateConfig.getTemplates();
+        TemplateConfig first = templateList.get(0);
+        TemplateUtils.setRoom(room);
+        TemplateUtils.drawTemplate(templateList.get(0),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);
+
+        drawTemplate(templateConfig.getRoom(),g);
     }
     /**
      * 1. 线段 / 折线
@@ -205,7 +210,5 @@ public class MyPanel extends JPanel{
         g2d.dispose();
     }
 
-    private void drawTemplate(Graphics g) {
 
-    }
 }

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


+ 1 - 1
src/main/java/model/Room.java

@@ -1,6 +1,6 @@
 package model;
 
-import config.RoomConfig;
+import config.subConfig.RoomConfig;
 
 import java.awt.*;
 

+ 4 - 4
src/main/java/model/XS.java

@@ -1,6 +1,6 @@
 package model;
 
-import config.XSConfig;
+import config.subConfig.TemplateConfig;
 
 import java.awt.*;
 
@@ -11,7 +11,7 @@ import java.awt.*;
  **/
 public class XS extends Template{
     private Room room;
-    private XSConfig config;
+    private TemplateConfig config;
     public XS(){
         setName("XS");
     }
@@ -39,11 +39,11 @@ public class XS extends Template{
         this.room = room;
     }
 
-    public XSConfig getConfig() {
+    public TemplateConfig getConfig() {
         return config;
     }
 
-    public void setConfig(XSConfig config) {
+    public void setConfig(TemplateConfig config) {
         this.config = config;
     }
 }

+ 63 - 0
src/main/java/utils/TemplateUtils.java

@@ -0,0 +1,63 @@
+package utils;
+
+import config.subConfig.RoomConfig;
+import config.subConfig.TemplateConfig;
+import config.subConfig.TemplateShadowConfig;
+
+import java.awt.*;
+
+/**
+ * @author duh
+ * @create 2018/7/17 20:10
+ * @email duh@elab-plus.com
+ **/
+public class TemplateUtils {
+    private static RoomConfig room;
+
+    public static void drawTemplate(TemplateConfig template, Graphics g){
+        if(null == room){
+            System.out.println("--------------room is not exist !!");
+            return;
+        }
+        drawTemplateSelf(template,g);
+        drawShadow(template,g);
+    }
+    private static void drawTemplateSelf(TemplateConfig template, Graphics g){
+        int x1 = room.getX()+template.getX();
+        int y1 = room.getY()+template.getY();
+        int x2 = x1+template.getLength();
+        int y2 = y1+template.getWidth();
+        g.drawRect(x1,y1,template.getLength(),template.getWidth());
+    }
+    private static void drawShadow(TemplateConfig template, Graphics g){
+        TemplateShadowConfig shadow = template.getShadow();
+        int cx = room.getX()+shadow.getX();
+        int cy = room.getY()+shadow.getY();
+        int x1,y1,x2,y2;
+        switch (shadow.getDirect()){
+            case 0:
+                x1 = cx;
+                y1 = cy - template.getWidth()/2;
+                x2 = cx+shadow.getRadis();
+                y2 = cy + template.getWidth()/2;
+                g.fillRect(x1,y1,shadow.getRadis(),template.getWidth());
+                break;
+            case 90:
+                x1 = cx-shadow.getRadis()/2;
+                y1 = cy;
+                x2 = cx+shadow.getRadis();
+                y2 = cy + template.getWidth()/2;
+                g.fillRect(x1,y1,shadow.getRadis(),shadow.getRadis());
+                break;
+            default:break;
+        }
+    }
+
+    public static RoomConfig getRoom() {
+        return room;
+    }
+
+    public static void setRoom(RoomConfig room) {
+        TemplateUtils.room = room;
+    }
+}

+ 4 - 5
src/main/java/utils/YmlUtils.java

@@ -1,7 +1,6 @@
 package utils;
 
-import config.TemplateConfig;
-import config.XSConfig;
+import config.Config;
 import org.yaml.snakeyaml.Yaml;
 
 import java.io.FileInputStream;
@@ -14,12 +13,12 @@ import java.net.URL;
  * @email duh@elab-plus.com
  **/
 public class YmlUtils {
-    public static TemplateConfig readYml(){
+    public static Config readYml(){
         Yaml yaml = new Yaml();
-        URL url = YmlUtils.class.getClassLoader().getResource("template.yml");
+        URL url = YmlUtils.class.getClassLoader().getResource("config.yml");
         if(null != url){
             try {
-                TemplateConfig templateConfig = yaml.loadAs(new FileInputStream(url.getFile()), TemplateConfig.class);
+                Config templateConfig = yaml.loadAs(new FileInputStream(url.getFile()), Config.class);
                 return templateConfig;
             } catch (FileNotFoundException e) {
                 e.printStackTrace();

+ 24 - 21
src/main/resources/template.yml

@@ -1,15 +1,17 @@
 room:
-  length: 550
-  width: 1000
+  length: 2800
+  width: 2000
   #相对于整个画面接入点
-  x: 550
-  y: 500
+  x: 20
+  y: 20
 #门
 door:
   x: 100
   y: 0
-  positon: 1
+  position: 1
   radis: 280
+  #左开0右开1
+  openDir: 0
   doorShadow:
     radis: 100
     #与x轴夹角
@@ -17,32 +19,33 @@ door:
     #与x轴夹角
     yDir: 30
 #洗漱台
-XS:
-  length: 1000
-  width: 550
-  shadow:
+templates:
+ - name: XS
+   length: 550
+   width: 1000
+   shadow:
     x: 550
     y: 500
     width: 1000
     direct: 0
     radis: 800
 #浴盆
-YP:
-  length: 1500
-  width: 800
-  shadow:
-    x: 550
-    y: 500
+ - name: YP
+   length: 1500
+   width: 800
+   shadow:
+    x: 1025
+    y: 800
     width: 650
     direct: 90
-    radis: 800
+    radis: 650
 #马桶
-MT:
-  length: 700
-  width: 850
-  shadow:
+ - name: MT
+   length: 700
+   width: 850
+   shadow:
     x: 700
-    y: 400
+    y: 425
     width: 800
     direct: 0
     radis: 500

BIN
src/main/resources/xs.png