Пример #1
0
  public static void paintShape(
      Graphics g, RemoteShape shapeModel, boolean fill, Component aComponent) {
    try {
      if (shapeModel.getWidth() == 0 && shapeModel.getHeight() == 0) return;
      Font graphicsFont = g.getFont();

      Color shapeColor = shapeModel.getColor();
      Color graphicsColor = g.getColor();
      Graphics2D g2d = (Graphics2D) g;
      Stroke graphicsStroke = g2d.getStroke();
      Paint graphicsPaint = g2d.getPaint();
      Font font = shapeModel.getFont();
      Integer myFontSize = shapeModel.getFontSize();
      if (myFontSize == null || myFontSize <= 0) {
        myFontSize = fontSize;
      }
      if (font != null) {
        g.setFont(font);
      } else if (myFontSize != null) {
        g.setFont(Common.toFontSize(g.getFont(), myFontSize));
        if (shapeModel instanceof ComponentModel) {
          ComponentModel componentModel = (ComponentModel) shapeModel;
          componentModel.setFont(Common.toFontSize(componentModel.getFont(), myFontSize));
        }
      }
      Stroke basicStroke = shapeModel.getStroke();
      if (basicStroke != null) g2d.setStroke(basicStroke);
      Paint gradientPaint = shapeModel.getPaint();
      if (gradientPaint != null) g2d.setPaint(gradientPaint);
      if (shapeColor != null) g.setColor(shapeColor);

      try {
        // Class shapeClass = shapeModel.getClass();
        // if (shapeClass == Class.forName("shapes.LineModel"))
        // if (shapeModel instanceof LineModel)
        if (shapeModel instanceof RemoteAWTShape) {
          paintAWTShape(g2d, (RemoteAWTShape) shapeModel);
        } else if (shapeModel instanceof RemoteLine) {
          // System.out.println(shapeModel.getBounds().x + " " + shapeModel.getBounds().y);
          // paintLine(g, (RemoteLine) shapeModel, fill);
          paintLine2D(g2d, (RemoteLine) shapeModel, fill);
        }
        // else if (shapeClass == Class.forName("shapes.OvalModel"))
        else if (shapeModel instanceof RemoteOval) {
          paintOval(g, (RemoteOval) shapeModel, fill);
        }
        // else if (shapeClass == Class.forName("shapes.RectangleModel"))
        else if (shapeModel instanceof RemoteRectangle) {
          // paintRectangle(g, (RemoteRectangle) shapeModel, fill);
          paintRectangle2D(g, (RemoteRectangle) shapeModel, fill);
        } else if (shapeModel instanceof RemoteArc) {
          // paintArc(g, (RemoteArc) shapeModel, fill);
          paintArc2D(g2d, (RemoteArc) shapeModel, fill);
        } else if (shapeModel instanceof RemoteCurve) {
          paintCurve2D(g2d, (RemoteCurve) shapeModel, fill);
        } else if (shapeModel instanceof shapes.StringModel) {
          paintString(g, (RemoteText) shapeModel, fill);
        } else if (shapeModel instanceof ImageModel) {
          paintImage((Graphics2D) g, (RemoteImage) shapeModel, fill, aComponent);
        }
        g.setColor(graphicsColor);
        g.setFont(graphicsFont);
        g2d.setPaint(graphicsPaint);
        g2d.setStroke(graphicsStroke);
      } catch (Exception e) {
        System.err.println("Should have stored shape id: " + e.toString());
        e.printStackTrace();
      }
      if (shapeColor != null) g.setColor(graphicsColor);
    } catch (Exception e) {
      e.printStackTrace();
      // System.out.println(e);
    }
  }