annotate dwt/layout/FormAttachment.d @ 187:bcdc37794717

Reverted changes from previous wrong reverting changes: See: -r026ce3b05f57, -r4d06074bb1af, -rc4643827733c
author Frank Benoit <benoit@tionex.de>
date Mon, 10 Mar 2008 17:08:22 +0100
parents 4d06074bb1af
children ab60f3309436
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
1 /*******************************************************************************
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
2 * Copyright (c) 2000, 2006 IBM Corporation and others.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
3 * All rights reserved. This program and the accompanying materials
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
4 * are made available under the terms of the Eclipse Public License v1.0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
5 * which accompanies this distribution, and is available at
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
6 * http://www.eclipse.org/legal/epl-v10.html
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
7 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
8 * Contributors:
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
9 * IBM Corporation - initial API and implementation
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
10 * Port to the D programming language:
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
11 * Frank Benoit <benoit@tionex.de>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
12 *******************************************************************************/
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
13 module dwt.layout.FormAttachment;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
14
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
15 import dwt.DWT;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
16 import dwt.widgets.Control;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
17 import dwt.layout.FormLayout;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
18 import dwt.layout.FormData;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
19
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
20 import tango.text.convert.Format;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
21
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
22 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
23 * Instances of this class are used to define the edges of a control
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
24 * within a <code>FormLayout</code>.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
25 * <p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
26 * <code>FormAttachments</code> are set into the top, bottom, left,
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
27 * and right fields of the <code>FormData</code> for a control.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
28 * For example:
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
29 * <pre>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
30 * FormData data = new FormData();
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
31 * data.top = new FormAttachment(0,5);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
32 * data.bottom = new FormAttachment(100,-5);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
33 * data.left = new FormAttachment(0,5);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
34 * data.right = new FormAttachment(100,-5);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
35 * button.setLayoutData(data);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
36 * </pre>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
37 * </p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
38 * <p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
39 * A <code>FormAttachment</code> defines where to attach the side of
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
40 * a control by using the equation, y = ax + b. The "a" term represents
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
41 * a fraction of the parent composite's width (from the left) or height
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
42 * (from the top). It can be defined using a numerator and denominator,
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
43 * or just a percentage value. If a percentage is used, the denominator
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
44 * is set to 100. The "b" term in the equation represents an offset, in
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
45 * pixels, from the attachment position. For example:
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
46 * <pre>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
47 * FormAttachment attach = new FormAttachment (20, -5);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
48 * </pre>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
49 * specifies that the side to which the <code>FormAttachment</code>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
50 * object belongs will lie at 20% of the parent composite, minus 5 pixels.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
51 * </p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
52 * <p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
53 * Control sides can also be attached to another control.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
54 * For example:
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
55 * <pre>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
56 * FormAttachment attach = new FormAttachment (button, 10);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
57 * </pre>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
58 * specifies that the side to which the <code>FormAttachment</code>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
59 * object belongs will lie in the same position as the adjacent side of
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
60 * the <code>button</code> control, plus 10 pixels. The control side can
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
61 * also be attached to the opposite side of the specified control.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
62 * For example:
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
63 * <pre>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
64 * FormData data = new FormData ();
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
65 * data.left = new FormAttachment (button, 0, DWT.LEFT);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
66 * </pre>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
67 * specifies that the left side of the control will lie in the same position
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
68 * as the left side of the <code>button</code> control. The control can also
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
69 * be attached in a position that will center the control on the specified
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
70 * control. For example:
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
71 * <pre>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
72 * data.left = new FormAttachment (button, 0, DWT.CENTER);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
73 * </pre>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
74 * specifies that the left side of the control will be positioned so that it is
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
75 * centered between the left and right sides of the <code>button</code> control.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
76 * If the alignment is not specified, the default is to attach to the adjacent side.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
77 * </p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
78 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
79 * @see FormLayout
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
80 * @see FormData
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
81 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
82 * @since 2.0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
83 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
84 public final class FormAttachment {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
85 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
86 * numerator specifies the numerator of the "a" term in the
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
87 * equation, y = ax + b, which defines the attachment.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
88 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
89 public int numerator;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
90
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
91 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
92 * denominator specifies the denominator of the "a" term in the
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
93 * equation, y = ax + b, which defines the attachment.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
94 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
95 * The default value is 100.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
96 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
97 public int denominator = 100;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
98
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
99 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
100 * offset specifies the offset, in pixels, of the control side
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
101 * from the attachment position.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
102 * If the offset is positive, then the control side is offset
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
103 * to the right of or below the attachment position. If it is
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
104 * negative, then the control side is offset to the left of or
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
105 * above the attachment position.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
106 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
107 * This is equivalent to the "b" term in the equation y = ax + b.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
108 * The default value is 0.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
109 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
110 public int offset;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
111
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
112 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
113 * control specifies the control to which the control side is
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
114 * attached.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
115 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
116 public Control control;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
117
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
118 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
119 * alignment specifies the alignment of the control side that is
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
120 * attached to a control.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
121 * <p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
122 * For top and bottom attachments, TOP, BOTTOM and CENTER are used. For left
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
123 * and right attachments, LEFT, RIGHT and CENTER are used. If any other case
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
124 * occurs, the default will be used instead.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
125 * </p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
126 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
127 * <br>Possible values are: <ul>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
128 * <li>TOP: Attach the side to the top side of the specified control.</li>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
129 * <li>BOTTOM : Attach the side to the bottom side of the specified control.</li>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
130 * <li>LEFT: Attach the side to the left side of the specified control.</li>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
131 * <li>RIGHT: Attach the side to the right side of the specified control.</li>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
132 * <li>CENTER: Attach the side at a position which will center the control on the specified control.</li>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
133 * <li>DEFAULT: Attach the side to the adjacent side of the specified control.</li>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
134 * </ul>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
135 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
136 public int alignment;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
137
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
138 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
139 * Constructs a new instance of this class.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
140 * Since no numerator, denominator or offset is specified,
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
141 * the attachment is treated as a percentage of the form.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
142 * The numerator is zero, the denominator is 100 and the
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
143 * offset is zero.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
144 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
145 * @since 3.2
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
146 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
147 public this () {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
148 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
149
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
150 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
151 * Constructs a new instance of this class given a numerator
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
152 * Since no denominator or offset is specified, the default
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
153 * is to treat the numerator as a percentage of the form, with a
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
154 * denominator of 100. The offset is zero.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
155 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
156 * @param numerator the percentage of the position
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
157 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
158 * @since 3.0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
159 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
160 public this (int numerator) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
161 this (numerator, 100, 0);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
162 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
163
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
164 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
165 * Constructs a new instance of this class given a numerator
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
166 * and an offset. Since no denominator is specified, the default
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
167 * is to treat the numerator as a percentage of the form, with a
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
168 * denominator of 100.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
169 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
170 * @param numerator the percentage of the position
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
171 * @param offset the offset of the side from the position
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
172 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
173 public this (int numerator, int offset) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
174 this (numerator, 100, offset);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
175 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
176
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
177 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
178 * Constructs a new instance of this class given a numerator
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
179 * and denominator and an offset. The position of the side is
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
180 * given by the fraction of the form defined by the numerator
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
181 * and denominator.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
182 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
183 * @param numerator the numerator of the position
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
184 * @param denominator the denominator of the position
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
185 * @param offset the offset of the side from the position
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
186 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
187 public this (int numerator, int denominator, int offset) {
187
bcdc37794717 Reverted changes from previous wrong reverting changes:
Frank Benoit <benoit@tionex.de>
parents: 184
diff changeset
188 if (denominator is 0) DWT.error (DWT.ERROR_CANNOT_BE_ZERO);
0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
189 this.numerator = numerator;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
190 this.denominator = denominator;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
191 this.offset = offset;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
192 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
193
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
194 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
195 * Constructs a new instance of this class given a control.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
196 * Since no alignment is specified, the default alignment is
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
197 * to attach the side to the adjacent side of the specified
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
198 * control. Since no offset is specified, an offset of 0 is
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
199 * used.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
200 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
201 * @param control the control the side is attached to
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
202 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
203 public this (Control control) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
204 this (control, 0, DWT.DEFAULT);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
205 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
206
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
207 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
208 * Constructs a new instance of this class given a control
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
209 * and an offset. Since no alignment is specified, the default
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
210 * alignment is to attach the side to the adjacent side of the
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
211 * specified control.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
212 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
213 * @param control the control the side is attached to
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
214 * @param offset the offset of the side from the control
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
215 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
216 public this (Control control, int offset) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
217 this (control, offset, DWT.DEFAULT);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
218 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
219
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
220 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
221 * Constructs a new instance of this class given a control,
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
222 * an offset and an alignment.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
223 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
224 * @param control the control the side is attached to
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
225 * @param offset the offset of the side from the control
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
226 * @param alignment the alignment of the side to the control it is attached to
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
227 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
228 public this (Control control, int offset, int alignment) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
229 this.control = control;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
230 this.offset = offset;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
231 this.alignment = alignment;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
232 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
233
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
234 FormAttachment divide (int value) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
235 return new FormAttachment (numerator, denominator * value, offset / value);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
236 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
237
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
238 int gcd (int m, int n) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
239 int temp;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
240 m = Math.abs (m);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
241 n = Math.abs (n);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
242 if (m < n) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
243 temp = m;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
244 m = n;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
245 n = temp;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
246 }
187
bcdc37794717 Reverted changes from previous wrong reverting changes:
Frank Benoit <benoit@tionex.de>
parents: 184
diff changeset
247 while (n !is 0){
0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
248 temp = m;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
249 m = n;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
250 n = temp % n;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
251 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
252 return m;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
253 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
254
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
255 FormAttachment minus (FormAttachment attachment) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
256 FormAttachment solution = new FormAttachment ();
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
257 solution.numerator = numerator * attachment.denominator - denominator * attachment.numerator;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
258 solution.denominator = denominator * attachment.denominator;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
259 int gcd = gcd (solution.denominator, solution.numerator);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
260 solution.numerator = solution.numerator / gcd;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
261 solution.denominator = solution.denominator / gcd;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
262 solution.offset = offset - attachment.offset;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
263 return solution;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
264 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
265
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
266 FormAttachment minus (int value) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
267 return new FormAttachment (numerator, denominator, offset - value);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
268 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
269
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
270 FormAttachment plus (FormAttachment attachment) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
271 FormAttachment solution = new FormAttachment ();
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
272 solution.numerator = numerator * attachment.denominator + denominator * attachment.numerator;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
273 solution.denominator = denominator * attachment.denominator;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
274 int gcd = gcd (solution.denominator, solution.numerator);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
275 solution.numerator = solution.numerator / gcd;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
276 solution.denominator = solution.denominator / gcd;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
277 solution.offset = offset + attachment.offset;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
278 return solution;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
279 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
280
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
281 FormAttachment plus (int value) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
282 return new FormAttachment (numerator, denominator, offset + value);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
283 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
284
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
285 int solveX (int value) {
187
bcdc37794717 Reverted changes from previous wrong reverting changes:
Frank Benoit <benoit@tionex.de>
parents: 184
diff changeset
286 if (denominator is 0) DWT.error (DWT.ERROR_CANNOT_BE_ZERO);
0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
287 return ((numerator * value) / denominator) + offset;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
288 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
289
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
290 int solveY (int value) {
187
bcdc37794717 Reverted changes from previous wrong reverting changes:
Frank Benoit <benoit@tionex.de>
parents: 184
diff changeset
291 if (numerator is 0) DWT.error (DWT.ERROR_CANNOT_BE_ZERO);
0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
292 return (value - offset) * denominator / numerator;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
293 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
294
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
295 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
296 * Returns a string containing a concise, human-readable
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
297 * description of the receiver.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
298 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
299 * @return a string representation of the FormAttachment
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
300 */
187
bcdc37794717 Reverted changes from previous wrong reverting changes:
Frank Benoit <benoit@tionex.de>
parents: 184
diff changeset
301 public override char[] toString () {
bcdc37794717 Reverted changes from previous wrong reverting changes:
Frank Benoit <benoit@tionex.de>
parents: 184
diff changeset
302 char[] string = control !is null ? control.toString () : Format( "{}/{}", numerator, denominator );
0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
303 return Format("{{y = ({})x + {}}", string, ( offset >= 0 ? Format(")x + {}", offset ) : Format( ")x - {}", -offset)));
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
304 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
305
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
306 }