Mercurial > projects > dwt-addons
comparison dwtx/draw2d/LineBorder.d @ 98:95307ad235d9
Added Draw2d code, still work in progress
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 03 Aug 2008 00:52:14 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
96:b492ba44e44d | 98:95307ad235d9 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2005 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.draw2d.LineBorder; | |
14 | |
15 import dwt.dwthelper.utils; | |
16 | |
17 | |
18 import dwtx.draw2d.AbstractBorder; | |
19 import dwtx.draw2d.IFigure; | |
20 import dwtx.draw2d.Graphics; | |
21 | |
22 import dwt.graphics.Color; | |
23 import dwtx.draw2d.geometry.Insets; | |
24 | |
25 /** | |
26 * Provides for a line border with sides of equal widths. | |
27 */ | |
28 public class LineBorder | |
29 : AbstractBorder | |
30 { | |
31 | |
32 private int width = 1; | |
33 private Color color; | |
34 | |
35 /** | |
36 * Constructs a LineBorder with the specified color and of the specified width. | |
37 * | |
38 * @param color The color of the border. | |
39 * @param width The width of the border in pixels. | |
40 * @since 2.0 | |
41 */ | |
42 public this(Color color, int width) { | |
43 setColor(color); | |
44 setWidth(width); | |
45 } | |
46 | |
47 /** | |
48 * Constructs a LineBorder with the specified color and a width of 1 pixel. | |
49 * | |
50 * @param color The color of the border. | |
51 * @since 2.0 | |
52 */ | |
53 public this(Color color) { | |
54 this(color, 1); | |
55 } | |
56 | |
57 /** | |
58 * Constructs a black LineBorder with the specified width. | |
59 * | |
60 * @param width The width of the border in pixels. | |
61 * @since 2.0 | |
62 */ | |
63 public this(int width) { | |
64 this(null, width); | |
65 } | |
66 | |
67 /** | |
68 * Constructs a default black LineBorder with a width of one pixel. | |
69 * | |
70 * @since 2.0 | |
71 */ | |
72 public this() { } | |
73 | |
74 /** | |
75 * Returns the line color of this border. | |
76 * @return The line color of this border | |
77 */ | |
78 public Color getColor() { | |
79 return color; | |
80 } | |
81 | |
82 /** | |
83 * Returns the space used by the border for the figure provided as input. In this border | |
84 * all sides always have equal width. | |
85 * @param figure The figure this border belongs to | |
86 * @return This border's insets | |
87 */ | |
88 public Insets getInsets(IFigure figure) { | |
89 return new Insets(getWidth()); | |
90 } | |
91 | |
92 /** | |
93 * Returns the line width of this border. | |
94 * @return The line width of this border | |
95 */ | |
96 public int getWidth() { | |
97 return width; | |
98 } | |
99 | |
100 /** | |
101 * Returns <code>true</code> since this border is opaque. Being opaque it is responsible | |
102 * to fill in the area within its boundaries. | |
103 * @return <code>true</code> since this border is opaque | |
104 */ | |
105 public bool isOpaque() { | |
106 return true; | |
107 } | |
108 | |
109 /** | |
110 * @see dwtx.draw2d.Border#paint(IFigure, Graphics, Insets) | |
111 */ | |
112 public void paint(IFigure figure, Graphics graphics, Insets insets) { | |
113 tempRect.setBounds(getPaintRectangle(figure, insets)); | |
114 if (getWidth() % 2 is 1) { | |
115 tempRect.width--; | |
116 tempRect.height--; | |
117 } | |
118 tempRect.shrink(getWidth() / 2, getWidth() / 2); | |
119 graphics.setLineWidth(getWidth()); | |
120 if (getColor() !is null) | |
121 graphics.setForegroundColor(getColor()); | |
122 graphics.drawRectangle(tempRect); | |
123 } | |
124 | |
125 /** | |
126 * Sets the line color for this border. | |
127 * @param color The line color | |
128 */ | |
129 public void setColor(Color color) { | |
130 this.color = color; | |
131 } | |
132 | |
133 /** | |
134 * Sets the line width for this border. | |
135 * @param width The line width | |
136 */ | |
137 public void setWidth(int width) { | |
138 this.width = width; | |
139 } | |
140 | |
141 } |