Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.53 KB | None | 0 0
  1. class Foo
  2. {
  3.     private void drawShape(Shape s, Graphics2D g2d)
  4.     {
  5.         if ( s instanceof ColouredLine )
  6.         {
  7.             ColouredLine line = (ColouredLine) s;
  8.             g2d.setPaint(line.getPaint());
  9.             g2d.setStroke(line.isStrokeDashed() ? new BasicStroke(line
  10.                     .getLineWidth(), BasicStroke.CAP_BUTT,
  11.                     BasicStroke.JOIN_MITER, 10.0f, new float[] { line
  12.                             .getDashWidth() }, 0f) : new BasicStroke(line
  13.                     .getLineWidth()));
  14.             g2d.draw(line);
  15.         }
  16.         else if ( s instanceof ColouredRectangle )
  17.         {
  18.             ColouredRectangle rect = (ColouredRectangle) s;
  19.             g2d.setPaint(rect.getPaint());
  20.             g2d.setStroke(rect.isStrokeDashed() ? new BasicStroke(rect
  21.                     .getLineWidth(), BasicStroke.CAP_BUTT,
  22.                     BasicStroke.JOIN_MITER, 10.0f, new float[] { rect
  23.                             .getDashWidth() }, 0f) : new BasicStroke(rect
  24.                     .getLineWidth()));
  25.             if ( rect.isFilled() )
  26.             {
  27.                 g2d.fill(rect);
  28.             }
  29.             else
  30.             {
  31.                 g2d.draw(rect);
  32.             }
  33.         }
  34.         else if ( s instanceof ColouredEllipse )
  35.         {
  36.             ColouredEllipse elli = (ColouredEllipse) s;
  37.             g2d.setPaint(elli.getPaint());
  38.             g2d.setStroke(elli.isStrokeDashed() ? new BasicStroke(elli
  39.                     .getLineWidth(), BasicStroke.CAP_BUTT,
  40.                     BasicStroke.JOIN_MITER, 10.0f, new float[] { elli
  41.                             .getDashWidth() }, 0f) : new BasicStroke(elli
  42.                     .getLineWidth()));
  43.             if ( elli.isFilled() )
  44.                 g2d.fill(elli);
  45.             else
  46.                 g2d.draw(elli);
  47.         }
  48.         else if ( s instanceof TextShape )
  49.         {
  50.             TextShape text = (TextShape) s;
  51.             g2d.setPaint(text.getPaint());
  52.             g2d.setFont(text.getFont());
  53.  
  54.             g2d.drawString(text.getContent(), (int) text.getX(), (int) text
  55.                     .getY());
  56.         }
  57.         else if ( s instanceof ColouredRoundedRectangle )
  58.         {
  59.             ColouredRoundedRectangle rect = (ColouredRoundedRectangle) s;
  60.             g2d.setPaint(rect.getPaint());
  61.             g2d.setStroke(rect.isStrokeDashed() ? new BasicStroke(rect
  62.                     .getLineWidth(), BasicStroke.CAP_BUTT,
  63.                     BasicStroke.JOIN_MITER, 10.0f, new float[] { rect
  64.                             .getDashWidth() }, 0f) : new BasicStroke(rect
  65.                     .getLineWidth()));
  66.             if ( rect.isFilled() )
  67.             {
  68.                 g2d.fill(rect);
  69.             }
  70.             else
  71.             {
  72.                 g2d.draw(rect);
  73.             }
  74.         }
  75.         else if ( s instanceof ColouredArc )
  76.         {
  77.             ColouredArc arc = (ColouredArc) s;
  78.             g2d.setPaint(arc.getPaint());
  79.             g2d.setStroke(arc.isStrokeDashed() ? new BasicStroke(arc
  80.                     .getLineWidth(), BasicStroke.CAP_BUTT,
  81.                     BasicStroke.JOIN_MITER, 10.0f, new float[] { arc
  82.                             .getDashWidth() }, 0f) : new BasicStroke(arc
  83.                     .getLineWidth()));
  84.            
  85.             if ( arc.isFilled() )
  86.                 g2d.fill(arc);
  87.             else
  88.                 g2d.draw(arc);
  89.         }
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement