View Javadoc
1   /**
2    * 
3    */
4   package de.japrost.excerpt;
5   
6   import java.awt.BasicStroke;
7   import java.awt.Color;
8   import java.awt.Graphics2D;
9   import java.awt.Rectangle;
10  import java.awt.Stroke;
11  
12  
13  /**
14   *
15   */
16  public class Decorator implements RenderLine {
17  
18  	// points to add above and blow
19  	int border = 2;
20  	// hight of the real content
21  	int height = 5;
22  	// usually decorators render centered.
23  	int align = -1;
24  
25  	private Graphics2D graphics;
26  	private final int pageWidht;
27  	private int color = 0;
28  
29  	public Decorator(final Graphics2D graphics2D, final int pageWidht) {
30  		super();
31  		graphics = graphics2D;
32  		this.pageWidht = pageWidht;
33  	}
34  
35  	/**
36  	 * {@inheritDoc} Decorators do not expand!
37  	 */
38  	@Override
39  	public int expand() {
40  		return 0;
41  	}
42  
43  	/**
44  	 * {@inheritDoc}
45  	 */
46  	@Override
47  	public int height() {
48  		return height + 2 * border;
49  	}
50  
51  	/**
52  	 * {@inheritDoc}
53  	 */
54  	@Override
55  	public void render(final Rectangle borders) {
56  		Color c = graphics.getColor();
57  		Stroke s = graphics.getStroke();
58  		graphics.setColor(new Color(color));
59  		BasicStroke bs = new BasicStroke(2);
60  		graphics.setStroke(bs);
61  		graphics.drawLine(borders.x, borders.y + border, borders.x + borders.width, borders.y + border);
62  		graphics.drawLine(borders.x, borders.y + border + height, borders.x + borders.width, borders.y + border + height);
63  		graphics.setColor(c);
64  		graphics.setStroke(s);
65  	}
66  
67  	/**
68  	 * {@inheritDoc}
69  	 */
70  	@Override
71  	public int align() {
72  		return align;
73  	}
74  
75  	/**
76  	 * {@inheritDoc}
77  	 */
78  	@Override
79  	public int width() {
80  		// TODO a bit more flexible, please!
81  		return pageWidht;
82  	}
83  
84  	/**
85  	 * @param color the color to use.
86  	 */
87  	public void setColor(final int color) {
88  		this.color = color;
89  
90  	}
91  
92  }