Beispiel #1
0
  public void repaintObjects(List<Component> list) {
    this.removeAll();
    for (Component component : list) {
      StandartFigure standartFigure = (StandartFigure) component;

      switch (standartFigure.getTypeFigure()) {
        case Circle:
          standartFigure.setBounds(
              standartFigure.getX(),
              standartFigure.getY(),
              standartFigure.getWidth() + 2,
              standartFigure.getHeight() + 2);
          break;
        case Square:
          standartFigure.setBounds(
              standartFigure.getX(),
              standartFigure.getY(),
              standartFigure.getWidth() + 2,
              standartFigure.getHeight() + 2);
          break;
        case RoundRect:
          standartFigure.setBounds(
              standartFigure.getX(),
              standartFigure.getY(),
              standartFigure.getWidth() + 2,
              standartFigure.getHeight() + 2);
          break;
        case Line:
          standartFigure.setBounds(
              standartFigure.getX(),
              standartFigure.getY(),
              standartFigure.getWidth() + 2,
              standartFigure.getHeight() + 2);
          break;

        default:
          break;
      }
      add(standartFigure);
      repaint();
      standartFigure = null;
    }
  }
  @Override
  public void save(List<Component> components) {
    try {
      FileOutputStream fos = new FileOutputStream(filename);
      StringBuilder xml = new StringBuilder();
      xml.append("<FigureList>");
      for (Component component : components) {
        xml.append("<Figure>");
        StandartFigure figure = (StandartFigure) component;

        switch (figure.getTypeFigure()) {
          case Circle:
            xml.append("<Type>").append("Circle").append("</Type>");
            xml.append("<X>").append(figure.getX()).append("</X>");
            xml.append("<Y>").append(figure.getY()).append("</Y>");
            xml.append("<Width>").append(figure.getWidth()).append("</Width>");
            xml.append("<Height>").append(figure.getHeight()).append("</Height>");
            xml.append("<BoundColor>");
            xml.append("<R>").append(figure.getColor().getRed()).append("</R>");
            xml.append("<G>").append(figure.getColor().getGreen()).append("</G>");
            xml.append("<B>").append(figure.getColor().getBlue()).append("</B>");
            xml.append("</BoundColor>");
            break;
          case Square:
            xml.append("<Type>").append("Circle").append("</Type>");
            xml.append("<X>").append(figure.getX()).append("</X>");
            xml.append("<Y>").append(figure.getY()).append("</Y>");
            xml.append("<Width>").append(figure.getWidth()).append("</Width>");
            xml.append("<Height>").append(figure.getHeight()).append("</Height>");
            xml.append("<BoundColor>");
            xml.append("<R>").append(figure.getColor().getRed()).append("</R>");
            xml.append("<G>").append(figure.getColor().getGreen()).append("</G>");
            xml.append("<B>").append(figure.getColor().getBlue()).append("</B>");
            xml.append("</BoundColor>");
            break;
          case RoundRect:
            xml.append("<Type>").append("RoundRect").append("</Type>");
            xml.append("<X>").append(figure.getX()).append("</X>");
            xml.append("<Y>").append(figure.getY()).append("</Y>");
            xml.append("<Width>").append(figure.getWidth()).append("</Width>");
            xml.append("<Height>").append(figure.getHeight()).append("</Height>");
            xml.append("<BoundColor>");
            xml.append("<R>").append(figure.getColor().getRed()).append("</R>");
            xml.append("<G>").append(figure.getColor().getGreen()).append("</G>");
            xml.append("<B>").append(figure.getColor().getBlue()).append("</B>");
            xml.append("</BoundColor>");
            break;
          case Line:
            xml.append("<Type>").append("Line").append("</Type>");
            xml.append("<X>").append(figure.getX()).append("</X>");
            xml.append("<Y>").append(figure.getY()).append("</Y>");
            xml.append("<Width>").append(figure.getWidth()).append("</Width>");
            xml.append("<BoundColor>");
            xml.append("<R>").append(figure.getColor().getRed()).append("</R>");
            xml.append("<G>").append(figure.getColor().getGreen()).append("</G>");
            xml.append("<B>").append(figure.getColor().getBlue()).append("</B>");
            xml.append("</BoundColor>");
            break;
          default:
            break;
        }
        xml.append("</Figure>");
      }
      fos.write(new String(xml).getBytes());
      String footer = "</FigureList>";
      fos.write(footer.getBytes());
      fos.flush();
      fos.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }