Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Foo
- {
- private void drawShape(Shape s, Graphics2D g2d)
- {
- if ( s instanceof ColouredLine )
- {
- ColouredLine line = (ColouredLine) s;
- g2d.setPaint(line.getPaint());
- g2d.setStroke(line.isStrokeDashed() ? new BasicStroke(line
- .getLineWidth(), BasicStroke.CAP_BUTT,
- BasicStroke.JOIN_MITER, 10.0f, new float[] { line
- .getDashWidth() }, 0f) : new BasicStroke(line
- .getLineWidth()));
- g2d.draw(line);
- }
- else if ( s instanceof ColouredRectangle )
- {
- ColouredRectangle rect = (ColouredRectangle) s;
- g2d.setPaint(rect.getPaint());
- g2d.setStroke(rect.isStrokeDashed() ? new BasicStroke(rect
- .getLineWidth(), BasicStroke.CAP_BUTT,
- BasicStroke.JOIN_MITER, 10.0f, new float[] { rect
- .getDashWidth() }, 0f) : new BasicStroke(rect
- .getLineWidth()));
- if ( rect.isFilled() )
- {
- g2d.fill(rect);
- }
- else
- {
- g2d.draw(rect);
- }
- }
- else if ( s instanceof ColouredEllipse )
- {
- ColouredEllipse elli = (ColouredEllipse) s;
- g2d.setPaint(elli.getPaint());
- g2d.setStroke(elli.isStrokeDashed() ? new BasicStroke(elli
- .getLineWidth(), BasicStroke.CAP_BUTT,
- BasicStroke.JOIN_MITER, 10.0f, new float[] { elli
- .getDashWidth() }, 0f) : new BasicStroke(elli
- .getLineWidth()));
- if ( elli.isFilled() )
- g2d.fill(elli);
- else
- g2d.draw(elli);
- }
- else if ( s instanceof TextShape )
- {
- TextShape text = (TextShape) s;
- g2d.setPaint(text.getPaint());
- g2d.setFont(text.getFont());
- g2d.drawString(text.getContent(), (int) text.getX(), (int) text
- .getY());
- }
- else if ( s instanceof ColouredRoundedRectangle )
- {
- ColouredRoundedRectangle rect = (ColouredRoundedRectangle) s;
- g2d.setPaint(rect.getPaint());
- g2d.setStroke(rect.isStrokeDashed() ? new BasicStroke(rect
- .getLineWidth(), BasicStroke.CAP_BUTT,
- BasicStroke.JOIN_MITER, 10.0f, new float[] { rect
- .getDashWidth() }, 0f) : new BasicStroke(rect
- .getLineWidth()));
- if ( rect.isFilled() )
- {
- g2d.fill(rect);
- }
- else
- {
- g2d.draw(rect);
- }
- }
- else if ( s instanceof ColouredArc )
- {
- ColouredArc arc = (ColouredArc) s;
- g2d.setPaint(arc.getPaint());
- g2d.setStroke(arc.isStrokeDashed() ? new BasicStroke(arc
- .getLineWidth(), BasicStroke.CAP_BUTT,
- BasicStroke.JOIN_MITER, 10.0f, new float[] { arc
- .getDashWidth() }, 0f) : new BasicStroke(arc
- .getLineWidth()));
- if ( arc.isFilled() )
- g2d.fill(arc);
- else
- g2d.draw(arc);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement