drawTo(String,String)   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
cc 2
rs 9.9
1
package org.gannacademy.cdf.turtlelogo.docs;
2
3
import org.gannacademy.cdf.turtlelogo.Terrarium;
4
5
import javax.imageio.ImageIO;
6
import java.awt.*;
7
import java.awt.image.BufferedImage;
8
import java.io.File;
9
import java.io.IOException;
10
11
public class SavableTerrarium extends Terrarium {
12
  public void drawTo(String path) {
13
    drawTo(path, "PNG");
14
  }
15
16
  public void drawTo(String path, String format) {
17
    try {
18
      BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
19
      Graphics2D context = image.createGraphics();
20
      context.setPaint(getBackground());
21
      context.fillRect(0, 0, image.getWidth(), image.getHeight());
22
      draw(context);
23
      ImageIO.write(image, format, new File(path));
24
    } catch (IOException e) {
25
      e.printStackTrace();
0 ignored issues
show
Best Practice introduced by
Throwable.printStackTrace writes to the console which might not be available at runtime. Using a logger is preferred.
Loading history...
26
    }
27
  }
28
}
29