annotate dwt/graphics/Point.d @ 246:fd9c62a2998e

Updater SWT 3.4M7 to 3.4
author Frank Benoit <benoit@tionex.de>
date Tue, 01 Jul 2008 10:15:59 +0200
parents ab60f3309436
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
174
f906dbcacee5 Minor changes to be more compatible to dwt-linux, formatting in toString, Display.DEBUG=true
Frank Benoit <benoit@tionex.de>
parents: 48
diff changeset
1 /*******************************************************************************
246
fd9c62a2998e Updater SWT 3.4M7 to 3.4
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
2 * Copyright (c) 2000, 2008 IBM Corporation and others.
4
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
3 * All rights reserved. This program and the accompanying materials
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
4 * are made available under the terms of the Eclipse Public License v1.0
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
5 * which accompanies this distribution, and is available at
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
6 * http://www.eclipse.org/legal/epl-v10.html
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
7 *
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
8 * Contributors:
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
9 * IBM Corporation - initial API and implementation
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
10 * Port to the D programming language:
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
11 * Frank Benoit <benoit@tionex.de>
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
12 *******************************************************************************/
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
13 module dwt.graphics.Point;
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
14
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
15
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
16 public import dwt.internal.SerializableCompatibility;
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
17
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
18 import tango.text.convert.Format;
212
ab60f3309436 reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents: 174
diff changeset
19 import dwt.dwthelper.utils;
4
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
20
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
21 /**
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
22 * Instances of this class represent places on the (x, y)
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
23 * coordinate plane.
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
24 * <p>
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
25 * The coordinate space for rectangles and points is considered
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
26 * to have increasing values downward and to the right from its
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
27 * origin making this the normal, computer graphics oriented notion
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
28 * of (x, y) coordinates rather than the strict mathematical one.
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
29 * </p>
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
30 * <p>
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
31 * The hashCode() method in this class uses the values of the public
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
32 * fields to compute the hash value. When storing instances of the
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
33 * class in hashed collections, do not modify these fields after the
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
34 * object has been inserted.
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
35 * </p>
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
36 * <p>
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
37 * Application code does <em>not</em> need to explicitly release the
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
38 * resources managed by each instance when those instances are no longer
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
39 * required, and thus no <code>dispose()</code> method is provided.
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
40 * </p>
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
41 *
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
42 * @see Rectangle
246
fd9c62a2998e Updater SWT 3.4M7 to 3.4
Frank Benoit <benoit@tionex.de>
parents: 212
diff changeset
43 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
4
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
44 */
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
45
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
46 public final class Point : SerializableCompatibility {
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
47
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
48 /**
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
49 * the x coordinate of the point
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
50 */
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
51 public int x;
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
52
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
53 /**
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
54 * the y coordinate of the point
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
55 */
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
56 public int y;
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
57
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
58 //static final long serialVersionUID = 3257002163938146354L;
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
59
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
60 /**
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
61 * Constructs a new point with the given x and y coordinates.
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
62 *
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
63 * @param x the x coordinate of the new point
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
64 * @param y the y coordinate of the new point
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
65 */
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
66 public this (int x, int y) {
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
67 this.x = x;
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
68 this.y = y;
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
69 }
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
70
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
71 /**
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
72 * Compares the argument to the receiver, and returns true
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
73 * if they represent the <em>same</em> object using a class
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
74 * specific comparison.
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
75 *
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
76 * @param object the object to compare with this object
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
77 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
78 *
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
79 * @see #hashCode()
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
80 */
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
81 public override int opEquals (Object object) {
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
82 if (object is this) return true;
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
83 if ( auto p = cast(Point)object ){
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
84 return (p.x is this.x) && (p.y is this.y);
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
85 }
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
86 return false;
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
87 }
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
88
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
89 /**
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
90 * Returns an integer hash code for the receiver. Any two
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
91 * objects that return <code>true</code> when passed to
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
92 * <code>equals</code> must return the same value for this
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
93 * method.
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
94 *
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
95 * @return the receiver's hash
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
96 *
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
97 * @see #equals(Object)
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
98 */
48
9a64a7781bab Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents: 4
diff changeset
99 override public hash_t toHash () {
4
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
100 return x ^ y;
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
101 }
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
102
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
103 /**
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
104 * Returns a string containing a concise, human-readable
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
105 * description of the receiver.
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
106 *
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
107 * @return a string representation of the point
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
108 */
212
ab60f3309436 reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents: 174
diff changeset
109 override public String toString () {
174
f906dbcacee5 Minor changes to be more compatible to dwt-linux, formatting in toString, Display.DEBUG=true
Frank Benoit <benoit@tionex.de>
parents: 48
diff changeset
110 return Format( "Point {{{}, {}}", x, y );; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
4
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
111 }
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
112
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
113 }
bf9fe45b4422 C, Platform, Point, Rectangle
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
114