📄 styleregion.java
字号:
/* =================================================
* JWorkbook : data export from Java to spreadsheets
* =================================================
*
* Project Info: http://www.jfree.org/jworkbook/index.html;
* Project Lead: David Gilbert (david.gilbert@object-refinery.com);
*
* (C) Copyright 2001-2003, by Object Refinery Limited.
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* ----------------
* StyleRegion.java
* ----------------
* (C) Copyright 2001, 2003, by Object Refinery Limited.
*
* Original Author: David Gilbert (for Object Refinery Limited);
* Contributor(s): -;
*
* $Id$
*
* Changes:
* --------
* 05-Nov-2001 : Version 1 (DG);
* 13-Feb-2002 : Reversed order of row and column parameters (DG);
* 07-Jul-2003 : Changed GPL --> LGPL, changed package name, updated company name (DG);
*
*/
package org.jfree.workbook;
import java.util.ArrayList;
import java.util.List;
/**
* Represents a region and its associated style.
* <P>
* Note that the style can be changed, but the region is immutable. This is done because the
* regions form part of a non-overlapping collection that completely cover a worksheet. If you
* could change the region, that would potentially break the collection.
*/
public class StyleRegion {
/** The style. */
protected Style style;
/** The start row. */
protected int startRow;
/** The start column. */
protected int startColumn;
/** The end row. */
protected int endRow;
/** The end column. */
protected int endColumn;
/**
* Constructs a style region.
*
* @param style the style.
* @param startRow the start row for the region.
* @param startColumn the start column for the region.
* @param endRow the end row for the region.
* @param endColumn the end column for the region.
*/
public StyleRegion(Style style, int startRow, int startColumn, int endRow, int endColumn) {
// check arguments...
if ((startRow < 0) || (startRow >= Worksheet.MAX_ROWS)) {
throw new IllegalArgumentException("StyleRegion constructor: "
+ "startRow outside valid range.");
}
if ((endRow < startRow) || (endRow >= Worksheet.MAX_ROWS)) {
throw new IllegalArgumentException("StyleRegion constructor: "
+ "endRow outside valid range.");
}
if ((startColumn < 0) || (startColumn >= Worksheet.MAX_COLUMNS)) {
throw new IllegalArgumentException("StyleRegion constructor: "
+ "startColumn outside valid range.");
}
if ((endColumn < startColumn) || (endColumn >= Worksheet.MAX_COLUMNS)) {
throw new IllegalArgumentException("StyleRegion constructor: "
+ "endColumn outside valid range.");
}
// initialise...
this.style = style;
this.startRow = startRow;
this.startColumn = startColumn;
this.endRow = endRow;
this.endColumn = endColumn;
}
/**
* Returns the style for this region.
*
* @return The style for this region.
*/
public Style getStyle() {
return this.style;
}
/**
* Sets the style for this region.
*
* @param style the new style.
*/
public void setStyle(Style style) {
this.style = style;
}
/**
* Returns the start row of the region.
*
* @return The start row of the region.
*/
public int getStartRow() {
return this.startRow;
}
/**
* Returns the start column of the region.
*
* @return The start column of the region.
*/
public int getStartColumn() {
return this.startColumn;
}
/**
* Returns the end row of the region.
*
* @return The end row of the region.
*/
public int getEndRow() {
return this.endRow;
}
/**
* Returns the end column of the region.
*
* @return The end column of the region.
*/
public int getEndColumn() {
return this.endColumn;
}
/**
* Returns true if the region include the cell at the specified row and column.
*
* @param row the row.
* @param column the column.
*
* @return A boolean.
*/
public boolean contains(int row, int column) {
if (row < this.startRow) {
return false;
}
if (row > this.endRow) {
return false;
}
if (column < this.startColumn) {
return false;
}
if (column > this.endColumn) {
return false;
}
return true;
}
/**
* Returns true if the specified range intersects with this region, and false otherwise.
*
* @param row1 the start row of the range.
* @param col1 the start column of the range.
* @param row2 the end row of the range.
* @param col2 the end column of the range.
*
* @return A boolean.
*/
public boolean intersects(int row1, int col1, int row2, int col2) {
if (row1 > this.endRow) {
return false;
}
else if (row2 < this.startRow) {
return false;
}
else if (col1 > this.endColumn) {
return false;
}
else if (col2 < this.startColumn) {
return false;
}
else {
return true;
}
}
/**
* Returns true if the specified region intersects with this region, and false otherwise.
*
* @param region the region being tested.
*
* @return A boolean.
*/
public boolean intersects(StyleRegion region) {
// pass over to more general method...
return intersects(region.startRow, region.startColumn, region.endRow, region.endColumn);
}
/**
* Returns a StyleRegion representing the portion of this region that intersects with the
* specified region. If there is no intersection, returns null.
*
* @param r1 the start row of the region.
* @param c1 the start column of the region.
* @param r2 the end row of the region.
* @param c2 the end column of the region.
* @param modifier an optional style modifier that will be applied to the style before
* returning the intersecting region.
*
* @return The style region.
*/
public StyleRegion getIntersectionStyleRegion(int r1, int c1, int r2, int c2,
StyleModifier modifier) {
StyleRegion result = null;
int intersectCase = getIntersectCase(r1, c1, r2, c2);
switch (intersectCase) {
case 0 : break; // no intersection
case 1 : result = new StyleRegion(this.style,
this.startRow, this.startColumn, r2, c2);
break;
case 2 : result = new StyleRegion(this.style, this.startRow, this.startColumn,
r2, this.endColumn);
break;
case 3 : result = new StyleRegion(this.style, this.startRow, c1, r2, this.endColumn);
break;
case 4 : result = new StyleRegion(this.style, this.startRow, this.startColumn,
this.endRow, c2);
break;
case 5 : result = this;
break;
case 6 : result = new StyleRegion(this.style, this.startRow, c1,
this.endRow, this.endColumn);
break;
case 7 : result = new StyleRegion(this.style, r1, this.startColumn, this.endRow, c2);
break;
case 8 : result = new StyleRegion(this.style, r1, this.startColumn,
this.endRow, this.endColumn);
break;
case 9 : result = new StyleRegion(this.style, r1, c1, this.endRow, this.endColumn);
break;
case 10 : result = new StyleRegion(this.style, this.startRow, c1, r2, c2);
break;
case 11 : result = new StyleRegion(this.style, r1, c1, r2, this.endColumn);
break;
case 12 : result = new StyleRegion(this.style, r1, c1, this.endRow, c2);
break;
case 13 : result = new StyleRegion(this.style, r1, this.startColumn, r2, c2);
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -