List of usage examples for com.google.gwt.canvas.dom.client CssColor value
public final native String value() ;
From source file:examples.geometry.containment.PolygonCubicCurveContainment.java
License:Open Source License
@Override protected AbstractControllableShape createControllableShape2(final Canvas canvas) { return new AbstractControllableShape(canvas) { @Override// w w w . j a v a 2s .c o m public void createControlPoints() { addControlPoint(new Point(200, 100)); addControlPoint(new Point(190, 310)); addControlPoint(new Point(410, 90)); addControlPoint(new Point(400, 300)); } @Override public CubicCurve createGeometry() { return new CubicCurve(getControlPoints()); } @Override public void drawShape() { CubicCurve c = createGeometry(); Path path = c.toPath(); CanvasDrawer.strokePath(path, canvas.getContext2d()); // gc.drawPath(new org.eclipse.swt.graphics.Path(Display // .getCurrent(), Geometry2SWT.toSWTPathData(c.toPath()))); } @Override public void fillShape(CssColor color) { // int lineWidth = gc.getLineWidth(); // Color fg = gc.getForeground(); Context2d context2d = canvas.getContext2d(); FillStrokeStyle fillStyle = context2d.getFillStyle(); context2d.setLineWidth(3); context2d.setStrokeStyle(color.value()); // gc.setLineWidth(3); // gc.setForeground(gc.getBackground()); drawShape(); context2d.setLineWidth(1); context2d.setStrokeStyle(fillStyle); // gc.setForeground(fg); // gc.setLineWidth(lineWidth); } }; }
From source file:examples.geometry.containment.PolygonEllipseContainment.java
License:Open Source License
@Override protected AbstractControllableShape createControllableShape2(final Canvas canvas) { return new AbstractControllableShape(canvas) { @Override// w w w . ja v a2s .com public void createControlPoints() { ControlPoint center = addControlPoint(new Point(300, 300)); ControlPoint a = addControlPoint(new Point(400, 300)); ControlPoint b = addControlPoint(new Point(300, 200)); a.setYLink(center); b.setXLink(center); } @Override public Ellipse createGeometry() { double a = Math.abs(points.get(0).getPoint().x - points.get(1).getPoint().x); double b = Math.abs(points.get(0).getPoint().y - points.get(2).getPoint().y); return new Ellipse(points.get(0).getPoint().x - a, points.get(0).getPoint().y - b, 2 * a, 2 * b); } @Override public void drawShape() { Ellipse ellipse = createGeometry(); CanvasDrawer.drawOval(ellipse, canvas.getContext2d()); } @Override public void fillShape(CssColor color) { Ellipse ellipse = createGeometry(); Context2d context2d = canvas.getContext2d(); FillStrokeStyle style = context2d.getFillStyle(); CanvasDrawer.drawOval(ellipse, context2d); context2d.setFillStyle(color.value()); context2d.fill(); context2d.setFillStyle(style); } }; }
From source file:examples.geometry.containment.PolygonLineContainment.java
License:Open Source License
@Override protected AbstractControllableShape createControllableShape2(final Canvas canvas) { return new AbstractControllableShape(canvas) { @Override// ww w .j a v a 2 s. co m public void createControlPoints() { addControlPoint(new Point(100, 100)); addControlPoint(new Point(300, 300)); } @Override public Line createGeometry() { Point[] points = getControlPoints(); return new Line(points[0], points[1]); } @Override public void drawShape() { Line line = createGeometry(); Context2d c = canvas.getContext2d(); c.beginPath(); c.moveTo(line.getX1(), line.getY1()); c.lineTo(line.getX2(), line.getY2()); c.closePath(); c.stroke(); } @Override public void fillShape(CssColor color) { Context2d context2d = canvas.getContext2d(); FillStrokeStyle style = context2d.getFillStyle(); context2d.setLineWidth(3); context2d.setStrokeStyle(color.value()); drawShape(); context2d.setLineWidth(1); // context2d.setStrokeStyle(CssColor.make(0, 0, 0).value()); context2d.setStrokeStyle(style); } }; }
From source file:examples.geometry.containment.PolygonPolygonContainment.java
License:Open Source License
@Override protected AbstractControllableShape createControllableShape2(final Canvas canvas) { return new AbstractControllableShape(canvas) { @Override// w ww . ja v a2 s . c om public void createControlPoints() { addControlPoint(new Point(200, 200)); } @Override public Polygon createGeometry() { Point[] points = getControlPoints(); Polygon polygon = new Polygon(points[0].x - 30, points[0].y - 30, points[0].x + 80, points[0].y - 20, points[0].x - 20, points[0].y + 40); return polygon; } @Override public void drawShape() { Polygon polygon = createGeometry(); Context2d c = canvas.getContext2d(); CanvasDrawer.strokePath(polygon.toPath(), c); } @Override public void fillShape(CssColor color) { Polygon polygon = createGeometry(); Context2d c = canvas.getContext2d(); FillStrokeStyle style = c.getFillStyle(); c.setFillStyle(color.value()); CanvasDrawer.fillPath(polygon.toPath(), c); c.setFillStyle(style); } }; }
From source file:examples.geometry.containment.PolygonPolylineContainment.java
License:Open Source License
@Override protected AbstractControllableShape createControllableShape2(final Canvas canvas) { return new AbstractControllableShape(canvas) { @Override/*from w ww . j a v a 2 s. c om*/ public void createControlPoints() { addControlPoint(new Point(100, 100)); addControlPoint(new Point(100, 300)); addControlPoint(new Point(300, 300)); addControlPoint(new Point(300, 100)); } @Override public Polyline createGeometry() { Point[] points = getControlPoints(); Polyline polyline = new Polyline(points); return polyline; } @Override public void drawShape() { Polyline polyline = createGeometry(); CanvasDrawer.strokePath(polyline.toPath(), canvas.getContext2d()); } @Override public void fillShape(CssColor color) { Context2d context2d = canvas.getContext2d(); FillStrokeStyle style = context2d.getStrokeStyle(); context2d.setLineWidth(3); context2d.setStrokeStyle(color.value()); drawShape(); context2d.setLineWidth(1); // context2d.setStrokeStyle(CssColor.make(0, 0, 0).value()); context2d.setStrokeStyle(style); } }; }
From source file:examples.geometry.containment.PolygonRectangleContainment.java
License:Open Source License
@Override protected AbstractControllableShape createControllableShape2(final Canvas canvas) { return new AbstractControllableShape(canvas) { private final double WIDTH = 50; private final double HEIGHT = 75; @Override/* w w w . j a v a 2s. c om*/ public void createControlPoints() { addControlPoint(new Point(110, 70)); } @Override public Rectangle createGeometry() { Point[] points = getControlPoints(); return new Rectangle(points[0].x - WIDTH / 2, points[0].y - HEIGHT / 2, WIDTH, HEIGHT); } @Override public void drawShape() { Rectangle rect = createGeometry(); Context2d context2d = canvas.getContext2d(); context2d.rect(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight()); context2d.stroke(); } @Override public void fillShape(CssColor color) { Rectangle rect = createGeometry(); Context2d context2d = canvas.getContext2d(); FillStrokeStyle style = context2d.getFillStyle(); context2d.setFillStyle(color.value()); context2d.fillRect(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight()); context2d.setFillStyle(style); } }; }
From source file:org.rstudio.studio.client.workbench.views.vcs.diff.NavGutter.java
License:Open Source License
public void setData(CssColor background, ArrayList<CssColor> lines) { Canvas newCanvas = Canvas.createIfSupported(); newCanvas.setSize("100%", "100%"); newCanvas.setCoordinateSpaceWidth(10); newCanvas.setCoordinateSpaceHeight(lines.size()); Context2d ctx = newCanvas.getContext2d(); ctx.translate(0.5, 0.5);/* w w w .jav a 2s.c o m*/ ctx.setFillStyle(background.value()); ctx.fillRect(0, 0, 10, lines.size()); for (int i = 0; i < lines.size(); i++) { CssColor color = lines.get(i); if (color != null) { ctx.setFillStyle(color.value()); ctx.fillRect(0, i, 10, 1); } } container_.setWidget(newCanvas); }