Search in sources :

Example 91 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.

the class SelectRowCommandHandler method selectRowWithCtrlKey.

private Range selectRowWithCtrlKey(int columnPosition, int rowPosition) {
    Rectangle selectedRowRectangle = new Rectangle(0, rowPosition, selectionLayer.getColumnCount(), 1);
    if (selectionLayer.isRowFullySelected(rowPosition)) {
        selectionLayer.clearSelection(selectedRowRectangle);
        if (selectionLayer.lastSelectedRegion != null && selectionLayer.lastSelectedRegion.equals(selectedRowRectangle)) {
            selectionLayer.lastSelectedRegion = null;
        }
    } else {
        // Preserve last selected region
        if (selectionLayer.lastSelectedRegion != null) {
            selectionLayer.selectionModel.addSelection(new Rectangle(selectionLayer.lastSelectedRegion.x, selectionLayer.lastSelectedRegion.y, selectionLayer.lastSelectedRegion.width, selectionLayer.lastSelectedRegion.height));
        }
        selectionLayer.selectRegion(0, rowPosition, selectionLayer.getColumnCount(), 1);
        selectionLayer.moveSelectionAnchor(columnPosition, rowPosition);
    }
    return new Range(rowPosition, rowPosition + 1);
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Range(net.sourceforge.nattable.coordinate.Range)

Example 92 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.

the class SelectionLayer method clear.

// Clear features
public void clear() {
    selectionModel.clearSelection();
    lastSelectedCell.columnPosition = -1;
    lastSelectedCell.rowPosition = -1;
    lastSelectedRegion = new Rectangle(0, 0, 0, 0);
    selectionAnchor.columnPosition = -1;
    selectionAnchor.rowPosition = -1;
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle)

Example 93 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.

the class SelectionLayer method hideMultipleColumnPositions.

/**
	 * Any selected columns will be hidden. A column is considered selected even if a cell is selected.
	 */
protected boolean hideMultipleColumnPositions(MultiColumnHideCommand command) {
    for (int columnPosition : command.getColumnPositions()) {
        if (isColumnFullySelected(columnPosition)) {
            Rectangle selection = new Rectangle(columnPosition, 0, 1, getRowCount());
            clearSelection(selection);
        }
    }
    return super.doCommand(command);
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle)

Example 94 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.

the class CellEdgeDetectUtil method getHorizontalCellEdge.

/**
	 * Figure out if the click point is closer to the left/right edge of the cell.
	 * @param cellBounds of the table cell containing the click
	 * @param clickPt
	 * @param distanceFromEdge distance from the edge to qualify as <i>close</i> to the cell edge
	 */
public static CellEdgeEnum getHorizontalCellEdge(Rectangle cellBounds, Point clickPt, int distanceFromEdge) {
    if (distanceFromEdge < 0) {
        distanceFromEdge = cellBounds.width / 2;
    }
    Rectangle left = new Rectangle(cellBounds.x, cellBounds.y, distanceFromEdge, cellBounds.height);
    Rectangle right = new Rectangle(cellBounds.x + cellBounds.width - distanceFromEdge, cellBounds.y, distanceFromEdge, cellBounds.height);
    if (left.contains(clickPt)) {
        return LEFT;
    } else if (right.contains(clickPt)) {
        return RIGHT;
    } else {
        return NONE;
    }
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle)

Example 95 with Rectangle

use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.

the class NatCombo method createTextControl.

private void createTextControl() {
    text = new Text(this, HorizontalAlignmentEnum.getSWTStyle(cellStyle));
    text.setBackground(cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
    text.setForeground(cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
    text.setFont(cellStyle.getAttributeValue(CellStyleAttributes.FONT));
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    text.setLayoutData(gridData);
    text.forceFocus();
    text.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent event) {
            if (event.keyCode == SWT.ARROW_DOWN || event.keyCode == SWT.ARROW_UP) {
                showDropdownControl();
                int selectionIndex = dropdownList.getSelectionIndex();
                selectionIndex += event.keyCode == SWT.ARROW_DOWN ? 1 : -1;
                if (selectionIndex < 0) {
                    selectionIndex = 0;
                }
                dropdownList.select(selectionIndex);
                text.setText(dropdownList.getSelection()[0]);
            }
        }
    });
    iconImage = GUIHelper.getImage("down_2");
    final Canvas iconCanvas = new Canvas(this, SWT.NONE) {

        @Override
        public Point computeSize(int wHint, int hHint, boolean changed) {
            Rectangle iconImageBounds = iconImage.getBounds();
            return new Point(iconImageBounds.width + 2, iconImageBounds.height + 2);
        }
    };
    gridData = new GridData(GridData.BEGINNING, SWT.FILL, false, true);
    iconCanvas.setLayoutData(gridData);
    iconCanvas.addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent event) {
            GC gc = event.gc;
            Rectangle iconCanvasBounds = iconCanvas.getBounds();
            Rectangle iconImageBounds = iconImage.getBounds();
            int horizontalAlignmentPadding = CellStyleUtil.getHorizontalAlignmentPadding(HorizontalAlignmentEnum.CENTER, iconCanvasBounds, iconImageBounds.width);
            int verticalAlignmentPadding = CellStyleUtil.getVerticalAlignmentPadding(VerticalAlignmentEnum.MIDDLE, iconCanvasBounds, iconImageBounds.height);
            gc.drawImage(iconImage, horizontalAlignmentPadding, verticalAlignmentPadding);
            Color originalFg = gc.getForeground();
            gc.setForeground(GUIHelper.COLOR_WIDGET_BORDER);
            gc.drawRectangle(0, 0, iconCanvasBounds.width - 1, iconCanvasBounds.height - 1);
            gc.setForeground(originalFg);
        }
    });
    iconCanvas.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            showDropdownControl();
        }
    });
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) PaintListener(org.eclipse.swt.events.PaintListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Canvas(org.eclipse.swt.widgets.Canvas) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) KeyEvent(org.eclipse.swt.events.KeyEvent) GridData(org.eclipse.swt.layout.GridData) GC(org.eclipse.swt.graphics.GC)

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