1 22 23 package org.netbeans.lib.terminalemulator; 24 25 37 38 class BCoord implements Comparable { 39 public int row; 40 public int col; 41 42 45 public BCoord() { 46 this.row = 0; 47 this.col = 0; 48 } 49 50 public BCoord(int row, int col) { 51 this.row = row; 53 this.col = col; 54 } 55 56 public BCoord(BCoord coord) { 57 this.row = coord.row; 58 this.col = coord.col; 59 } 60 61 public void copyFrom(BCoord src) { 62 this.row = src.row; 63 this.col = src.col; 64 } 65 66 68 public Object clone() { 69 return new BCoord(row, col); 70 } 71 72 public boolean equals(BCoord target) { if (row != target.row) 74 return false; 75 return col == target.col; 76 } 77 78 public String toString() { 79 return "(r=" + row + ",c=" + col + ")"; } 81 82 91 public int compareTo(Object o) throws ClassCastException { 92 BCoord target = (BCoord) o; 93 94 98 if (this.row < target.row) 99 return -1; 100 else if (this.row > target.row) 101 return +1; 102 else { 103 return this.col - target.col; 104 } 105 } 106 107 public void clip(int rows, int cols) { 108 if (row < 0) 111 row = 0; 112 else if (row > rows) 113 row = rows; 114 if (col < 0) 115 col = 0; 116 else if (col > cols) 117 col = cols; 118 } 119 } 120 | Popular Tags |