📄 styleregion.java
字号:
case 14 : result = new StyleRegion(this.style, r1, c1, r2, c2);
break;
case 15 : result = new StyleRegion(this.style, this.startRow, c1, this.endRow, c2);
break;
case 16 : result = new StyleRegion(this.style, r1, this.startColumn,
r2, this.endColumn);
break;
default : // do nothing
}
if (modifier != null) {
if (result != null) {
result.setStyle(modifier.getModifiedStyle(result.getStyle()));
}
}
return result;
}
/**
* Returns a list of style regions that cover the non-intersecting part of this region.
*
* @param region the region to calculate the intersection against.
*
* @return A list of style regions that cover the non-intersecting part of this region.
*/
public List getNonIntersectionStyleRegionList(StyleRegion region) {
return getNonIntersectionStyleRegionList(region.startRow,
region.startColumn,
region.endRow,
region.endColumn);
}
/**
* Returns a list of StyleRegions equivalent to the non-intersection with the specified
* range.
* <P>
* There are 17 cases to deal with, one of which entirely obliterates
* the existing StyleRegion.
*
* @param row1 the start row.
* @param col1 the start column.
* @param row2 the end row.
* @param col2 the end column.
*
* @return A list of style regions equivalent to the non-intersection with the specified
* range.
*/
public List getNonIntersectionStyleRegionList(int row1, int col1, int row2, int col2) {
List result = new ArrayList();
int intersectCase = getIntersectCase(row1, col1, row2, col2);
switch (intersectCase) {
case 0 : break; // no intersection
case 1 : result = getNonIntersect1RegionList(row1, col1, row2, col2);
break;
case 2 : result = getNonIntersect2RegionList(row1, col1, row2, col2);
break;
case 3 : result = getNonIntersect3RegionList(row1, col1, row2, col2);
break;
case 4 : result = getNonIntersect4RegionList(row1, col1, row2, col2);
break;
case 5 : result = getNonIntersect5RegionList(row1, col1, row2, col2);
break;
case 6 : result = getNonIntersect6RegionList(row1, col1, row2, col2);
break;
case 7 : result = getNonIntersect7RegionList(row1, col1, row2, col2);
break;
case 8 : result = getNonIntersect8RegionList(row1, col1, row2, col2);
break;
case 9 : result = getNonIntersect9RegionList(row1, col1, row2, col2);
break;
case 10 : result = getNonIntersect10RegionList(row1, col1, row2, col2);
break;
case 11 : result = getNonIntersect11RegionList(row1, col1, row2, col2);
break;
case 12 : result = getNonIntersect12RegionList(row1, col1, row2, col2);
break;
case 13 : result = getNonIntersect13RegionList(row1, col1, row2, col2);
break;
case 14 : result = getNonIntersect14RegionList(row1, col1, row2, col2);
break;
case 15 : result = getNonIntersect15RegionList(row1, col1, row2, col2);
break;
case 16 : result = getNonIntersect16RegionList(row1, col1, row2, col2);
break;
default : // do nothing
}
return result;
}
/**
* Returns an integer denoting one of the 17 cases of intersection. Each case represents a
* general type of intersection from which it is straightforward to calculate the subregions
* that make up either the intersection or the non-intersection regions.
* <P>
* The 17 cases to deal with are:
* 0: no intersection;
* 1: top left corner;
* 2: top section;
* 3: top right corner;
* 4: left section;
* 5: all;
* 6: right section;
* 7: bottom left corner;
* 8: bottom section;
* 9: bottom right corner;
* 10: top "bite";
* 11: right "bite";
* 12: bottom "bite";
* 13: left "bite";
* 14: central "bite";
* 15: vertical section;
* 16: horizontal section;
*
* @param c1 the start column.
* @param r1 the start row.
* @param c2 the end column.
* @param r2 the end row.
*
* @return The case number.
*/
public int getIntersectCase(int r1, int c1, int r2, int c2) {
int result = 0;
// first check for no intersection at all...
if ((r1 > this.endRow) || (r2 < this.startRow)
|| (c1 > this.endColumn)
|| (c2 < this.startColumn)) {
result = 0;
}
else { // one of remaining 16 cases of intersection...
if (r1 <= this.startRow) { // 1, 2, 3, 4, 5, 6, 10, 15 ***
if (r2 < this.endRow) { // 1, 2, 3, 10 ***
if (c1 <= this.startColumn) { // 1, 2 ***
if (c2 < this.endColumn) {
// CASE 1 ***
result = 1;
}
else {
// CASE 2 ***
result = 2;
}
}
else { // 3, 10 ***
if (c2 >= this.endColumn) {
// CASE 3 ***
result = 3;
}
else {
// CASE 10 ***
result = 10;
}
}
}
else { // 4, 5, 6, 15 ***
if (c1 <= this.startColumn) { // 4, 5***
if (c2 < this.endColumn) {
// CASE 4 ***
result = 4;
}
else {
// CASE 5 ***
result = 5;
}
}
else { // 6, 15 ***
if (c2 <= this.endColumn) {
// CASE 6 ***
result = 6;
}
else {
// CASE 15 ***
result = 15;
}
}
}
}
else { // 7, 8, 9, 11, 12, 13, 14, 16 ***
if (c1 <= this.startColumn) { // 7, 8, 13, 16 ***
if (c2 < this.endColumn) { // 7, 13 ***
if (r2 >= this.endRow) {
// CASE 7 ***
result = 7;
}
else {
// CASE 13 ***
result = 13;
}
}
else { // 8, 16 ***
if (r2 >= this.endRow) {
// CASE 8 ***
result = 8;
}
else {
// CASE 16 ***
result = 16;
}
}
}
else { // 9, 11, 12, 14 ***
if (r2 >= this.endRow) { // 9, 12 ***
if (c2 >= this.endColumn) {
// CASE 9 ***
result = 9;
}
else {
// CASE 12 ***
result = 12;
}
}
else { // 11, 14 **
if (c2 >= this.endColumn) {
// CASE 11 ***
result = 11;
}
else {
// CASE 14 ***
result = 14;
}
}
}
}
}
return result;
}
/**
* Returns non-intersecting regions for case 1.
*
* @param r1 the start row for the intersecting region.
* @param c1 the start column for the intersecting region.
* @param r2 the end row for the intersecting region.
* @param c2 the end column for the intersecting region.
*
* @return A list of non-intersecting regions.
*/
private List getNonIntersect1RegionList(int r1, int c1, int r2, int c2) {
StyleRegion a = new StyleRegion(style, r2 + 1, this.startColumn, this.endRow, c2);
StyleRegion b = new StyleRegion(style, this.startRow, c2 + 1, this.endRow, this.endColumn);
ArrayList result = new ArrayList();
result.add(a);
result.add(b);
return result;
}
/**
* Returns non-intersecting regions for case 2.
*
* @param r1 the start row for the intersecting region.
* @param c1 the start column for the intersecting region.
* @param r2 the end row for the intersecting region.
* @param c2 the end column for the intersecting region.
*
* @return A list of non-intersecting regions.
*/
private List getNonIntersect2RegionList(int r1, int c1, int r2, int c2) {
StyleRegion a = new StyleRegion(
style, r2 + 1, this.startColumn, this.endRow, this.endColumn
);
ArrayList result = new ArrayList();
result.add(a);
return result;
}
/**
* Returns non-intersecting regions for case 3.
*
* @param r1 the start row for the intersecting region.
* @param c1 the start column for the intersecting region.
* @param r2 the end row for the intersecting region.
* @param c2 the end column for the intersecting region.
*
* @return A list of non-intersecting regions.
*/
private List getNonIntersect3RegionList(int r1, int c1, int r2, int c2) {
StyleRegion a = new StyleRegion(
style, this.startRow, this.startColumn, this.endRow, c1 - 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -