Java Examples for org.eclipse.draw2d.Graphics
The following java examples will help you to understand the usage of org.eclipse.draw2d.Graphics. These source code samples are taken from different open source projects.
Example 1
Project: Henshin-Editor-master File: ExportViewerImageAction.java View source code |
/**
* Returns the bytes of an encoded image for the specified IFigure in the
* specified format.
*
* @param figure
* the Figure to create an image for.
* @param format
* one of SWT.IMAGE_BMP, SWT.IMAGE_BMP_RLE, SWT.IMAGE_GIF
* SWT.IMAGE_ICO, SWT.IMAGE_JPEG, or SWT.IMAGE_PNG
* @return the bytes of an encoded image for the specified Figure
*/
private byte[] createImage(final IFigure figure, final int format) {
final Device device = viewer.getControl().getDisplay();
final Rectangle r = figure.getBounds();
final ByteArrayOutputStream result = new ByteArrayOutputStream();
Image image = null;
GC gc = null;
Graphics g = null;
try {
image = new Image(device, r.width, r.height);
gc = new GC(image);
g = new SWTGraphics(gc);
g.translate(r.x * -1, r.y * -1);
figure.paint(g);
final ImageLoader imageLoader = new ImageLoader();
imageLoader.data = new ImageData[] { image.getImageData() };
imageLoader.save(result, format);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (g != null) {
g.dispose();
}
if (gc != null) {
gc.dispose();
}
if (image != null) {
image.dispose();
}
}
return result.toByteArray();
}
Example 2
Project: rap.incubator.gef-master File: FlyoutPaletteComposite.java View source code |
protected void paintFigure(Graphics graphics) {
// paint the gradient
graphics.pushState();
org.eclipse.draw2d.geometry.Rectangle r = org.eclipse.draw2d.geometry.Rectangle.getSINGLETON();
r.setBounds(getBounds());
graphics.setForegroundColor(PaletteColorUtil.WIDGET_LIST_BACKGROUND);
graphics.setBackgroundColor(PaletteColorUtil.WIDGET_BACKGROUND);
graphics.fillGradient(r, true);
// draw bottom border
graphics.setForegroundColor(PaletteColorUtil.WIDGET_NORMAL_SHADOW);
graphics.drawLine(r.getBottomLeft().getTranslated(0, -1), r.getBottomRight().getTranslated(0, -1));
graphics.popState();
// paint the text and icon
super.paintFigure(graphics);
// paint the focus rectangle around the text
if (hasFocus()) {
org.eclipse.draw2d.geometry.Rectangle textBounds = getTextBounds();
// We reduce the width by 1 because FigureUtilities grows it by
// 1 unnecessarily
textBounds.width--;
graphics.drawFocus(bounds.getResized(-1, -1).intersect(textBounds.getExpanded(getInsets())));
}
}
Example 3
Project: Diver-master File: QuickClearingFigure.java View source code |
/** * Paints this Figure's children. The caller must save the state of the graphics prior to * calling this method, such that <code>graphics.restoreState()</code> may be called * safely, and doing so will return the graphics to its original state when the method was * entered. * <P> * This method must leave the Graphics in its original state upon return. * @param graphics the graphics used to paint * @since 2.0 */ protected void paintChildren(Graphics graphics) { IFigure child; Rectangle clip = Rectangle.SINGLETON; for (Iterator<IFigure> i = children.iterator(); i.hasNext(); ) { child = i.next(); if (child.isVisible() && child.intersects(graphics.getClip(clip))) { graphics.clipRect(child.getBounds()); child.paint(graphics); graphics.restoreState(); } } }
Example 4
Project: modellipse-master File: Utils.java View source code |
// Debug purpose
public static void drawRect(IGraphicalEditPart editPart, Rectangle refContentArea) {
RoundedRectangle rectFeedback = new RoundedRectangle();
rectFeedback.setBounds(refContentArea);
rectFeedback.setCornerDimensions(new Dimension(0, 0));
rectFeedback.setLineWidth(2);
rectFeedback.setLineStyle(Graphics.LINE_DASH);
rectFeedback.setForegroundColor(editPart.getFigure().getForegroundColor());
rectFeedback.setOpaque(true);
rectFeedback.setFill(false);
IFigure layer = LayerManager.Helper.find(editPart).getLayer(LayerConstants.FEEDBACK_LAYER);
layer.add(rectFeedback);
}
Example 5
Project: statecharts-master File: DirectEditManagerEx.java View source code |
public void paint(IFigure figure, Graphics graphics, Insets insets) {
Rectangle rect = getPaintRectangle(figure, insets);
graphics.setForegroundColor(ColorConstants.white);
graphics.drawLine(rect.x, rect.y, rect.x, rect.bottom());
rect.x++;
rect.width--;
rect.resize(-1, -1);
graphics.setForegroundColor(ColorConstants.black);
graphics.drawLine(rect.x + 2, rect.bottom(), rect.right(), rect.bottom());
graphics.drawLine(rect.right(), rect.bottom(), rect.right(), rect.y + 2);
rect.resize(-1, -1);
graphics.setForegroundColor(BLUE);
graphics.drawRectangle(rect);
}
Example 6
Project: gmp.graphiti-master File: PictogramElementDelegate.java View source code |
/** * returns null if the decorator does not produce a figure of its own */ private IFigure decorateFigure(IFigure figure, IDecorator decorator) { if (decorator == null) { return null; } String messageText = decorator.getMessage(); // Variable to store an additional figure for the decorator (needed in // case of an image decorator. Cannot be created in the if for image // decorators, because a shape can have more than one decorator (also of // different kinds) IFigure decoratorFigure = null; org.eclipse.draw2d.geometry.Rectangle boundsForDecoratorFigure = new org.eclipse.draw2d.geometry.Rectangle(0, 0, 16, 16); // Decorate with an image if (decorator instanceof IImageDecorator) { IImageDecorator imageDecorator = (IImageDecorator) decorator; org.eclipse.swt.graphics.Image imageForId = GraphitiUi.getImageService().getImageForId(configurationProvider.getDiagramTypeProvider().getProviderId(), imageDecorator.getImageId()); ImageFigure imageFigure = new DecoratorImageFigure(imageForId); decoratorFigure = imageFigure; org.eclipse.swt.graphics.Rectangle imageBounds = imageFigure.getImage().getBounds(); boundsForDecoratorFigure.setSize(imageBounds.width, imageBounds.height); if (decorator instanceof ILocation) { ILocation location = (ILocation) decorator; boundsForDecoratorFigure.setLocation(location.getX(), location.getY()); } IFigure parent = figure.getParent(); if (parent != null) { org.eclipse.draw2d.geometry.Rectangle ownerBounds = (org.eclipse.draw2d.geometry.Rectangle) parent.getLayoutManager().getConstraint(figure); boundsForDecoratorFigure.translate(ownerBounds.getLocation()); } decoratorFigure.setVisible(true); if (messageText != null && messageText.length() > 0) { decoratorFigure.setToolTip(new Label(messageText)); } if (parent.getLayoutManager() == null) { parent.setLayoutManager(new XYLayout()); } parent.add(decoratorFigure, boundsForDecoratorFigure, parent.getChildren().indexOf(figure) + 1); } // Decorate with text if (decorator instanceof ITextDecorator) { ITextDecorator textDecorator = (ITextDecorator) decorator; String text = textDecorator.getText(); decoratorFigure = new Label(text); Font font = new org.eclipse.swt.graphics.Font(null, textDecorator.getFontName(), textDecorator.getFontSize(), SWT.NORMAL); decoratorFontList.add(font); Dimension dimension = TextUtilities.INSTANCE.getStringExtents(text, font); boundsForDecoratorFigure.setSize(dimension.width, dimension.height); decoratorFigure.setFont(font); IResourceRegistry resourceRegistry = getConfigurationProvider().getResourceRegistry(); IColorConstant backgroundColor = textDecorator.getBackgroundColor(); if (backgroundColor != null) { decoratorFigure.setOpaque(true); decoratorFigure.setBackgroundColor(resourceRegistry.getSwtColor(backgroundColor.getRed(), backgroundColor.getGreen(), backgroundColor.getBlue())); } IColorConstant foregroundColor = textDecorator.getForegroundColor(); if (foregroundColor != null) { decoratorFigure.setForegroundColor(resourceRegistry.getSwtColor(foregroundColor.getRed(), foregroundColor.getGreen(), foregroundColor.getBlue())); } if (decorator instanceof ILocation) { ILocation location = (ILocation) decorator; boundsForDecoratorFigure.setLocation(location.getX(), location.getY()); } IFigure parent = figure.getParent(); if (parent != null) { org.eclipse.draw2d.geometry.Rectangle ownerBounds = (org.eclipse.draw2d.geometry.Rectangle) parent.getLayoutManager().getConstraint(figure); boundsForDecoratorFigure.translate(ownerBounds.getLocation()); } decoratorFigure.setVisible(true); if (messageText != null && messageText.length() > 0) { decoratorFigure.setToolTip(new Label(messageText)); } if (parent.getLayoutManager() == null) { parent.setLayoutManager(new XYLayout()); } parent.add(decoratorFigure, boundsForDecoratorFigure, parent.getChildren().indexOf(figure) + 1); } // Decorate the border of the shape if (decorator instanceof IBorderDecorator) { IBorderDecorator renderingDecorator = ((IBorderDecorator) decorator); IResourceRegistry resourceRegistry = getConfigurationProvider().getResourceRegistry(); // Get the width for the border (or set to default) Integer borderWidth = renderingDecorator.getBorderWidth(); if (borderWidth == null || borderWidth < 1) { borderWidth = 1; } // Get the style for the border (or set to default) Integer borderStyle = renderingDecorator.getBorderStyle(); if (borderStyle == null || (Graphics.LINE_DASH != borderStyle && Graphics.LINE_DASHDOT != borderStyle && Graphics.LINE_DASHDOTDOT != borderStyle && Graphics.LINE_DOT != borderStyle && Graphics.LINE_SOLID != borderStyle)) { borderStyle = Graphics.LINE_SOLID; } // Get the color for the border (or set to default) Color borderColor = null; IColorConstant colorConstant = renderingDecorator.getBorderColor(); if (colorConstant == null) { colorConstant = IColorConstant.BLACK; } borderColor = resourceRegistry.getSwtColor(colorConstant.getRed(), colorConstant.getGreen(), colorConstant.getBlue()); // Apply border decorations figure.setBorder(new LineBorder(borderColor, borderWidth, borderStyle)); } // Decorate using the colors of the shape if (decorator instanceof IColorDecorator) { IColorDecorator renderingDecorator = ((IColorDecorator) decorator); IResourceRegistry resourceRegistry = getConfigurationProvider().getResourceRegistry(); // Get the background color (or set to default) Color backgroundColor = null; IColorConstant colorConstant = renderingDecorator.getBackgroundColor(); if (colorConstant != null) { backgroundColor = resourceRegistry.getSwtColor(colorConstant.getRed(), colorConstant.getGreen(), colorConstant.getBlue()); } // Get the foreground color (or set to default) Color foregroundColor = null; colorConstant = renderingDecorator.getForegroundColor(); if (colorConstant != null) { foregroundColor = resourceRegistry.getSwtColor(colorConstant.getRed(), colorConstant.getGreen(), colorConstant.getBlue()); } // Apply color decorations if (foregroundColor != null) { figure.setForegroundColor(foregroundColor); } if (backgroundColor != null) { figure.setBackgroundColor(backgroundColor); } if (figure instanceof Shape) { ((Shape) figure).setFill(true); } } // Return additionally created figure return decoratorFigure; }
Example 7
Project: xmind-master File: StyleFigureUtils.java View source code |
public static void drawArrow(Graphics graphics, String arrowValue, Point head, Point tail, int lineWidth) {
Path shape = new Path(Display.getCurrent());
boolean fill = true;
double angle = new PrecisionPoint(tail).getAngle(new PrecisionPoint(head));
if (Styles.ARROW_SHAPE_DIAMOND.equals(arrowValue)) {
diamondArrow(shape, head, angle, lineWidth);
} else if (Styles.ARROW_SHAPE_DOT.equals(arrowValue)) {
dotArrow(shape, head, angle, lineWidth);
} else if (Styles.ARROW_SHAPE_HERRINGBONE.equals(arrowValue)) {
herringBone(shape, head, angle, lineWidth);
fill = false;
} else if (Styles.ARROW_SHAPE_SPEARHEAD.equals(arrowValue)) {
spearhead(shape, head, angle, lineWidth);
} else if (Styles.ARROW_SHAPE_SQUARE.equals(arrowValue)) {
square(shape, head, angle, lineWidth);
} else if (Styles.ARROW_SHAPE_TRIANGLE.equals(arrowValue)) {
triangle(shape, head, angle, lineWidth);
} else {
normalArrow(shape, head, angle, lineWidth);
fill = false;
}
Color fgColor = graphics.getForegroundColor();
if (fgColor != null) {
if (fill) {
graphics.setBackgroundColor(fgColor);
graphics.fillPath(shape);
}
graphics.drawPath(shape);
}
shape.dispose();
}
Example 8
Project: mobicents-master File: ExportDrawing.java View source code |
////////////////////////////////////////////////////////////
//
// Utilities
//
////////////////////////////////////////////////////////////
/**
*@param draw2DFigure The figure to save
*@param filename The path where the figure must be saved
*/
private void saveFile(IFigure draw2DFigure, final String filename) {
if (filename != null) {
try {
Rectangle rectangle = draw2DFigure.getClientArea();
System.out.println("Size of client area before : " + rectangle);
//IFigure copy = copy(draw2DFigure);
// VScalableFigure drawing = new VScalableFigure();
// drawing.setContent(copy);
// drawing.setFactor(4);
// drawing.lessZoom();
//
// rectangle = drawing.getClientArea();
// System.out.println("Size of client area after: " + rectangle);
final Image image = new Image(null, rectangle.width, rectangle.height);
GC gc = new GC(image);
Graphics graphics = new SWTGraphics(gc);
graphics.translate(draw2DFigure.getBounds().getLocation().getNegated());
draw2DFigure.paint(graphics);
// graphics.translate(drawing.getBounds().getLocation().getNegated());
// drawing.paint(graphics);
//
graphics.dispose();
gc.dispose();
IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
progressService.runInUI(PlatformUI.getWorkbench().getProgressService(), new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) {
try {
monitor.setTaskName("Save image in " + filename);
monitor.subTask(" Get image Data ..");
ImageData data = image.getImageData();
ImageLoader loader = new ImageLoader();
monitor.subTask(" Get Load into Image loader ..");
loader.data = new ImageData[1];
loader.data[0] = data;
System.out.println(" data lenght : =" + data.width + " , " + data.height);
monitor.subTask(" Save Image ..");
loader.save(filename, SWT.IMAGE_JPEG);
monitor.done();
} catch (OutOfMemoryError e) {
MessageDialog.openError(new Shell(), "SCE-SE Error", " Sorry: an Out of Memory was caugth");
}
}
}, null);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (OutOfMemoryError e) {
MessageDialog.openError(new Shell(), "SCE-SE Error", " Sorry: an Out of Memory was caugth");
}
} else {
MessageDialog.openError(new Shell(), "SCE-SE Error", " The specified file name is not valid ! \n The image wa not saved");
}
}
Example 9
Project: XFlow-master File: TableFigure.java View source code |
protected void paintFigure(Graphics graphics) {
super.paintFigure(graphics);
graphics.setForegroundColor(ColorConstants.gray);
// ͨ¹ýGraphicsUtil»æÖƽ¥±äÇøÓò
Point plusPoint = new Point(getLocation().x, getLocation().y);
Dimension plusDimension = new Dimension(getBounds().getSize().width, 20);
GraphicsUtil.paintPlusArea(graphics, plusPoint, plusDimension);
Rectangle bounds = getBounds();
graphics.drawRectangle(new Rectangle(bounds.x, bounds.y, bounds.width - 1, bounds.height - 1));
int y = getBounds().y + getBorder().getInsets(this).bottom + this.tableNameLabel.getSize().height;
graphics.drawLine(getBounds().x, y, getBounds().x + getBounds().width, y);
}
Example 10
Project: xmind-source-master File: StyleFigureUtils.java View source code |
public static void drawArrow(Graphics graphics, String arrowValue, Point head, Point tail, int lineWidth) {
Path shape = new Path(Display.getCurrent());
boolean fill = true;
double angle = new PrecisionPoint(tail).getAngle(new PrecisionPoint(head));
if (Styles.ARROW_SHAPE_DIAMOND.equals(arrowValue)) {
diamondArrow(shape, head, angle, lineWidth);
} else if (Styles.ARROW_SHAPE_DOT.equals(arrowValue)) {
dotArrow(shape, head, angle, lineWidth);
} else if (Styles.ARROW_SHAPE_HERRINGBONE.equals(arrowValue)) {
herringBone(shape, head, angle, lineWidth);
fill = false;
} else if (Styles.ARROW_SHAPE_SPEARHEAD.equals(arrowValue)) {
spearhead(shape, head, angle, lineWidth);
} else if (Styles.ARROW_SHAPE_SQUARE.equals(arrowValue)) {
square(shape, head, angle, lineWidth);
} else if (Styles.ARROW_SHAPE_TRIANGLE.equals(arrowValue)) {
triangle(shape, head, angle, lineWidth);
} else {
normalArrow(shape, head, angle, lineWidth);
fill = false;
}
if (fill) {
graphics.setBackgroundColor(graphics.getForegroundColor());
graphics.fillPath(shape);
}
graphics.drawPath(shape);
shape.dispose();
}
Example 11
Project: xmind3-master File: StyleFigureUtils.java View source code |
public static void drawArrow(Graphics graphics, String arrowValue, Point head, Point tail, int lineWidth) {
Path shape = new Path(Display.getCurrent());
boolean fill = true;
double angle = new PrecisionPoint(tail).getAngle(new PrecisionPoint(head));
if (Styles.ARROW_SHAPE_DIAMOND.equals(arrowValue)) {
diamondArrow(shape, head, angle, lineWidth);
} else if (Styles.ARROW_SHAPE_DOT.equals(arrowValue)) {
dotArrow(shape, head, angle, lineWidth);
} else if (Styles.ARROW_SHAPE_HERRINGBONE.equals(arrowValue)) {
herringBone(shape, head, angle, lineWidth);
fill = false;
} else if (Styles.ARROW_SHAPE_SPEARHEAD.equals(arrowValue)) {
spearhead(shape, head, angle, lineWidth);
} else if (Styles.ARROW_SHAPE_SQUARE.equals(arrowValue)) {
square(shape, head, angle, lineWidth);
} else if (Styles.ARROW_SHAPE_TRIANGLE.equals(arrowValue)) {
triangle(shape, head, angle, lineWidth);
} else {
normalArrow(shape, head, angle, lineWidth);
fill = false;
}
if (fill) {
graphics.setBackgroundColor(graphics.getForegroundColor());
graphics.fillPath(shape);
}
graphics.drawPath(shape);
shape.dispose();
}
Example 12
Project: gmf-runtime-master File: PolylineConnectionEx.java View source code |
/**
* Override the figure method "outlineShape" to draw the actual polyline connection shape.
* Special code to regenerate the jumplinks, draw the polyline smooth, and round the bendpoints
* is also done during this method call.
*/
protected void outlineShape(Graphics g) {
PointList displayPoints = getSmoothPoints(false);
Hashtable<Point, Integer> originalDisplayPoints = null;
if (isRoundingBendpoints()) {
// If rounded bendpoints feature is turned on, remember the original points, will be
// needed later.
originalDisplayPoints = new Hashtable<Point, Integer>();
for (int i = 0; i < displayPoints.size(); i++) {
originalDisplayPoints.put(displayPoints.getPoint(i), new Integer(i));
}
}
int incline = calculateJumpLinkIncline(isFeedbackLayer());
if (shouldJumpLinks()) {
regenerateJumpLinks();
JumpLinkSet pJumpLinkSet = getJumpLinkSet();
if (pJumpLinkSet != null && pJumpLinkSet.m_pJumpLinks != null) {
int nSmoothNess = 0;
if (isJumpLinksSmooth())
nSmoothNess = JUMPLINK_DEFAULT_SMOOTHNESS;
boolean bOnBottom = isJumpLinksOnBottom();
ListIterator linkIter = pJumpLinkSet.m_pJumpLinks.listIterator();
while (linkIter.hasNext()) {
JumpLink pJumpLink = (JumpLink) linkIter.next();
PointList jumpLinkPoints = PointListUtilities.routeAroundPoint(displayPoints, pJumpLink.m_ptIntersect, pJumpLink.m_nHeight, pJumpLink.m_nWidth, nSmoothNess, incline, !bOnBottom);
if (jumpLinkPoints != null)
displayPoints = jumpLinkPoints;
}
}
}
if (!isRoundingBendpoints()) {
g.drawPolyline(displayPoints);
if (origRoundedBendpointsRad > 0) {
// we unsuccessfully tried to do rounding, allow the next routing to try again.
roundedBendpointsRadius = origRoundedBendpointsRad;
origRoundedBendpointsRad = 0;
}
} else {
// In originalDisplayPoints, each bendpoint will be replaced with two points: start and end point of the arc.
// If jump links is on, then displayPoints will also contain points identifying jump links, if any.
int i = 1;
int rDefault = getRoundedBendpointsRadius();
while (i < displayPoints.size() - 1) {
// Consider points at indexes i-1, i, i+1.
int x0 = 0, y0 = 0;
boolean firstPointAssigned = false;
if (shouldJumpLinks()) {
boolean containsPoint2;
boolean containsPoint3;
PointList jumpLinkPoints = new PointList();
do {
// First, check if point at index i or i+1 is start point of a jump link (if the point is not in original points).
// If so, draw a polyline ending at the last point of the jump link.
containsPoint2 = true;
containsPoint3 = true;
if (i < displayPoints.size()) {
containsPoint2 = originalDisplayPoints.containsKey(displayPoints.getPoint(i));
if (i < displayPoints.size() - 1) {
containsPoint3 = originalDisplayPoints.containsKey(displayPoints.getPoint(i + 1));
}
}
if (!containsPoint2 || !containsPoint3) {
// start adding jump link points
jumpLinkPoints.addPoint(displayPoints.getPoint(i - 1));
// next point to be added to jump link points
Point p;
// index of the next point in jump link
int j;
if (!containsPoint2) {
// jump link starts somewhere on the segment before the arc begins
j = i;
p = displayPoints.getPoint(i);
} else {
// jump link starts within an arc; it means that one part of the arc will be replaced with
// a segment between points at i and i-1, and another part is replaced with the jump link,
j = i + 1;
p = displayPoints.getPoint(i + 1);
jumpLinkPoints.addPoint(displayPoints.getPoint(i));
}
do {
jumpLinkPoints.addPoint(p);
j++;
p = displayPoints.getPoint(j);
} while (!originalDisplayPoints.containsKey(p) && j < displayPoints.size() - 1);
// Now, check if p is start point of a line segment or an arc. In first case, index of p in
// the original list is even, in second it's odd.
int origIndex = ((Integer) originalDisplayPoints.get(p)).intValue();
firstPointAssigned = false;
if (origIndex % 2 == 0) {
// p is start point of a segment, it means that the jump link finished somewhere within the arc,
// so one part of the arc is replaced with the jump link, and another will be replaced with a segment.
jumpLinkPoints.addPoint(p);
i = j + 1;
} else {
// p is start point of an arc, the last point in jump link polyline becomes the first point for
// the drawing that follows (p could be the last point too)
x0 = jumpLinkPoints.getLastPoint().x;
y0 = jumpLinkPoints.getLastPoint().y;
i = j;
firstPointAssigned = true;
}
// Jump link algorithm sometimes inserts duplicate points, we need to get rid of those.
while (i < displayPoints.size() - 1 && displayPoints.getPoint(i).equals(displayPoints.getPoint(i + 1))) {
i++;
}
}
} while (!containsPoint2 || !containsPoint3);
if (jumpLinkPoints != null) {
// draw jump link
g.drawPolyline(jumpLinkPoints);
}
}
if (// if we still didn't reach the end after drawing jump link polyline
i < displayPoints.size() - 1) {
// But first, find points at i-1, i and i+1.
if (!firstPointAssigned) {
x0 = displayPoints.getPoint(i - 1).x;
y0 = displayPoints.getPoint(i - 1).y;
}
int x1;
;
int y1;
// inserts a point that already exists), just skip the point i
while (i < displayPoints.size() - 1 && x0 == displayPoints.getPoint(i).x && y0 == displayPoints.getPoint(i).y) {
i++;
}
if (i < displayPoints.size() - 1) {
x1 = displayPoints.getPoint(i).x;
y1 = displayPoints.getPoint(i).y;
} else {
break;
}
// The same goes for point at i and i+1
int x2;
int y2;
while (i + 1 < displayPoints.size() - 1 && x1 == displayPoints.getPoint(i + 1).x && y1 == displayPoints.getPoint(i + 1).y) {
i++;
}
if (i < displayPoints.size() - 1) {
x2 = displayPoints.getPoint(i + 1).x;
y2 = displayPoints.getPoint(i + 1).y;
} else {
break;
}
// Draw the segment
g.drawLine(x0, y0, x1, y1);
// Find out if arc size is default, or if it had to be decreased because of lack of space
int r = rDefault;
Point p = displayPoints.getPoint(i);
int origIndex = ((Integer) originalDisplayPoints.get(p)).intValue();
Object o = rForBendpointArc.get(new Integer((origIndex + 1) / 2));
if (o != null) {
r = ((Integer) o).intValue();
}
// Find out the location of enclosing rectangle (x, y), as well as staring angle of the arc.
int x, y;
int startAngle;
if (x0 == x1 && x1 < x2) {
x = x1;
y = y1 - r;
if (y1 > y2) {
startAngle = 90;
} else {
startAngle = 180;
}
} else if (x0 > x1 && x1 > x2) {
x = x2;
y = y2 - r;
if (y1 > y2) {
startAngle = 180;
} else {
startAngle = 90;
}
} else if (x0 == x1 && x1 > x2) {
if (y1 > y2) {
x = x2 - r;
y = y2;
startAngle = 0;
} else {
x = x1 - 2 * r;
y = y1 - r;
startAngle = 270;
}
} else // x0 < x1 && x1 < x2
{
if (y1 > y2) {
x = x2 - 2 * r;
y = y2 - r;
startAngle = 270;
} else {
x = x1 - r;
y = y1;
startAngle = 0;
}
}
// Draw the arc.
g.drawArc(x, y, 2 * r, 2 * r, startAngle, 90);
i += 2;
}
}
// Draw the last segment.
g.drawLine(displayPoints.getPoint(displayPoints.size() - 2), displayPoints.getLastPoint());
}
}
Example 13
Project: rce-master File: WorkflowNodePart.java View source code |
@Override
public void paintFigure(Graphics graphics) {
int offsetX;
int offsetY;
if (ci.getShape() == ComponentShape.CIRCLE) {
offsetX = OFFSET_SMALL_CIRCLE_COMPONENT_ICON;
offsetY = OFFSET_SMALL_CIRCLE_COMPONENT_ICON;
graphics.fillOval(this.getBounds());
graphics.setAntialias(SWT.ON);
Rectangle b = this.getBounds().getCopy();
b.width--;
b.height--;
graphics.drawOval(b);
graphics.setAntialias(SWT.OFF);
} else {
offsetX = OFFSET_SMALL_SQUARE_COMPONENT_ICON_X;
offsetY = OFFSET_SMALL_SQUARE_COMPONENT_ICON_Y;
graphics.fillRectangle(this.getBounds());
Rectangle b = this.getBounds().getCopy();
b.width--;
b.height--;
graphics.drawRectangle(b);
}
graphics.drawImage(icon, new Point(this.getLocation().x + offsetX, this.getLocation().y - 1 + offsetY));
}
Example 14
Project: webtools.jsf-master File: CSSBlockFlowLayout.java View source code |
/**
* when the "overflow" is "scroll", we need to paint the scrollbar
*/
public void paintFigurePostClientArea(Graphics g) {
ICSSStyle style = this.getCSSStyle();
if (style != null) {
Object overflow = style.getStyleProperty(ICSSPropertyID.ATTR_OVERFLOW);
if (ICSSPropertyID.VAL_SCROLL.equals(overflow) || ICSSPropertyID.VAL_AUTO.equals(overflow)) {
if (this._needHScroll || this._needVScroll) {
// as this is using localCoordinate, so translate to
// relative to left/up corder of whole
// blockbox.
g.translate(-_blockBox.getBorderPaddingInsets().left, -_blockBox.getBorderPaddingInsets().top);
Rectangle rect = new Rectangle(0, 0, _blockBox.getWidth(), _blockBox.getHeight());
rect.crop(_blockBox.getBorderInsets());
if (this._needHScroll && this._needVScroll) {
BorderUtil.drawScrollBar(g, BorderUtil.SCROLL_WIDTH, rect, BorderUtil.BOTH);
} else if (this._needHScroll) {
BorderUtil.drawScrollBar(g, BorderUtil.SCROLL_WIDTH, rect, BorderUtil.HORIZONTAL_BAR);
} else if (this._needVScroll) {
BorderUtil.drawScrollBar(g, BorderUtil.SCROLL_WIDTH, rect, BorderUtil.VERTICAL_BAR);
}
}
}
}
}
Example 15
Project: windowtester-master File: Connection.java View source code |
/**
* Returns the lineStyle as String for the Property Sheet
* @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
*/
public Object getPropertyValue(Object id) {
if (id.equals(LINESTYLE_PROP)) {
if (getLineStyle() == Graphics.LINE_DASH)
// Dashed is the second value in the combo dropdown
return new Integer(1);
// Solid is the first value in the combo dropdown
return new Integer(0);
}
return super.getPropertyValue(id);
}
Example 16
Project: CertWare-master File: LayoutUtil.java View source code |
/**
* Moves the label to the center of the figure.
* @param label label
* @param parent parent figure for dimensions
* @param graphics graphics for font metrics
*/
public static void moveToCenter(WrappingLabel label, Figure parent, Graphics graphics) {
Rectangle r = parent.getBounds();
Rectangle newLabelBounds = new Rectangle();
Point middle = new Point(r.x + r.width / 2, r.y + r.height / 2);
int textWidth = (label.getText().length() + 2) * graphics.getFontMetrics().getAverageCharWidth();
int textHeight = graphics.getFontMetrics().getHeight();
newLabelBounds.x = middle.x - textWidth / 2;
newLabelBounds.y = middle.y - textHeight / 2;
newLabelBounds.width = textWidth;
newLabelBounds.height = textHeight;
// use as much space as possible to enable wrapped text to display
/*
Rectangle clientArea = parent.getClientArea();
newLabelBounds.x = middle.x - textWidth/2;
newLabelBounds.y = middle.y - textHeight/2;
newLabelBounds.width = textWidth;
newLabelBounds.height = clientArea.height;
*/
label.setBounds(newLabelBounds);
}
Example 17
Project: dawn-isenciaui-master File: DirectorFigure.java View source code |
protected void fillShape(Graphics graphics) {
graphics.pushState();
graphics.setForegroundColor(ColorConstants.white);
graphics.setBackgroundColor(getBackgroundColor());
final Rectangle bounds = getBounds();
graphics.fillGradient(bounds.x + 1, bounds.y + 1, bounds.width - 2, bounds.height - 2, false);
graphics.popState();
}
Example 18
Project: ermaster-b-master File: Activator.java View source code |
public void run() {
GC figureCanvasGC = null;
GC imageGC = null;
try {
ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart) viewer.getRootEditPart();
rootEditPart.refresh();
IFigure rootFigure = ((LayerManager) rootEditPart).getLayer(LayerConstants.PRINTABLE_LAYERS);
EditPart editPart = viewer.getContents();
editPart.refresh();
ERDiagram diagram = (ERDiagram) editPart.getModel();
Rectangle rootFigureBounds = ExportToImageAction.getBounds(diagram, rootEditPart, rootFigure.getBounds());
Control figureCanvas = viewer.getControl();
figureCanvasGC = new GC(figureCanvas);
img = new Image(Display.getCurrent(), rootFigureBounds.width + 20, rootFigureBounds.height + 20);
imageGC = new GC(img);
imageGC.setBackground(figureCanvasGC.getBackground());
imageGC.setForeground(figureCanvasGC.getForeground());
imageGC.setFont(figureCanvasGC.getFont());
imageGC.setLineStyle(figureCanvasGC.getLineStyle());
imageGC.setLineWidth(figureCanvasGC.getLineWidth());
imageGC.setAntialias(SWT.OFF);
// imageGC.setInterpolation(SWT.HIGH);
Graphics imgGraphics = new SWTGraphics(imageGC);
imgGraphics.setBackgroundColor(figureCanvas.getBackground());
imgGraphics.fillRectangle(0, 0, rootFigureBounds.width + 20, rootFigureBounds.height + 20);
imgGraphics.translate(ExportToImageAction.translateX(rootFigureBounds.x), ExportToImageAction.translateY(rootFigureBounds.y));
rootFigure.paint(imgGraphics);
} finally {
if (figureCanvasGC != null) {
figureCanvasGC.dispose();
}
if (imageGC != null) {
imageGC.dispose();
}
}
}
Example 19
Project: FRaMED-master File: ShadowRoundedRectangle.java View source code |
/** * @see Shape#outlineShape(Graphics) */ protected void outlineShape(final Graphics graphics) { final Rectangle f = Rectangle.SINGLETON.setBounds(getBounds()); final Insets shadowInset = new Insets(lineWidth / 2, lineWidth / 2, lineWidth + SHADOW_INSET, lineWidth + SHADOW_INSET); f.crop(shadowInset); graphics.drawRoundRectangle(f, Math.max(0, corner.width - SHADOW_INSET), Math.max(0, corner.height - SHADOW_INSET)); }
Example 20
Project: gmf-tooling-master File: OrganizeImportsPostprocessorTest.java View source code |
public void testFullQualifiedArrays() throws Exception {
String testClassName = "FullQualifiedArrays";
List<Class<?>> typeRefs = Arrays.asList(new Class<?>[] { ArrayList.class, List.class, Map.class, Map.Entry.class });
final String[] conflictedTypeNames = new String[] { "javax.some.Map" };
final List<String> typeNameRefs = new ArrayList<String>(typeRefs.size() + conflictedTypeNames.length);
for (Class<?> next : typeRefs) {
typeNameRefs.add(getInnerClassAwareName(next));
}
String localVariable = typeNameRefs.get(2) + ".SMTH.ourEntries";
//String localVariable2 = "org.eclipse.draw2d.Graphics";
typeNameRefs.add(localVariable);
//typeNameRefs.add(localVariable2);
typeNameRefs.addAll(Arrays.asList(conflictedTypeNames));
StringBuffer buf = new StringBuffer();
buf.append("import ").append(typeNameRefs.get(0)).append(";").append(nl);
buf.append(nl);
buf.append("public class ").append(testClassName).append(" {").append(nl);
buf.append(nl);
buf.append(" private ").append(typeNameRefs.get(1)).append("[] list;").append(nl);
buf.append(" private ").append(typeNameRefs.get(2)).append("[] entry = new ").append(typeNameRefs.get(4)).append("[0];").append(nl);
buf.append(" private ").append(typeNameRefs.get(3)).append("[] maps;").append(nl);
buf.append(" private ").append(typeRefs.get(0).getSimpleName()).append("[] arrayLists;").append(nl);
buf.append(" private ").append(typeNameRefs.get(5)).append(" conflictEntry;").append(nl);
buf.append(" private int style = setLineStyle(").append(localVariable).append(".LINE_DASH);");
buf.append(nl);
buf.append(" private static int setLineStyle(int style) {");
buf.append(" return 0;");
buf.append(" }");
buf.append(nl);
buf.append("}").append(nl);
ICompilationUnit icu = JavaProjectHelper.createJavaFile(testClassName + ".java", buf.toString());
new OrganizeImportsPostprocessor().organizeImports(icu, null);
icu.save(null, true);
ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setSource(icu);
CompilationUnit cu = (CompilationUnit) parser.createAST(null);
List imports = cu.imports();
assertEquals("Failed to generate enough import statements: " + imports, typeRefs.size(), imports.size());
for (int i = 0; i < imports.size(); i++) {
String nextImport = ((ImportDeclaration) imports.get(i)).getName().getFullyQualifiedName();
assertEquals("Unexpected import found", typeNameRefs.get(i), nextImport);
}
cu.accept(new ASTVisitor() {
public boolean visit(FieldDeclaration node) {
node.getType().accept(new ExpectedSimpleNamesVisitor(typeNameRefs) {
public boolean visit(QualifiedName node) {
assertEquals("Unexpected full-qualified name found!", conflictedTypeNames[0], node.getFullyQualifiedName());
return false;
}
});
return super.visit(node);
}
});
assertEquals("Failed to leave unqualified only 1 reference", conflictedTypeNames.length, typeNameRefs.size() - 1);
}
Example 21
Project: jbosstools-base-master File: GEFLabel.java View source code |
protected void paintFigure(Graphics graphics) {
Rectangle bounds = getBounds();
graphics.translate(bounds.x, bounds.y);
if (graphics.getForegroundColor().equals(normalColor))
graphics.setForegroundColor(ColorConstants.black);
if (getIcon() != null)
graphics.drawImage(getIcon(), getIconLocation());
graphics.drawText(getSubStringText(), getTextLocation());
graphics.translate(-bounds.x, -bounds.y);
}
Example 22
Project: KompicsIDE-master File: TestLabel.java View source code |
@Override
protected void paintFigure(Graphics g) {
super.paintFigure(g);
Rectangle r = getTextBounds();
r.resize(-1, -1);
r.expand(1, 1);
r.width -= 1;
r.x -= 2;
// Top line
g.drawLine(r.x, r.y, r.right(), r.y);
// Bottom line
g.drawLine(r.x, r.bottom(), r.right(), r.bottom());
// left line
g.drawLine(r.x, r.bottom(), r.x, r.y);
g.drawLine(r.right() + 7, r.y + r.height / 2, r.right(), r.y);
g.drawLine(r.right() + 7, r.y + r.height / 2, r.right(), r.bottom());
}
Example 23
Project: limpet-master File: JFreeChartFigure.java View source code |
@Override
protected void paintFigure(Graphics graphics) {
super.paintFigure(graphics);
Rectangle clientArea = getClientArea();
JFreeChart freeChart = ChartBuilder.build(chart);
BufferedImage image = freeChart.createBufferedImage(clientArea.width, clientArea.height);
Image srcImage = new Image(Display.getCurrent(), convertToSWT(image));
graphics.drawImage(srcImage, clientArea.x, clientArea.y);
srcImage.dispose();
}
Example 24
Project: org.openscada.dakara-master File: ScalableLayeredPane.java View source code |
/** * @see org.eclipse.draw2d.Figure#paintClientArea(Graphics) */ @Override protected void paintClientArea(final Graphics graphics) { if (getChildren().isEmpty()) { return; } if (this.scale == 1.0) { super.paintClientArea(graphics); } else { final ScaledGraphics g = new ScaledGraphics(graphics); final boolean optimizeClip = getBorder() == null || getBorder().isOpaque(); if (!optimizeClip) { g.clipRect(getBounds().getCropped(getInsets())); } g.scale(this.scale); g.pushState(); paintChildren(g); g.dispose(); graphics.restoreState(); } }
Example 25
Project: swtbot-master File: LEDFigure.java View source code |
/** * @see org.eclipse.draw2d.Figure#paintFigure(Graphics) */ protected void paintFigure(Graphics g) { Rectangle r = getBounds().getCopy(); g.translate(r.getLocation()); g.setBackgroundColor(LogicColorConstants.logicGreen); g.setForegroundColor(LogicColorConstants.connectorGreen); g.fillRectangle(0, 2, r.width, r.height - 4); int right = r.width - 1; g.drawLine(0, Y1, right, Y1); g.drawLine(0, Y1, 0, Y2); g.setForegroundColor(LogicColorConstants.connectorGreen); g.drawLine(0, Y2, right, Y2); g.drawLine(right, Y1, right, Y2); // Draw the gaps for the connectors g.setForegroundColor(ColorConstants.listBackground); for (int i = 0; i < 4; i++) { g.drawLine(GAP_CENTERS_X[i] - 2, Y1, GAP_CENTERS_X[i] + 3, Y1); g.drawLine(GAP_CENTERS_X[i] - 2, Y2, GAP_CENTERS_X[i] + 3, Y2); } // Draw the connectors g.setForegroundColor(LogicColorConstants.connectorGreen); g.setBackgroundColor(LogicColorConstants.connectorGreen); for (int i = 0; i < 4; i++) { connector.translate(GAP_CENTERS_X[i], 0); g.fillPolygon(connector); g.drawPolygon(connector); connector.translate(-GAP_CENTERS_X[i], 0); bottomConnector.translate(GAP_CENTERS_X[i], r.height - 1); g.fillPolygon(bottomConnector); g.drawPolygon(bottomConnector); bottomConnector.translate(-GAP_CENTERS_X[i], -r.height + 1); } // Draw the display g.setBackgroundColor(LogicColorConstants.logicHighlight); g.fillRectangle(displayHighlight); g.setBackgroundColor(DISPLAY_SHADOW); g.fillRectangle(displayShadow); g.setBackgroundColor(ColorConstants.black); g.fillRectangle(displayRectangle); // Draw the value g.setFont(DISPLAY_FONT); g.setForegroundColor(DISPLAY_TEXT); g.drawText(value, valuePoint); }
Example 26
Project: swtbot-original-master File: LEDFigure.java View source code |
/** * @see org.eclipse.draw2d.Figure#paintFigure(Graphics) */ protected void paintFigure(Graphics g) { Rectangle r = getBounds().getCopy(); g.translate(r.getLocation()); g.setBackgroundColor(LogicColorConstants.logicGreen); g.setForegroundColor(LogicColorConstants.connectorGreen); g.fillRectangle(0, 2, r.width, r.height - 4); int right = r.width - 1; g.drawLine(0, Y1, right, Y1); g.drawLine(0, Y1, 0, Y2); g.setForegroundColor(LogicColorConstants.connectorGreen); g.drawLine(0, Y2, right, Y2); g.drawLine(right, Y1, right, Y2); // Draw the gaps for the connectors g.setForegroundColor(ColorConstants.listBackground); for (int i = 0; i < 4; i++) { g.drawLine(GAP_CENTERS_X[i] - 2, Y1, GAP_CENTERS_X[i] + 3, Y1); g.drawLine(GAP_CENTERS_X[i] - 2, Y2, GAP_CENTERS_X[i] + 3, Y2); } // Draw the connectors g.setForegroundColor(LogicColorConstants.connectorGreen); g.setBackgroundColor(LogicColorConstants.connectorGreen); for (int i = 0; i < 4; i++) { connector.translate(GAP_CENTERS_X[i], 0); g.fillPolygon(connector); g.drawPolygon(connector); connector.translate(-GAP_CENTERS_X[i], 0); bottomConnector.translate(GAP_CENTERS_X[i], r.height - 1); g.fillPolygon(bottomConnector); g.drawPolygon(bottomConnector); bottomConnector.translate(-GAP_CENTERS_X[i], -r.height + 1); } // Draw the display g.setBackgroundColor(LogicColorConstants.logicHighlight); g.fillRectangle(displayHighlight); g.setBackgroundColor(DISPLAY_SHADOW); g.fillRectangle(displayShadow); g.setBackgroundColor(ColorConstants.black); g.fillRectangle(displayRectangle); // Draw the value g.setFont(DISPLAY_FONT); g.setForegroundColor(DISPLAY_TEXT); g.drawText(value, valuePoint); }
Example 27
Project: teiid-designer-master File: SummaryExtentFigure.java View source code |
@Override
protected void paintOutline(Graphics graphics) {
// System.out.println("[SummaryExtentFigure.paintOutline] TOP " );
PointList pts = extentOutline.getPoints();
// System.out.println("\n[SummaryExtentFigure.paintOutline] Label size: " + numberLabel.getBounds() );
// System.out.println("[SummaryExtentFigure.paintOutline] SE Figure size: " + this.getBounds() );
// if ( getSomeMappingClassesAreVisible() == true ) {
// System.out.println("[SummaryExtentFigure.paintOutline] Should be Pointed Face - " + createDisplayString() );
// System.out.println("[SummaryExtentFigure.paintOutline] SE Figure size: " + this.getBounds() );
// System.out.println("[SummaryExtentFigure.paintOutline] pts.getPoint(2): " + pts.getPoint(2) );
// } else {
// System.out.println("[SummaryExtentFigure.paintOutline] Should be Flat Face - " + createDisplayString() );
// System.out.println("[SummaryExtentFigure.paintOutline] SE Figure size: " + this.getBounds() );
// System.out.println("[SummaryExtentFigure.paintOutline] pts.getPoint(2): " + pts.getPoint(2) );
// }
int orgX = this.getBounds().x;
int orgY = this.getBounds().y;
// System.out.println("[SummaryExtentFigure.paintOutline] point list size: " + pts.size() );
graphics.setLineWidth(1);
graphics.setForegroundColor(ColorConstants.buttonDarkest);
// System.out.println("[SummaryExtentFigure.paintOutline] About to call first drawLine " );
graphics.drawLine(orgX + pts.getPoint(0).x, orgY + pts.getPoint(0).y + 1, orgX + pts.getPoint(1).x, orgY + pts.getPoint(1).y + 1);
graphics.drawLine(orgX + pts.getPoint(1).x, orgY + pts.getPoint(1).y, orgX + pts.getPoint(2).x - 1, orgY + pts.getPoint(2).y);
graphics.setForegroundColor(ColorConstants.buttonDarkest);
graphics.drawLine(orgX + pts.getPoint(2).x - 1, orgY + pts.getPoint(2).y, orgX + pts.getPoint(3).x, orgY + pts.getPoint(3).y - 2);
graphics.drawLine(orgX + pts.getPoint(3).x, orgY + pts.getPoint(3).y - 2, orgX + pts.getPoint(4).x, orgY + pts.getPoint(4).y - 2);
// System.out.println("[SummaryExtentFigure.paintOutline] After calling drawLine 4 x" );
// jh experiment:
graphics.drawLine(orgX + pts.getPoint(4).x, orgY + pts.getPoint(4).y - 2, orgX + pts.getPoint(5).x, orgY + pts.getPoint(5).y - 2);
// System.out.println("[SummaryExtentFigure.paintOutline] BOT " );
}
Example 28
Project: gef-gwt-master File: FlyoutPaletteComposite.java View source code |
protected void paintFigure(Graphics graphics) {
// paint the gradient
graphics.pushState();
org.eclipse.draw2d.geometry.Rectangle r = org.eclipse.draw2d.geometry.Rectangle.SINGLETON;
r.setBounds(getBounds());
graphics.setForegroundColor(PaletteColorUtil.WIDGET_LIST_BACKGROUND);
graphics.setBackgroundColor(PaletteColorUtil.WIDGET_BACKGROUND);
graphics.fillGradient(r, true);
// draw bottom border
graphics.setForegroundColor(PaletteColorUtil.WIDGET_NORMAL_SHADOW);
graphics.drawLine(r.getBottomLeft().getTranslated(0, -1), r.getBottomRight().getTranslated(0, -1));
graphics.popState();
// paint the text and icon
super.paintFigure(graphics);
// paint the focus rectangle around the text
if (hasFocus()) {
org.eclipse.draw2d.geometry.Rectangle textBounds = getTextBounds();
// We reduce the width by 1 because FigureUtilities grows it by
// 1 unnecessarily
textBounds.width--;
graphics.drawFocus(bounds.getResized(-1, -1).intersect(textBounds.getExpanded(getInsets())));
}
}
Example 29
Project: savara-tools-eclipse-master File: GenerateImageAction.java View source code |
private void saveEditorContentsAsImage(IEditorPart editorPart, GraphicalViewer viewer, String saveFilePath, int format) { /* 1. First get the figure whose visuals we want to save as image. * So we would like to save the rooteditpart which actually hosts all the printable layers. * * NOTE: ScalableRootEditPart manages layers and is registered graphicalviewer's editpartregistry with * the key LayerManager.ID ... well that is because ScalableRootEditPart manages all layers that * are hosted on a FigureCanvas. Many layers exist for doing different things */ //ScalableRootEditPart rootEditPart = (ScalableRootEditPart)viewer.getEditPartRegistry().get(LayerManager.ID); org.eclipse.gef.editparts.LayerManager lm = (org.eclipse.gef.editparts.LayerManager) viewer.getEditPartRegistry().get(LayerManager.ID); IFigure rootFigure = lm.getLayer(LayerConstants.PRINTABLE_LAYERS); Rectangle rootFigureBounds = null; Rectangle additionalBounds = null; java.util.List children = null; if (lm instanceof org.eclipse.gef.RootEditPart) { org.eclipse.gef.EditPart ep = ((org.eclipse.gef.RootEditPart) lm).getContents(); if (ep instanceof ScenarioEditPart) { children = ep.getChildren(); rootFigureBounds = ((ScenarioEditPart) ep).getComponentBoundsWithoutIdentityDetails(); additionalBounds = ((ScenarioEditPart) ep).getIdentityDetailsBounds(); } } if (rootFigureBounds == null) { rootFigureBounds = rootFigure.getBounds(); } /* 2. Now we want to get the GC associated with the control on which all figures are * painted by SWTGraphics. For that first get the SWT Control associated with the viewer on which the * rooteditpart is set as contents */ Control figureCanvas = viewer.getControl(); GC figureCanvasGC = new GC(figureCanvas); /* 3. Create a new Graphics for an Image onto which we want to paint rootFigure */ Image img = new Image(null, rootFigureBounds.width, rootFigureBounds.height); GC imageGC = new GC(img); imageGC.setBackground(figureCanvasGC.getBackground()); imageGC.setForeground(figureCanvasGC.getForeground()); imageGC.setFont(figureCanvasGC.getFont()); imageGC.setLineStyle(figureCanvasGC.getLineStyle()); imageGC.setLineWidth(figureCanvasGC.getLineWidth()); imageGC.setXORMode(figureCanvasGC.getXORMode()); Graphics imgGraphics = new SWTGraphics(imageGC); /* 4. Draw rootFigure onto image. After that image will be ready for save */ rootFigure.paint(imgGraphics); /* 5. Save image */ ImageData[] imgData = new ImageData[1]; imgData[0] = img.getImageData(); ImageLoader imgLoader = new ImageLoader(); imgLoader.data = imgData; imgLoader.save(saveFilePath, format); /* release OS resources */ imageGC.dispose(); img.dispose(); if (additionalBounds != null && additionalBounds.width > 0 && additionalBounds.height > 0) { /* 3. Create a new Graphics for an Image onto which we want to paint rootFigure */ int width = additionalBounds.width; if (rootFigureBounds.width > width) { width = rootFigureBounds.width; } img = new Image(null, width, rootFigureBounds.height + additionalBounds.height); imageGC = new GC(img); imageGC.setBackground(figureCanvasGC.getBackground()); imageGC.setForeground(figureCanvasGC.getForeground()); imageGC.setFont(figureCanvasGC.getFont()); imageGC.setLineStyle(figureCanvasGC.getLineStyle()); imageGC.setLineWidth(figureCanvasGC.getLineWidth()); imageGC.setXORMode(figureCanvasGC.getXORMode()); imgGraphics = new SWTGraphics(imageGC); /* 4. Draw rootFigure onto image. After that image will be ready for save */ rootFigure.paint(imgGraphics); Image copy = new Image(null, additionalBounds.width, additionalBounds.height); imageGC.copyArea(copy, 0, rootFigureBounds.height); StringBuffer filepath = new StringBuffer(); filepath.append(saveFilePath); int ind = saveFilePath.lastIndexOf('.'); if (ind != -1) { filepath.insert(ind, "-ids"); } else { filepath.append("-ids"); } /* 5. Save image */ imgData = new ImageData[1]; imgData[0] = copy.getImageData(); imgLoader = new ImageLoader(); imgLoader.data = imgData; imgLoader.save(filepath.toString(), format); /* release OS resources */ figureCanvasGC.dispose(); imageGC.dispose(); img.dispose(); copy.dispose(); // Write message link information in tabular form //saveMessageLinkTable(editorPart, filepath.toString(), children); } figureCanvasGC.dispose(); }
Example 30
Project: spring-ide-master File: GraphEditor.java View source code |
/**
* Returns the bytes of an encoded image from this viewer.
* @param format one of SWT.IMAGE_BMP, SWT.IMAGE_BMP_RLE, SWT.IMAGE_GIF SWT.IMAGE_ICO, SWT.IMAGE_JPEG or
* SWT.IMAGE_PNG
* @return the bytes of an encoded image for the specified viewer
*/
public byte[] createImage(int format) {
ByteArrayOutputStream result = new ByteArrayOutputStream();
Device device = getGraphicalViewer().getControl().getDisplay();
LayerManager lm = (LayerManager) getGraphicalViewer().getEditPartRegistry().get(LayerManager.ID);
IFigure figure = lm.getLayer(LayerConstants.PRINTABLE_LAYERS);
Rectangle r = figure.getClientArea();
Image image = null;
GC gc = null;
Graphics g = null;
try {
image = new Image(device, 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();
}
Example 31
Project: ssSKB-master File: FlyoutPaletteComposite.java View source code |
protected void paintFigure(Graphics graphics) {
// paint the gradient
graphics.pushState();
org.eclipse.draw2d.geometry.Rectangle r = org.eclipse.draw2d.geometry.Rectangle.SINGLETON;
r.setBounds(getBounds());
graphics.setForegroundColor(PaletteColorUtil.WIDGET_LIST_BACKGROUND);
graphics.setBackgroundColor(PaletteColorUtil.WIDGET_BACKGROUND);
graphics.fillGradient(r, true);
// draw bottom border
graphics.setForegroundColor(PaletteColorUtil.WIDGET_NORMAL_SHADOW);
graphics.drawLine(r.getBottomLeft().getTranslated(0, -1), r.getBottomRight().getTranslated(0, -1));
graphics.popState();
// paint the text and icon
super.paintFigure(graphics);
// paint the focus rectangle around the text
if (hasFocus()) {
org.eclipse.draw2d.geometry.Rectangle textBounds = getTextBounds();
// We reduce the width by 1 because FigureUtilities grows it by 1 unnecessarily
textBounds.width--;
graphics.drawFocus(bounds.getResized(-1, -1).intersect(textBounds.getExpanded(getInsets())));
}
}
Example 32
Project: starschema-talend-plugins-master File: AbstractTalendEditor.java View source code |
/**
* 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
int width = contentLayer.getSize().width;
int height = contentLayer.getSize().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.setScreenshot(ImageUtils.saveImageToData(img));
img.dispose();
// service.getProxyRepositoryFactory().refreshJobPictureFolder(outlinePicturePath);
GlobalConstant.generatingScreenShoot = false;
}
Example 33
Project: iee-master File: ChartFigure.java View source code |
@Override
protected void paintClientArea(Graphics graphics) {
// first determine the size of the chart rendering area...
// TODO workout insets for SWT
org.eclipse.draw2d.geometry.Rectangle available = getBounds();
// skip if chart is null
if (this.chart == null) {
graphics.drawRectangle(available.x, available.y, available.width, available.height);
return;
}
// work out if scaling is required...
int drawWidth = available.width;
int drawHeight = available.height;
if (drawWidth == 0.0 || drawHeight == 0.0)
return;
this.scaleX = 1.0;
this.scaleY = 1.0;
if (drawWidth < this.minimumDrawWidth) {
this.scaleX = (double) drawWidth / this.minimumDrawWidth;
drawWidth = this.minimumDrawWidth;
} else if (drawWidth > this.maximumDrawWidth) {
this.scaleX = (double) drawWidth / this.maximumDrawWidth;
drawWidth = this.maximumDrawWidth;
}
if (drawHeight < this.minimumDrawHeight) {
this.scaleY = (double) drawHeight / this.minimumDrawHeight;
drawHeight = this.minimumDrawHeight;
} else if (drawHeight > this.maximumDrawHeight) {
this.scaleY = (double) drawHeight / this.maximumDrawHeight;
drawHeight = this.maximumDrawHeight;
}
org.eclipse.draw2d.geometry.Rectangle bounds = getBounds();
graphics.translate(bounds.x, bounds.y);
renderer.prepareRendering(graphics);
Graphics2D graphics2d = renderer.getGraphics2D();
this.chart.draw(graphics2d, new Rectangle2D.Double(0, 0, bounds.width, bounds.height), getAnchor(), this.info);
renderer.render(graphics);
graphics.translate(-bounds.x, -bounds.y);
Rectangle area = getScreenDataArea();
if (this.horizontalAxisTrace && area.x < this.verticalTraceLineX && area.x + area.width > this.verticalTraceLineX) {
graphics.drawLine(this.verticalTraceLineX, area.y, this.verticalTraceLineX, area.y + area.height);
}
if (this.verticalAxisTrace && area.y < this.horizontalTraceLineY && area.y + area.height > this.horizontalTraceLineY) {
graphics.drawLine(area.x, this.horizontalTraceLineY, area.x + area.width, this.horizontalTraceLineY);
}
this.verticalTraceLineX = 0;
this.horizontalTraceLineY = 0;
if (this.zoomRectangle != null) {
graphics.drawRectangle(this.zoomRectangle);
}
}
Example 34
Project: monticore-master File: ImageSaveUtil.java View source code |
private static void saveEditorContentsAsImage(IEditorPart editorPart, GraphicalViewer viewer, String saveFilePath, int format) { /* * 1. First get the figure whose visuals we want to save as image. So we * would like to save the rooteditpart which actually hosts all the * printable layers. NOTE: ScalableRootEditPart manages layers and is * registered graphicalviewer's editpartregistry with the key * LayerManager.ID ... well that is because ScalableRootEditPart manages all * layers that are hosted on a FigureCanvas. Many layers exist for doing * different things */ ScalableRootEditPart rootEditPart = (ScalableRootEditPart) viewer.getEditPartRegistry().get(LayerManager.ID); // rootEditPart.getFigure(); IFigure rootFigure = ((LayerManager) rootEditPart).getLayer(LayerConstants.PRINTABLE_LAYERS); Rectangle rootFigureBounds = rootFigure.getBounds(); /* * 2. Now we want to get the GC associated with the control on which all * figures are painted by SWTGraphics. For that first get the SWT Control * associated with the viewer on which the rooteditpart is set as contents */ Control figureCanvas = viewer.getControl(); GC figureCanvasGC = new GC(figureCanvas); /* * 3. Create a new Graphics for an Image onto which we want to paint * rootFigure */ Image img = new Image(null, rootFigureBounds.width, rootFigureBounds.height); GC imageGC = new GC(img); imageGC.setBackground(figureCanvasGC.getBackground()); imageGC.setForeground(figureCanvasGC.getForeground()); imageGC.setFont(figureCanvasGC.getFont()); imageGC.setLineStyle(figureCanvasGC.getLineStyle()); imageGC.setLineWidth(figureCanvasGC.getLineWidth()); // imageGC.setXORMode(figureCanvasGC.getXORMode()); Graphics imgGraphics = new SWTGraphics(imageGC); /* 4. Draw rootFigure onto image. After that image will be ready for save */ rootFigure.paint(imgGraphics); /* 5. Save image */ ImageData[] imgData = new ImageData[1]; imgData[0] = img.getImageData(); ImageLoader imgLoader = new ImageLoader(); imgLoader.data = imgData; imgLoader.save(saveFilePath, format); /* release OS resources */ figureCanvasGC.dispose(); imageGC.dispose(); img.dispose(); }
Example 35
Project: petals-studio-master File: ExportDiagramAction.java View source code |
/*
* (non-Jsdoc)
* @see org.eclipse.jface.action.Action
* #run()
*/
@Override
public void run() {
// Determine the export location
FileDialog dlg = new FileDialog(new Shell(), SWT.SAVE);
dlg.setText("Image Export");
dlg.setOverwrite(true);
dlg.setFilterNames(new String[] { "JPEG Files (*.jpg)", "PNG Files (*.png)", "GIF Files (*.gif)" });
String[] extensions = new String[] { "*.jpg", "*.png", "*.gif" };
dlg.setFilterExtensions(extensions);
String path = dlg.open();
if (path != null) {
String ext = extensions[dlg.getFilterIndex()].substring(1);
if (!path.endsWith(ext))
path += ext;
// Only print printable layers
ScalableFreeformRootEditPart rootEditPart = (ScalableFreeformRootEditPart) this.graphicalViewer.getEditPartRegistry().get(LayerManager.ID);
IFigure rootFigure = ((LayerManager) rootEditPart).getLayer(LayerConstants.PRINTABLE_LAYERS);
IFigure eipChainFigure = null;
for (Object o : rootFigure.getChildren()) {
if (o instanceof FreeformLayer)
eipChainFigure = (FreeformLayer) o;
}
Rectangle bounds = eipChainFigure == null ? rootFigure.getBounds() : eipChainFigure.getBounds();
GC figureCanvasGC = new GC(this.graphicalViewer.getControl());
// Add 20 pixels to write the title of the diagram on the image
Image img = new Image(null, bounds.width, bounds.height);
GC gc = new GC(img);
gc.setBackground(figureCanvasGC.getBackground());
gc.setForeground(figureCanvasGC.getForeground());
gc.setFont(figureCanvasGC.getFont());
gc.setLineStyle(figureCanvasGC.getLineStyle());
gc.setLineWidth(figureCanvasGC.getLineWidth());
Graphics imgGraphics = new SWTGraphics(gc);
// Paint it...
rootFigure.paint(imgGraphics);
// Prepare the next step
Font font = new Font(Display.getCurrent(), "Arial", 14, SWT.BOLD);
gc.setFont(font);
int height = Dialog.convertHeightInCharsToPixels(gc.getFontMetrics(), 1);
gc.dispose();
// Create a second image with the title and diagram version
// Write the title and its border
bounds.height += height + (height % 2 == 0 ? 6 : 7);
// Add a border + some margin
bounds.height += 3 * BORDER_MARGIN_UPDOWN + 2;
// Add a border
bounds.width += 2 * BORDER_MARGIN_SIDES + 2;
Image finalImg = new Image(null, bounds.width, bounds.height);
gc = new GC(finalImg);
// Draw a surrounding border
gc.setAntialias(SWT.ON);
gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
gc.drawLine(BORDER_MARGIN_SIDES, BORDER_MARGIN_UPDOWN, BORDER_MARGIN_SIDES, bounds.height - BORDER_MARGIN_UPDOWN);
gc.drawLine(BORDER_MARGIN_SIDES, bounds.height - BORDER_MARGIN_UPDOWN, bounds.width - BORDER_MARGIN_SIDES, bounds.height - BORDER_MARGIN_UPDOWN);
gc.drawLine(BORDER_MARGIN_SIDES, BORDER_MARGIN_UPDOWN, bounds.width - BORDER_MARGIN_SIDES, BORDER_MARGIN_UPDOWN);
gc.drawLine(bounds.width - BORDER_MARGIN_SIDES, BORDER_MARGIN_UPDOWN, bounds.width - BORDER_MARGIN_SIDES, bounds.height - BORDER_MARGIN_UPDOWN);
// Draw the title
gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
gc.setFont(font);
gc.setClipping((Region) null);
gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
String title = this.eipChain.getTitle() != null ? this.eipChain.getTitle() : "No diagram title";
if (!StringUtils.isEmpty(this.eipChain.getVersion()))
title += " - Version " + this.eipChain.getVersion().trim();
int width = Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), title.length());
if (width > bounds.width) {
title = Dialog.shortenText(title, this.graphicalViewer.getControl());
width = Dialog.convertWidthInCharsToPixels(gc.getFontMetrics(), title.length());
}
gc.drawText(title, 6 + BORDER_MARGIN_SIDES, 4 + BORDER_MARGIN_UPDOWN, true);
// Draw a surrounding shape for the title
gc.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
Rectangle titleRectangle = new Rectangle(BORDER_MARGIN_SIDES, BORDER_MARGIN_UPDOWN, BORDER_MARGIN_SIDES + width + (width % 2 == 0 ? 10 : 11), BORDER_MARGIN_UPDOWN + height + (height % 2 == 0 ? 6 : 7));
final int arrowPadding = (titleRectangle.height + bounds.y) / 2;
gc.drawLine(titleRectangle.x, titleRectangle.height, titleRectangle.width, titleRectangle.height);
gc.drawLine(titleRectangle.width, titleRectangle.y, titleRectangle.width + arrowPadding, arrowPadding);
gc.drawLine(titleRectangle.width, titleRectangle.height, titleRectangle.width + arrowPadding, arrowPadding);
// Draw the image
gc.drawImage(img, BORDER_MARGIN_SIDES + 1, BORDER_MARGIN_UPDOWN + titleRectangle.height + 1);
// Save the second image
ImageData[] imgData = new ImageData[1];
imgData[0] = finalImg.getImageData();
int format;
String tail = path.toLowerCase().substring(path.length() - 4);
if (tail.endsWith(".jpg"))
format = SWT.IMAGE_JPEG;
else if (tail.endsWith(".png"))
format = SWT.IMAGE_PNG;
else
format = SWT.IMAGE_GIF;
ImageLoader imgLoader = new ImageLoader();
imgLoader.data = imgData;
imgLoader.save(path, format);
// Dispose everything
figureCanvasGC.dispose();
gc.dispose();
img.dispose();
finalImg.dispose();
font.dispose();
}
}
Example 36
Project: ASEME-master File: HyperlinkFigure.java View source code |
protected void paintFigure(Graphics graphics) {
Color color = graphics.getForegroundColor();
if (action.isEnabled()) {
graphics.setForegroundColor(ColorConstants.blue);
} else {
graphics.setForegroundColor(ColorConstants.gray);
}
super.paintFigure(graphics);
if (underlined) {
Rectangle bounds = getBounds();
int y = bounds.y + bounds.height - 1;
graphics.drawLine(bounds.x, y, bounds.x + bounds.width, y);
}
graphics.setForegroundColor(color);
}
Example 37
Project: bpel-master File: ProcessEditPart.java View source code |
public void switchLayout(boolean horizontal) {
AlignedFlowLayout handlerLayout = (AlignedFlowLayout) handlerHolder.getLayoutManager();
handlerLayout.setHorizontal(!horizontal);
// Adjust the layout of the activityAndHandlerHolder
((AlignedFlowLayout) activityAndHandlerHolder.getLayoutManager()).setHorizontal(horizontal);
// Adjust the layout of the activityHolder
((AlignedFlowLayout) activityHolder.getLayoutManager()).setHorizontal(horizontal);
// Remove the LayoutPolicy which is responsible for creating the implicit links
removeEditPolicy(EditPolicy.LAYOUT_ROLE);
if (horizontal) {
// Handler Holder layout
handlerLayout.setSecondaryAlignment(AlignedFlowLayout.ALIGN_BEGIN);
// If we are in horizontal mode we add a top margin
activityAndHandlerHolder.setBorder(new MarginBorder(20, 20, 0, 20));
this.handlerHolder.setBorder(new MarginBorder(0, 20, 0, 0));
installEditPolicy(EditPolicy.LAYOUT_ROLE, new ProcessOrderedHorizontalLayoutEditPolicy());
} else {
// Handler Holder layout
handlerLayout.setSecondaryAlignment(AlignedFlowLayout.ALIGN_BEGIN);
// If we are in horizontal mode we remove the border
activityAndHandlerHolder.setBorder(null);
this.handlerHolder.setBorder(new AbstractBorder() {
public Insets getInsets(IFigure arg0) {
return new Insets(20, 0, 10, 0);
}
public void paint(IFigure arg0, Graphics arg1, Insets arg2) {
}
});
installEditPolicy(EditPolicy.LAYOUT_ROLE, new ProcessOrderedLayoutEditPolicy());
}
}
Example 38
Project: EPF-Composer-master File: WrappableLabel.java View source code |
/** * @see Figure#paintFigure(Graphics) */ protected void paintFigure(Graphics graphics) { if (isSelected()) { graphics.pushState(); graphics.setBackgroundColor(ColorConstants.menuBackgroundSelected); graphics.fillRectangle(getSelectionRectangle()); graphics.popState(); graphics.setForegroundColor(ColorConstants.white); } if (hasFocus()) { graphics.pushState(); graphics.setXORMode(true); graphics.setForegroundColor(ColorConstants.menuBackgroundSelected); graphics.setBackgroundColor(ColorConstants.white); graphics.drawFocus(getSelectionRectangle().resize(-1, -1)); graphics.popState(); } if (isOpaque()) super.paintFigure(graphics); Rectangle bounds = getBounds(); graphics.translate(bounds.x, bounds.y); if (icon != null) graphics.drawImage(icon, getIconLocation()); if (!isEnabled()) { graphics.translate(1, 1); graphics.setForegroundColor(ColorConstants.buttonLightest); graphicsdrawText(graphics); graphics.drawText(getSubStringText(), getTextLocation()); graphics.translate(-1, -1); graphics.setForegroundColor(ColorConstants.buttonDarker); } graphicsdrawText(graphics); graphics.translate(-bounds.x, -bounds.y); }
Example 39
Project: gda-dal-master File: AbstractChartFigure.java View source code |
@Override
protected void draw(final Graphics g, final Point p) {
// #
// ###
// #####
// ###
// #
// Note: the call to drawPolygon is required because otherwise
// for some reason the polygon drawn by fillPolygon is a bit
// too small (the right edge is drawn one pixel to the left).
g.drawPolygon(new int[] { p.x - 2, p.y, p.x, p.y - 2, p.x + 2, p.y, p.x, p.y + 2 });
g.fillPolygon(new int[] { p.x - 2, p.y, p.x, p.y - 2, p.x + 2, p.y, p.x, p.y + 2 });
}
Example 40
Project: gmf-tooling.uml2tools-master File: CollaborationUse2EditPart.java View source code |
/**
* @NOT-generated
*/
@Override
public void paintFigure(Graphics graphics) {
Rectangle r = getBounds().getCopy();
double a = r.width / 2;
double b = r.height / 2;
double sin45 = Math.sqrt(2) / 2;
double cos45 = sin45;
double diagx = a * sin45;
double diagy = b * cos45;
int newxmargin = (int) (a - diagx);
int newymargin = (int) (b - diagy);
if (newxmargin != myXMargin || newymargin != myYMargin) {
myXMargin = newxmargin;
myYMargin = newymargin;
setBorder(new MarginBorder(myYMargin, myXMargin, myYMargin, myXMargin));
}
super.paintFigure(graphics);
}
Example 41
Project: javadude-master File: DependencyEditPart.java View source code |
@Override
protected void refreshVisuals() {
Dependency dependency = (Dependency) getModel();
if (!dependency.isExported()) {
((PolylineConnection) getFigure()).setLineStyle(Graphics.LINE_DOT);
lineColor = DependencyEditPart.PINK;
}
if (DependencyManager.indirectPathExists(dependency, dependency.getSource(), dependency.getTarget())) {
lineColor = DependencyEditPart.WHITE;
}
figure.setForegroundColor(DependenciesPlugin.getDefault().getColor(lineColor));
}
Example 42
Project: jbosstools-hibernate-master File: ExportImageAction.java View source code |
/***
* Returns the bytes of an encoded image for the specified
* IFigure in the specified format.
*
* @param figure the Figure to create an image for.
* @param format one of SWT.IMAGE_BMP, SWT.IMAGE_BMP_RLE, SWT.IMAGE_GIF
* SWT.IMAGE_ICO, SWT.IMAGE_JPEG, or SWT.IMAGE_PNG
* @return the bytes of an encoded image for the specified Figure
*/
private byte[] createImage(IFigure figure, int format) {
//Device device = getDiagramViewer().getEditPartViewer().getControl()
// .getDisplay();
Device device = null;
Rectangle r = figure.getBounds();
ByteArrayOutputStream result = new ByteArrayOutputStream();
Image image = null;
GC gc = null;
Graphics g = null;
try {
image = new Image(device, 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);
} catch (Throwable e) {
HibernateConsolePlugin.getDefault().logErrorMessage("ExportImageAction - save:", e);
} finally {
if (g != null) {
g.dispose();
}
if (gc != null) {
gc.dispose();
}
if (image != null) {
image.dispose();
}
}
return result.toByteArray();
}
Example 43
Project: jbosstools-javaee-master File: JSFEditor.java View source code |
public void run() {
GraphicalViewer viewer;
viewer = (GraphicalViewer) getWorkbenchPart().getAdapter(GraphicalViewer.class);
PrintPreviewDialog d = new PrintPreviewDialog(this.getWorkbenchPart().getSite().getShell(), SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
d.setPrintViewer(viewer);
d.setEditor(JSFEditor.this);
Printer printer = new Printer();
Exception ex = null;
try {
printer.getDPI();
} catch (SWTException ee) {
ex = ee;
printer.dispose();
d = null;
Status status = new Status(IStatus.ERROR, "org.jboss.tools.jsf.ui", 0, WizardKeys.getString("PRN_ERROR"), ee);
LogHelper.logError(JsfUiPlugin.PLUGIN_ID, ee);
}
//if ex is not null then d is set to null and we cannot access it.
if (ex == null) {
d.setPages(new Pages(viewer, new PageFormat(printer, this.getWorkbenchPart().getSite().getShell().getDisplay())));
String result = d.open();
if (//$NON-NLS-1$
result != null && result.equals("ok")) {
LayerManager lm = (LayerManager) viewer.getEditPartRegistry().get(LayerManager.ID);
IFigure figure = lm.getLayer(LayerConstants.PRINTABLE_LAYERS);
PrintDialog dialog = new PrintDialog(viewer.getControl().getShell(), SWT.NULL);
PrinterData data = dialog.open();
if (data != null) {
printer = new Printer(data);
double scale = d.getPages().getScale();
double dpiScale = printer.getDPI().x / Display.getCurrent().getDPI().x;
GC printerGC = new GC(printer);
SWTGraphics g = new SWTGraphics(printerGC);
Graphics graphics = new PrinterGraphics(g, printer);
if (printer.startJob(getWorkbenchPart().getTitle())) {
Pages p = d.getPages();
for (int i = 0; i < p.getNumberOfPages(); i++) {
if (printer.startPage()) {
graphics.pushState();
Page pg = p.getPrintable(i);
Rectangle r1 = pg.getRectangle();
Rectangle r = new Rectangle(r1.x + p.ix, r1.y + p.iy, r1.width, r1.height);
org.eclipse.draw2d.geometry.Rectangle clipRect = new org.eclipse.draw2d.geometry.Rectangle();
graphics.translate(-(int) (r.x * dpiScale * scale), -(int) (r.y * dpiScale * scale));
graphics.getClip(clipRect);
clipRect.setLocation((int) (r.x * dpiScale * scale), (int) (r.y * dpiScale * scale));
graphics.clipRect(clipRect);
graphics.scale(dpiScale * scale);
figure.paint(graphics);
graphics.popState();
printer.endPage();
}
}
graphics.dispose();
printer.endJob();
}
}
}
}
}
Example 44
Project: jbosstools-jbpm-master File: NodeFigure.java View source code |
protected void paintBorder(Graphics graphics) {
Rectangle bounds = getBounds().getCopy();
Point origin = bounds.getLocation();
int height = bounds.height;
int width = bounds.width;
graphics.translate(origin);
graphics.setForegroundColor(ColorConstants.lightGray);
graphics.drawLine(0, 0, width - 2, 0);
graphics.drawLine(width - 2, 0, width - 2, height - 2);
graphics.drawLine(width - 2, height - 2, 0, height - 2);
graphics.drawLine(0, height - 2, 0, 0);
graphics.setForegroundColor(Constants.veryLightGray);
graphics.drawLine(width - 1, 1, width - 1, height - 1);
graphics.drawLine(width - 1, height - 1, 1, height - 1);
}
Example 45
Project: melanee-core-master File: CustomBorder.java View source code |
/** * @see org.eclipse.draw2d.Border#paint(IFigure, Graphics, Insets) */ public void paint(IFigure figure, Graphics graphics, Insets insets) { tempRect.setBounds(getPaintRectangle(figure, insets)); if (getWidth() % 2 == 1) { tempRect.width--; tempRect.height--; } tempRect.shrink(getWidth() / 2, getWidth() / 2); graphics.setLineWidth(getWidth()); graphics.setLineStyle(getStyle()); if (getColor() != null) graphics.setForegroundColor(getColor()); graphics.setForegroundColor(PlatformUI.getWorkbench().getDisplay().getSystemColor(SWT.COLOR_BLACK)); if (bottom) graphics.drawLine(tempRect.getBottomLeft(), tempRect.getBottomRight()); if (top) graphics.drawLine(tempRect.getTopLeft(), tempRect.getTopRight()); if (left) graphics.drawLine(tempRect.getTopLeft(), tempRect.getBottomLeft()); if (right) graphics.drawLine(tempRect.getTopRight(), tempRect.getBottomRight()); }
Example 46
Project: MMI-master File: TaskFigure.java View source code |
@Override
public void paint(Graphics graphics) {
Rectangle r = getBounds();
// Define the points of a diamond
Point p1 = new Point(r.x, r.y + r.height / 2);
Point p2 = new Point(r.x + r.width / 4, r.y + r.height - 1);
Point p3 = new Point(r.x + r.width / 4 + r.width / 2, r.y + r.height - 1);
Point p4 = new Point(r.x + r.width - 1, r.y + r.height / 2);
Point p5 = new Point(r.x + r.width / 4 + r.width / 2, r.y);
Point p6 = new Point(r.x + r.width / 4, r.y);
PointList pointList = new PointList();
pointList.addPoint(p1);
pointList.addPoint(p2);
pointList.addPoint(p3);
pointList.addPoint(p4);
pointList.addPoint(p5);
pointList.addPoint(p6);
// Fill the shape
graphics.fillPolygon(pointList);
graphics.setLineWidth(1);
// Draw the outline
graphics.drawLine(p1, p2);
graphics.drawLine(p2, p3);
graphics.drawLine(p3, p4);
graphics.drawLine(p4, p5);
graphics.drawLine(p5, p6);
graphics.drawLine(p6, p1);
for (int i = 0; i < getChildren().size(); i++) {
WrappingLabel label = (WrappingLabel) getChildren().get(i);
label.paint(graphics);
}
}
Example 47
Project: MMINT-master File: TaskFigure.java View source code |
@Override
public void paint(Graphics graphics) {
Rectangle r = getBounds();
// Define the points of a diamond
Point p1 = new Point(r.x, r.y + r.height / 2);
Point p2 = new Point(r.x + r.width / 4, r.y + r.height - 1);
Point p3 = new Point(r.x + r.width / 4 + r.width / 2, r.y + r.height - 1);
Point p4 = new Point(r.x + r.width - 1, r.y + r.height / 2);
Point p5 = new Point(r.x + r.width / 4 + r.width / 2, r.y);
Point p6 = new Point(r.x + r.width / 4, r.y);
PointList pointList = new PointList();
pointList.addPoint(p1);
pointList.addPoint(p2);
pointList.addPoint(p3);
pointList.addPoint(p4);
pointList.addPoint(p5);
pointList.addPoint(p6);
// Fill the shape
graphics.fillPolygon(pointList);
graphics.setLineWidth(1);
// Draw the outline
graphics.drawLine(p1, p2);
graphics.drawLine(p2, p3);
graphics.drawLine(p3, p4);
graphics.drawLine(p4, p5);
graphics.drawLine(p5, p6);
graphics.drawLine(p6, p1);
for (int i = 0; i < getChildren().size(); i++) {
WrappingLabel label = (WrappingLabel) getChildren().get(i);
label.paint(graphics);
}
}
Example 48
Project: nebula-master File: Trace.java View source code |
private void drawErrorBar(Graphics graphics, Point dpPos, ISample dp) {
graphics.pushState();
graphics.setForegroundColor(errorBarColor);
graphics.setLineStyle(SWTConstants.LINE_SOLID);
graphics.setLineWidth(1);
Point ep;
switch(yErrorBarType) {
case BOTH:
case MINUS:
ep = new Point(xAxis.getValuePosition(dp.getXValue(), false), yAxis.getValuePosition(dp.getYValue() - dp.getYMinusError(), false));
graphics.drawLine(dpPos, ep);
graphics.drawLine(ep.x - errorBarCapWidth / 2, ep.y, ep.x + errorBarCapWidth / 2, ep.y);
if (yErrorBarType != ErrorBarType.BOTH)
break;
case PLUS:
ep = new Point(xAxis.getValuePosition(dp.getXValue(), false), yAxis.getValuePosition(dp.getYValue() + dp.getYPlusError(), false));
graphics.drawLine(dpPos, ep);
graphics.drawLine(ep.x - errorBarCapWidth / 2, ep.y, ep.x + errorBarCapWidth / 2, ep.y);
break;
default:
break;
}
switch(xErrorBarType) {
case BOTH:
case MINUS:
ep = new Point(xAxis.getValuePosition(dp.getXValue() - dp.getXMinusError(), false), yAxis.getValuePosition(dp.getYValue(), false));
graphics.drawLine(dpPos, ep);
graphics.drawLine(ep.x, ep.y - errorBarCapWidth / 2, ep.x, ep.y + errorBarCapWidth / 2);
if (xErrorBarType != ErrorBarType.BOTH)
break;
case PLUS:
ep = new Point(xAxis.getValuePosition(dp.getXValue() + dp.getXPlusError(), false), yAxis.getValuePosition(dp.getYValue(), false));
graphics.drawLine(dpPos, ep);
graphics.drawLine(ep.x, ep.y - errorBarCapWidth / 2, ep.x, ep.y + errorBarCapWidth / 2);
break;
default:
break;
}
graphics.popState();
}
Example 49
Project: olca-app-master File: ProcessFigure.java View source code |
@Override
protected void paintFigure(Graphics graphics) {
graphics.pushState();
graphics.setBackgroundColor(ColorConstants.white);
graphics.fillRectangle(new Rectangle(getLocation(), getSize()));
paintTop(graphics);
if (!node.isMinimized() || Animation.isRunning())
paintTable(graphics);
graphics.popState();
super.paintFigure(graphics);
}
Example 50
Project: org.eclipse.bpel-master File: ProcessEditPart.java View source code |
public void switchLayout(boolean horizontal) {
AlignedFlowLayout handlerLayout = (AlignedFlowLayout) handlerHolder.getLayoutManager();
handlerLayout.setHorizontal(!horizontal);
// Adjust the layout of the activityAndHandlerHolder
((AlignedFlowLayout) activityAndHandlerHolder.getLayoutManager()).setHorizontal(horizontal);
// Adjust the layout of the activityHolder
((AlignedFlowLayout) activityHolder.getLayoutManager()).setHorizontal(horizontal);
// Remove the LayoutPolicy which is responsible for creating the implicit links
removeEditPolicy(EditPolicy.LAYOUT_ROLE);
if (horizontal) {
// Handler Holder layout
handlerLayout.setSecondaryAlignment(AlignedFlowLayout.ALIGN_BEGIN);
// If we are in horizontal mode we add a top margin
activityAndHandlerHolder.setBorder(new MarginBorder(20, 20, 0, 20));
this.handlerHolder.setBorder(new MarginBorder(0, 20, 0, 0));
installEditPolicy(EditPolicy.LAYOUT_ROLE, new ProcessOrderedHorizontalLayoutEditPolicy());
} else {
// Handler Holder layout
handlerLayout.setSecondaryAlignment(AlignedFlowLayout.ALIGN_BEGIN);
// If we are in horizontal mode we remove the border
activityAndHandlerHolder.setBorder(null);
this.handlerHolder.setBorder(new AbstractBorder() {
public Insets getInsets(IFigure arg0) {
return new Insets(20, 0, 10, 0);
}
public void paint(IFigure arg0, Graphics arg1, Insets arg2) {
}
});
installEditPolicy(EditPolicy.LAYOUT_ROLE, new ProcessOrderedLayoutEditPolicy());
}
}
Example 51
Project: Reuseware-master File: PortInstanceEditPart.java View source code |
private void setColors(IFigure shape) { setBackgroundColor(ColorConstants.white); if (!(shape instanceof PortInstanceFigure)) { return; } PortInstanceFigure figure = (PortInstanceFigure) shape; PortInstance port = (PortInstance) ((Node) getModel()).getElement(); if (port.canContribute()) { figure.setForegroundColor(ColorConstants.black); figure.setLineStyle(Graphics.LINE_SOLID); } else if (port.canReceive()) { figure.setForegroundColor(ColorConstants.black); figure.setLineStyle(Graphics.LINE_SOLID); } else /*configuring*/ { figure.setForegroundColor(ColorConstants.black); figure.setLineStyle(Graphics.LINE_DOT); } if (port.port() == null) { figure.setForegroundColor(ColorConstants.darkGray); } }
Example 52
Project: sapphire-master File: ContextButtonPad.java View source code |
// ============================== painting ================================ /** * Outlines this Shape on the given Graphics. This will draw the paths * {@link #pathInnerLine}, {@link #pathMiddleLine} and * {@link #pathOuterLine}. * * @param graphics * The Graphics on which to outline this Shape. */ @Override protected void outlineShape(Graphics graphics) { int lw = (int) (getZoomLevel() * getDeclaration().getPadLineWidth()); graphics.setLineWidth(lw); graphics.setForegroundColor(getEditor().getResourceCache().getColor(getDeclaration().getPadInnerLineColor())); graphics.drawPath(pathInnerLine); graphics.setForegroundColor(getEditor().getResourceCache().getColor(getDeclaration().getPadMiddleLineColor())); graphics.drawPath(pathMiddleLine); graphics.setForegroundColor(getEditor().getResourceCache().getColor(getDeclaration().getPadOuterLineColor())); graphics.drawPath(pathOuterLine); }
Example 53
Project: smooks-editor-master File: FreemarkerCSVNodeEditPart.java View source code |
/* * (non-Javadoc) * * @see * org.jboss.tools.smooks.gef.tree.editparts.TreeNodeEditPart#createFigure() */ @Override protected IFigure createFigure() { CSVNodeModel node = (CSVNodeModel) ((AbstractSmooksGraphicalModel) getModel()).getData(); if (node.isRecord()) { IFigure figure = new TreeNodeFigure((TreeNodeModel) getModel()) { /* * (non-Javadoc) * * @see * org.jboss.tools.smooks.gef.tree.figures.TreeNodeFigure#initFigure * () */ @Override protected void initFigure() { super.initFigure(); SPACE_INT = 0; CLICKNODE_HEIGHT = 0; CLICKNODE_WIDTH = 0; expand = true; } /* * (non-Javadoc) * * @seeorg.jboss.tools.smooks.gef.tree.figures.TreeNodeFigure# * getPreferredSize(int, int) */ @Override public Dimension getPreferredSize(int hint, int hint2) { expand = true; return super.getPreferredSize(hint, hint2); } /* * (non-Javadoc) * * @seeorg.jboss.tools.smooks.gef.tree.figures.TreeNodeFigure# * createLabelContainerLayout() */ @Override protected LayoutManager createLabelContainerLayout() { ToolbarLayout tl = new ToolbarLayout(); tl.setVertical(false); tl.setMinorAlignment(ToolbarLayout.ALIGN_BOTTOMRIGHT); return tl; } /* * (non-Javadoc) * * @seeorg.jboss.tools.smooks.gef.tree.figures.TreeNodeFigure# * drawClickFigure(org.eclipse.draw2d.IFigure, * org.eclipse.draw2d.Graphics) */ @Override protected void drawClickFigure(IFigure clickFigure, Graphics graphics) { } /* * (non-Javadoc) * * @seeorg.jboss.tools.smooks.gef.tree.figures.TreeNodeFigure# * needClickFigure() */ @Override protected boolean needClickFigure() { Object data = this.getModel().getData(); if (data instanceof CSVNodeModel) { if (((CSVNodeModel) data).isRecord()) { return true; } } return false; } /* * (non-Javadoc) * * @seeorg.jboss.tools.smooks.gef.tree.figures.TreeNodeFigure# * needSpaceFigure() */ @Override protected boolean needSpaceFigure() { Object data = this.getModel().getData(); if (data instanceof CSVNodeModel) { if (((CSVNodeModel) data).isRecord()) { return true; } } return false; } /* * (non-Javadoc) * * @seeorg.jboss.tools.smooks.gef.tree.figures.TreeNodeFigure# * createContentFigureLayout() */ @Override protected ToolbarLayout createContentFigureLayout() { ToolbarLayout layout = super.createContentFigureLayout(); layout.setVertical(true); return layout; } /* * (non-Javadoc) * * @seeorg.jboss.tools.smooks.gef.tree.figures.TreeNodeFigure# * createTreeNodeFigureLayout() */ @Override protected ToolbarLayout createTreeNodeFigureLayout() { ToolbarLayout layout = super.createTreeNodeFigureLayout(); // layout.setSpacing(5); layout.setMinorAlignment(ToolbarLayout.ALIGN_CENTER); return layout; } /* * (non-Javadoc) * * @seeorg.jboss.tools.smooks.gef.tree.figures.TreeNodeFigure# * collapsedNode() */ @Override public void collapsedNode() { } /* * (non-Javadoc) * * @see * org.jboss.tools.smooks.gef.tree.figures.TreeNodeFigure#expandNode * () */ @Override public void expandNode() { } }; return figure; } return super.createFigure(); }
Example 54
Project: snaker-designer-master File: FieldBorder.java View source code |
public void paint(IFigure figure, Graphics graphics, Insets insets) {
Rectangle bounds = figure.getBounds();
Rectangle r = new Rectangle(bounds.x, bounds.y, this.grabBarWidth, bounds.height);
AbstractBorder.tempRect.setBounds(r);
graphics.setBackgroundColor(ColorUtils.Blue);
graphics.setForegroundColor(ColorUtils.xorGate);
graphics.fillRectangle(AbstractBorder.tempRect);
figure.setOpaque(false);
int i = AbstractBorder.tempRect.bottom() - AbstractBorder.tempRect.height / 2;
graphics.drawText(getText(), AbstractBorder.tempRect.x + this.BLANK_SPACES, i - this.WORD_HEIGHT);
super.paint(figure, graphics, insets);
}
Example 55
Project: webtools.sourceediting-master File: TopLevelComponentEditPart.java View source code |
public void paint(Graphics graphics) {
super.paint(graphics);
if (hasFocus) {
try {
graphics.pushState();
Rectangle r = getBounds();
graphics.setXORMode(true);
graphics.drawFocus(r.x, r.y + 1, r.width - 1, r.height - 2);
} finally {
graphics.popState();
}
}
}
Example 56
Project: whole-master File: FramesPartFactoryVisitor.java View source code |
@Override
public void visit(EntityType entity) {
part = new EntityTypePart() {
public IFigure createFigure() {
IFigure f = super.createFigure();
f.setBorder(new RoundBracketsBorder() {
@Override
protected void setBracketsStyle(Graphics g) {
g.setForegroundColor(FigureConstants.contentLighterColor);
}
});
return f;
}
};
}
Example 57
Project: antlr-ide-master File: AntlrDFAViewer.java View source code |
public void exportAsImage(File file, int format) {
IFigure figure = graph.getContents();
Rectangle r = figure.getBounds();
OutputStream out = null;
Image image = null;
GC gc = null;
Graphics g = null;
try {
out = new BufferedOutputStream(new FileOutputStream(file));
image = new Image(getControl().getDisplay(), 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(out, SWT.IMAGE_PNG);
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
if (g != null) {
g.dispose();
}
if (gc != null) {
gc.dispose();
}
if (image != null) {
image.dispose();
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Example 58
Project: bundlemaker-master File: DsmViewWidget.java View source code |
/**
* <p>
* Initializes the {@link DsmViewWidget}.
* </p>
*/
private void init() {
LightweightSystem lws = new LightweightSystem(this);
//
DsmViewWidgetMouseMotionListener motionListener = new DsmViewWidgetMouseMotionListener(this);
//
this.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseScrolled(org.eclipse.swt.events.MouseEvent e) {
if (e.count > 0) {
DsmViewWidget.this.setZoom(getZoom() * 1.05f);
} else if (e.count < 0) {
DsmViewWidget.this.setZoom(getZoom() * 0.95f);
}
}
});
//
// this.addMouseMoveListener(new MyMouseMoveListener(this));
_mainFigure = new Figure() {
@Override
public void paint(Graphics graphics) {
super.paint(graphics);
if (_drawToolTip && _x >= _verticalFigureWidth && _y >= _horizontalFigureHeight) {
graphics.fillRectangle(_x, _y, 100, 100);
graphics.drawRectangle(_x, _y, 100, 100);
}
}
};
_mainFigure.setLayoutManager(new XYLayout());
_mainFigure.addMouseMotionListener(motionListener);
lws.setContents(_mainFigure);
_colorScheme = new DefaultMatrixColorScheme();
_matrixFigure = new Matrix(_dsmContentProvider, _dependencyLabelProvider, _colorScheme);
_matrixFigure.addMouseMotionListener(motionListener);
_matrixFigure.addMouseListener(motionListener);
_zoomableScrollpane = new ZoomableScrollPane(_matrixFigure, ScrollPane.ALWAYS, ScrollPane.ALWAYS);
_verticalListFigure = new VerticalSideMarker(_dsmContentProvider, _artifactLabelProvider, _colorScheme);
_verticalListFigure.addMouseMotionListener(motionListener);
_zoomableScrollpaneVerticalBar = new ZoomableScrollPane(_verticalListFigure, ScrollPane.NEVER, ScrollPane.NEVER);
_horizontalListFigure = new HorizontalSideMarker(_dsmContentProvider, _artifactLabelProvider, _colorScheme);
_horizontalListFigure.addMouseMotionListener(motionListener);
_zoomableScrollpaneHorizontalBar = new ZoomableScrollPane(_horizontalListFigure, ScrollPane.NEVER, ScrollPane.NEVER);
_matrixFigure.addMouseMotionListener(new MouseMotionListener.Stub() {
/**
* {@inheritDoc}
*/
@Override
public void mouseExited(org.eclipse.draw2d.MouseEvent me) {
_drawToolTip = false;
}
});
_matrixFigure.addMatrixListener(new IMatrixListener() {
@Override
public void toolTip(MatrixEvent event) {
_drawToolTip = true;
_mainFigure.repaint();
}
@Override
public void singleClick(MatrixEvent event) {
_drawToolTip = false;
_mainFigure.repaint();
}
@Override
public void doubleClick(MatrixEvent event) {
_drawToolTip = false;
_mainFigure.repaint();
}
@Override
public void marked(MatrixEvent event) {
_mainFigure.repaint();
_horizontalListFigure.mark(event.getX());
_verticalListFigure.mark(event.getY());
}
});
// _zoomScrollBar = new ScrollBar();
// final Label zoomLabel = new Label("Zoom");
// zoomLabel.setBorder(new SchemeBorder(ButtonBorder.SCHEMES.BUTTON_SCROLLBAR));
// _zoomScrollBar.setThumb(zoomLabel);
// _zoomScrollBar.setHorizontal(true);
// _zoomScrollBar.setMaximum(200);
// _zoomScrollBar.setMinimum(0);
// _zoomScrollBar.setExtent(25);
// _zoomScrollBar.addPropertyChangeListener("value", new PropertyChangeListener() {
// @Override
// public void propertyChange(PropertyChangeEvent evt) {
// float z = (_zoomScrollBar.getValue() + 10) * 0.02f;
// _zoomableScrollpane.setZoom(z);
// _zoomableScrollpaneVerticalBar.setZoom(z);
// _zoomableScrollpaneHorizontalBar.setZoom(z);
// _zoom = z;
// }
// });
//
// _useShortendLabelsCheckBox = new CheckBox("Shorten labels");
// _useShortendLabelsCheckBox.getModel().addChangeListener(new ChangeListener() {
//
// @Override
// public void handleStateChanged(ChangeEvent event) {
// if ("selected".equals(event.getPropertyName())) {
// _model.setUseShortendLabels(_useShortendLabelsCheckBox.isSelected());
// _mainFigure.revalidate();
// _mainFigure.repaint();
// }
// }
// });
_zoomableScrollpane.getViewport().addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
Viewport viewport = (Viewport) evt.getSource();
_zoomableScrollpaneVerticalBar.getViewport().setViewLocation(0, viewport.getViewLocation().y);
_zoomableScrollpaneHorizontalBar.getViewport().setViewLocation(viewport.getViewLocation().x, 0);
// _zoomableScrollpaneHorizontalBar.getViewport().setViewLocation(0, 0);
_zoomableScrollpane.getViewport().setViewLocation(viewport.getViewLocation().x, viewport.getViewLocation().y);
_mainFigure.revalidate();
_mainFigure.repaint();
}
});
// _mainFigure.add(_zoomScrollBar);
// _mainFigure.add(_useShortendLabelsCheckBox);
_mainFigure.add(_zoomableScrollpane);
_mainFigure.add(_zoomableScrollpaneVerticalBar);
_mainFigure.add(_zoomableScrollpaneHorizontalBar);
_mainFigure.addLayoutListener(new LayoutListener.Stub() {
@Override
public boolean layout(IFigure container) {
layoutFigures(container);
return true;
}
});
}
Example 59
Project: dbeaver-master File: EditableLabel.java View source code |
/**
* paints figure differently depends on the whether the figure has focus or is selected
*/
@Override
protected void paintFigure(Graphics graphics) {
if (selected) {
graphics.pushState();
graphics.setBackgroundColor(ColorConstants.menuBackgroundSelected);
graphics.fillRectangle(getSelectionRectangle());
graphics.popState();
graphics.setForegroundColor(ColorConstants.white);
}
super.paintFigure(graphics);
}
Example 60
Project: eu.geclipse.core-master File: OutputPortFigure.java View source code |
/** * @see org.eclipse.draw2d.Figure#paintFigure(Graphics) */ @Override protected void paintFigure(final Graphics g) { final Rectangle r = getBounds().getCopy(); final IMapMode mm = MapModeUtil.getMapMode(this); r.translate(mm.DPtoLP(2), mm.DPtoLP(2)); r.setSize(mm.DPtoLP(9), mm.DPtoLP(11)); // draw a line at the bottom //g.drawLine(r.x, r.bottom(), r.right(), r.bottom()); //draw figure g.translate(getLocation()); final PointList outline = points.getCopy(); mm.DPtoLP(outline); g.fillPolygon(outline); g.drawPolyline(outline); g.translate(getLocation().getNegated()); }
Example 61
Project: glance-master File: HighlightFlow.java View source code |
@Override
public void paint(final Graphics g) {
if (!isVisible()) {
return;
}
final String originalText = delegate.getText();
final String matchString = originalText.substring(match.getOffset(), match.getOffset() + match.getLength());
g.setBackgroundColor(isSelected() ? ColorManager.getInstance().getSelectedBackgroundColor() : ColorManager.getInstance().getBackgroundColor());
final Dimension extent = getTextExtents(matchString);
final Point topLeft = bounds.getTopLeft();
g.fillRectangle(topLeft.x, topLeft.y, extent.width, extent.height);
g.setForegroundColor(ColorConstants.black);
g.setFont(getFont());
g.drawText(matchString, topLeft.getCopy());
}
Example 62
Project: Hydrograph-master File: ComponentFigure.java View source code |
@Override
protected void paintFigure(Graphics graphics) {
Rectangle r = getBounds().getCopy();
graphics.translate(r.getLocation());
Rectangle q = new Rectangle(4, 4 + componentLabelMargin, r.width - 8, r.height - 8 - componentLabelMargin);
graphics.fillRoundRectangle(q, 5, 5);
graphics.drawImage(canvasIcon, new Point(q.width / 2 - 16, q.height / 2 + componentLabelMargin - 11));
drawPropertyStatus(graphics);
if ((StringUtils.equalsIgnoreCase(component.getCategory(), Constants.TRANSFORM) && !StringUtils.equalsIgnoreCase(component.getComponentName(), Constants.FILTER) && !StringUtils.equalsIgnoreCase(component.getComponentName(), Constants.UNIQUE_SEQUENCE))) {
PropertyToolTipInformation propertyToolTipInformation;
if (component.isContinuousSchemaPropogationAllow()) {
drawSchemaPropogationInfoImageIfSchemaPropogationBreaks(graphics);
propertyToolTipInformation = createPropertyToolTipInformation(Messages.CONTINUOUS_SCHEMA_PROPAGATION_STOPPED, Constants.SHOW_TOOLTIP);
} else {
propertyToolTipInformation = createPropertyToolTipInformation("", Constants.HIDE_TOOLTIP);
}
component.getTooltipInformation().put(Constants.ISSUE_PROPERTY_NAME, propertyToolTipInformation);
} else if (StringUtils.equalsIgnoreCase(Constants.UNION_ALL, component.getComponentName())) {
PropertyToolTipInformation propertyToolTipInformation;
if (component.getProperties().get(Constants.IS_UNION_ALL_COMPONENT_SYNC) != null && StringUtils.equalsIgnoreCase(((String) component.getProperties().get(Constants.IS_UNION_ALL_COMPONENT_SYNC)), Constants.FALSE)) {
drawSchemaPropogationInfoImageIfSchemaPropogationBreaks(graphics);
propertyToolTipInformation = createPropertyToolTipInformation(Messages.INPUTS_SCHEMA_ARE_NOT_IN_SYNC, Constants.SHOW_TOOLTIP);
} else {
propertyToolTipInformation = createPropertyToolTipInformation("", Constants.HIDE_TOOLTIP);
}
component.getTooltipInformation().put(Constants.ISSUE_PROPERTY_NAME, propertyToolTipInformation);
} else if (component instanceof SubjobComponent) {
boolean isTransformComponentPresent = SubjobUtility.INSTANCE.checkIfSubJobHasTransformOrUnionAllComponent(component);
PropertyToolTipInformation propertyToolTipInformation;
if (isTransformComponentPresent) {
drawSchemaPropogationInfoImageIfSchemaPropogationBreaks(graphics);
propertyToolTipInformation = createPropertyToolTipInformation(Messages.CONTINUOUS_SCHEMA_PROPAGATION_STOPPED_IN_SUBJOB, Constants.SHOW_TOOLTIP);
} else {
propertyToolTipInformation = createPropertyToolTipInformation("", Constants.HIDE_TOOLTIP);
}
component.getTooltipInformation().put(Constants.ISSUE_PROPERTY_NAME, propertyToolTipInformation);
}
graphics.drawText(acronym, new Point((q.width - (acronym.length() * 5)) / 2, q.height / 2 + componentLabelMargin - 23));
if (componentProperties != null && componentProperties.get(StringUtils.lowerCase(Constants.BATCH)) != null) {
if (String.valueOf(componentProperties.get(StringUtils.lowerCase(Constants.BATCH))).length() > 2) {
graphics.drawText(StringUtils.substring(String.valueOf(componentProperties.get(StringUtils.lowerCase(Constants.BATCH))), 0, 2) + "..", new Point(q.width - 16, q.height + getComponentLabelMargin() - 20));
} else {
graphics.drawText(String.valueOf(componentProperties.get(StringUtils.lowerCase(Constants.BATCH))), new Point(q.width - 14, q.height + getComponentLabelMargin() - 20));
}
}
trackExecution(graphics);
}
Example 63
Project: liferay-ide-master File: PortletColumnEditPart.java View source code |
@Override
protected void paintFigure(Graphics graphics) {
Rectangle r = Rectangle.SINGLETON.setBounds(getBounds());
r.width -= 1;
r.height -= 1;
//draw the outline
graphics.drawRoundRectangle(r, 10, 10);
r.width -= 1;
r.height -= 1;
r.x += 1;
r.y += 1;
//fill the color
graphics.fillRoundRectangle(r, 10, 10);
}
Example 64
Project: liquidware_beagleboard_android_sdk-master File: LayoutFigure.java View source code |
/** * Paints the "border" for this figure. * <p/> * The parent {@link Figure#paint(Graphics)} calls {@link #paintFigure(Graphics)} then * {@link #paintClientArea(Graphics)} then {@link #paintBorder(Graphics)}. Here we thus * draw the actual highlight border but also the highlight anchor lines and points so that * we can make sure they are all drawn on top of the border. * <p/> * Note: This method doesn't really need to restore its graphic state. The parent * Figure will do it for us. * <p/> * * @param graphics The Graphics object used for painting */ @Override protected void paintBorder(Graphics graphics) { super.paintBorder(graphics); if (mHighlightInfo == null) { return; } // Draw the border. We want other highlighting to be drawn on top of the border. if (mHighlightInfo.drawDropBorder) { graphics.setLineWidth(3); graphics.setLineStyle(SWT.LINE_SOLID); graphics.setForegroundColor(ColorConstants.green); graphics.drawRectangle(getInnerBounds().getCopy().shrink(1, 1)); } Rectangle bounds = getBounds(); int bx = bounds.x; int by = bounds.y; int w = bounds.width; int h = bounds.height; // Draw frames of target child parts, if any if (mHighlightInfo.childParts != null) { graphics.setLineWidth(2); graphics.setLineStyle(SWT.LINE_DOT); graphics.setForegroundColor(ColorConstants.lightBlue); for (UiElementEditPart part : mHighlightInfo.childParts) { if (part != null) { graphics.drawRectangle(part.getBounds().getCopy().translate(bx, by)); } } } // Draw the target line, if any if (mHighlightInfo.linePoints != null) { int x1 = mHighlightInfo.linePoints[0].x; int y1 = mHighlightInfo.linePoints[0].y; int x2 = mHighlightInfo.linePoints[1].x; int y2 = mHighlightInfo.linePoints[1].y; // full 2-pixel width be visible. if (x1 <= 0) x1++; if (x2 <= 0) x2++; if (y1 <= 0) y1++; if (y2 <= 0) y2++; if (x1 >= w - 1) x1--; if (x2 >= w - 1) x2--; if (y1 >= h - 1) y1--; if (y2 >= h - 1) y2--; x1 += bx; x2 += bx; y1 += by; y2 += by; graphics.setLineWidth(2); graphics.setLineStyle(SWT.LINE_DASH); graphics.setLineCap(SWT.CAP_ROUND); graphics.setForegroundColor(ColorConstants.orange); graphics.drawLine(x1, y1, x2, y2); } // Draw the anchor point, if any if (mHighlightInfo.anchorPoint != null) { int x = mHighlightInfo.anchorPoint.x; int y = mHighlightInfo.anchorPoint.y; // matches the highlight line. It makes it slightly more visible that way. if (x <= 0) x++; if (y <= 0) y++; if (x >= w - 1) x--; if (y >= h - 1) y--; x += bx; y += by; graphics.setLineWidth(2); graphics.setLineStyle(SWT.LINE_SOLID); graphics.setLineCap(SWT.CAP_ROUND); graphics.setForegroundColor(ColorConstants.orange); graphics.drawLine(x - 5, y - 5, x + 5, y + 5); graphics.drawLine(x - 5, y + 5, x + 5, y - 5); // 7 * cos(45) == 5 so we use 8 for the circle radius (it looks slightly better than 7) graphics.setLineWidth(1); graphics.drawOval(x - 8, y - 8, 16, 16); } }
Example 65
Project: scout-master File: Trace.java View source code |
private void drawErrorBar(Graphics graphics, Point dpPos, ISample dp) {
graphics.pushState();
graphics.setForegroundColor(errorBarColor);
graphics.setLineStyle(SWTConstants.LINE_SOLID);
graphics.setLineWidth(1);
Point ep;
switch(yErrorBarType) {
case BOTH:
case MINUS:
ep = new Point(xAxis.getValuePosition(dp.getXValue(), false), yAxis.getValuePosition(dp.getYValue() - dp.getYMinusError(), false));
graphics.drawLine(dpPos, ep);
graphics.drawLine(ep.x - errorBarCapWidth / 2, ep.y, ep.x + errorBarCapWidth / 2, ep.y);
if (yErrorBarType != ErrorBarType.BOTH)
break;
case PLUS:
ep = new Point(xAxis.getValuePosition(dp.getXValue(), false), yAxis.getValuePosition(dp.getYValue() + dp.getYPlusError(), false));
graphics.drawLine(dpPos, ep);
graphics.drawLine(ep.x - errorBarCapWidth / 2, ep.y, ep.x + errorBarCapWidth / 2, ep.y);
break;
default:
break;
}
switch(xErrorBarType) {
case BOTH:
case MINUS:
ep = new Point(xAxis.getValuePosition(dp.getXValue() - dp.getXMinusError(), false), yAxis.getValuePosition(dp.getYValue(), false));
graphics.drawLine(dpPos, ep);
graphics.drawLine(ep.x, ep.y - errorBarCapWidth / 2, ep.x, ep.y + errorBarCapWidth / 2);
if (xErrorBarType != ErrorBarType.BOTH)
break;
case PLUS:
ep = new Point(xAxis.getValuePosition(dp.getXValue() + dp.getXPlusError(), false), yAxis.getValuePosition(dp.getYValue(), false));
graphics.drawLine(dpPos, ep);
graphics.drawLine(ep.x, ep.y - errorBarCapWidth / 2, ep.x, ep.y + errorBarCapWidth / 2);
break;
default:
break;
}
graphics.popState();
}
Example 66
Project: scouter-master File: Trace.java View source code |
private void drawErrorBar(Graphics graphics, Point dpPos, ISample dp) {
graphics.pushState();
graphics.setForegroundColor(errorBarColor);
graphics.setLineStyle(SWTConstants.LINE_SOLID);
graphics.setLineWidth(1);
Point ep;
switch(yErrorBarType) {
case BOTH:
case MINUS:
ep = new Point(xAxis.getValuePosition(dp.getXValue(), false), yAxis.getValuePosition(dp.getYValue() - dp.getYMinusError(), false));
graphics.drawLine(dpPos, ep);
graphics.drawLine(ep.x - errorBarCapWidth / 2, ep.y, ep.x + errorBarCapWidth / 2, ep.y);
if (yErrorBarType != ErrorBarType.BOTH)
break;
case PLUS:
ep = new Point(xAxis.getValuePosition(dp.getXValue(), false), yAxis.getValuePosition(dp.getYValue() + dp.getYPlusError(), false));
graphics.drawLine(dpPos, ep);
graphics.drawLine(ep.x - errorBarCapWidth / 2, ep.y, ep.x + errorBarCapWidth / 2, ep.y);
break;
default:
break;
}
switch(xErrorBarType) {
case BOTH:
case MINUS:
ep = new Point(xAxis.getValuePosition(dp.getXValue() - dp.getXMinusError(), false), yAxis.getValuePosition(dp.getYValue(), false));
graphics.drawLine(dpPos, ep);
graphics.drawLine(ep.x, ep.y - errorBarCapWidth / 2, ep.x, ep.y + errorBarCapWidth / 2);
if (xErrorBarType != ErrorBarType.BOTH)
break;
case PLUS:
ep = new Point(xAxis.getValuePosition(dp.getXValue() + dp.getXPlusError(), false), yAxis.getValuePosition(dp.getYValue(), false));
graphics.drawLine(dpPos, ep);
graphics.drawLine(ep.x, ep.y - errorBarCapWidth / 2, ep.x, ep.y + errorBarCapWidth / 2);
break;
default:
break;
}
graphics.popState();
}
Example 67
Project: TadpoleForDBTools-master File: SubTableFigureBorder.java View source code |
public void paint(IFigure figure, Graphics graphics, Insets insets) {
Rectangle r = figure.getBounds().getCopy();
r.crop(insets);
graphics.setLineWidth(1);
// solid long edges around border
graphics.drawLine(r.x + FOLD, r.y, r.x + r.width - 1, r.y);
graphics.drawLine(r.x, r.y + FOLD, r.x, r.y + r.height - 1);
graphics.drawLine(r.x + r.width - 1, r.y, r.x + r.width - 1, r.y + r.height - 1);
// solid short edges
graphics.drawLine(r.x, r.y + r.height - 1, r.x + r.width - 1, r.y + r.height - 1);
graphics.drawLine(r.x + FOLD, r.y, r.x + FOLD, r.y + FOLD);
graphics.drawLine(r.x, r.y + FOLD, r.x + FOLD, r.y + FOLD);
// gray small triangle
graphics.setBackgroundColor(ColorConstants.lightGray());
graphics.fillPolygon(new int[] { r.x, r.y + FOLD, r.x + FOLD, r.y, r.x + FOLD, r.y + FOLD });
// dotted short diagonal line
graphics.setLineStyle(SWT.LINE_DOT);
graphics.drawLine(r.x, r.y + FOLD, r.x + FOLD, r.y);
}
Example 68
Project: xUnit-master File: CompositeUnitNodeFigure.java View source code |
private void initBorder(StructureType type) { if (!(type == StructureType.adapter || type == StructureType.decorator)) return; ((ToolbarLayout) getLayoutManager()).setSpacing(V_NODE_SPACE / 2); Color color = type == StructureType.adapter ? ADAPTER_TITLE_COLOR : DECORATOR_TITLE_COLOR; textBorder = new TitleBarBorder(); textBorder.setTextAlignment(PositionConstants.CENTER); textBorder.setBackgroundColor(color); CompoundBorder border = new CompoundBorder(textBorder, new LineBorder(ColorConstants.darkGreen, 1, Graphics.LINE_SOLID)); setBorder(border); footer = new Label(type.name()); footer.setForegroundColor(color); footer.setBorder(new LineBorder(ColorConstants.white, 1, Graphics.LINE_SOLID)); endPanel.add(footer); }
Example 69
Project: yang-ide-master File: FeedbackFigure.java View source code |
@Override
protected void outlineShape(Graphics g) {
int x = getParent().getBounds().x + 15;
int x2 = x + getParent().getBounds().width - 30;
g.setForegroundColor(Display.getDefault().getSystemColor(SWT.COLOR_BLUE));
g.drawPolyline(new int[] { x - 2, position - 2, x, position, x - 2, position + 2 });
g.drawPolyline(new int[] { x, position, x2, position });
g.drawPolyline(new int[] { x2 + 3, position - 3, x2, position, x2 + 2, position + 2 });
}
Example 70
Project: d-case_editor-master File: CustomWrappingLabel.java View source code |
/**
* {@inheritDoc}
*/
@Override
protected void paintClientArea(Graphics graphics) {
if (!isSelected()) {
graphics.pushState();
graphics.setBackgroundColor(backgroundColor);
graphics.fillRectangle(getVisibleTextBounds());
graphics.popState();
graphics.setForegroundColor(getForegroundColor());
}
super.paintClientArea(graphics);
}
Example 71
Project: eclipse-gef-imageexport-master File: Utils.java View source code |
/** Paints the figure onto the given graphics */ public static void paintDiagram(Graphics g, IFigure figure) { // Store state, so modified state of Graphics (while painting children) can be easily restored g.pushState(); try { IClippingStrategy clippingStrategy = figure.getClippingStrategy(); // supported (like Graphics#setTextAntiAliassing()) for (Object childObject : figure.getChildren()) { if (childObject instanceof Layer) { // Found another layer, process it to search for actual figures paintDiagram(g, (IFigure) childObject); } else { // Found something to draw // Use same/similar method as being using in Figure#paintChildren() in order to get clipping right IFigure child = (IFigure) childObject; if (child.isVisible()) { // determine clipping areas for child Rectangle[] clipping = null; if (clippingStrategy != null) { clipping = clippingStrategy.getClip(child); } else { // default clipping behaviour is to clip at bounds clipping = new Rectangle[] { child.getBounds() }; } // child may now paint inside the clipping areas for (int j = 0; j < clipping.length; j++) { if (clipping[j].intersects(g.getClip(Rectangle.SINGLETON))) { g.clipRect(clipping[j]); child.paint(g); g.restoreState(); } } } } } } finally { // Always pop the state again to prevent problems g.popState(); } }
Example 72
Project: LEADT-master File: GEFImageWriter.java View source code |
private static Image drawFigureOnImage(GraphicalViewer viewer) {
IFigure figure = getRootFigure(viewer);
Rectangle bounds = figure.getBounds();
Image image = new Image(null, bounds.width, bounds.height);
GC imageGC = new GC(image);
Graphics imgGraphics = new SWTGraphics(imageGC);
imgGraphics.translate(-bounds.x, -bounds.y);
figure.paint(imgGraphics);
imgGraphics.translate(bounds.x, bounds.y);
imageGC.dispose();
return image;
}
Example 73
Project: org.nightlabs.jfire.max-master File: AbstractInputNodeFigure.java View source code |
@Override
protected void paintFigure(Graphics g) {
Rectangle bounds = getBounds();
g.setBackgroundColor(PageColorUtil.getPageColor(colorIndex));
g.setForegroundColor(PageColorUtil.getPageColor(colorIndex));
g.fillRectangle(getBounds());
g.setBackgroundColor(PageColorUtil.getHeaderColor(colorIndex));
g.fillRectangle(bounds.x, bounds.y, bounds.width, nameHeight);
// g.drawLine(bounds.x, bounds.y + nameHeight - spacerHeight, bounds.x + bounds.width, bounds.y + nameHeight - spacerHeight);
String text = getName();
int textWidth = FigureUtilities.getTextWidth(text, getFont());
int space = bounds.width - textWidth;
Font normalFont = g.getFont();
try {
g.setFont(getBoldFont(g));
g.setForegroundColor(PageColorUtil.getHeaderFontColor(colorIndex));
g.fillText(text, bounds.x + space / 2, bounds.y + 3);
} finally {
g.setFont(normalFont);
}
drawInputConnectors(g, getBounds());
}
Example 74
Project: org.nightlabs.jfire.max.eclipse-master File: AbstractInputNodeFigure.java View source code |
@Override
protected void paintFigure(Graphics g) {
Rectangle bounds = getBounds();
g.setBackgroundColor(PageColorUtil.getPageColor(colorIndex));
g.setForegroundColor(PageColorUtil.getPageColor(colorIndex));
g.fillRectangle(getBounds());
g.setBackgroundColor(PageColorUtil.getHeaderColor(colorIndex));
g.fillRectangle(bounds.x, bounds.y, bounds.width, nameHeight);
// g.drawLine(bounds.x, bounds.y + nameHeight - spacerHeight, bounds.x + bounds.width, bounds.y + nameHeight - spacerHeight);
String text = getName();
int textWidth = FigureUtilities.getTextWidth(text, getFont());
int space = bounds.width - textWidth;
Font normalFont = g.getFont();
try {
g.setFont(getBoldFont(g));
g.setForegroundColor(PageColorUtil.getHeaderFontColor(colorIndex));
g.fillText(text, bounds.x + space / 2, bounds.y + 3);
} finally {
g.setFont(normalFont);
}
drawInputConnectors(g, getBounds());
}
Example 75
Project: eclipse-gov.redhawk.core-master File: ComponentInstantiationFigure.java View source code |
@Override
protected void fillShape(final Graphics graphics) {
final Rectangle r = getBounds().getCopy();
final Point topLeft = r.getTopLeft();
final float x = (r.getTopRight().x - r.getTopLeft().x) / 2 + r.getTopLeft().x;
super.fillShape(graphics);
// SUPPRESS CHECKSTYLE MagicNumber
final int height = this.fComponentInstantiationLabelFigure.getBounds().height + 10;
final Pattern pattern = new Pattern(Display.getCurrent(), x, topLeft.y, x, topLeft.y + height, this.gradientColor, graphics.getBackgroundColor());
final int oldFillRule = graphics.getFillRule();
// We do this to support graphics that potentially don't support gradient fill, for some reason the save as image doesn't support this
try {
graphics.setBackgroundPattern(pattern);
r.setSize(r.width, height);
graphics.setClip(r);
graphics.fillRoundRectangle(getBounds(), this.corner.width, this.corner.height);
graphics.setClip(getBounds());
graphics.setBackgroundPattern(null);
graphics.setFillRule(oldFillRule);
} catch (final RuntimeException e) {
} finally {
pattern.dispose();
}
}
Example 76
Project: Socio-technical-Security-Requirements-master File: AuthorisationMiddleFigure.java View source code |
private IFigure createLabel(StsElement element, Map<IFigure, StsElement> map, final Color startColor, final Color endColor, int alpha) {
Label l = new Label(element.getName());
RoundedRectangle e = new RoundedRectangle() {
@Override
protected void fillShape(Graphics graphics) {
graphics.setBackgroundColor(startColor);
super.fillShape(graphics);
}
};
e.setCornerDimensions(new Dimension(4, 4));
e.setLayoutManager(new StackLayout() {
@Override
protected Dimension calculatePreferredSize(IFigure figure, int wHint, int hHint) {
Dimension d = super.calculatePreferredSize(figure, wHint, hHint);
d.height = d.height + 4;
d.width = d.width + 6;
return d;
}
});
e.setOutline(false);
e.add(l);
map.put(e, element);
return e;
}
Example 77
Project: WS171-development-master File: LayoutFigure.java View source code |
/** * Paints the "border" for this figure. * <p/> * The parent {@link Figure#paint(Graphics)} calls {@link #paintFigure(Graphics)} then * {@link #paintClientArea(Graphics)} then {@link #paintBorder(Graphics)}. Here we thus * draw the actual highlight border but also the highlight anchor lines and points so that * we can make sure they are all drawn on top of the border. * <p/> * Note: This method doesn't really need to restore its graphic state. The parent * Figure will do it for us. * <p/> * * @param graphics The Graphics object used for painting */ @Override protected void paintBorder(Graphics graphics) { super.paintBorder(graphics); if (mHighlightInfo == null) { return; } // Draw the border. We want other highlighting to be drawn on top of the border. if (mHighlightInfo.drawDropBorder) { graphics.setLineWidth(3); graphics.setLineStyle(SWT.LINE_SOLID); graphics.setForegroundColor(ColorConstants.green); graphics.drawRectangle(getInnerBounds().getCopy().shrink(1, 1)); } Rectangle bounds = getBounds(); int bx = bounds.x; int by = bounds.y; int w = bounds.width; int h = bounds.height; // Draw frames of target child parts, if any if (mHighlightInfo.childParts != null) { graphics.setLineWidth(2); graphics.setLineStyle(SWT.LINE_DOT); graphics.setForegroundColor(ColorConstants.lightBlue); for (UiElementEditPart part : mHighlightInfo.childParts) { if (part != null) { graphics.drawRectangle(part.getBounds().getCopy().translate(bx, by)); } } } // Draw the target line, if any if (mHighlightInfo.linePoints != null) { int x1 = mHighlightInfo.linePoints[0].x; int y1 = mHighlightInfo.linePoints[0].y; int x2 = mHighlightInfo.linePoints[1].x; int y2 = mHighlightInfo.linePoints[1].y; // full 2-pixel width be visible. if (x1 <= 0) x1++; if (x2 <= 0) x2++; if (y1 <= 0) y1++; if (y2 <= 0) y2++; if (x1 >= w - 1) x1--; if (x2 >= w - 1) x2--; if (y1 >= h - 1) y1--; if (y2 >= h - 1) y2--; x1 += bx; x2 += bx; y1 += by; y2 += by; graphics.setLineWidth(2); graphics.setLineStyle(SWT.LINE_DASH); graphics.setLineCap(SWT.CAP_ROUND); graphics.setForegroundColor(ColorConstants.orange); graphics.drawLine(x1, y1, x2, y2); } // Draw the anchor point, if any if (mHighlightInfo.anchorPoint != null) { int x = mHighlightInfo.anchorPoint.x; int y = mHighlightInfo.anchorPoint.y; // matches the highlight line. It makes it slightly more visible that way. if (x <= 0) x++; if (y <= 0) y++; if (x >= w - 1) x--; if (y >= h - 1) y--; x += bx; y += by; graphics.setLineWidth(2); graphics.setLineStyle(SWT.LINE_SOLID); graphics.setLineCap(SWT.CAP_ROUND); graphics.setForegroundColor(ColorConstants.orange); graphics.drawLine(x - 5, y - 5, x + 5, y + 5); graphics.drawLine(x - 5, y + 5, x + 5, y - 5); // 7 * cos(45) == 5 so we use 8 for the circle radius (it looks slightly better than 7) graphics.setLineWidth(1); graphics.drawOval(x - 8, y - 8, 16, 16); } }
Example 78
Project: cogtool-master File: GraphicalWidgetBase.java View source code |
@Override
protected void paintRightIcon(Graphics g) {
Rectangle bds = getBounds();
int x = bds.width - bds.height - 2;
int y = 4;
int w = bds.height - 6;
int h = bds.height - 8;
if (x < 0) {
x = 1;
}
if (y >= bds.height) {
y = bds.height;
}
if (w <= 0) {
w = 1;
}
if (h <= 0) {
h = 1;
}
int[] triangle = { x, y, x + w, y + (h / 2), x, y + h };
g.drawPolygon(triangle);
}
Example 79
Project: framesoc-master File: Snapshot.java View source code |
/**
* Generate the image
*
* @param figure
* Figure from which the image is created
* @param format
* format of the generated image
* @return an array of bytes corresponding to an image
*/
private byte[] createImage(Figure figure, int format) {
Device device = Display.getCurrent();
Rectangle r = figure.getBounds();
if (r.width <= 0 || r.height <= 0) {
logger.debug("Size of figure is 0: stopping generation");
return null;
}
ByteArrayOutputStream result = new ByteArrayOutputStream();
Image image = null;
GC gc = null;
Graphics g = null;
try {
image = new Image(device, 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);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (g != null) {
g.dispose();
}
if (gc != null) {
gc.dispose();
}
if (image != null) {
image.dispose();
}
}
return result.toByteArray();
}
Example 80
Project: lunifera-sharky-m2m-master File: Connection.java View source code |
/**
* Returns the lineStyle as String for the Property Sheet
*
* @see org.eclipse.ui.views.properties.IPropertySource#getPropertyValue(java.lang.Object)
*/
public Object getPropertyValue(Object id) {
if (id.equals(LINESTYLE_PROP)) {
if (getLineStyle() == Graphics.LINE_DASH)
// Dashed is the second value in the combo dropdown
return new Integer(1);
// Solid is the first value in the combo dropdown
return new Integer(0);
}
return super.getPropertyValue(id);
}
Example 81
Project: org.openscada.orilla-master File: InputScaleDetails.java View source code |
@Override protected IFigure createMain() { final Figure rootFigure = new Figure(); rootFigure.setLayoutManager(new GridLayout(4, true)); rootFigure.setBackgroundColor(ColorConstants.white); // cell 1,1 rootFigure.add(new Figure()); // cell 2,1 rootFigure.add(this.factorFigure = new RoundedRectangle(), new GridData(GridData.CENTER, GridData.CENTER, true, true)); this.factorFigure.setBackgroundColor(ColorConstants.lightGray); this.factorFigure.setForegroundColor(ColorConstants.black); this.factorFigure.setBorder(new MarginBorder(10)); this.factorFigure.setLayoutManager(new BorderLayout()); this.factorFigure.add(this.factorLabel = new Label(), BorderLayout.CENTER); this.factorFigure.addMouseMotionListener(new MouseMotionListener.Stub() { @Override public void mouseEntered(final MouseEvent me) { InputScaleDetails.this.factorFigure.setLineWidth(2); } @Override public void mouseExited(final MouseEvent me) { InputScaleDetails.this.factorFigure.setLineWidth(1); } }); // cell 3,1 rootFigure.add(this.offsetFigure = new RoundedRectangle(), new GridData(GridData.CENTER, GridData.CENTER, true, true)); this.offsetFigure.setBackgroundColor(ColorConstants.lightGray); this.offsetFigure.setForegroundColor(ColorConstants.black); this.offsetFigure.setBorder(new MarginBorder(10)); this.offsetFigure.setLayoutManager(new BorderLayout()); this.offsetFigure.add(this.offsetLabel = new Label(), BorderLayout.CENTER); this.offsetFigure.addMouseMotionListener(new MouseMotionListener.Stub() { @Override public void mouseEntered(final MouseEvent me) { InputScaleDetails.this.offsetFigure.setLineWidth(2); } @Override public void mouseExited(final MouseEvent me) { InputScaleDetails.this.offsetFigure.setLineWidth(1); } }); // cell 4,1 rootFigure.add(new Figure()); // cell 1,2 rootFigure.add(this.rawFigure = new RoundedRectangle(), new GridData(GridData.CENTER, GridData.CENTER, true, true)); this.rawFigure.setBackgroundColor(ColorConstants.lightGray); this.rawFigure.setForegroundColor(ColorConstants.black); this.rawFigure.setBorder(new MarginBorder(10)); this.rawFigure.setLayoutManager(new BorderLayout()); this.rawFigure.add(this.rawLabel = new Label(), BorderLayout.CENTER); // cell 2,2 final RectangleFigure factorRect = new RectangleFigure(); factorRect.setLayoutManager(new BorderLayout()); factorRect.add(new Label(Messages.InputScaleDetails_Multiply), BorderLayout.CENTER); factorRect.setBorder(new MarginBorder(10)); factorRect.setBackgroundColor(ColorConstants.lightGray); factorRect.setForegroundColor(ColorConstants.black); factorRect.setLineStyle(Graphics.LINE_SOLID); factorRect.setLineWidth(1); factorRect.setFill(true); factorRect.setOpaque(true); rootFigure.add(factorRect, new GridData(GridData.CENTER, GridData.CENTER, true, true)); // cell 3, 2 final RectangleFigure offsetRect = new RectangleFigure(); offsetRect.setLayoutManager(new BorderLayout()); offsetRect.add(new Label(Messages.InputScaleDetails_Add), BorderLayout.CENTER); offsetRect.setBorder(new MarginBorder(10)); offsetRect.setBackgroundColor(ColorConstants.lightGray); offsetRect.setForegroundColor(ColorConstants.black); offsetRect.setLineStyle(Graphics.LINE_SOLID); offsetRect.setLineWidth(1); offsetRect.setFill(true); offsetRect.setOpaque(true); rootFigure.add(offsetRect, new GridData(GridData.CENTER, GridData.CENTER, true, true)); // cell 4,2 rootFigure.add(this.valueFigure = new RoundedRectangle(), new GridData(GridData.CENTER, GridData.CENTER, true, true)); this.valueFigure.setLayoutManager(new BorderLayout()); this.valueFigure.setBackgroundColor(ColorConstants.lightGray); this.valueFigure.setForegroundColor(ColorConstants.black); this.valueFigure.setBorder(new MarginBorder(10)); this.valueFigure.add(this.valueLabel = new Label(), BorderLayout.CENTER); // add connections connect(rootFigure, this.factorFigure, factorRect); connect(rootFigure, this.rawFigure, factorRect); connect(rootFigure, factorRect, offsetRect); connect(rootFigure, this.offsetFigure, offsetRect); connect(rootFigure, offsetRect, this.valueFigure); // hook up entry dialogs this.factorFigure.addMouseListener(new MouseListener.Stub() { @Override public void mouseDoubleClicked(final MouseEvent me) { InputScaleDetails.this.triggerFactorInput(); } }); this.offsetFigure.addMouseListener(new MouseListener.Stub() { @Override public void mouseDoubleClicked(final MouseEvent me) { InputScaleDetails.this.triggerOffsetInput(); } }); return rootFigure; }
Example 82
Project: overture-master File: GenericTabItem.java View source code |
public void exportJPG(String fileName) {
Image theImage = new Image(null, xmax + 50, ymax + 50);
GC theGC = new GC(theImage);
Graphics theGraphics = new SWTGraphics(theGC);
theFigure.paint(theGraphics);
theGraphics.fillRectangle(xmax + 50, 0, 10, ymax + 50);
ImageData imgData[] = new ImageData[1];
imgData[0] = theImage.getImageData();
ImageLoader theLoader = new ImageLoader();
theLoader.data = imgData;
theLoader.save((new StringBuilder(String.valueOf(fileName))).append(".jpg").toString(), 4);
theGraphics.dispose();
theGC.dispose();
theImage.dispose();
}
Example 83
Project: Spoon-master File: ScrollableThumbnail.java View source code |
public void paintFigure(Graphics g) {
Rectangle bounds = getBounds().getCopy();
// Avoid drawing images that are 0 in dimension
if (bounds.width < 5 || bounds.height < 5)
return;
// Don't paint the selector figure if the entire source is visible.
Dimension thumbnailSize = new Dimension(getThumbnailImage());
// expand to compensate for rounding errors in calculating bounds
Dimension size = getSize().getExpanded(1, 1);
if (size.contains(thumbnailSize))
return;
bounds.height--;
bounds.width--;
g.drawImage(image, iBounds, bounds);
g.setForegroundColor(ColorConstants.menuBackgroundSelected);
g.drawRectangle(bounds);
}
Example 84
Project: vespucci-master File: WarningDecoration.java View source code |
private void paintExclamationMark(Graphics graphics) {
Point lineStartPoint = new Point(LINE_XPOS, LINE_Y1);
Point lineEndPoint = new Point(LINE_XPOS, DOT_POS_Y + 2);
graphics.drawLine(transform.getTransformed(lineStartPoint), transform.getTransformed(lineEndPoint));
graphics.setBackgroundColor(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
Point separatorTopLeftPoint = new Point(LINE_XPOS - 2, LINE_Y2);
Point separatorBottomRightPoint = new Point(LINE_XPOS + 2, DOT_POS_Y);
PointList separatorPoints = new PointList(5);
separatorPoints.addPoint(transform.getTransformed(separatorTopLeftPoint));
separatorPoints.addPoint(transform.getTransformed(new Point(separatorBottomRightPoint.x, separatorTopLeftPoint.y)));
separatorPoints.addPoint(transform.getTransformed(separatorBottomRightPoint));
separatorPoints.addPoint(transform.getTransformed(new Point(separatorTopLeftPoint.x, separatorBottomRightPoint.y)));
separatorPoints.addPoint(transform.getTransformed(separatorTopLeftPoint));
graphics.fillPolygon(separatorPoints);
}
Example 85
Project: eclipse-gov.redhawk.ide-master File: PaletteNamespaceFolderFigure.java View source code |
/**
* Paints the background gradient on the drawer toggle figure.
*
* @param g
* the graphics object
* @param rect
* the rectangle which the background gradient should cover
*/
private void paintToggleGradient(Graphics g, Rectangle rect) {
if (collapseToggle.getModel().isMouseOver()) {
Color color1 = PaletteColorUtil.WIDGET_BACKGROUND_LIST_BACKGROUND_60;
Color color2 = PaletteColorUtil.WIDGET_BACKGROUND_NORMAL_SHADOW_90;
Color color3 = PaletteColorUtil.WIDGET_BACKGROUND_NORMAL_SHADOW_95;
Color color4 = PaletteColorUtil.WIDGET_BACKGROUND_LIST_BACKGROUND_90;
g.setForegroundColor(color1);
g.setBackgroundColor(color2);
g.fillGradient(rect.x, rect.y, rect.width, rect.height - 4, true);
g.setForegroundColor(color2);
g.setBackgroundColor(color3);
g.fillGradient(rect.x, rect.bottom() - 4, rect.width, 2, true);
g.setForegroundColor(color3);
g.setBackgroundColor(color4);
g.fillGradient(rect.x, rect.bottom() - 2, rect.width, 2, true);
} else {
g.setForegroundColor(ColorConstants.white);
g.fillGradient(rect, true);
}
}
Example 86
Project: gda-common-rcp-master File: ColourSliderComposite.java View source code |
private IFigure getContents() {
RectangleFigure boundaryFigure = new RectangleFigure() {
@Override
public void paint(Graphics graphics) {
super.paint(graphics);
graphics.drawLine(0, bottomLimitInPixel, 30, bottomLimitInPixel);
}
};
boundaryFigure.setLayoutManager(new ColourSliderCompositeLayout());
boundaryFigure.setBackgroundColor(ColorConstants.white);
// Top slider figure
topSliderHolder = new Panel();
topSliderHolder.setLayoutManager(new XYLayout());
topTriangleFigure = new Triangle();
topTriangleFigure.setDirection(PositionConstants.SOUTH);
topTriangleFigure.setFill(true);
topTriangleFigure.setBackgroundColor(ColorConstants.buttonDarker);
topTriangleFigure.setForegroundColor(ColorConstants.black);
topTriangleFigure.setCursor(Display.getCurrent().getSystemCursor(SWT.CURSOR_HAND));
topClosureFigure = new RectangleFigure();
topClosureFigure.setBackgroundColor(ColorConstants.black);
topClosureFigure.setForegroundColor(ColorConstants.black);
topClosureFigure.setOpaque(true);
topClosureFigure.setFill(true);
topSliderHolder.add(topTriangleFigure, new Rectangle(0, 0, 20, 15));
topSliderHolder.add(topClosureFigure, new Rectangle(0, 13, 20, 1));
topSliderDragger = new Dragger();
topSliderHolder.addMouseMotionListener(topSliderDragger);
topSliderHolder.addMouseListener(topSliderDragger);
topSliderHolder.setBounds(new Rectangle(5, 5, 20, 15));
// Bottom slider figure
bottomSliderHolder = new Panel();
bottomSliderHolder.setLayoutManager(new XYLayout());
bottomTriangleFigure = new Triangle();
bottomTriangleFigure.setDirection(PositionConstants.NORTH);
bottomTriangleFigure.setFill(true);
bottomTriangleFigure.setBackgroundColor(ColorConstants.buttonDarker);
bottomTriangleFigure.setForegroundColor(ColorConstants.black);
bottomTriangleFigure.setCursor(Display.getCurrent().getSystemCursor(SWT.CURSOR_HAND));
bottomClosureFigure = new RectangleFigure();
bottomClosureFigure.setFill(true);
bottomClosureFigure.setBackgroundColor(ColorConstants.black);
bottomClosureFigure.setForegroundColor(ColorConstants.black);
bottomSliderHolder.add(bottomTriangleFigure);
bottomSliderHolder.add(bottomClosureFigure);
bottomSliderDragger = new Dragger();
bottomSliderHolder.addMouseMotionListener(bottomSliderDragger);
bottomSliderHolder.addMouseListener(bottomSliderDragger);
bottomSliderHolder.setBounds(new Rectangle(5, 5, 20, 15));
//
upperGradientedFigure = new ColorGradientedFigure(ColorConstants.white, ColorConstants.white);
//
lowerGradientedFigure = new ColorGradientedFigure(ColorConstants.white, ColorConstants.white);
histogramRect = new ColorGradientedFigure(ColorConstants.black, ColorConstants.white);
boundaryFigure.add(upperGradientedFigure);
boundaryFigure.add(lowerGradientedFigure);
boundaryFigure.add(histogramRect);
boundaryFigure.add(topSliderHolder);
boundaryFigure.add(bottomSliderHolder);
return boundaryFigure;
}
Example 87
Project: ocelotl-master File: Snapshot.java View source code |
/**
* Generate the image
*
* @param figure
* Figure from which the image is created
* @param format
* format of the generated image
* @return an array of bytes corresponding to an image
*/
private byte[] createImage(Figure figure, int format) {
Device device = Display.getCurrent();
Rectangle r = figure.getBounds();
if (r.width <= 0 || r.height <= 0) {
logger.debug("Size of figure is 0: stopping generation");
return null;
}
ByteArrayOutputStream result = new ByteArrayOutputStream();
Image image = null;
GC gc = null;
Graphics g = null;
try {
image = new Image(device, 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);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (g != null) {
g.dispose();
}
if (gc != null) {
gc.dispose();
}
if (image != null) {
image.dispose();
}
}
return result.toByteArray();
}
Example 88
Project: chrysalix-master File: FocusTreeCanvas.java View source code |
@Override
public void paint(final IFigure figure, final Graphics graphics, final Insets insets) {
tempRect.setBounds(getPaintRectangle(figure, insets));
if (getWidth() % 2 == 1) {
tempRect.width--;
tempRect.height--;
}
tempRect.shrink(getWidth() / 2, getWidth() / 2);
graphics.setLineWidth(getWidth());
graphics.setLineStyle(getStyle());
graphics.setForegroundColor(getColor());
graphics.drawRoundRectangle(tempRect, 8, 8);
}
Example 89
Project: sloot-editor-master File: HorizontalEdgeFigure.java View source code |
/* * (non-Javadoc) * * @see org.eclipse.draw2d.Shape#fillShape(org.eclipse.draw2d.Graphics) */ @Override protected void fillShape(Graphics graphics) { graphics.setBackgroundColor(ColorConstants.cyan); graphics.setForegroundColor(ColorConstants.blue); int w = getBounds().x + getBounds().width; int h = getBounds().y + getBounds().height; graphics.drawLine(getBounds().x, getBounds().y, w, getBounds().y); }
Example 90
Project: drools-guvnor-plugin-master File: ConnectionFigure.java View source code |
/**
* Painting antialiased connector
*/
public void paint(Graphics g) {
g.setAntialias(SWT.ON);
super.paint(g);
}
Example 91
Project: droolsjbpm-master File: ConnectionFigure.java View source code |
/**
* Painting antialiased connector
*/
public void paint(Graphics g) {
g.setAntialias(SWT.ON);
super.paint(g);
}
Example 92
Project: droolsjbpm-tools-master File: ConnectionFigure.java View source code |
/**
* Painting antialiased connector
*/
public void paint(Graphics g) {
g.setAntialias(SWT.ON);
super.paint(g);
}
Example 93
Project: EMF-IncQuery-Examples-master File: HumanCircleFigure.java View source code |
@Override
protected void paintFigure(Graphics graphics) {
Rectangle r = getBounds().getCopy();
setConstraint(rectangle, new Rectangle(0, 0, r.width, r.height));
setConstraint(label, new Rectangle(0, 0, r.width, r.height));
}
Example 94
Project: plugin.maven-drools-plugin-master File: ConnectionFigure.java View source code |
/**
* Painting antialiased connector
*/
public void paint(Graphics g) {
g.setAntialias(SWT.ON);
super.paint(g);
}
Example 95
Project: Green-UML-master File: CompartmentFigure.java View source code |
/** * @see org.eclipse.draw2d.Border#paint(org.eclipse.draw2d.IFigure, org.eclipse.draw2d.Graphics, org.eclipse.draw2d.geometry.Insets) */ public void paint(IFigure figure, Graphics graphics, Insets insets) { graphics.drawLine(getPaintRectangle(figure, insets).getTopLeft(), tempRect.getTopRight()); }
Example 96
Project: ecoretools-master File: DNodeListEditPartWithAlpha.java View source code |
@Override
protected void paintChildren(Graphics graphics) {
int prevAlpha = graphics.getAlpha();
graphics.setAlpha(alpha);
super.paintChildren(graphics);
graphics.setAlpha(prevAlpha);
}
Example 97
Project: hale-master File: AbstractPolygonPainter.java View source code |
@Override
public void fillShape(Graphics graphics, Rectangle bounds) {
int[] points = getPoints(bounds, graphics.getLineWidth());
graphics.fillPolygon(points);
}
Example 98
Project: org.roxgt-master File: RoxgtTextSelectionEditPolicy.java View source code |
protected void paintFigure(Graphics graphics) {
graphics.drawFocus(getBounds().getResized(-1, -1));
}
Example 99
Project: cdo-master File: AcoreTextSelectionEditPolicy.java View source code |
@Override
protected void paintFigure(Graphics graphics) {
graphics.drawFocus(getBounds().getResized(-1, -1));
}
Example 100
Project: eclipse-optimus-master File: TransformationDependencyTextNonResizableEditPolicy.java View source code |
protected void paintFigure(Graphics graphics) {
graphics.drawFocus(getBounds().getResized(-1, -1));
}
Example 101
Project: molic-master File: MolicTextNonResizableEditPolicy.java View source code |
protected void paintFigure(Graphics graphics) {
graphics.drawFocus(getBounds().getResized(-1, -1));
}