Search in sources :

Example 11 with GC

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

the class DefaultColumnFooterRenderer method getTextBounds.

/**
     * {@inheritDoc}
     */
public Rectangle getTextBounds(Object value, boolean preferred) {
    GridColumn column = (GridColumn) value;
    int x = leftMargin;
    if (column.getImage() != null) {
        x += column.getImage().getBounds().width + imageSpacing;
    }
    GC gc = new GC(column.getParent());
    gc.setFont(column.getFooterFont());
    int y = getBounds().height - bottomMargin - gc.getFontMetrics().getHeight();
    Rectangle bounds = new Rectangle(x, y, 0, 0);
    Point p = gc.stringExtent(column.getText());
    bounds.height = p.y;
    if (preferred) {
        bounds.width = p.x;
    } else {
        int width = getBounds().width - x;
        if (column.getSort() == SWT.NONE) {
            width -= rightMargin;
        }
        bounds.width = width;
    }
    gc.dispose();
    return bounds;
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point)

Example 12 with GC

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

the class AutoResizeColumnAction method run.

public void run(NatTable natTable, MouseEvent event) {
    if (gc == null) {
        gc = new GC(natTable);
        natTable.addDisposeListener(new DisposeListener() {

            public void widgetDisposed(DisposeEvent e) {
                gc.dispose();
            }
        });
    }
    Point clickPoint = new Point(event.x, event.y);
    int column = CellEdgeDetectUtil.getColumnPositionToResize(natTable, clickPoint);
    InitializeAutoResizeColumnsCommand command = new InitializeAutoResizeColumnsCommand(natTable, column, natTable.getConfigRegistry(), gc);
    natTable.doCommand(command);
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) InitializeAutoResizeColumnsCommand(net.sourceforge.nattable.resize.command.InitializeAutoResizeColumnsCommand) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Point(org.eclipse.swt.graphics.Point)

Example 13 with GC

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

the class AutoResizeRowAction method run.

public void run(NatTable natTable, MouseEvent event) {
    if (gc == null) {
        gc = new GC(natTable);
        natTable.addDisposeListener(new DisposeListener() {

            public void widgetDisposed(DisposeEvent e) {
                gc.dispose();
            }
        });
    }
    Point clickPoint = new Point(event.x, event.y);
    int row = CellEdgeDetectUtil.getRowPositionToResize(natTable, clickPoint);
    InitializeAutoResizeRowsCommand command = new InitializeAutoResizeRowsCommand(natTable, row, natTable.getConfigRegistry(), gc);
    natTable.doCommand(command);
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) InitializeAutoResizeRowsCommand(net.sourceforge.nattable.resize.command.InitializeAutoResizeRowsCommand) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Point(org.eclipse.swt.graphics.Point)

Example 14 with GC

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

the class GridLayerPrinter method print.

public void print(final Shell shell) {
    final Printer printer = setupPrinter(shell);
    if (printer == null) {
        return;
    }
    setGridLayerSize(printer.getPrinterData());
    Display.getDefault().asyncExec(new Runnable() {

        public void run() {
            if (printer.startJob("NatTable")) {
                final Rectangle printerClientArea = computePrintArea(printer);
                final Point scaleFactor = computeScaleFactor(printer);
                final Point pageCount = getPageCount(printer);
                GC gc = new GC(printer);
                // Print pages Left to Right and then Top to Down
                int currentPage = 1;
                for (int verticalPageNumber = 0; verticalPageNumber < pageCount.y; verticalPageNumber++) {
                    for (int horizontalPageNumber = 0; horizontalPageNumber < pageCount.x; horizontalPageNumber++) {
                        // Calculate bounds for the next page
                        Rectangle printBounds = new Rectangle((printerClientArea.width / scaleFactor.x) * horizontalPageNumber, ((printerClientArea.height - FOOTER_HEIGHT_IN_PRINTER_DPI) / scaleFactor.y) * verticalPageNumber, printerClientArea.width / scaleFactor.x, (printerClientArea.height - FOOTER_HEIGHT_IN_PRINTER_DPI) / scaleFactor.y);
                        if (shouldPrint(printer.getPrinterData(), currentPage)) {
                            printer.startPage();
                            Transform printerTransform = new Transform(printer);
                            // Adjust for DPI difference between display and printer
                            printerTransform.scale(scaleFactor.x, scaleFactor.y);
                            // Adjust for margins
                            printerTransform.translate(printerClientArea.x / scaleFactor.x, printerClientArea.y / scaleFactor.y);
                            // Grid will nor automatically print the pages at the left margin.
                            // Example: page 1 will print at x = 0, page 2 at x = 100, page 3 at x = 300
                            // Adjust to print from the left page margin. i.e x = 0
                            printerTransform.translate(-1 * printBounds.x, -1 * printBounds.y);
                            gc.setTransform(printerTransform);
                            printGrid(gc, printBounds);
                            printFooter(gc, currentPage, printBounds);
                            printer.endPage();
                            printerTransform.dispose();
                        }
                        currentPage++;
                    }
                }
                printer.endJob();
                gc.dispose();
                printer.dispose();
            }
            restoreGridLayerState();
        }

        private void printGrid(GC gc, Rectangle printBounds) {
            gridLayer.getLayerPainter().paintLayer(gridLayer, gc, 0, 0, printBounds, configRegistry);
        }

        private void printFooter(GC gc, int totalPageCount, Rectangle printBounds) {
            gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
            gc.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
            gc.drawLine(printBounds.x, printBounds.y + printBounds.height + 10, printBounds.x + printBounds.width, printBounds.y + printBounds.height + 10);
            gc.drawText("Page " + totalPageCount, printBounds.x, printBounds.y + printBounds.height + 15);
            // Approximate width of the date string: 140
            gc.drawText(footerDate, printBounds.x + printBounds.width - 140, printBounds.y + printBounds.height + 15);
        }
    });
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Printer(org.eclipse.swt.printing.Printer) GC(org.eclipse.swt.graphics.GC) Transform(org.eclipse.swt.graphics.Transform) Point(org.eclipse.swt.graphics.Point)

Example 15 with GC

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

the class ColorPicker method getColorImage.

private Image getColorImage(Color color) {
    Display display = Display.getCurrent();
    image = new Image(display, new Rectangle(10, 10, 70, 20));
    GC gc = new GC(image);
    gc.setBackground(color);
    gc.fillRectangle(image.getBounds());
    gc.dispose();
    return image;
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC) Display(org.eclipse.swt.widgets.Display)

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