Search in sources :

Example 96 with Rectangle

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

the class TypeColunmCellRenderer method getTextBounds.

/**
	 * {@inheritDoc}
	 */
public Rectangle getTextBounds(GridItem item, boolean preferred) {
    int x = leftMargin;
    Image image = item.getImage(getColumn());
    if (image != null) {
        x += image.getBounds().width + 3;
    }
    Rectangle bounds = new Rectangle(x, topMargin + textTopMargin, 0, 0);
    GC gc = new GC(item.getParent());
    gc.setFont(item.getFont(getColumn()));
    Point size = gc.stringExtent(item.getText(getColumn()));
    bounds.height = size.y;
    if (preferred) {
        bounds.width = size.x - 1;
    } else {
        bounds.width = getBounds().width - x - rightMargin;
    }
    gc.dispose();
    return bounds;
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point)

Example 97 with Rectangle

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

the class GridCopyEnable method clearSelection.

void clearSelection() {
    int start = selection.x;
    int end = selection.y;
    selection.x = selection.y = caretOffset;
    selectionAnchor = -1;
    // redraw old selection, if any
    if (end - start > 0 && gridTable.getItems().length != 0) {
        if (layout == null && focusItemIndex != -1 && focusItemIndex != -1) {
            GridItem item = gridTable.getItem(focusItemIndex);
            GridColumn col = gridTable.getColumn(focusColIndex);
            GridCellRenderer gcr = col.getCellRenderer();
            if (gcr != null && gcr instanceof XGridCellRenderer) {
                GC gc = new GC(gcr.getDisplay());
                layout = ((XGridCellRenderer) gcr).getTextLayout(gc, item, focusColIndex, true, false);
                gc.dispose();
            }
            if (layout == null) {
                return;
            }
        }
        Rectangle rect = layout.getBounds(start, end);
        gridTable.redraw(rect.x + coordinateOffsetX, rect.y + coordinateOffsetY, rect.width, rect.height, false);
    }
}
Also used : GridItem(org.eclipse.nebula.widgets.grid.GridItem) GridCellRenderer(org.eclipse.nebula.widgets.grid.GridCellRenderer) Rectangle(org.eclipse.swt.graphics.Rectangle) GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point)

Example 98 with Rectangle

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

the class GridCopyEnable method handleVerticalScroll.

void handleVerticalScroll(Event event) {
    GridVisibleRange visibleR = gridTable.getVisibleRange();
    GridItem[] items = visibleR.getItems();
    boolean itemFlg = false;
    for (GridItem item : items) {
        if (focusItem == item) {
            itemFlg = true;
        }
    }
    boolean columnFlg = false;
    GridColumn[] columns = visibleR.getColumns();
    if (columns.length - 1 >= focusColIndex) {
        columnFlg = true;
    }
    if (!itemFlg || !columnFlg) {
        defaultCaret.setVisible(false);
        return;
    }
    defaultCaret.setVisible(true);
    GridColumn col = gridTable.getColumn(focusColIndex);
    GridCellRenderer gcr = col.getCellRenderer();
    int colIndex = gcr.getColumn();
    if (gcr == null || !(gcr instanceof XGridCellRenderer) || !copyAbleColumnIndexs.contains(colIndex)) {
        return;
    }
    XGridCellRenderer cellRender = (XGridCellRenderer) gcr;
    Rectangle cellBounds = focusItem.getBounds(colIndex);
    GC gc = new GC(Display.getDefault());
    TextLayout layout = null;
    try {
        layout = cellRender.getTextLayout(gc, focusItem, colIndex, true, false);
        if (layout == null) {
            gc.dispose();
            return;
        }
        Point point = layout.getLocation(caretOffset, false);
        coordinateOffsetX = cellBounds.x + cellRender.leftMargin;
        coordinateOffsetY = cellBounds.y + cellRender.topMargin + cellRender.textTopMargin;
        defaultCaret.setLocation(point.x + coordinateOffsetX, point.y + coordinateOffsetY);
    } finally {
        if (layout != null) {
            layout.dispose();
        }
        if (gc != null) {
            gc.dispose();
        }
    }
}
Also used : GridVisibleRange(org.eclipse.nebula.widgets.grid.Grid.GridVisibleRange) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) TextLayout(org.eclipse.swt.graphics.TextLayout) GridItem(org.eclipse.nebula.widgets.grid.GridItem) GridCellRenderer(org.eclipse.nebula.widgets.grid.GridCellRenderer) GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) GC(org.eclipse.swt.graphics.GC)

Example 99 with Rectangle

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

the class InputDialog method setErrorMessage.

/**
	 * Sets or clears the error message. If not <code>null</code>, the OK button is disabled.
	 * @param errorMessage
	 *            the error message, or <code>null</code> to clear
	 * @since 3.0
	 */
public void setErrorMessage(String errorMessage) {
    this.errorMessage = errorMessage;
    if (errorMessageText != null && !errorMessageText.isDisposed()) {
        String msg = errorMessageText.getText();
        msg = msg == null ? "" : msg;
        //$NON-NLS-1$
        errorMessageText.setText(errorMessage == null ? "" : errorMessage);
        // Disable the error message text control if there is no error, or
        // no error text (empty or whitespace only). Hide it also to avoid
        // color change.
        // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=130281
        boolean hasError = errorMessage != null && (StringConverter.removeWhiteSpaces(errorMessage)).length() > 0;
        errorMessageText.setEnabled(hasError);
        errorMessageText.setVisible(hasError);
        errorMessageText.getParent().update();
        String msg2 = errorMessageText.getText();
        if (!msg.equals(msg2) && initLocation != null && initSize != null) {
            Point p = getShell().computeSize(initSize.x, SWT.DEFAULT);
            getShell().setBounds(getConstrainedShellBounds(new Rectangle(initLocation.x, initLocation.y, initSize.x, p.y)));
        }
        // Access the ok button by id, in case clients have overridden button creation.
        // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=113643
        Control button = getButton(IDialogConstants.OK_ID);
        if (button != null) {
            button.setEnabled(errorMessage == null);
        }
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point)

Example 100 with Rectangle

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

the class HorizontalRowSelectionModel method getSelections.

public List<Rectangle> getSelections() {
    List<Rectangle> selectionRectangles = new ArrayList<Rectangle>();
    selectionsLock.readLock().lock();
    try {
        int width = selectionLayer.getColumnCount();
        for (int selectedRow : selectedRows) {
            if (selectedRow > -1) {
                selectionRectangles.add(new Rectangle(0, selectedRow, width, 1));
            }
        }
    } finally {
        selectionsLock.readLock().unlock();
    }
    return selectionRectangles;
}
Also used : ArrayList(java.util.ArrayList) Rectangle(org.eclipse.swt.graphics.Rectangle)

Aggregations

Rectangle (org.eclipse.swt.graphics.Rectangle)315 Point (org.eclipse.swt.graphics.Point)173 Image (org.eclipse.swt.graphics.Image)53 SelectionEvent (org.eclipse.swt.events.SelectionEvent)41 Color (org.eclipse.swt.graphics.Color)31 GC (org.eclipse.swt.graphics.GC)29 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)24 TableItem (org.eclipse.swt.widgets.TableItem)23 Event (org.eclipse.swt.widgets.Event)20 Menu (org.eclipse.swt.widgets.Menu)20 ArrayList (java.util.ArrayList)18 MenuItem (org.eclipse.swt.widgets.MenuItem)18 Listener (org.eclipse.swt.widgets.Listener)17 SelectionListener (org.eclipse.swt.events.SelectionListener)15 FocusEvent (org.eclipse.swt.events.FocusEvent)14 Composite (org.eclipse.swt.widgets.Composite)14 GridData (org.eclipse.swt.layout.GridData)13 Shell (org.eclipse.swt.widgets.Shell)13 MouseEvent (org.eclipse.swt.events.MouseEvent)12 HashMap (java.util.HashMap)10