org.gannacademy.cdf.turtlelogo.docs.SavableTerrarium   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
c 0
b 0
f 0
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A drawTo(String,String) 0 10 2
A drawTo(String) 0 2 1
drawTo 0 2 ?
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