Project

General

Profile

Download (2.54 KB) Statistics
| Branch: | Tag: | Revision:
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 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
 *******************************************************************************/
11
package org.eclipse.draw2d.geometry;
12

    
13
/**
14
 * Conditionally transposes geometrical objects based on an "enabled" flag. When
15
 * enabled, the method t(Object) will transpose the passed geometrical object.
16
 * Otherwise, the object will be returned without modification
17
 */
18
public class Transposer {
19

    
20
	private boolean enabled = false;
21

    
22
	/**
23
	 * Disables transposing of inputs.
24
	 * 
25
	 * @since 2.0
26
	 */
27
	public void disable() {
28
		enabled = false;
29
	}
30

    
31
	/**
32
	 * Enables transposing of inputs.
33
	 * 
34
	 * @since 2.0
35
	 */
36
	public void enable() {
37
		enabled = true;
38
	}
39

    
40
	/**
41
	 * Returns <code>true</code> if this Transposer is enabled.
42
	 * 
43
	 * @return <code>true</code> if this Transposer is enabled
44
	 * @since 2.0
45
	 */
46
	public boolean isEnabled() {
47
		return enabled;
48
	}
49

    
50
	/**
51
	 * Sets the enabled state of this Transposer.
52
	 * 
53
	 * @param e
54
	 *            New enabled value
55
	 * @since 2.0
56
	 */
57
	public void setEnabled(boolean e) {
58
		enabled = e;
59
	}
60

    
61
	/**
62
	 * Returns a new transposed Dimension of the input Dimension.
63
	 * 
64
	 * @param d
65
	 *            Input dimension being transposed.
66
	 * @return The new transposed dimension.
67
	 * @since 2.0
68
	 */
69
	public Dimension t(Dimension d) {
70
		if (isEnabled())
71
			return d.getTransposed();
72
		return d;
73
	}
74

    
75
	/**
76
	 * Returns a new transposed Insets of the input Insets.
77
	 * 
78
	 * @param i
79
	 *            Insets to be transposed.
80
	 * @return The new transposed Insets.
81
	 * @since 2.0
82
	 */
83
	public Insets t(Insets i) {
84
		if (isEnabled())
85
			return i.getTransposed();
86
		return i;
87
	}
88

    
89
	/**
90
	 * Returns a new transposed Point of the input Point.
91
	 * 
92
	 * @param p
93
	 *            Point to be transposed.
94
	 * @return The new transposed Point.
95
	 * @since 2.0
96
	 */
97
	public Point t(Point p) {
98
		if (isEnabled())
99
			return p.getTransposed();
100
		return p;
101
	}
102

    
103
	/**
104
	 * Returns a new transposed Rectangle of the input Rectangle.
105
	 * 
106
	 * @param r
107
	 *            Rectangle to be transposed.
108
	 * @return The new trasnposed Rectangle.
109
	 * @since 2.0
110
	 */
111
	public Rectangle t(Rectangle r) {
112
		if (isEnabled())
113
			return r.getTransposed();
114
		return r;
115
	}
116

    
117
}
(15-15/17)