|
@@ -33,13 +33,18 @@ public class MyPanel extends JPanel{
|
|
|
@Override
|
|
|
protected void paintComponent(Graphics g) {
|
|
|
super.paintComponent(g);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
drawAxis(config,g);
|
|
|
- drawRoom(g);
|
|
|
+ Room room = new Room(config.getRoom());
|
|
|
+ drawRoom(room,g);
|
|
|
+
|
|
|
+ drawTemplateAndMove(room,g);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ * 画坐标系
|
|
|
+ * @param config
|
|
|
+ * @param g
|
|
|
+ */
|
|
|
private void drawAxis(Config config,Graphics g){
|
|
|
Axis axis = new Axis();
|
|
|
AxisConfig axisConfig = config.getAxisPoint();
|
|
@@ -60,176 +65,20 @@ public class MyPanel extends JPanel{
|
|
|
TemplateUtils.drawTemplate(templateConfig,g);
|
|
|
}
|
|
|
}
|
|
|
- private void drawRoom(Graphics g){
|
|
|
- Room room = new Room(config.getRoom());
|
|
|
+ private void drawTemplateAndMove(Room room, Graphics g) {
|
|
|
+ List<TemplateConfig> templateList = config.getTemplates();
|
|
|
+ TemplateUtils.setRoom(room);
|
|
|
+ TemplateConfig templateConfig = templateList.get(0);
|
|
|
+ TemplateUtils.drawTemplate(templateConfig,g);
|
|
|
+ }
|
|
|
+ private void drawRoom(Room room, Graphics g){
|
|
|
+
|
|
|
room.drawSelf(g);
|
|
|
DoorConfig doorConfig = config.getDoor();
|
|
|
Door door = new Door();
|
|
|
door.setConfig(doorConfig);
|
|
|
door.setRoom(room);
|
|
|
door.drawSelf(g);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- * 1. 线段 / 折线
|
|
|
- */
|
|
|
- private void drawLine(Graphics g) {
|
|
|
- frame.setTitle("1. 线段 / 折线");
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- Graphics2D g2d = (Graphics2D) g.create();
|
|
|
-
|
|
|
-
|
|
|
- g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
-
|
|
|
- g2d.setColor(Color.RED);
|
|
|
-
|
|
|
-
|
|
|
- g2d.drawLine(50, 50, 200, 50);
|
|
|
-
|
|
|
-
|
|
|
- int[] xPoints = new int[] { 50, 100, 150, 200 };
|
|
|
- int[] yPoints = new int[] { 100, 120, 80, 100 };
|
|
|
- int nPoints = 4;
|
|
|
- g2d.drawPolyline(xPoints, yPoints, nPoints);
|
|
|
-
|
|
|
-
|
|
|
- BasicStroke bs1 = new BasicStroke(5);
|
|
|
- g2d.setStroke(bs1);
|
|
|
- g2d.drawLine(50, 150, 200, 150);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- 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);
|
|
|
-
|
|
|
-
|
|
|
- g2d.drawRect(30, 20, 80, 100);
|
|
|
-
|
|
|
-
|
|
|
- g2d.fillRect(140, 20, 80, 100);
|
|
|
-
|
|
|
-
|
|
|
- g2d.drawRoundRect(30, 150, 80, 100, 30, 30);
|
|
|
-
|
|
|
-
|
|
|
- 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);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- g2d.drawArc(0, 0, 100, 100, 0, -90);
|
|
|
-
|
|
|
-
|
|
|
- g2d.drawArc(120, 20, 100, 100, 0, 360);
|
|
|
-
|
|
|
- g2d.setColor(Color.GRAY);
|
|
|
-
|
|
|
-
|
|
|
- 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);
|
|
|
-
|
|
|
-
|
|
|
- g2d.drawOval(0, 0, 100, 100);
|
|
|
-
|
|
|
- g2d.setColor(Color.GRAY);
|
|
|
-
|
|
|
-
|
|
|
- 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);
|
|
|
-
|
|
|
- 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);
|
|
|
-
|
|
|
-
|
|
|
- g2d.setFont(new Font(null, Font.PLAIN, 25));
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- g2d.drawString("Hello World!", 20, 60);
|
|
|
- g2d.drawString("你好, 世界!", 20, 120);
|
|
|
-
|
|
|
- g2d.dispose();
|
|
|
}
|
|
|
|
|
|
|