Search in sources :

Example 16 with Range

use of net.sourceforge.nattable.coordinate.Range in project translationstudio8 by heartsome.

the class RowVisualChangeEvent method getChangedPositionRectangles.

public Collection<Rectangle> getChangedPositionRectangles() {
    Collection<Rectangle> changedPositionRectangles = new ArrayList<Rectangle>();
    int columnCount = layer.getColumnCount();
    for (Range range : rowPositionRanges) {
        changedPositionRectangles.add(new Rectangle(0, range.start, columnCount, range.end - range.start));
    }
    return changedPositionRectangles;
}
Also used : ArrayList(java.util.ArrayList) Rectangle(org.eclipse.swt.graphics.Rectangle) Range(net.sourceforge.nattable.coordinate.Range)

Example 17 with Range

use of net.sourceforge.nattable.coordinate.Range in project translationstudio8 by heartsome.

the class SelectionLayer method getSelectedCells.

public PositionCoordinate[] getSelectedCells() {
    int[] selectedColumnPositions = getSelectedColumns();
    Set<Range> selectedRowPositions = getSelectedRows();
    List<PositionCoordinate> selectedCells = new LinkedList<PositionCoordinate>();
    for (int columnPositionIndex = 0; columnPositionIndex < selectedColumnPositions.length; columnPositionIndex++) {
        final int columnPosition = selectedColumnPositions[columnPositionIndex];
        for (Range rowIndexRange : selectedRowPositions) {
            for (int rowPositionIndex = rowIndexRange.start; rowPositionIndex < rowIndexRange.end; rowPositionIndex++) {
                if (selectionModel.isCellPositionSelected(columnPosition, rowPositionIndex)) {
                    selectedCells.add(new PositionCoordinate(this, columnPosition, rowPositionIndex));
                }
            }
        }
    }
    return selectedCells.toArray(new PositionCoordinate[0]);
}
Also used : PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate) Range(net.sourceforge.nattable.coordinate.Range) LinkedList(java.util.LinkedList)

Example 18 with Range

use of net.sourceforge.nattable.coordinate.Range in project translationstudio8 by heartsome.

the class SelectionModel method getSelectedRows.

/**
	 * @return all selected rows in the model
	 */
public Set<Range> getSelectedRows() {
    Set<Range> selectedRowsRange = new HashSet<Range>();
    selectionsLock.readLock().lock();
    try {
        for (Rectangle r : selections) {
            selectedRowsRange.add(new Range(r.y, r.y + r.height));
        }
    } finally {
        selectionsLock.readLock().unlock();
    }
    ArrayList<Range> ranges = new ArrayList<Range>(selectedRowsRange);
    Range.sortByStart(ranges);
    List<Range> uniqueRanges = new ArrayList<Range>();
    // Adjust for overlaps - between consecutive selections
    for (int i = 0; i < ranges.size(); i++) {
        if (i > 0) {
            Range previousRange = ranges.get(i - 1);
            Range currrentRange = ranges.get(i);
            if (previousRange.overlap(currrentRange)) {
                int largerRangeEnd = (previousRange.end > currrentRange.end) ? previousRange.end : currrentRange.end;
                uniqueRanges.get(uniqueRanges.size() - 1).end = largerRangeEnd;
                ranges.get(i).end = largerRangeEnd;
            } else {
                uniqueRanges.add(ranges.get(i));
            }
        } else {
            uniqueRanges.add(ranges.get(i));
        }
    }
    return new HashSet<Range>(uniqueRanges);
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) ArrayList(java.util.ArrayList) Range(net.sourceforge.nattable.coordinate.Range) HashSet(java.util.HashSet)

Example 19 with Range

use of net.sourceforge.nattable.coordinate.Range in project translationstudio8 by heartsome.

the class SelectionModel method getFullySelectedRows.

public int[] getFullySelectedRows(int rowWidth) {
    final Set<Range> selectedRows = getSelectedRows();
    int[] fullySelectedRows = new int[getSelectedRowCount()];
    int index = 0;
    for (Range rowRange : selectedRows) {
        for (int i = rowRange.start; i < rowRange.end; i++) {
            if (isRowFullySelected(i, rowWidth)) {
                fullySelectedRows[index++] = i;
            }
        }
    }
    return index > 0 ? ArrayUtils.subarray(fullySelectedRows, 0, index) : new int[0];
}
Also used : Range(net.sourceforge.nattable.coordinate.Range)

Example 20 with Range

use of net.sourceforge.nattable.coordinate.Range in project translationstudio8 by heartsome.

the class FreezeEventHandler method handleLayerEvent.

public void handleLayerEvent(IStructuralChangeEvent event) {
    PositionCoordinate topLeftPosition = freezeLayer.getTopLeftPosition();
    PositionCoordinate bottomRightPosition = freezeLayer.getBottomRightPosition();
    Collection<StructuralDiff> columnDiffs = event.getColumnDiffs();
    if (columnDiffs != null) {
        int leftOffset = 0;
        int rightOffset = 0;
        for (StructuralDiff columnDiff : columnDiffs) {
            switch(columnDiff.getDiffType()) {
                case ADD:
                    Range afterPositionRange = columnDiff.getAfterPositionRange();
                    if (afterPositionRange.start < topLeftPosition.columnPosition) {
                        leftOffset += afterPositionRange.size();
                    }
                    if (afterPositionRange.start <= bottomRightPosition.columnPosition) {
                        rightOffset += afterPositionRange.size();
                    }
                    break;
                case DELETE:
                    Range beforePositionRange = columnDiff.getBeforePositionRange();
                    if (beforePositionRange.start < topLeftPosition.columnPosition) {
                        leftOffset -= Math.min(beforePositionRange.end, topLeftPosition.columnPosition + 1) - beforePositionRange.start;
                    }
                    if (beforePositionRange.start <= bottomRightPosition.columnPosition) {
                        rightOffset -= Math.min(beforePositionRange.end, bottomRightPosition.columnPosition + 1) - beforePositionRange.start;
                    }
                    break;
            }
        }
        topLeftPosition.columnPosition += leftOffset;
        bottomRightPosition.columnPosition += rightOffset;
    }
    Collection<StructuralDiff> rowDiffs = event.getRowDiffs();
    if (rowDiffs != null) {
        int leftOffset = 0;
        int rightOffset = 0;
        for (StructuralDiff rowDiff : rowDiffs) {
            switch(rowDiff.getDiffType()) {
                case ADD:
                    Range afterPositionRange = rowDiff.getAfterPositionRange();
                    if (afterPositionRange.start < topLeftPosition.rowPosition) {
                        leftOffset += afterPositionRange.size();
                    }
                    if (afterPositionRange.start <= bottomRightPosition.rowPosition) {
                        rightOffset += afterPositionRange.size();
                    }
                    break;
                case DELETE:
                    Range beforePositionRange = rowDiff.getBeforePositionRange();
                    if (beforePositionRange.start < topLeftPosition.rowPosition) {
                        leftOffset -= Math.min(beforePositionRange.end, topLeftPosition.rowPosition + 1) - beforePositionRange.start;
                    }
                    if (beforePositionRange.start <= bottomRightPosition.rowPosition) {
                        rightOffset -= Math.min(beforePositionRange.end, bottomRightPosition.rowPosition + 1) - beforePositionRange.start;
                    }
                    break;
            }
        }
        topLeftPosition.rowPosition += leftOffset;
        bottomRightPosition.rowPosition += rightOffset;
    }
}
Also used : PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate) StructuralDiff(net.sourceforge.nattable.layer.event.StructuralDiff) Range(net.sourceforge.nattable.coordinate.Range)

Aggregations

Range (net.sourceforge.nattable.coordinate.Range)25 ArrayList (java.util.ArrayList)12 HashSet (java.util.HashSet)6 Rectangle (org.eclipse.swt.graphics.Rectangle)6 StructuralDiff (net.sourceforge.nattable.layer.event.StructuralDiff)5 Serializable (java.io.Serializable)2 PositionCoordinate (net.sourceforge.nattable.coordinate.PositionCoordinate)2 LinkedList (java.util.LinkedList)1 LayerCell (net.sourceforge.nattable.layer.cell.LayerCell)1 RowSelectionEvent (net.sourceforge.nattable.selection.event.RowSelectionEvent)1