comparison dwtx/draw2d/geometry/Transposer.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.geometry.Transposer;
14
15 import dwt.dwthelper.utils;
16
17 import dwtx.draw2d.geometry.Dimension;
18 import dwtx.draw2d.geometry.Insets;
19 import dwtx.draw2d.geometry.Point;
20 import dwtx.draw2d.geometry.Rectangle;
21
22 /**
23 * Conditionally transposes geometrical objects based on an "enabled" flag. When
24 * enabled, the method t(Object) will transpose the passed geometrical object.
25 * Otherwise, the object will be returned without modification
26 */
27 public class Transposer {
28
29 private bool enabled = false;
30
31 /**
32 * Disables transposing of inputs.
33 *
34 * @since 2.0
35 */
36 public void disable() {
37 enabled = false;
38 }
39
40 /**
41 * Enables transposing of inputs.
42 *
43 * @since 2.0
44 */
45 public void enable() {
46 enabled = true;
47 }
48
49 /**
50 * Returns <code>true</code> if this Transposer is enabled.
51 *
52 * @return <code>true</code> if this Transposer is enabled
53 * @since 2.0
54 */
55 public bool isEnabled() {
56 return enabled;
57 }
58
59 /**
60 * Sets the enabled state of this Transposer.
61 *
62 * @param e New enabled value
63 * @since 2.0
64 */
65 public void setEnabled(bool e) {
66 enabled = e;
67 }
68
69 /**
70 * Returns a new transposed Dimension of the input Dimension.
71 *
72 * @param d Input dimension being transposed.
73 * @return The new transposed dimension.
74 * @since 2.0
75 */
76 public Dimension t(Dimension d) {
77 if (isEnabled())
78 return d.getTransposed();
79 return d;
80 }
81
82 /**
83 * Returns a new transposed Insets of the input Insets.
84 *
85 * @param i Insets to be transposed.
86 * @return The new transposed Insets.
87 * @since 2.0
88 */
89 public Insets t(Insets i) {
90 if (isEnabled())
91 return i.getTransposed();
92 return i;
93 }
94
95 /**
96 * Returns a new transposed Point of the input Point.
97 *
98 * @param p Point to be transposed.
99 * @return The new transposed Point.
100 * @since 2.0
101 */
102 public Point t(Point p) {
103 if (isEnabled())
104 return p.getTransposed();
105 return p;
106 }
107
108 /**
109 * Returns a new transposed Rectangle of the input Rectangle.
110 *
111 * @param r Rectangle to be transposed.
112 * @return The new trasnposed Rectangle.
113 * @since 2.0
114 */
115 public Rectangle t(Rectangle r) {
116 if (isEnabled())
117 return r.getTransposed();
118 return r;
119 }
120
121 }