Search in sources :

Example 16 with GC

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

the class MenuItemProviders method autoResizeRowMenuItemProvider.

public static IMenuItemProvider autoResizeRowMenuItemProvider() {
    return new IMenuItemProvider() {

        public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
            MenuItem autoResizeRows = new MenuItem(popupMenu, SWT.PUSH);
            autoResizeRows.setText("Auto resize row");
            autoResizeRows.setEnabled(true);
            autoResizeRows.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent event) {
                    int rowPosition = getNatEventData(event).getRowPosition();
                    natTable.doCommand(new InitializeAutoResizeRowsCommand(natTable, rowPosition, natTable.getConfigRegistry(), new GC(natTable)));
                }
            });
        }
    };
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) InitializeAutoResizeRowsCommand(net.sourceforge.nattable.resize.command.InitializeAutoResizeRowsCommand) NatTable(net.sourceforge.nattable.NatTable) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) GC(org.eclipse.swt.graphics.GC)

Example 17 with GC

use of org.eclipse.swt.graphics.GC 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)

Example 18 with GC

use of org.eclipse.swt.graphics.GC 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 19 with GC

use of org.eclipse.swt.graphics.GC 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 20 with GC

use of org.eclipse.swt.graphics.GC 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)

Aggregations

GC (org.eclipse.swt.graphics.GC)122 Point (org.eclipse.swt.graphics.Point)90 FormAttachment (org.eclipse.swt.layout.FormAttachment)46 FormData (org.eclipse.swt.layout.FormData)46 CLabel (org.eclipse.swt.custom.CLabel)42 Node (org.talend.designer.core.ui.editor.nodes.Node)39 Control (org.eclipse.swt.widgets.Control)31 Rectangle (org.eclipse.swt.graphics.Rectangle)29 DecoratedField (org.eclipse.jface.fieldassist.DecoratedField)28 FieldDecoration (org.eclipse.jface.fieldassist.FieldDecoration)27 Image (org.eclipse.swt.graphics.Image)27 Button (org.eclipse.swt.widgets.Button)24 Composite (org.eclipse.swt.widgets.Composite)18 CCombo (org.eclipse.swt.custom.CCombo)16 Text (org.eclipse.swt.widgets.Text)12 SelectionEvent (org.eclipse.swt.events.SelectionEvent)11 GridData (org.eclipse.swt.layout.GridData)11 SelectAllTextControlCreator (org.talend.designer.core.ui.editor.properties.controllers.creator.SelectAllTextControlCreator)11 INode (org.talend.core.model.process.INode)10 Label (org.eclipse.swt.widgets.Label)9