org.jpedal.utils.repositories.generic.Vector_Rectangle_Int Maven / Gradle / Ivy
/*
* ===========================================
* Java Pdf Extraction Decoding Access Library
* ===========================================
*
* Project Info: http://www.idrsolutions.com
* Help section for developers at http://www.idrsolutions.com/support/
*
* (C) Copyright 1997-2017 IDRsolutions and Contributors.
*
* This file is part of JPedal/JPDF2HTML5
*
@LICENSE@
*
* ---------------
* Vector_Rectangle_Int.java
* ---------------
*/
package org.jpedal.utils.repositories.generic;
/**
* A generic class to create and manipulate the raw
* x,y,w,h values for Swing/JavaFX rectangles.
*/
public class Vector_Rectangle_Int extends GUIVector_Rectangle {
//holds the data
private int[][] items = new int[max_size][4];
//set size
public Vector_Rectangle_Int(final int number) {
max_size = number;
items = new int[max_size][4];
}
public Vector_Rectangle_Int() {
}
/**
* check the size of the array and increase if needed
*/
private void checkSize(final int i) {
if (i >= max_size) {
final int old_size = max_size;
max_size += increment_size;
//allow for it not creating space
if (max_size <= i) {
max_size = i + increment_size + 2;
}
final int[][] temp = items;
items = new int[max_size][4];
System.arraycopy(temp, 0, items, 0, old_size);
//increase size increase for next time
increment_size = incrementSize(increment_size);
}
}
/**
* add an item
*/
public synchronized void addElement(final int[] value) {
checkSize(current_item);
items[current_item] = value;
current_item++;
}
/**
* clear the array
*/
public final void clear() {
checkPoint = -1;
//items = null;
//holds the data
//items = new Rectangle[max_size];
if (current_item > 0) {
for (int i = 0; i < current_item; i++) {
items[i] = null;
}
} else {
for (int i = 0; i < max_size; i++) {
items[i] = null;
}
}
current_item = 0;
}
/**
* Returns two dimensional array
* containing raw x,y,w,h data for
* rectangle construction.
*/
public final int[][] get() {
return items;
}
/**
* Returns an array containing x,y,w,h
* of one of items[][] elements.
*/
public final synchronized int[] elementAt(final int id) {
if (id >= max_size) {
return null;
} else {
final int[] rectParams = new int[4];
System.arraycopy(items[id], 0, rectParams, 0, rectParams.length);
return rectParams;
}
}
public void trim() {
final int[][] newItems = new int[current_item][4];
System.arraycopy(items, 0, newItems, 0, current_item);
items = newItems;
max_size = current_item;
}
}