use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.
the class SelectionLayer method selectAll.
public void selectAll() {
Rectangle selection = new Rectangle(0, 0, getColumnCount(), getRowCount());
addSelection(selection);
fireCellSelectionEvent(lastSelectedCell.columnPosition, lastSelectedCell.rowPosition, false, false, false);
}
use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.
the class SelectionLayer method selectRegion.
protected void selectRegion(int startColumnPosition, int startRowPosition, int regionWidth, int regionHeight) {
if (lastSelectedRegion == null) {
lastSelectedRegion = new Rectangle(startColumnPosition, startRowPosition, regionWidth, regionHeight);
} else {
lastSelectedRegion.x = startColumnPosition;
lastSelectedRegion.y = startRowPosition;
lastSelectedRegion.width = regionWidth;
lastSelectedRegion.height = regionHeight;
}
selectionModel.addSelection(lastSelectedRegion);
}
use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.
the class SelectionLayerPainter method paintLayer.
@Override
public void paintLayer(ILayer natLayer, GC gc, int xOffset, int yOffset, Rectangle pixelRectangle, IConfigRegistry configRegistry) {
Rectangle positionRectangle = getPositionRectangleFromPixelRectangle(natLayer, pixelRectangle);
columnPositionOffset = positionRectangle.x;
rowPositionOffset = positionRectangle.y;
cells = new HashMap<PositionCoordinate, LayerCell>();
super.paintLayer(natLayer, gc, xOffset, yOffset, pixelRectangle, configRegistry);
// Save gc settings
int originalLineStyle = gc.getLineStyle();
Color originalForeground = gc.getForeground();
// Apply border settings
gc.setLineStyle(SWT.LINE_CUSTOM);
gc.setLineDash(new int[] { 1, 1 });
gc.setForeground(GUIHelper.COLOR_BLACK);
// Draw horizontal borders
boolean selectedMode = false;
for (int columnPosition = columnPositionOffset; columnPosition < columnPositionOffset + positionRectangle.width; columnPosition++) {
LayerCell cell = null;
for (int rowPosition = rowPositionOffset; rowPosition < rowPositionOffset + positionRectangle.height; rowPosition++) {
cell = cells.get(new PositionCoordinate(natLayer, columnPosition, rowPosition));
if (cell != null) {
if (selectedMode != isSelected(cell)) {
selectedMode = !selectedMode;
Rectangle cellBounds = cell.getBounds();
// Draw top edge
gc.drawLine(cellBounds.x - 1, cellBounds.y - 1, cellBounds.x + cellBounds.width - 1, cellBounds.y - 1);
}
}
}
if (selectedMode && cell != null) {
// If last cell is selected, draw its bottom edge
Rectangle cellBounds = cell.getBounds();
gc.drawLine(cellBounds.x - 1, cellBounds.y + cellBounds.height - 1, cellBounds.x + cellBounds.width - 1, cellBounds.y + cellBounds.height - 1);
}
selectedMode = false;
}
// Draw vertical borders
for (int rowPosition = rowPositionOffset; rowPosition < rowPositionOffset + positionRectangle.height; rowPosition++) {
LayerCell cell = null;
for (int columnPosition = columnPositionOffset; columnPosition < columnPositionOffset + positionRectangle.width; columnPosition++) {
cell = cells.get(new PositionCoordinate(natLayer, columnPosition, rowPosition));
if (cell != null) {
if (selectedMode != isSelected(cell)) {
selectedMode = !selectedMode;
Rectangle cellBounds = cell.getBounds();
// Draw left edge
gc.drawLine(cellBounds.x - 1, cellBounds.y - 1, cellBounds.x - 1, cellBounds.y + cellBounds.height - 1);
}
}
}
if (selectedMode && cell != null) {
// If last cell is selected, draw its right edge
Rectangle cellBounds = cell.getBounds();
gc.drawLine(cellBounds.x + cellBounds.width - 1, cellBounds.y - 1, cellBounds.x + cellBounds.width - 1, cellBounds.y + cellBounds.height - 1);
}
selectedMode = false;
}
// Restore original gc settings
gc.setLineStyle(originalLineStyle);
gc.setForeground(originalForeground);
}
use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.
the class SelectionModel method addSelectionIntoList.
private void addSelectionIntoList(Rectangle selection) {
selectionsLock.writeLock().lock();
try {
ArrayList<Rectangle> itemsToRemove = null;
for (Rectangle r : selections) {
if (selection.intersects(r)) {
if (r.equals(selection)) {
break;
}
Rectangle intersection = selection.intersection(r);
if (intersection.equals(r)) {
// r is a subset of intersection
if (itemsToRemove == null)
itemsToRemove = new ArrayList<Rectangle>();
itemsToRemove.add(r);
} else if (intersection.equals(selection)) {
// selection is a subset of r
break;
}
}
}
if (itemsToRemove != null) {
selections.removeAll(itemsToRemove);
}
selections.add(selection);
} finally {
selectionsLock.writeLock().unlock();
}
}
use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.
the class SelectColumnCommandHandler method selectColumnWithCtrlKey.
private void selectColumnWithCtrlKey(int columnPosition, int rowPosition) {
Rectangle selectedColumnRectangle = new Rectangle(columnPosition, 0, 1, selectionLayer.getRowCount());
if (selectionLayer.isColumnFullySelected(columnPosition)) {
selectionLayer.clearSelection(selectedColumnRectangle);
if (selectionLayer.lastSelectedRegion != null && selectionLayer.lastSelectedRegion.equals(selectedColumnRectangle)) {
selectionLayer.lastSelectedRegion = null;
}
} else {
if (selectionLayer.lastSelectedRegion != null) {
selectionLayer.selectionModel.addSelection(new Rectangle(selectionLayer.lastSelectedRegion.x, selectionLayer.lastSelectedRegion.y, selectionLayer.lastSelectedRegion.width, selectionLayer.lastSelectedRegion.height));
}
selectionLayer.selectRegion(columnPosition, 0, 1, selectionLayer.getRowCount());
selectionLayer.moveSelectionAnchor(columnPosition, rowPosition);
}
}
Aggregations