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;
}
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);
}
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);
}
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);
}
});
}
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;
}
Aggregations