annotate dwt/layout/FormAttachment.d @ 212:ab60f3309436

reverted the char[] to String and use the an alias.
author Frank Benoit <benoit@tionex.de>
date Mon, 05 May 2008 00:12:38 +0200
parents bcdc37794717
children fd9c62a2998e
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;
212
ab60f3309436 reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents: 187
diff changeset
21 import dwt.dwthelper.utils;
0
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 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
24 * 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
25 * within a <code>FormLayout</code>.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
26 * <p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
27 * <code>FormAttachments</code> are set into the top, bottom, left,
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
28 * and right fields of the <code>FormData</code> for a control.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
29 * For example:
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
30 * <pre>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
31 * FormData data = new FormData();
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
32 * data.top = new FormAttachment(0,5);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
33 * data.bottom = new FormAttachment(100,-5);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
34 * data.left = new FormAttachment(0,5);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
35 * data.right = new FormAttachment(100,-5);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
36 * button.setLayoutData(data);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
37 * </pre>
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 * <p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
40 * A <code>FormAttachment</code> defines where to attach the side of
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
41 * 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
42 * 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
43 * (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
44 * 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
45 * 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
46 * pixels, from the attachment position. For example:
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
47 * <pre>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
48 * FormAttachment attach = new FormAttachment (20, -5);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
49 * </pre>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
50 * specifies that the side to which the <code>FormAttachment</code>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
51 * 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
52 * </p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
53 * <p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
54 * Control sides can also be attached to another control.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
55 * For example:
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
56 * <pre>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
57 * FormAttachment attach = new FormAttachment (button, 10);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
58 * </pre>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
59 * specifies that the side to which the <code>FormAttachment</code>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
60 * 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
61 * 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
62 * also be attached to the opposite side of the specified control.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
63 * For example:
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
64 * <pre>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
65 * FormData data = new FormData ();
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
66 * data.left = new FormAttachment (button, 0, DWT.LEFT);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
67 * </pre>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
68 * 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
69 * 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
70 * 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
71 * control. For example:
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
72 * <pre>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
73 * data.left = new FormAttachment (button, 0, DWT.CENTER);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
74 * </pre>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
75 * 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
76 * 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
77 * 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
78 * </p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
79 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
80 * @see FormLayout
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
81 * @see FormData
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
82 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
83 * @since 2.0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
84 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
85 public final class FormAttachment {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
86 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
87 * numerator specifies the numerator of the "a" term in the
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
88 * equation, y = ax + b, which defines the attachment.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
89 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
90 public int numerator;
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 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
93 * denominator specifies the denominator of the "a" term in the
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
94 * equation, y = ax + b, which defines the attachment.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
95 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
96 * The default value is 100.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
97 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
98 public int denominator = 100;
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 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
101 * offset specifies the offset, in pixels, of the control side
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
102 * from the attachment position.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
103 * If the offset is positive, then the control side is offset
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
104 * 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
105 * 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
106 * above the attachment position.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
107 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
108 * 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
109 * The default value is 0.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
110 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
111 public int offset;
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 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
114 * control specifies the control to which the control side is
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
115 * attached.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
116 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
117 public Control control;
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 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
120 * alignment specifies the alignment of the control side that is
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
121 * attached to a control.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
122 * <p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
123 * 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
124 * 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
125 * occurs, the default will be used instead.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
126 * </p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
127 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
128 * <br>Possible values are: <ul>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
129 * <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
130 * <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
131 * <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
132 * <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
133 * <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
134 * <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
135 * </ul>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
136 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
137 public int alignment;
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 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
140 * Constructs a new instance of this class.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
141 * Since no numerator, denominator or offset is specified,
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
142 * the attachment is treated as a percentage of the form.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
143 * The numerator is zero, the denominator is 100 and the
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
144 * offset is zero.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
145 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
146 * @since 3.2
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
147 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
148 public this () {
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 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
152 * Constructs a new instance of this class given a numerator
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
153 * Since no denominator or offset is specified, the default
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
154 * 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
155 * denominator of 100. The offset is zero.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
156 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
157 * @param numerator the percentage of the position
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
158 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
159 * @since 3.0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
160 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
161 public this (int numerator) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
162 this (numerator, 100, 0);
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 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
166 * Constructs a new instance of this class given a numerator
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
167 * and an offset. Since no denominator is specified, the default
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
168 * 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
169 * denominator of 100.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
170 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
171 * @param numerator the percentage of the position
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
172 * @param offset the offset of the side from the position
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
173 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
174 public this (int numerator, int offset) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
175 this (numerator, 100, offset);
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 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
179 * Constructs a new instance of this class given a numerator
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
180 * and denominator and an offset. The position of the side is
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
181 * given by the fraction of the form defined by the numerator
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
182 * and denominator.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
183 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
184 * @param numerator the numerator of the position
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
185 * @param denominator the denominator of the position
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
186 * @param offset the offset of the side from the position
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
187 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
188 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
189 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
190 this.numerator = numerator;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
191 this.denominator = denominator;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
192 this.offset = offset;
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 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
196 * Constructs a new instance of this class given a control.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
197 * Since no alignment is specified, the default alignment is
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
198 * to attach the side to the adjacent side of the specified
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
199 * control. Since no offset is specified, an offset of 0 is
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
200 * used.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
201 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
202 * @param control the control the side is attached to
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
203 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
204 public this (Control control) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
205 this (control, 0, DWT.DEFAULT);
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 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
209 * Constructs a new instance of this class given a control
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
210 * and an offset. Since no alignment is specified, the default
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
211 * 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
212 * specified control.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
213 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
214 * @param control the control the side is attached to
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
215 * @param offset the offset of the side from the control
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
216 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
217 public this (Control control, int offset) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
218 this (control, offset, DWT.DEFAULT);
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 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
222 * Constructs a new instance of this class given a control,
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
223 * an offset and an alignment.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
224 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
225 * @param control the control the side is attached to
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
226 * @param offset the offset of the side from the control
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
227 * @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
228 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
229 public this (Control control, int offset, int alignment) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
230 this.control = control;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
231 this.offset = offset;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
232 this.alignment = alignment;
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
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
235 FormAttachment divide (int value) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
236 return new FormAttachment (numerator, denominator * value, offset / value);
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
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
239 int gcd (int m, int n) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
240 int temp;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
241 m = Math.abs (m);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
242 n = Math.abs (n);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
243 if (m < n) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
244 temp = m;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
245 m = n;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
246 n = temp;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
247 }
187
bcdc37794717 Reverted changes from previous wrong reverting changes:
Frank Benoit <benoit@tionex.de>
parents: 184
diff changeset
248 while (n !is 0){
0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
249 temp = m;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
250 m = n;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
251 n = temp % n;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
252 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
253 return m;
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
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
256 FormAttachment minus (FormAttachment attachment) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
257 FormAttachment solution = new FormAttachment ();
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
258 solution.numerator = numerator * attachment.denominator - denominator * attachment.numerator;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
259 solution.denominator = denominator * attachment.denominator;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
260 int gcd = gcd (solution.denominator, solution.numerator);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
261 solution.numerator = solution.numerator / gcd;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
262 solution.denominator = solution.denominator / gcd;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
263 solution.offset = offset - attachment.offset;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
264 return solution;
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
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
267 FormAttachment minus (int value) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
268 return new FormAttachment (numerator, denominator, offset - value);
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
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
271 FormAttachment plus (FormAttachment attachment) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
272 FormAttachment solution = new FormAttachment ();
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
273 solution.numerator = numerator * attachment.denominator + denominator * attachment.numerator;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
274 solution.denominator = denominator * attachment.denominator;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
275 int gcd = gcd (solution.denominator, solution.numerator);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
276 solution.numerator = solution.numerator / gcd;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
277 solution.denominator = solution.denominator / gcd;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
278 solution.offset = offset + attachment.offset;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
279 return solution;
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
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
282 FormAttachment plus (int value) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
283 return new FormAttachment (numerator, denominator, offset + value);
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
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
286 int solveX (int value) {
187
bcdc37794717 Reverted changes from previous wrong reverting changes:
Frank Benoit <benoit@tionex.de>
parents: 184
diff changeset
287 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
288 return ((numerator * value) / denominator) + offset;
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
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
291 int solveY (int value) {
187
bcdc37794717 Reverted changes from previous wrong reverting changes:
Frank Benoit <benoit@tionex.de>
parents: 184
diff changeset
292 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
293 return (value - offset) * denominator / numerator;
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 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
297 * Returns a string containing a concise, human-readable
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
298 * description of the receiver.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
299 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
300 * @return a string representation of the FormAttachment
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
301 */
212
ab60f3309436 reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents: 187
diff changeset
302 public override String toString () {
ab60f3309436 reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents: 187
diff changeset
303 String string = control !is null ? control.toString () : Format( "{}/{}", numerator, denominator );
0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
304 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
305 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
306
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
307 }