Ir a la documentación de este archivo.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00026 package com.googlecode.leptonica.android;
00027
00033 public class Box {
00034 static {
00035 System.loadLibrary("lept");
00036 }
00037
00039 public static final int INDEX_X = 0;
00040
00042 public static final int INDEX_Y = 1;
00043
00045 public static final int INDEX_W = 2;
00046
00048 public static final int INDEX_H = 3;
00049
00054 final int mNativeBox;
00055
00056 private boolean mRecycled = false;
00057
00064 Box(int nativeBox) {
00065 mNativeBox = nativeBox;
00066 mRecycled = false;
00067 }
00068
00082 public Box(int x, int y, int w, int h) {
00083 if (x < 0 || y < 0 || w < 0 || h < 0) {
00084 throw new IllegalArgumentException(
00085 "All box dimensions must be non-negative");
00086 }
00087
00088 int nativeBox = nativeCreate(x, y, w, h);
00089
00090 if (nativeBox == 0) {
00091 throw new OutOfMemoryError();
00092 }
00093
00094 mNativeBox = nativeBox;
00095 mRecycled = false;
00096 }
00097
00103 public int getX() {
00104 return nativeGetX(mNativeBox);
00105 }
00106
00112 public int getY() {
00113 return nativeGetY(mNativeBox);
00114 }
00115
00121 public int getWidth() {
00122 return nativeGetWidth(mNativeBox);
00123 }
00124
00130 public int getHeight() {
00131 return nativeGetHeight(mNativeBox);
00132 }
00133
00140 public int[] getGeometry() {
00141 int[] geometry = new int[4];
00142
00143 if (getGeometry(geometry)) {
00144 return geometry;
00145 }
00146
00147 return null;
00148 }
00149
00158 public boolean getGeometry(int[] geometry) {
00159 if (geometry.length < 4) {
00160 throw new IllegalArgumentException(
00161 "Geometry array must be at least 4 elements long");
00162 }
00163
00164 return nativeGetGeometry(mNativeBox, geometry);
00165 }
00166
00170 public void recycle() {
00171 if (!mRecycled) {
00172 nativeDestroy(mNativeBox);
00173
00174 mRecycled = true;
00175 }
00176 }
00177
00178 @Override
00179 protected void finalize() throws Throwable {
00180 recycle();
00181
00182 super.finalize();
00183 }
00184
00185
00186
00187
00188
00189 private static native int nativeCreate(int x, int y, int w, int h);
00190
00191 private static native int nativeGetX(int nativeBox);
00192
00193 private static native int nativeGetY(int nativeBox);
00194
00195 private static native int nativeGetWidth(int nativeBox);
00196
00197 private static native int nativeGetHeight(int nativeBox);
00198
00199 private static native void nativeDestroy(int nativeBox);
00200
00201 private static native boolean nativeGetGeometry(int nativeBox,
00202 int[] geometry);
00203 }