📄 tablegridlayout.java
字号:
final int colspan = Math.max(1, findBoundary(xCuts, maxBoundsX, true) - col);
int row = findBoundary(yCuts, (int) bounds.getY());
if (row > 0)
{
// if not the first row, then bind it to the previous cell ...
row = row - 1;
}
gPos = new TableGridPosition(pos, col, row, colspan, 1);
}
else if (bounds.getWidth() == 0)
{
final int row = findBoundary(yCuts, (int) bounds.getY());
final int rowspan = Math.max(1, findBoundary(yCuts, maxBoundsY, true) - row);
int col = findBoundary(xCuts, (int) bounds.getX());
if (col > 0)
{
// if not the first column, bind to the previous cell ...
col = col - 1;
}
gPos = new TableGridPosition(pos, col, row, 1, rowspan);
}
else
{
final int row = findBoundary(yCuts, (int) bounds.getY());
final int col = findBoundary(xCuts, (int) bounds.getX());
final int rowspan = Math.max(1, findBoundary(yCuts, maxBoundsY, true) - row);
final int colspan = Math.max(1, findBoundary(xCuts, maxBoundsX, true) - col);
gPos = new TableGridPosition(pos, col, row, colspan, rowspan);
}
final int startY = gPos.getRow();
final int endY = gPos.getRow() + gPos.getRowSpan();
// calculated the x and y position in the table, now add it to the element.
for (int posY = startY; posY < endY; posY++)
{
final int startX = gPos.getCol();
final int endX = gPos.getCol() + gPos.getColSpan();
for (int posX = startX; posX < endX; posX++)
{
addToGrid(posX, posY, gPos);
}
}
// Log.info ("AddTablePos: Col=" + gPos.getCol() +
// "; Row= " + gPos.getRow() +
// "; ColSpan=" + gPos.getColSpan() +
// "; RowSpan=" + gPos.getRowSpan() + "; -> Bounds: "+ bounds);
// Log.info ("AddTablePos: Col=" + gPos.getCol() +
// "; Row= " + gPos.getRow() + "; " + pos.toString());
//
//
// if (pos instanceof TableBandArea)
// {
// Log.debug ("gPos.getCol: " + gPos.getCol() + " -> " + getColumnStart(gPos.getCol()));
// Log.debug ("gPos.getRow: " + gPos.getRow() + " -> " + getRowStart(gPos.getRow()));
// Log.debug ("gPos.getColSpan: " + gPos.getColSpan() + " -> "
// + getColumnEnd(gPos.getColSpan() + gPos.getCol() - 1));
// Log.debug ("gPos.getRowSpan: " + gPos.getRowSpan() + " -> "
// + getRowEnd(gPos.getRowSpan() + gPos.getRow() - 1));
// }
this.maxX = Math.max(this.maxX, maxBoundsX);
this.maxY = Math.max(this.maxY, maxBoundsY);
}
/**
* Adds the gridposition into the table, positionated at the cell (posX, posY).
*
* @param posX the x position within the tablegrid.
* @param posY the y position within the tablegrid.
* @param gPos the TableGridPosition that should be added to the table.
*
* @throws IndexOutOfBoundsException if posX or posY are invalid.
* @throws NullPointerException if the given table grid position is invalid
*/
protected void addToGrid(final int posX, final int posY, final TableGridPosition gPos)
{
// Log.debug ("Add To Grid: " + posX + ", " + posY + " GPos: " + gPos);
if (gPos == null)
{
throw new NullPointerException();
}
if (posX > getWidth() || posX < 0)
{
throw new IndexOutOfBoundsException("X: " + posX + " > " + getWidth());
}
if (posY > getHeight() || posY < 0)
{
throw new IndexOutOfBoundsException("Y: " + posY + " > " + getHeight());
}
final Object o = data[posX][posY];
if (o == null)
{
final Element e = new Element();
e.add(gPos);
data[posX][posY] = e;
}
else
{
final Element e = (Element) o;
e.add(gPos);
}
}
/**
* Checks, whether the cell at the given coordinates contains data.
*
* @param x the column of the grid layout
* @param y the row of the grid layout
* @return true, if the cell contains data, false otherwise.
*/
public boolean containsData (final int x, final int y)
{
return (getData(x, y) != null);
}
/**
* Returns the element located in the specified cell.
*
* @param x the table column
* @param y the table row
* @return the element, or null, if there is no element defined.
*/
public Element getData(final int x, final int y)
{
return (Element) data[x][y];
}
/**
* Returns the number of columns of the table.
*
* @return the width of the table, the number of columns.
*/
public int getWidth()
{
return xCuts.length - 1;
}
/**
* Returns the number of rows of the table.
*
* @return the height of the table, the number of rows.
*/
public int getHeight()
{
return yCuts.length - 1;
}
/**
* Returns the start position of the given column in points.
*
* @param column the column
* @return the position of the column in points
*/
public int getColumnStart(final int column)
{
return xCuts[column];
}
/**
* Returns the start position of the given row in points.
*
* @param row the row
* @return the position of the row in points
*/
public int getRowStart(final int row)
{
return yCuts[row];
}
/**
* Returns the end position of the given column in points.
*
* @param column the column
* @return the end position of the column in points
*/
public int getColumnEnd(final int column)
{
if (column == xCuts.length - 1)
{
return maxX;
}
else
{
return getColumnStart(column + 1);
}
}
/**
* Returns the start position of the given row in points.
*
* @param row the row
* @return the end position of the column in points
*/
public int getRowEnd(final int row)
{
if (row == yCuts.length - 1)
{
return maxY;
}
else
{
return getRowStart(row + 1);
}
}
/**
* Tries to find the cell position of the value <code>value</code>. If the position
* was not found in the data array, then the next lower position is returned.
*
* @param data the data where to find the value
* @param value the value that is searched in the data array.
* @return the position of the value in the array or the next lower position.
*/
private static int findBoundary(final int[] data, final int value)
{
return findBoundary(data, value, false);
}
/**
* Tries to find the cell position of the value <code>value</code>. If the position
* was not found in the data array, then the position of the first element greater or
* equal or the value is returned.
*
* @param data the data where to find the value
* @param value the value that is searched in the data array.
* @param upperLimit set to true, if index of the first element greater or equal to
* the given value is returned, else the first element lesser or equal the value is
* returned.
* @return the position of the value in the array or the next lower position.
*/
private static int findBoundary(final int[] data, final int value, final boolean upperLimit)
{
for (int i = 0; i < data.length; i++)
{
final int dV = data[i];
if (dV == value)
{
return i;
}
if (dV > value)
{
if (i == 0)
{
return 0;
}
else
{
if (upperLimit)
{
return i;
}
else
{
return i - 1;
}
}
}
}
return data.length;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -