KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sshtools > ui > swing > StrokeIcon


1 /*
2  * SSHTools - Java SSH2 API
3  *
4  * Copyright (C) 2002 Lee David Painter.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * You may also distribute it and/or modify it under the terms of the
12  * Apache style J2SSH Software License. A copy of which should have
13  * been provided with the distribution.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * License document supplied with your distribution for more details.
19  *
20  */

21
22 package com.sshtools.ui.swing;
23
24 import java.awt.Component JavaDoc;
25 import java.awt.Dimension JavaDoc;
26 import java.awt.Graphics JavaDoc;
27 import java.awt.Graphics2D JavaDoc;
28 import java.awt.Stroke JavaDoc;
29
30 import javax.swing.Icon JavaDoc;
31
32 /**
33  *
34  *
35  * @author $author$
36  */

37 public class StrokeIcon implements Icon JavaDoc {
38     // Private instance variables
39
private Dimension JavaDoc size;
40     private Stroke JavaDoc stroke;
41
42     /**
43      * Creates a new ColorIcon object.
44      */

45     public StrokeIcon() {
46         this(null);
47     }
48
49     /**
50      * Creates a new ColorIcon object.
51      *
52      * @param color
53      */

54     public StrokeIcon(Stroke JavaDoc stroke) {
55         this(stroke, null);
56     }
57
58     /**
59      * Creates a new ColorIcon object.
60      *
61      * @param color
62      * @param size
63      * @param borderColor
64      */

65     public StrokeIcon(Stroke JavaDoc stroke, Dimension JavaDoc size) {
66         setStroke(stroke);
67         setSize(size);
68     }
69
70     /**
71      *
72      *
73      * @param c
74      * @param g
75      * @param x
76      * @param y
77      */

78     public void paintIcon(Component JavaDoc c, Graphics JavaDoc g, int x, int y) {
79         Graphics2D JavaDoc g2 = (Graphics2D JavaDoc)g;
80         g2.setStroke(stroke);
81         g2.drawLine(x, y, x + getIconWidth(), y);
82     }
83
84     /**
85      *
86      *
87      * @param size
88      */

89     public void setSize(Dimension JavaDoc size) {
90         this.size = size;
91     }
92
93     /**
94      *
95      *
96      * @param color
97      */

98     public void setStroke(Stroke JavaDoc stroke) {
99         this.stroke = stroke;
100     }
101
102     /**
103      *
104      *
105      * @return
106      */

107     public int getIconWidth() {
108         return (size == null) ? 48 : size.width;
109     }
110
111     /**
112      *
113      *
114      * @return
115      */

116     public int getIconHeight() {
117         return (size == null) ? 16 : size.height;
118     }
119 }
Popular Tags