use of org.eclipse.swt.graphics.Rectangle in project dbeaver by serge-rider.
the class ImageViewCanvas method fitCanvas.
/**
* Fit the image onto the canvas
*/
public void fitCanvas() {
if (sourceImage == null)
return;
Rectangle imageBound = sourceImage.getBounds();
Rectangle destRect = getClientArea();
double sx = (double) destRect.width / (double) imageBound.width;
double sy = (double) destRect.height / (double) imageBound.height;
double s = Math.min(sx, sy);
double dx = 0.5 * destRect.width;
double dy = 0.5 * destRect.height;
centerZoom(dx, dy, s, new AffineTransform());
}
use of org.eclipse.swt.graphics.Rectangle in project dbeaver by serge-rider.
the class ImageViewCanvas method zoomIn.
/**
* Zoom in around the center of client Area.
*/
public void zoomIn() {
if (sourceImage == null)
return;
Rectangle rect = getClientArea();
int w = rect.width, h = rect.height;
double dx = ((double) w) / 2;
double dy = ((double) h) / 2;
centerZoom(dx, dy, ZOOMIN_RATE, transform);
}
use of org.eclipse.swt.graphics.Rectangle in project dbeaver by serge-rider.
the class ImageViewUtil method transformRect.
/**
* Given an arbitrary rectangle, get the rectangle with the given transform.
* The result rectangle is positive width and positive height.
*
* @param af AffineTransform
* @param src source rectangle
* @return rectangle after transform with positive width and height
*/
public static Rectangle transformRect(AffineTransform af, Rectangle src) {
Rectangle dest = new Rectangle(0, 0, 0, 0);
src = absRect(src);
Point p1 = new Point(src.x, src.y);
p1 = transformPoint(af, p1);
dest.x = p1.x;
dest.y = p1.y;
dest.width = (int) (src.width * af.getScaleX());
dest.height = (int) (src.height * af.getScaleY());
return dest;
}
use of org.eclipse.swt.graphics.Rectangle in project dbeaver by serge-rider.
the class DatabaseNavigatorTree method renameItem.
private void renameItem(final TreeItem item) {
// Clean up any previous editor control
disposeOldEditor();
if (item.isDisposed()) {
return;
}
final DBNNode node = (DBNNode) item.getData();
Text text = new Text(treeViewer.getTree(), SWT.BORDER);
text.setText(node.getNodeName());
text.selectAll();
text.setFocus();
text.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
disposeOldEditor();
}
});
text.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.CR) {
Text text = (Text) treeEditor.getEditor();
final String newName = text.getText();
disposeOldEditor();
treeViewer.getTree().setFocus();
if (!CommonUtils.isEmpty(newName) && !newName.equals(node.getNodeName())) {
NavigatorHandlerObjectRename.renameNode(DBeaverUI.getActiveWorkbenchWindow(), node, newName);
}
} else if (e.keyCode == SWT.ESC) {
disposeOldEditor();
treeViewer.getTree().setFocus();
}
}
});
final Rectangle itemBounds = item.getBounds(0);
final Rectangle treeBounds = treeViewer.getTree().getBounds();
treeEditor.minimumWidth = Math.max(itemBounds.width, 50);
treeEditor.minimumWidth = Math.min(treeEditor.minimumWidth, treeBounds.width - (itemBounds.x - treeBounds.x) - item.getImageBounds(0).width - 4);
treeEditor.setEditor(text, item, 0);
}
use of org.eclipse.swt.graphics.Rectangle in project translationstudio8 by heartsome.
the class SmileyCellRenderer method draw.
/**
* {@inheritDoc}
*/
public void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row, IColumn column, boolean drawFocus, boolean selected, boolean printing) {
drawBackground(gc, drawingArea, cellStyle, selected, printing);
Rectangle drect = drawBorder(gc, cellStyle, drawingArea, printing);
Rectangle rect = applyInsets(drect);
Object value = column.getValue(row);
if (value != null) {
saveGCAttributes(gc);
int val = ((Integer) value).intValue();
_brModel.setValue(val);
calcSmileFactor();
if (_forceCircle) {
int a = Math.min(rect.width, rect.height);
Rectangle nrect = new Rectangle(0, 0, a, a);
nrect.x = rect.x + (rect.width - a) / 2;
nrect.y = rect.y + (rect.height - a) / 2;
rect = nrect;
}
int width = rect.width;
int height = rect.height;
int offx = rect.x;
int offy = rect.y;
float foffx = (float) offx;
float foffy = (float) offy;
int lineWidth = height / 40;
if (!_colorChange) {
gc.setBackground(_neutral);
} else {
if (_currentValue >= 0) {
// positive
gc.setBackground(calcColor(_positive, printing));
} else {
// negative
gc.setBackground(calcColor(_negative, printing));
}
}
Device device = printing ? _printer : Display.getCurrent();
Path p = new Path(device);
p.addArc(foffx + 0 + lineWidth / 2, foffy + 0 + lineWidth / 2, width - 1 - lineWidth, height - 1 - lineWidth, 0, 360);
gc.fillPath(p);
gc.setForeground(_black);
gc.setLineWidth(lineWidth);
gc.drawPath(p);
p.dispose();
// eyes
int y = height / 3;
int x1 = width / 3;
int x2 = width - width / 3;
int r = width / 30;
// eyes have a minimal size
if (r == 0) {
r = 1;
}
gc.setBackground(_black);
gc.fillOval(offx + x1 - r, offy + y - r, 2 * r, 2 * r);
gc.fillOval(offx + x2 - r, offy + y - r, 2 * r, 2 * r);
// eye brows
if (_eyeBrows) {
gc.setLineWidth(lineWidth / 2);
int ebWidth = width / 10;
int yDist = height / 13;
int yOff = (int) (_currentValue * (double) height / 30);
int xShift = (int) (_currentValue * (double) width / 90);
p = new Path(device);
p.moveTo(foffx + x1 - ebWidth / 2 + xShift, foffy + y - yDist + yOff);
p.lineTo(foffx + x1 + ebWidth / 2 - xShift, foffy + y - yDist - yOff);
gc.drawPath(p);
p.dispose();
p = new Path(device);
p.moveTo(foffx + x2 - ebWidth / 2 + xShift, foffy + y - yDist - yOff);
p.lineTo(foffx + x2 + ebWidth / 2 - xShift, foffy + y - yDist + yOff);
gc.drawPath(p);
p.dispose();
}
// mouth
gc.setLineWidth(lineWidth);
x1 = (int) (width / 4.5);
x2 = width - x1;
y = height - height / 3;
int midX = width / 2;
int offset = (int) (_currentValue * (double) height / 3);
p = new Path(Display.getCurrent());
p.moveTo(foffx + x1, foffy + y);
p.quadTo(foffx + midX, foffy + y + offset, foffx + x2, foffy + y);
gc.drawPath(p);
p.dispose();
restoreGCAttributes(gc);
}
if (drawFocus) {
drawFocus(gc, drect);
}
drawSelection(gc, drawingArea, cellStyle, selected, printing);
}
Aggregations