use of org.eclipse.draw2d.Graphics in project cubrid-manager by CUBRID.
the class ExportPictureTask method createImage.
private byte[] createImage(IFigure figure, int format) {
Rectangle r = figure.getBounds();
ByteArrayOutputStream result = new ByteArrayOutputStream();
Image image = null;
GC gc = null;
Graphics g = null;
try {
image = new Image(null, r.width, r.height);
gc = new GC(image);
g = new SWTGraphics(gc);
g.translate(r.x * -1, r.y * -1);
figure.paint(g);
ImageLoader imageLoader = new ImageLoader();
imageLoader.data = new ImageData[] { image.getImageData() };
imageLoader.save(result, format);
} finally {
if (g != null) {
g.dispose();
}
if (gc != null) {
gc.dispose();
}
if (image != null) {
image.dispose();
}
}
return result.toByteArray();
}
use of org.eclipse.draw2d.Graphics in project tdi-studio-se by Talend.
the class AbstractTalendEditor method saveOutlinePicture.
/**
* Save the outline picture for this editor.
*
* @param viewer
*/
protected void saveOutlinePicture(ScrollingGraphicalViewer viewer) {
GlobalConstant.generatingScreenShoot = true;
LayerManager layerManager = (LayerManager) viewer.getEditPartRegistry().get(LayerManager.ID);
// save image using swt
// get root figure
IFigure backgroundLayer = layerManager.getLayer(LayerConstants.GRID_LAYER);
IFigure contentLayer = layerManager.getLayer(LayerConstants.PRINTABLE_LAYERS);
// create image from root figure
FreeformViewport viewport = (FreeformViewport) ((TalendScalableFreeformRootEditPart) layerManager).getFigure();
viewport.getUpdateManager().performUpdate();
int width = contentLayer.getBounds().width;
int height = contentLayer.getBounds().height;
Image img = new Image(null, width, height);
GC gc = new GC(img);
Graphics graphics = new SWTGraphics(gc);
Point point = contentLayer.getBounds().getTopLeft();
graphics.translate(-point.x, -point.y);
IProcess2 process = getProcess();
process.setPropertyValue(IProcess.SCREEN_OFFSET_X, String.valueOf(-point.x));
process.setPropertyValue(IProcess.SCREEN_OFFSET_Y, String.valueOf(-point.y));
backgroundLayer.paint(graphics);
contentLayer.paint(graphics);
graphics.dispose();
gc.dispose();
process.getScreenshots().put("process", ImageUtils.saveImageToData(img));
img.dispose();
// service.getProxyRepositoryFactory().refreshJobPictureFolder(outlinePicturePath);
GlobalConstant.generatingScreenShoot = false;
}
use of org.eclipse.draw2d.Graphics in project tdi-studio-se by Talend.
the class TalendDrawerFigure method createHoverHelp.
protected void createHoverHelp(final Control control) {
if (control == null) {
return;
}
// If a control was provided, create the tipLabel -- if the text in the
// header is
// truncated, it will display it as a tooltip.
tipLabel = new Label() {
/**
* @see org.eclipse.draw2d.Figure#getToolTip()
*/
@Override
public IFigure getToolTip() {
return buildTooltip();
}
@Override
protected void paintFigure(Graphics graphics) {
Rectangle r = Rectangle.SINGLETON;
r.setBounds(getBounds());
graphics.pushState();
paintToggleGradient(graphics, getBounds());
graphics.popState();
super.paintFigure(graphics);
}
};
tipLabel.setOpaque(false);
tipLabel.setBorder(TOOLTIP_BORDER);
try {
Field tipLabelField = DrawerFigure.class.getDeclaredField("tipLabel");
tipLabelField.setAccessible(true);
tipLabelField.set(this, tipLabel);
} catch (Exception e) {
CommonExceptionHandler.process(e);
}
collapseToggle.addMouseMotionListener(new MouseMotionListener.Stub() {
@Override
public void mouseMoved(MouseEvent e) {
if (!talendDrawerLabel.getBounds().contains(e.getLocation())) {
return;
}
if (skipNextEvent) {
skipNextEvent = false;
return;
}
if (talendDrawerLabel.isTextTruncated() && !TalendEditPartTipHelper.isCurrent(tipHelper)) {
tipLabel.setText(talendDrawerLabel.getText());
tipLabel.setIcon(talendDrawerLabel.getIcon());
tipLabel.setFont(talendDrawerLabel.getFont());
tipHelper = new TalendEditPartTipHelper(control);
Rectangle bounds = talendDrawerLabel.getBounds().getExpanded(2, 2);
talendDrawerLabel.translateToAbsolute(bounds);
org.eclipse.swt.graphics.Rectangle loc = new org.eclipse.swt.graphics.Rectangle(bounds.x, bounds.y, bounds.width, bounds.height);
loc = Display.getCurrent().map(control, null, loc);
tipHelper.displayToolTipAt(tipLabel, loc.x, loc.y);
}
}
});
tipLabel.addMouseListener(new MouseListener.Stub() {
@Override
public void mousePressed(MouseEvent e) {
if (e.button == 1) {
Rectangle original = getCollapseToggle().getBounds().getCopy();
getCollapseToggle().requestFocus();
setExpanded(!isExpanded());
// toggle to move
if (!original.equals(getCollapseToggle().getBounds())) {
tipHelper.hide();
}
} else {
tipHelper.hide();
if (e.button == 3) {
skipNextEvent = true;
}
}
}
});
}
Aggregations