1
2
3
4
5
6
7 package com.octo.captcha.component.image.backgroundgenerator;
8
9 import java.security.SecureRandom;
10 import java.util.Random;
11
12 /***
13 * <p>Abstract base class for background generator.</br> Sub classes must implement the getBackground() method that
14 * return a newly generated background.</br> use constructor to specify your backgroundGenerator properties. This base
15 * class only use two parameter, width and height of the generated background. By default widht = 200 and height=
16 * 100.</p>
17 *
18 * @author <a href="mailto:mag@jcaptcha.net">Marc-Antoine Garrigue</a>
19 * @version 1.0
20 */
21 public abstract class AbstractBackgroundGenerator
22 implements BackgroundGenerator {
23
24 private int height = 100;
25 private int width = 200;
26
27 Random myRandom = new SecureRandom();
28
29 /***
30 * Default constructor takes a width and a height of the generated backgrounds
31 *
32 * @param width the backgroud width
33 * @param height the backgroud height
34 */
35 AbstractBackgroundGenerator(Integer width, Integer height) {
36 this.width = width != null ? width.intValue() : this.width;
37 this.height = height != null ? height.intValue() : this.height;
38
39 }
40
41 /***
42 * @return the generated image height
43 */
44 public int getImageHeight() {
45 return height;
46 }
47
48 /***
49 * @return teh generated image width
50 */
51 public int getImageWidth() {
52 return width;
53 }
54
55 }