applyBorderStyle(gc, configRegistry);
// Draw horizontal borders
for (int columnPosition = columnPositionOffset; columnPosition < columnPositionOffset
+ positionRectangle.width; columnPosition++) {
ILayerCell previousCell = null;
ILayerCell currentCell = null;
ILayerCell afterCell = null;
for (int rowPosition = rowPositionOffset; rowPosition < rowPositionOffset
+ positionRectangle.height; rowPosition++) {
currentCell = natLayer.getCellByPosition(columnPosition,
rowPosition);
afterCell = natLayer.getCellByPosition(columnPosition,
rowPosition + 1);
if (currentCell != null) {
Rectangle currentCellBounds = currentCell.getBounds();
if (isSelected(currentCell)) {
int x0 = currentCellBounds.x - 1;
int x1 = currentCellBounds.x + currentCellBounds.width
- 1;
int y = currentCellBounds.y - 1;
if (previousCell != null) {
Rectangle previousCellBounds = previousCell
.getBounds();
x0 = Math.max(x0, previousCellBounds.x - 1);
x1 = Math.min(x1, previousCellBounds.x
+ previousCellBounds.width - 1);
}
if (previousCell == null || !isSelected(previousCell))
gc.drawLine(x0, y, x1, y);
// check after
if (afterCell == null || !isSelected(afterCell)) {
Rectangle cellBounds = afterCell != null ? afterCell
.getBounds() : currentCell.getBounds();
y = currentCellBounds.y + currentCellBounds.height
- 1;
x0 = Math.max(x0, cellBounds.x - 1);
x1 = Math.min(x1, cellBounds.x + cellBounds.width
- 1);
gc.drawLine(x0, y, x1, y);
}
} else {
// check if previous was selected to not override the
// border again
// this is necessary because of single cell updates
if (positionRectangle.width == 2
|| positionRectangle.height == 2) {
if (afterCell != null && isSelected(afterCell)) {
Rectangle afterCellBounds = afterCell
.getBounds();
int x0 = Math.max(afterCellBounds.x - 1,
currentCellBounds.x - 1);
int x1 = Math.min(afterCellBounds.x
+ afterCellBounds.width - 1,
currentCellBounds.x
+ currentCellBounds.width - 1);
int y = currentCellBounds.y
+ currentCellBounds.height - 1;
gc.drawLine(x0, y, x1, y);
}
}
}
}
previousCell = currentCell;
}
}
// Draw vertical borders
for (int rowPosition = rowPositionOffset; rowPosition < rowPositionOffset
+ positionRectangle.height; rowPosition++) {
ILayerCell previousCell = null;
ILayerCell currentCell = null;
ILayerCell afterCell = null;
for (int columnPosition = columnPositionOffset; columnPosition < columnPositionOffset
+ positionRectangle.width; columnPosition++) {
currentCell = natLayer.getCellByPosition(columnPosition,
rowPosition);
afterCell = natLayer.getCellByPosition(columnPosition + 1,
rowPosition);
if (currentCell != null) {
Rectangle currentCellBounds = currentCell.getBounds();
if (isSelected(currentCell)) {
int y0 = currentCellBounds.y - 1;
int y1 = currentCellBounds.y + currentCellBounds.height
- 1;
int x = currentCellBounds.x - 1;
if (previousCell != null) {
Rectangle previousCellBounds = previousCell
.getBounds();
y0 = Math.max(y0, previousCellBounds.y - 1);
y1 = Math.min(y1, previousCellBounds.y
+ previousCellBounds.height - 1);
}
if (previousCell == null || !isSelected(previousCell))
gc.drawLine(x, y0, x, y1);
// check after
if (afterCell == null || !isSelected(afterCell)) {
Rectangle cellBounds = afterCell != null ? afterCell
.getBounds() : currentCell.getBounds();
x = currentCellBounds.x + currentCellBounds.width
- 1;
y0 = Math.max(y0, cellBounds.y - 1);
y1 = Math.min(y1, cellBounds.y + cellBounds.height
- 1);
gc.drawLine(x, y0, x, y1);
}
} else {
// check if previous was selected to not override the
// border again
// this is necessary because of single cell updates
// check if previous was selected to not override the
// border again
// this is necessary because of single cell updates
if (positionRectangle.width == 2
|| positionRectangle.height == 2) {
if (afterCell != null && isSelected(afterCell)) {
Rectangle afterCellBounds = afterCell
.getBounds();
int y0 = Math.max(afterCellBounds.y - 1,
currentCellBounds.y - 1);
int y1 = Math.min(afterCellBounds.y