Java Code Examples for com.google.gwt.dom.client.CanvasElement

The following examples show how to use com.google.gwt.dom.client.CanvasElement. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: djvu-html5   Source File: DataStore.java    License: GNU General Public License v2.0 6 votes vote down vote up
private CanvasElement prepareMissingTileImage() {
	int tileSize = DjvuContext.getTileSize();
	CanvasElement canvas = createImage(tileSize, tileSize);
	Context2d context2d = canvas.getContext2d();
	context2d.setFillStyle("white");
	context2d.fillRect(0, 0, canvas.getWidth(), canvas.getHeight());
	Image image = new Image();
	final ImageElement imageElement = image.getElement().cast();
	imageElement.getStyle().setProperty("visibility", "hidden");
	Event.setEventListener(imageElement, event -> {
		if (Event.ONLOAD == event.getTypeInt()) {
			missingTileImage.getContext2d().drawImage(imageElement, 0, 0);
			RootPanel.get().getElement().removeChild(imageElement);
		}
	});
	RootPanel.get().getElement().appendChild(imageElement);
	image.setUrl(getBlankImageUrl());
	return canvas;
}
 
Example 2
Source Project: djvu-html5   Source File: DataStore.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void setTile(TileInfo tileInfo, GMap bufferGMap) {
	if (bufferImageData == null || bufferImageData.getWidth() != bufferGMap.getDataWidth()
			|| bufferImageData.getHeight() != bufferGMap.getDataHeight()) {
		bufferImageData = bufferCanvas.getContext2d()
				.createImageData(bufferGMap.getDataWidth(), bufferGMap.getDataHeight());
	}
	Uint8Array imageArray = bufferImageData.getData().cast();
	imageArray.set(bufferGMap.getImageData());
	bufferCanvas.getContext2d().putImageData(bufferImageData, -bufferGMap.getBorder(), 0);

	CanvasElement tile = tiles.get(tileInfo);
	if (tile == null) {
		tile = createImage(bufferGMap.getDataWidth() - bufferGMap.getBorder(), bufferGMap.getDataHeight());
		tiles.put(new TileInfo(tileInfo), tile);
	}
	Context2d c = tile.getContext2d();
	c.setFillStyle("white");
	c.fillRect(0, 0, tileSize, tileSize);
	c.drawImage(bufferCanvas, 0, 0);
	for (Consumer<Integer> listener : tileListeners)
		listener.accept(tileInfo.page);
}
 
Example 3
Source Project: circuitjs1   Source File: CirSim.java    License: GNU General Public License v2.0 5 votes vote down vote up
native void printCanvas(CanvasElement cv) /*-{
    var img    = cv.toDataURL("image/png");
    var win = window.open("", "print", "height=500,width=500,status=yes,location=no");
    win.document.title = "Print Circuit";
    win.document.open();
    win.document.write('<img src="'+img+'"/>');
    win.document.close();
    setTimeout(function(){win.print();},1000);
}-*/;
 
Example 4
Source Project: gwt-material-addins   Source File: MaterialSignaturePad.java    License: Apache License 2.0 5 votes vote down vote up
protected void applyResize() {
    CanvasElement element = getElement().cast();
    double ratio = getRatio();
    element.setWidth((int) (getOffsetWidth() * ratio));
    element.setHeight((int) (getOffsetHeight() * ratio));
    element.getContext2d().scale(ratio, ratio);
    getSignaturePad().clear();
}
 
Example 5
Source Project: djvu-html5   Source File: DataStore.java    License: GNU General Public License v2.0 5 votes vote down vote up
public CanvasElement[][] getTileImages(int pageNum, int subsample, GRect range, CanvasElement[][] reuse) {
	CanvasElement[][] result = reuse;
	int w = range.width() + 1, h = range.height() + 1;
	if (reuse == null || reuse.length != h || reuse[0].length != w) {
		result = new CanvasElement[h][w];
	}

	tempTI.page = pageNum;
	tempTI.subsample = subsample;
	for (int y = range.ymin; y <= range.ymax; y++)
		for (int x = range.xmin; x <= range.xmax; x++)
			result[y - range.ymin][x - range.xmin] = getTileImage(tempTI.setXY(x, y));

	return result;
}
 
Example 6
Source Project: djvu-html5   Source File: DataStore.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static CanvasElement createImage(int width, int height) {
	Canvas canvas = Canvas.createIfSupported();
	canvas.setWidth(width + "px");
	canvas.setCoordinateSpaceWidth(width);
	canvas.setHeight(height + "px");
	canvas.setCoordinateSpaceHeight(height);
	return canvas.getCanvasElement();
}
 
Example 7
Source Project: djvu-html5   Source File: SinglePageLayout.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void redraw() {
	Context2d graphics2d = canvas.getContext2d();
	int w = canvas.getCoordinateSpaceWidth(), h = canvas.getCoordinateSpaceHeight();
	graphics2d.setFillStyle(background);
	graphics2d.fillRect(0, 0, w, h);
	if (pageInfo == null)
		return;

	int subsample = toSubsample(zoom);
	double scale = zoom / toZoom(subsample);
	graphics2d.save();
	int startX = w / 2 - centerX, startY = h / 2 - centerY;
	graphics2d.translate(startX, startY);
	graphics2d.scale(scale, scale);
	graphics2d.translate(-startX, -startY);
	graphics2d.scale(1, -1); // DjVu images have y-axis inverted 

	int tileSize = DjvuContext.getTileSize();
	int pw = (int) (pageInfo.width * zoom), ph = (int) (pageInfo.height * zoom);
	range.xmin = (int) (Math.max(0, centerX - w * 0.5) / tileSize / scale);
	range.xmax = (int) Math.ceil(Math.min(pw, centerX + w * 0.5) / tileSize / scale);
	range.ymin = (int) (Math.max(0, centerY - h * 0.5) / tileSize / scale);
	range.ymax = (int) Math.ceil(Math.min(ph, centerY + h * 0.5) / tileSize / scale);
	imagesArray = dataStore.getTileImages(page, subsample, range , imagesArray);
	for (int y = range.ymin; y <= range.ymax; y++) {
		for (int x = range.xmin; x <= range.xmax; x++) {
			CanvasElement canvasElement = imagesArray[y - range.ymin][x - range.xmin];
			for (int repeats = scale == 1 ? 1 : 3; repeats > 0; repeats--) {
				graphics2d.drawImage(canvasElement, startX + x * tileSize,
						-startY - y * tileSize - canvasElement.getHeight());
			}
		}
	}
	graphics2d.restore();
	// missing tile graphics may exceed the page boundary
	graphics2d.fillRect(startX + pw, 0, w, h);
	graphics2d.fillRect(0, startY + ph, w, h);

	DjvuContext.setTileRange(range, subsample);
}
 
Example 8
public static String getIDCode(String id) {
    Element el = Document.get().getElementById(id);
    if (el instanceof CanvasElement) {
        return el.getAttribute("data-idcode");
    }
    return null;
}
 
Example 9
private static void drawStructure(String id, String idcode, String coordinates, int displayMode,
        String[] atomText) {
    Element el = Document.get().getElementById(id);
    if (el instanceof CanvasElement) {
        CanvasElement ce = (CanvasElement) el;
        StructureElement.drawIDCode(ce, idcode, coordinates, displayMode, atomText);
    }
}
 
Example 10
private static void draw(CanvasElement el, String idcode, String coordinates) {
    Canvas canvas = Canvas.wrap(el);
    if (idcode != null && idcode.length() > 0) {
        String combined = idcode + (coordinates != null ? " " + coordinates : "");
        Context2d ctx = canvas.getContext2d();
        drawMolecule(ctx, combined, canvas.getCoordinateSpaceWidth(), canvas.getCoordinateSpaceHeight());
    }
}
 
Example 11
public static void drawIDCode(CanvasElement el, String idcode, String coordinates, int displayMode,
        String[] atomText) {
    Canvas canvas = Canvas.wrap(el);
    if (idcode != null && idcode.length() > 0) {
        String combined = idcode + (coordinates != null ? " " + coordinates : "");
        Context2d ctx = canvas.getContext2d();
        drawMolecule(ctx, combined, canvas.getCoordinateSpaceWidth(), canvas.getCoordinateSpaceHeight(),
                displayMode, atomText);
    }
}
 
Example 12
Source Project: circuitjs1   Source File: CirSim.java    License: GNU General Public License v2.0 4 votes vote down vote up
native void doTouchHandlers(CanvasElement cv) /*-{
// Set up touch events for mobile, etc
var lastTap;
var tmout;
var sim = this;
cv.addEventListener("touchstart", function (e) {
       	mousePos = getTouchPos(cv, e);
 		var touch = e.touches[0];
 		var etype = "mousedown";
 		clearTimeout(tmout);
 		if (e.timeStamp-lastTap < 300) {
    		    etype = "dblclick";
 		} else {
 		    tmout = setTimeout(function() {
 		        [email protected]::longPress()();
 		    }, 500);
 		}
 		lastTap = e.timeStamp;
 		
 		var mouseEvent = new MouseEvent(etype, {
   			clientX: touch.clientX,
   			clientY: touch.clientY
 		});
 		e.preventDefault();
 		cv.dispatchEvent(mouseEvent);
}, false);
cv.addEventListener("touchend", function (e) {
 		var mouseEvent = new MouseEvent("mouseup", {});
 		e.preventDefault();
 		clearTimeout(tmout);
 		cv.dispatchEvent(mouseEvent);
}, false);
cv.addEventListener("touchmove", function (e) {
 		var touch = e.touches[0];
 		var mouseEvent = new MouseEvent("mousemove", {
   			clientX: touch.clientX,
   			clientY: touch.clientY
 		});
 		e.preventDefault();
 		clearTimeout(tmout);
 		cv.dispatchEvent(mouseEvent);
}, false);

// Get the position of a touch relative to the canvas
function getTouchPos(canvasDom, touchEvent) {
 		var rect = canvasDom.getBoundingClientRect();
 		return {
   			x: touchEvent.touches[0].clientX - rect.left,
   			y: touchEvent.touches[0].clientY - rect.top
 		};
}

   }-*/;
 
Example 13
Source Project: dashbuilder   Source File: Chart.java    License: Apache License 2.0 4 votes vote down vote up
protected CanvasElement getNativeElement(){
    return canvas;
}
 
Example 14
public static void drawMolecule(CanvasElement el, JSMolecule mol, JavaScriptObject options) {
    drawMolecule(el, mol, Util.getDisplayMode(options), null);
}
 
Example 15
private static void drawMolecule(CanvasElement el, JSMolecule mol, int displayMode, String[] atomText) {
    StructureElement.drawMolecule(el, mol, displayMode, atomText);
}
 
Example 16
public static void drawIDCode(CanvasElement el, String idcode, String coordinates, String[] atomText) {
    drawIDCode(el, idcode, coordinates, 0, atomText);
}
 
Example 17
public static void drawMolecule(CanvasElement el, JSMolecule mol, int displayMode, String[] atomText) {
    Canvas canvas = Canvas.wrap(el);
    Context2d ctx = canvas.getContext2d();
    drawMolecule(ctx, mol.getStereoMolecule(), canvas.getCoordinateSpaceWidth(), canvas.getCoordinateSpaceHeight(),
            displayMode, atomText);
}