1 22 23 package org.netbeans.lib.terminalemulator; 24 25 37 38 public class Coord implements Comparable { 39 public int row; 40 public int col; 41 42 45 public Coord() { 46 this.row = 0; 47 this.col = 0; 48 } 49 50 private Coord(int row, int col) { 51 this.row = row; 53 this.col = col; 54 } 55 56 public static Coord make(int row, int col) { 57 return new Coord(row, col); 59 } 60 61 public Coord(Coord coord) { 62 this.row = coord.row; 63 this.col = coord.col; 64 } 65 66 public Coord(BCoord coord, int bias) { 67 this.row = coord.row + bias; 68 this.col = coord.col; 69 } 70 71 public BCoord toBCoord(int bias) { 72 int new_row = row - bias; 73 if (new_row < 0) 74 return new BCoord(0, 0); else 76 return new BCoord(new_row, col); 77 } 78 79 public void copyFrom(Coord src) { 80 this.row = src.row; 81 this.col = src.col; 82 } 83 84 86 public Object clone() { 87 return new Coord(row, col); 88 } 89 90 public boolean equals(Coord target) { if (row != target.row) 92 return false; 93 return col == target.col; 94 } 95 96 public String toString() { 97 return "(r=" + row + ",c=" + col + ")"; } 99 100 109 public int compareTo(Object o) throws ClassCastException { 110 Coord target = (Coord) o; 111 112 116 if (this.row < target.row) 117 return -1; 118 else if (this.row > target.row) 119 return +1; 120 else { 121 return this.col - target.col; 122 } 123 } 124 125 void clip(int rows, int cols, int bias) { 126 134 135 if (row < bias) 136 row = bias; 137 else if (row > bias + rows) 138 row = bias + rows; 139 140 if (col < 0) 141 col = 0; 142 else if (col > cols) 143 col = cols; 144 } 145 } 146 | Popular Tags |