Search in sources :

Example 71 with Rectangle

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

the class AbstractLayer method getBoundsByPosition.

public Rectangle getBoundsByPosition(int columnPosition, int rowPosition) {
    LayerCell cell = getCellByPosition(columnPosition, rowPosition);
    ILayer cellLayer = cell.getLayer();
    int originColumnPosition = cell.getOriginColumnPosition();
    int originRowPosition = cell.getOriginRowPosition();
    int x = cellLayer.getStartXOfColumnPosition(originColumnPosition);
    int y = cellLayer.getStartYOfRowPosition(originRowPosition);
    int width = 0;
    for (int i = 0; i < cell.getColumnSpan(); i++) {
        width += cellLayer.getColumnWidthByPosition(originColumnPosition + i);
    }
    int height = 0;
    for (int i = 0; i < cell.getRowSpan(); i++) {
        height += cellLayer.getRowHeightByPosition(originRowPosition + i);
    }
    return new Rectangle(x, y, width, height);
}
Also used : LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) Rectangle(org.eclipse.swt.graphics.Rectangle)

Example 72 with Rectangle

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

the class XPBackgroundDecorator method paintCell.

public void paintCell(LayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
    // Draw background
    super.paintCell(cell, gc, rectangle, configRegistry);
    // Draw interior
    Rectangle interiorBounds = new Rectangle(rectangle.x + 2, rectangle.y + 2, rectangle.width - 4, rectangle.height - 4);
    super.paintCell(cell, gc, interiorBounds, configRegistry);
    // Save GC settings
    Color originalBackground = gc.getBackground();
    Color originalForeground = gc.getForeground();
    // Draw separator
    int x = rectangle.x;
    gc.setForeground(GUIHelper.COLOR_WHITE);
    gc.drawLine(x, rectangle.y + 3, x, rectangle.y + rectangle.height - 6);
    x = rectangle.x + rectangle.width - 1;
    gc.setForeground(separatorColor);
    gc.drawLine(x, rectangle.y + 3, x, rectangle.y + rectangle.height - 6);
    // Restore GC settings
    gc.setBackground(originalBackground);
    gc.setForeground(originalForeground);
    // Draw bottom edge
    boolean isHighlight = false;
    int y = rectangle.y + rectangle.height - 3;
    gc.setForeground(isHighlight ? highlightColor1 : gradientColor1);
    gc.drawLine(rectangle.x, y, rectangle.x + rectangle.width, y);
    y++;
    gc.setForeground(isHighlight ? highlightColor2 : gradientColor2);
    gc.drawLine(rectangle.x, y, rectangle.x + rectangle.width, y);
    y++;
    gc.setForeground(isHighlight ? highlightColor3 : gradientColor3);
    gc.drawLine(rectangle.x, y, rectangle.x + rectangle.width, y);
}
Also used : Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle)

Example 73 with Rectangle

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

the class CellLayerPainter method paintLayer.

public void paintLayer(ILayer natLayer, GC gc, int xOffset, int yOffset, Rectangle pixelRectangle, IConfigRegistry configRegistry) {
    if (pixelRectangle.width <= 0 || pixelRectangle.height <= 0) {
        return;
    }
    Collection<LayerCell> spannedCells = new HashSet<LayerCell>();
    Rectangle positionRectangle = getPositionRectangleFromPixelRectangle(natLayer, pixelRectangle);
    for (int columnPosition = positionRectangle.x; columnPosition < positionRectangle.x + positionRectangle.width; columnPosition++) {
        for (int rowPosition = positionRectangle.y; rowPosition < positionRectangle.y + positionRectangle.height; rowPosition++) {
            LayerCell cell = natLayer.getCellByPosition(columnPosition, rowPosition);
            if (cell != null) {
                if (cell.isSpannedCell()) {
                    spannedCells.add(cell);
                } else {
                    paintCell(cell, gc, configRegistry);
                }
            }
        }
    }
    for (LayerCell cell : spannedCells) {
        paintCell(cell, gc, configRegistry);
    }
}
Also used : LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) Rectangle(org.eclipse.swt.graphics.Rectangle) HashSet(java.util.HashSet)

Example 74 with Rectangle

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

the class GridLayerPrinter method getPageCount.

/**
	 * Calculate number of horizontal and vertical pages needed
	 * to print the entire grid.
	 */
private Point getPageCount(Printer printer) {
    Rectangle gridArea = getTotalGridArea();
    Rectangle printArea = computePrintArea(printer);
    Point scaleFactor = computeScaleFactor(printer);
    int numOfHorizontalPages = gridArea.width / (printArea.width / scaleFactor.x);
    int numOfVerticalPages = gridArea.height / (printArea.height / scaleFactor.y);
    // Adjusting for 0 index
    return new Point(numOfHorizontalPages + 1, numOfVerticalPages + 1);
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 75 with Rectangle

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

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