KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > terminalemulator > Extent


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is Terminal Emulator.
16  * The Initial Developer of the Original Software is Sun Microsystems, Inc..
17  * Portions created by Sun Microsystems, Inc. are Copyright (C) 2001.
18  * All Rights Reserved.
19  *
20  * Contributor(s): Ivan Soleimanipour.
21  */

22
23 /*
24  * "Extent.java"
25  * Extent.java 1.5 01/07/26
26  */

27
28 package org.netbeans.lib.terminalemulator;
29
30 public class Extent {
31     public Coord begin;
32     public Coord end;
33
34     public Extent(Coord begin, Coord end) {
35     this.begin = (Coord) begin.clone();
36     this.end = (Coord) end.clone();
37     }
38
39     /**
40      * Override Object.toString
41      */

42     public String JavaDoc toString() {
43     return "Extent[" + begin + " " + end + "]"; // NOI18N
44
}
45
46     /**
47      * Ensure that 'begin' is before 'end'.
48      */

49     public Extent order() {
50     if (begin.compareTo(end) > 0) {
51         Coord tmp = begin;
52         begin = end;
53         end = tmp;
54     }
55     return this;
56     }
57
58     /*
59      * Return true if selection intersects the given row/column
60      */

61     public boolean intersects(int arow, int col) {
62     if (begin.row > arow)
63         return false;
64     else if (end.row < arow)
65         return false;
66     else if (begin.row == end.row)
67         return col >= begin.col && col <= end.col;
68     else if (arow == begin.row)
69         return col >= begin.col;
70     else if (arow == end.row)
71         return col <= end.col;
72     else
73         return true;
74     }
75 }
76
Popular Tags