KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > print > cLine


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.core.print;
17
18 import java.awt.BasicStroke JavaDoc;
19 import java.awt.Color JavaDoc;
20 import java.awt.Graphics2D JavaDoc;
21 import java.awt.Stroke JavaDoc;
22 import java.awt.geom.Line2D JavaDoc;
23
24
25 public class cLine extends cPrintObject {
26     private double thickness;
27
28     public cLine() {
29         super();
30
31         thickness = 1.0;
32         color = Color.black;
33     }
34
35     public void setThickness(double t) {
36         thickness = t;
37     }
38
39     public double getThickness() {
40         return thickness;
41     }
42
43     public void print(Graphics2D JavaDoc g) {
44         computePositionAndSize();
45
46         double x1 = getDrawingOrigin().getX().getPoints();
47         double x2 = x1 + getDrawingSize().getWidth().getPoints();
48
49         Line2D.Double JavaDoc line = new Line2D.Double JavaDoc(x1,
50                 getDrawingOrigin().getY().getPoints(), x2,
51                 getDrawingOrigin().getY().getPoints());
52
53         Stroke JavaDoc lineStroke = new BasicStroke JavaDoc((float) thickness);
54         g.setStroke(lineStroke);
55
56         Color JavaDoc saveForeground = g.getColor();
57
58         g.setColor(color);
59         g.draw(line);
60         g.setColor(saveForeground);
61     }
62
63     public cSize getSize(cUnit width) {
64         cUnit height = new cPointUnit(thickness);
65         height.addI(topMargin);
66         height.addI(bottomMargin);
67
68         return new cSize(width, height);
69     }
70 }
71
Popular Tags