List of usage examples for com.google.gwt.canvas.dom.client Context2d stroke
public final native void stroke() ;
From source file:anagram.client.Lens.java
License:Apache License
public void draw(Context2d back, Context2d front) { front.drawImage(back.getCanvas(), 0, 0); if (!GWT.isScript()) { // in devmode this effect is slow so we disable it here } else {/*from w w w . j ava 2s . c om*/ ImageData frontData = front.getImageData((int) (pos.x - radius), (int) (pos.y - radius), 2 * radius, 2 * radius); CanvasPixelArray frontPixels = frontData.getData(); ImageData backData = back.getImageData((int) (pos.x - radius), (int) (pos.y - radius), 2 * radius, 2 * radius); CanvasPixelArray backPixels = backData.getData(); int srcIdx, dstIdx; for (int i = lensArray.length - 1; i >= 0; i--) { dstIdx = 4 * lensArray[i][0]; srcIdx = 4 * lensArray[i][1]; frontPixels.set(dstIdx + 0, backPixels.get(srcIdx + 0)); frontPixels.set(dstIdx + 1, backPixels.get(srcIdx + 1)); frontPixels.set(dstIdx + 2, backPixels.get(srcIdx + 2)); } front.putImageData(frontData, (int) (pos.x - radius), (int) (pos.y - radius)); } front.setStrokeStyle(strokeStyle); front.beginPath(); front.arc(pos.x, pos.y, radius, 0, Math.PI * 2, true); front.closePath(); front.stroke(); }
From source file:com.kk_electronic.kkportal.debug.modules.UsageGraph.java
License:Open Source License
@Inject public UsageGraph(CpuUsage model) { Context2d context = canvas.getContext2d(); model.addDisplay(this); context.setLineWidth(1);/*ww w .j a v a 2s. c om*/ context.setStrokeStyle("black"); canvas.getElement().getStyle().setBorderWidth(borderSize, Unit.PX); canvas.getElement().getStyle().setBorderStyle(BorderStyle.SOLID); canvas.getElement().getStyle().setBorderColor(borderColor); context.beginPath(); context.moveTo(1, 1); context.lineTo(1, 50); context.lineTo(100, 50); context.lineTo(50, 1); context.closePath(); context.stroke(); timer.scheduleRepeating(100); }
From source file:com.kk_electronic.kkportal.debug.modules.UsageGraph.java
License:Open Source License
private void drawPath(List<? extends Double> values, double shift) { if (values == null || values.isEmpty()) return;/*from w w w . j a va2 s .co m*/ Context2d context = canvas.getContext2d(); // context.setTransform(m11, m12, m21, m22, dx, dy) context.clearRect(0, 0, canvas.getOffsetWidth(), canvas.getCoordinateSpaceHeight()); // context.clear(); context.beginPath(); double pixelpersecond = canvas.getCoordinateSpaceWidth() / magicNumber; int o = Math.max(60 - values.size(), 0); // How many missing values context.moveTo((o - shift * 2 - 1) * pixelpersecond, canvas.getCoordinateSpaceHeight() * values.get(0)); for (int i = 1, l = values.size(); i < l; i++) { double x = (i + o - shift * 2 - 1) * pixelpersecond; double y = canvas.getCoordinateSpaceHeight() * (1 - values.get(i)); context.lineTo(x, y); } context.stroke(); }
From source file:com.mecatran.otp.gwt.client.view.ItineraryDetailsWidget.java
License:Open Source License
/** * Build the background image for the widget, according to the mode. Draw * the mode image and a solid line below it with the route color (if in * transit mode) or a dotted line (if in road mode). Set the * background-image to the generated image for the given widget. */// w w w . ja v a 2 s .c o m public static void styleComponentWithMode(final Widget widget, TransportMode mode, String color) { PlannerResources resources = PlannerResources.INSTANCE; ImageResource baseImage = null; boolean road = false; switch (mode) { case WALK: road = true; color = "#666666"; baseImage = resources.modeWalkPng(); break; case BICYCLE: road = true; color = "#23C30B"; baseImage = resources.modeBicyclePng(); break; case BICYCLE_RENTAL: road = true; color = "#23C30B"; baseImage = resources.modeBikeRentalPng(); break; case CAR: road = true; color = "#333333"; baseImage = resources.modeCarPng(); break; default: case BUS: baseImage = resources.modeBusPng(); break; case TRAM: baseImage = resources.modeTramPng(); break; case FERRY: baseImage = resources.modeFerryPng(); break; case GONDOLA: baseImage = resources.modeGondolaPng(); break; case PLANE: baseImage = resources.modePlanePng(); break; case RAIL: baseImage = resources.modeRailPng(); break; case SUBWAY: baseImage = resources.modeSubwayPng(); break; case TROLLEY: baseImage = resources.modeTrolleyPng(); break; } final String url = baseImage.getSafeUri().asString(); final Canvas canvas = Canvas.createIfSupported(); if (canvas != null) { int width = baseImage.getWidth(); int height = 1000; canvas.setCoordinateSpaceWidth(width); canvas.setCoordinateSpaceHeight(height); final Context2d context = canvas.getContext2d(); context.setLineCap(LineCap.BUTT); if (road) { context.setStrokeStyle(CssColor.make(color)); context.setLineWidth(4); for (int y = baseImage.getHeight(); y < 1000; y += 7) { context.moveTo(width / 2, y); context.lineTo(width / 2, y + 5); } context.stroke(); } else { context.setStrokeStyle(CssColor.make("#000000")); context.setLineWidth(5); context.moveTo(width / 2, 0); context.lineTo(width / 2, height - 1); context.stroke(); context.setStrokeStyle(CssColor.make(color)); context.setLineWidth(4); context.moveTo(width / 2, 0); context.lineTo(width / 2, height - 1); context.stroke(); } /* * HACK ALERT! Image.onLoad event does not fire up when using * internal resources (URL is internal data), but using the image * immediately does not work (image does not seems to be ready). We * defer the processing of the image rendering to a timer delayed a * bit. */ Timer timer = new Timer() { @Override public void run() { Image image = new Image(url); ImageElement e = ImageElement.as(image.getElement()); context.drawImage(e, 0, 0); String url2 = canvas.toDataUrl("image/png"); widget.getElement().getStyle().setBackgroundImage("url('" + url2 + "')"); } }; timer.schedule(500); } else { widget.getElement().getStyle().setBackgroundImage("url('" + url + "')"); } }
From source file:com.philbeaudoin.quebec.client.scene.Arrow.java
License:Apache License
@Override public void drawUntransformed(double time, Context2d context) { context.beginPath();//from w w w . j av a 2 s. c o m context.moveTo(from.getX(), from.getY()); context.bezierCurveTo(p1.getX(), p1.getY(), p2.getX(), p2.getY(), p3.getX(), p3.getY()); context.lineTo(p4.getX(), p4.getY()); context.lineTo(to.getX(), to.getY()); context.lineTo(p5.getX(), p5.getY()); context.lineTo(p6.getX(), p6.getY()); context.bezierCurveTo(p2.getX(), p2.getY(), p1.getX(), p1.getY(), from.getX(), from.getY()); context.setLineWidth(0.0045); context.setStrokeStyle("#aaa"); context.stroke(); context.setLineWidth(0.001); context.setStrokeStyle("#000"); context.stroke(); context.fill(); }
From source file:com.philbeaudoin.quebec.client.scene.Callout.java
License:Apache License
@Override public void drawUntransformed(double time, Context2d context) { context.beginPath();//from w w w.ja va2s . co m context.moveTo(p1.getX(), p1.getY()); context.lineTo(to.getX(), to.getY()); context.lineTo(p3.getX(), p3.getY()); context.lineTo(p1.getX(), p1.getY()); context.setLineWidth(0.002); context.setStrokeStyle("#000"); context.stroke(); context.setFillStyle("#aaa"); context.fill(); }
From source file:com.sencha.gxt.chart.client.draw.engine.Canvas2d.java
License:sencha.com license
/** * In the Canvas2d class, this method does more or less what renderSprite does in SVG and VML - it * actually renders the sprite to the dom. * @param sprite the sprite to draw// ww w .j a v a 2 s. c o m */ protected void append(Sprite sprite) { if (sprite.isHidden() || sprite.getOpacity() == 0) { return; } Context2d ctx = getContext(); ctx.save(); //set global stuff, fill, stroke, clip, etc //clip - deal with translation or normal rectangle if (sprite.getClipRectangle() != null) { PreciseRectangle clip = sprite.getClipRectangle(); if (sprite.getScaling() != null || sprite.getTranslation() != null || sprite.getRotation() != null) { PathSprite transPath = new PathSprite(new RectangleSprite(clip)); transPath = transPath.map(sprite.transformMatrix()); appendPath(ctx, transPath); } else { ctx.beginPath(); ctx.rect(clip.getX(), clip.getY(), clip.getWidth(), clip.getHeight()); ctx.closePath(); } ctx.clip(); } if (sprite.getScaling() != null || sprite.getTranslation() != null || sprite.getRotation() != null || (component.isViewBox() && viewbox != null)) { Matrix matrix = sprite.transformMatrix(); if (matrix != null) { //TODO consider replacing this transform call with three distinct calls to translate/scale/rotate if cheaper ctx.transform(matrix.get(0, 0), matrix.get(1, 0), matrix.get(0, 1), matrix.get(1, 1), matrix.get(0, 2), matrix.get(1, 2)); } if (component.isViewBox() && viewbox != null) { double size = Math.min(getWidth() / viewbox.getWidth(), getHeight() / viewbox.getHeight()); ctx.scale(size, size); ctx.translate(-viewbox.getX(), -viewbox.getY()); } } //TODO see about caching colors via the dirty flag? If we don't use a color/gradient for a pass or three, dump it double opacity = Double.isNaN(sprite.getOpacity()) ? 1.0 : sprite.getOpacity(); PreciseRectangle untransformedBbox = sprite.getPathSprite().dimensions(); if (sprite.getStroke() != null && sprite.getStroke() != Color.NONE && sprite.getStrokeWidth() != 0) { ctx.setLineWidth(Double.isNaN(sprite.getStrokeWidth()) ? 1.0 : sprite.getStrokeWidth()); ctx.setStrokeStyle(getColor(sprite.getStroke(), untransformedBbox));//TODO read bbox from cache } if (sprite.getFill() != null && sprite.getFill() != Color.NONE) { ctx.setFillStyle(getColor(sprite.getFill(), untransformedBbox));//TODO read bbox from cache } if (sprite instanceof PathSprite) { appendPath(ctx, (PathSprite) sprite); } else if (sprite instanceof TextSprite) { TextSprite text = (TextSprite) sprite; //TODO style and weight ctx.setFont(text.getFontSize() + "px " + text.getFont()); ctx.setTextAlign(getTextAlign(text.getTextAnchor())); ctx.setTextBaseline(getTextBaseline(text.getTextBaseline())); ctx.fillText(text.getText(), text.getX(), text.getY()); } else if (sprite instanceof RectangleSprite) { RectangleSprite rect = (RectangleSprite) sprite; if (Double.isNaN(rect.getRadius()) || rect.getRadius() == 0) { if (sprite.getFill() != null && sprite.getFill() != Color.NONE) { ctx.setGlobalAlpha( Double.isNaN(sprite.getFillOpacity()) ? opacity : opacity * sprite.getFillOpacity()); ctx.fillRect(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight()); } if (sprite.getStroke() != null && sprite.getStroke() != Color.NONE && sprite.getStrokeWidth() != 0) { ctx.setGlobalAlpha(Double.isNaN(sprite.getStrokeOpacity()) ? opacity : opacity * sprite.getStrokeOpacity()); ctx.strokeRect(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight()); } } else { appendPath(ctx, rect.getPathSprite()); } } else if (sprite instanceof CircleSprite) { CircleSprite circle = (CircleSprite) sprite; ctx.beginPath(); ctx.arc(circle.getCenterX(), circle.getCenterY(), circle.getRadius(), 0, 2 * Math.PI); ctx.closePath(); if (sprite.getFill() != null && sprite.getFill() != Color.NONE) { ctx.setGlobalAlpha( Double.isNaN(sprite.getFillOpacity()) ? opacity : opacity * sprite.getFillOpacity()); ctx.fill(); } if (sprite.getStroke() != null && sprite.getStroke() != Color.NONE && sprite.getStrokeWidth() != 0) { ctx.setGlobalAlpha( Double.isNaN(sprite.getStrokeOpacity()) ? opacity : opacity * sprite.getStrokeOpacity()); ctx.stroke(); } } else if (sprite instanceof EllipseSprite) { appendPath(ctx, sprite.getPathSprite()); } else if (sprite instanceof ImageSprite) { ImageSprite image = (ImageSprite) sprite; ImageElement elt = Document.get().createImageElement(); elt.setSrc(image.getResource().getSafeUri().asString()); ctx.drawImage(elt, image.getX(), image.getY(), image.getWidth(), image.getHeight()); } ctx.restore(); if (!REDRAW_ALL) { renderedBbox.put(sprite, getBBox(sprite)); } sprite.clearDirtyFlags(); }
From source file:com.sencha.gxt.chart.client.draw.engine.Canvas2d.java
License:sencha.com license
protected void appendPath(Context2d ctx, PathSprite sprite) { ctx.beginPath();/*from w w w .j av a 2 s.c o m*/ sprite.toAbsolute(); // sprite = sprite.copy().toCurve(); PrecisePoint currentPoint = new PrecisePoint(); PrecisePoint movePoint = new PrecisePoint(); PrecisePoint curvePoint = new PrecisePoint(); PrecisePoint quadraticPoint = new PrecisePoint(); appendPathCommands(ctx, sprite.getCommands(), currentPoint, movePoint, curvePoint, quadraticPoint); double opacity = Double.isNaN(sprite.getOpacity()) ? 1.0 : sprite.getOpacity(); if (sprite.getFill() != null && sprite.getFill() != Color.NONE) { ctx.setGlobalAlpha(Double.isNaN(sprite.getFillOpacity()) ? opacity : opacity * sprite.getFillOpacity()); ctx.fill(); } if (sprite.getStroke() != null && sprite.getStroke() != Color.NONE && sprite.getStrokeWidth() != 0) { ctx.setLineCap(sprite.getStrokeLineCap() == null ? LineCap.BUTT : sprite.getStrokeLineCap()); ctx.setLineJoin(sprite.getStrokeLineJoin() == null ? LineJoin.MITER : sprite.getStrokeLineJoin()); ctx.setMiterLimit(sprite.getMiterLimit() == Double.NaN ? 4 : sprite.getMiterLimit()); ctx.setGlobalAlpha( Double.isNaN(sprite.getStrokeOpacity()) ? opacity : opacity * sprite.getStrokeOpacity()); ctx.stroke(); } }
From source file:edu.umb.jsPedigrees.client.Pelican.PelicanLines.java
License:Open Source License
public static Canvas drawLines(AbsolutePanel panel) { Canvas canvas = Canvas.createIfSupported(); Context2d ctx = canvas.getContext2d(); canvas.setCoordinateSpaceHeight(panel.getOffsetHeight()); canvas.setCoordinateSpaceWidth(panel.getOffsetWidth()); ctx.setStrokeStyle(CssColor.make("0,0,0")); ctx.setLineWidth(1.0f);/* w ww . j a va2 s .c om*/ ctx.setFont("12px sans-serif"); int fontHeight = 15; int fontAscent = 15; int dropSize = Math.max(2, Math.min(PelicanPerson.symbolSize / 2, 3 * (PelicanPerson.ySpace - PelicanPerson.symbolSize - fontHeight) / 4)); for (int i = 0; i < panel.getWidgetCount(); i++) if (panel.getWidget(i) instanceof PelicanPerson) { // draw a line from this person to its parents PelicanPerson person = (PelicanPerson) panel.getWidget(i); if (person.father != null && person.mother != null) { //System.out.println("HERE "+String.valueOf(i)); // find the mother and father PelicanPerson father = person.father; PelicanPerson mother = person.mother; if (father != null && mother != null) { // line between parents int fatherX = panel.getWidgetLeft(father) + ((panel.getWidgetLeft(father) < panel.getWidgetLeft(mother)) ? PelicanPerson.symbolSize : 0); int motherX = panel.getWidgetLeft(mother) + ((panel.getWidgetLeft(mother) < panel.getWidgetLeft(father)) ? PelicanPerson.symbolSize : 0); int fatherY = panel.getWidgetTop(father) + PelicanPerson.symbolSize / 2; int motherY = panel.getWidgetTop(mother) + PelicanPerson.symbolSize / 2; int leftX = fatherX; int leftY = fatherY; int rightX = motherX; int rightY = motherY; if (motherX < fatherX) { leftX = motherX; leftY = motherY; rightX = fatherX; rightY = fatherY; } int gap = PelicanPerson.xSpace - PelicanPerson.symbolSize; // see if any subjects lie between the father and mother if (!adjacent(panel, father, mother) && father.generation == mother.generation) { // draw lines which avoid other symbols // g2.drawLine(leftX,leftY,leftX+gap/4,leftY); ctx.beginPath(); ctx.moveTo(leftX, leftY); ctx.lineTo(leftX + gap / 4, leftY); ctx.closePath(); ctx.stroke(); // g2.drawLine(rightX,rightY,rightX-gap/2,rightY); ctx.beginPath(); ctx.moveTo(rightX, rightY); ctx.lineTo(rightX - gap / 2, rightY); ctx.closePath(); ctx.stroke(); leftX += gap / 4; rightX -= gap / 2; // g2.drawLine(leftX,leftY,leftX,leftY-(PelicanPerson.symbolSize+dropSize)/2); ctx.beginPath(); ctx.moveTo(leftX, leftY); ctx.lineTo(leftX, leftY - (PelicanPerson.symbolSize + dropSize) / 2); ctx.closePath(); ctx.stroke(); // g2.drawLine(rightX,rightY,rightX,rightY-(PelicanPerson.symbolSize+dropSize)/2); ctx.beginPath(); ctx.moveTo(rightX, rightY); ctx.lineTo(rightX, rightY - (PelicanPerson.symbolSize + dropSize) / 2); ctx.closePath(); ctx.stroke(); leftY -= (PelicanPerson.symbolSize + dropSize) / 2; rightY -= (PelicanPerson.symbolSize + dropSize) / 2; } // g2.drawLine(leftX,leftY,rightX,rightY); ctx.beginPath(); ctx.moveTo(leftX, leftY); ctx.lineTo(rightX, rightY); ctx.closePath(); ctx.stroke(); // line up from child // g2.drawLine(person.getX()+PelicanPerson.symbolSize/2,person.getY(),person.getX()+PelicanPerson.symbolSize/2,person.getY()-dropSize); ctx.beginPath(); ctx.moveTo(panel.getWidgetLeft(person) + PelicanPerson.symbolSize / 2, panel.getWidgetTop(person)); ctx.lineTo(panel.getWidgetLeft(person) + PelicanPerson.symbolSize / 2, panel.getWidgetTop(person) - dropSize); ctx.closePath(); ctx.stroke(); // line across from child // try to attach to an orphan parent int parentX = fatherX; if (father.isOrphan() || mother.isOrphan()) { parentX = Math.max(fatherX, motherX) - gap / 2; } else { // if no orphan parents, go straight up from // middle laid out sib int nsib = 0; for (int j = 0; j < panel.getWidgetCount(); j++) if (panel.getWidget(j) instanceof PelicanPerson) { PelicanPerson sib = (PelicanPerson) panel.getWidget(j); if (areSibs(person, sib)) nsib++; } int sibs = 0; for (int j = 0; j < panel.getWidgetCount() && sibs <= nsib / 2; j++) if (panel.getWidget(j) instanceof PelicanPerson) { PelicanPerson sib = (PelicanPerson) panel.getWidget(j); if (areSibs(person, sib)) sibs++; parentX = panel.getWidgetLeft(sib) + PelicanPerson.symbolSize / 2; } if (nsib > 1 && nsib % 2 == 0) parentX -= PelicanPerson.xSpace / 2; if (parentX <= leftX) parentX = leftX + PelicanPerson.symbolSize / 2; if (parentX >= rightX) parentX = rightX - PelicanPerson.symbolSize / 2; } // g2.drawLine(person.getX()+PelicanPerson.symbolSize/2,person.getY()-dropSize,parentX,person.getY()-dropSize); ctx.beginPath(); ctx.moveTo(panel.getWidgetLeft(person) + PelicanPerson.symbolSize / 2, panel.getWidgetTop(person) - dropSize); ctx.lineTo(parentX, panel.getWidgetTop(person) - dropSize); ctx.closePath(); ctx.stroke(); // line up to parents // Draw a vertical line up to the line joining the parents // if this happens to be not between the parents, // change it to a line to the midpoint between the parents int parentY = (rightX != leftX) ? leftY + (rightY - leftY) * (parentX - leftX) / (rightX - leftX) : (leftY + rightY) / 2; if (rightX == leftX || parentY > Math.max(leftY, rightY) || parentY < Math.min(leftY, rightY)) { // g2.drawLine(parentX,person.getY()-dropSize, (leftX+rightX)/2,(leftY+rightY)/2); ctx.beginPath(); ctx.moveTo(parentX, panel.getWidgetTop(person) - dropSize); ctx.lineTo((leftX + rightX) / 2, (leftY + rightY) / 2); ctx.closePath(); ctx.stroke(); } else { // g2.drawLine(parentX,person.getY()-dropSize,parentX,parentY); ctx.beginPath(); ctx.moveTo(parentX, panel.getWidgetTop(person) - dropSize); ctx.lineTo(parentX, parentY); ctx.closePath(); ctx.stroke(); } } } // write out id int verticalPosn = panel.getWidgetTop(person) + PelicanPerson.symbolSize + fontAscent; String idString = String.valueOf(person.id); int fontWidth = (int) ctx.measureText(idString).getWidth(); // g2.drawString(idString, // person.getX() + PelicanPerson.symbolSize/2 - fontWidth/2, // verticalPosn); ctx.fillText(idString, panel.getWidgetLeft(person) + PelicanPerson.symbolSize / 2 - fontWidth / 2, verticalPosn); verticalPosn += fontAscent; } return canvas; }
From source file:edu.umb.jsPedigrees.client.Pelican.PelicanPerson.java
License:Open Source License
public void drawSymbol() { Context2d ctx = canvas.getContext2d(); // clear old symbol ctx.clearRect(0, 0, symbolSize + 1, symbolSize + 1); ctx.setStrokeStyle(CssColor.make("0,0,0")); ctx.setLineWidth(1.0f);/*from w ww. j a v a 2 s .c o m*/ if (sex == male) { ctx.strokeRect(0, 0, symbolSize, symbolSize); if (affection == affected) { ctx.fillRect(0, 0, symbolSize, symbolSize); } } if (sex == female) { // g2.drawArc(0,0,symbolSize,symbolSize,0,360); ctx.beginPath(); ctx.arc(symbolSize / 2, symbolSize / 2, (symbolSize / 2) - 1, 0, 360); if (affection == affected) { ctx.fill(); } else { ctx.stroke(); } } }