KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > gestures > CaptureEvent


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.internal.gestures;
13
14 import java.util.Arrays JavaDoc;
15
16 import org.eclipse.ui.internal.util.Util;
17
18 public final class CaptureEvent implements Comparable JavaDoc {
19
20     private final static int HASH_FACTOR = 89;
21     private final static int HASH_INITIAL =
22         CaptureEvent.class.getName().hashCode();
23
24     public static CaptureEvent create(int data, int pen, Point[] points) {
25         return new CaptureEvent(data, pen, points);
26     }
27
28     private int data;
29     private int pen;
30     private Point[] points;
31
32     private CaptureEvent(int data, int pen, Point[] points) {
33         super();
34         this.data = data;
35         this.pen = pen;
36
37         if (points == null)
38             throw new NullPointerException JavaDoc();
39
40         points = (Point[]) points.clone();
41
42         for (int i = 0; i < points.length; i++)
43             if (points[i] == null)
44                 throw new IllegalArgumentException JavaDoc();
45
46         this.points = points;
47     }
48
49     public int compareTo(Object JavaDoc object) {
50         CaptureEvent castedObject = (CaptureEvent) object;
51         int compareTo = data - castedObject.data;
52
53         if (compareTo == 0) {
54             compareTo = pen - castedObject.pen;
55
56             if (compareTo == 0)
57                 compareTo = Util.compare(points, castedObject.points);
58         }
59
60         return compareTo;
61     }
62
63     public boolean equals(Object JavaDoc object) {
64         if (!(object instanceof CaptureEvent))
65             return false;
66
67         CaptureEvent castedObject = (CaptureEvent) object;
68         return data == castedObject.data
69             && pen == castedObject.pen
70             && Arrays.equals(points, castedObject.points);
71     }
72
73     public int getData() {
74         return data;
75     }
76
77     public int getPen() {
78         return pen;
79     }
80
81     public Point[] getPoints() {
82         return (Point[]) points.clone();
83     }
84
85     public int hashCode() {
86         int result = HASH_INITIAL;
87         result = result * HASH_FACTOR + data;
88         result = result * HASH_FACTOR + pen;
89
90         for (int i = 0; i < points.length; i++)
91             result = result * HASH_FACTOR + points[i].hashCode();
92
93         return result;
94     }
95 }
96
Popular Tags