Search in sources :

Example 86 with Rectangle

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);
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle)

Example 87 with Rectangle

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);
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle)

Example 88 with Rectangle

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);
}
Also used : LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate)

Example 89 with Rectangle

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();
    }
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) ArrayList(java.util.ArrayList)

Example 90 with Rectangle

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);
    }
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle)

Aggregations

Rectangle (org.eclipse.swt.graphics.Rectangle)651 Point (org.eclipse.swt.graphics.Point)370 Image (org.eclipse.swt.graphics.Image)114 GC (org.eclipse.swt.graphics.GC)104 Test (org.junit.Test)80 Color (org.eclipse.swt.graphics.Color)61 Shell (org.eclipse.swt.widgets.Shell)54 Composite (org.eclipse.swt.widgets.Composite)53 SelectionEvent (org.eclipse.swt.events.SelectionEvent)51 TableItem (org.eclipse.swt.widgets.TableItem)47 GridLayout (org.eclipse.swt.layout.GridLayout)44 Display (org.eclipse.swt.widgets.Display)44 Button (org.eclipse.swt.widgets.Button)42 Menu (org.eclipse.swt.widgets.Menu)40 GridData (org.eclipse.swt.layout.GridData)38 Label (org.eclipse.swt.widgets.Label)37 SWT (org.eclipse.swt.SWT)34 Event (org.eclipse.swt.widgets.Event)34 Font (org.eclipse.swt.graphics.Font)30 Listener (org.eclipse.swt.widgets.Listener)29