Java Code Examples for javafx.scene.canvas.GraphicsContext#fillText()

The following examples show how to use javafx.scene.canvas.GraphicsContext#fillText() . 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 File: StateTransitionEdgeViewer.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
private void drawLabel(StateTransitionEdge pEdge, GraphicsContext pGraphics)
{
	adjustLabelFont(pEdge);
	Rectangle2D labelBounds = getLabelBounds(pEdge);
	double x = labelBounds.getMinX();
	double y = labelBounds.getMinY();
	
	Paint oldFill = pGraphics.getFill();
	Font oldFont = pGraphics.getFont();
	pGraphics.translate(x, y);
	pGraphics.setFill(Color.BLACK);
	pGraphics.setFont(aFont);
	pGraphics.setTextAlign(TextAlignment.CENTER);
	pGraphics.fillText(pEdge.getMiddleLabel(), labelBounds.getWidth()/2, 0);
	pGraphics.setFill(oldFill);
	pGraphics.setFont(oldFont);
	pGraphics.translate(-x, -y);        
}
 
Example 2
Source File: MultiplierPeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void paint(GraphicsContext graphics, CircuitState circuitState) {
	GuiUtils.drawName(graphics, this, getProperties().getValue(Properties.LABEL_LOCATION));
	
	graphics.setFill(Color.WHITE);
	graphics.setStroke(Color.BLACK);
	GuiUtils.drawShape(graphics::fillRect, this);
	GuiUtils.drawShape(graphics::strokeRect, this);
	
	graphics.setFont(GuiUtils.getFont(16, true));
	Bounds bounds = GuiUtils.getBounds(graphics.getFont(), "×");
	graphics.setFill(Color.BLACK);
	graphics.fillText("×",
	                  getScreenX() + (getScreenWidth() - bounds.getWidth()) * 0.5,
	                  getScreenY() + (getScreenHeight() + bounds.getHeight()) * 0.45);
}
 
Example 3
Source File: AdderPeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void paint(GraphicsContext graphics, CircuitState circuitState) {
	GuiUtils.drawName(graphics, this, getProperties().getValue(Properties.LABEL_LOCATION));
	
	graphics.setFill(Color.WHITE);
	graphics.setStroke(Color.BLACK);
	GuiUtils.drawShape(graphics::fillRect, this);
	GuiUtils.drawShape(graphics::strokeRect, this);
	
	graphics.setFont(GuiUtils.getFont(16, true));
	Bounds bounds = GuiUtils.getBounds(graphics.getFont(), "+");
	graphics.setFill(Color.BLACK);
	graphics.fillText("+",
	                  getScreenX() + (getScreenWidth() - bounds.getWidth()) * 0.5,
	                  getScreenY() + (getScreenHeight() + bounds.getHeight()) * 0.45);
}
 
Example 4
Source File: LetterAvatar.java    From youtube-comment-suite with MIT License 6 votes vote down vote up
private void draw() {
    Canvas canvas = new Canvas(scale, scale);
    GraphicsContext gc = canvas.getGraphicsContext2D();

    gc.setFill(Color.TRANSPARENT);
    gc.fillRect(0, 0, scale, scale);

    gc.setFill(background);
    gc.fillRect(0, 0, scale, scale);

    gc.setFill(Color.WHITE);
    gc.setTextAlign(TextAlignment.CENTER);
    gc.setTextBaseline(VPos.CENTER);
    gc.setFont(Font.font("Tahoma", FontWeight.SEMI_BOLD, scale * 0.6));

    gc.fillText(String.valueOf(character), Math.round(scale / 2.0), Math.round(scale / 2.0));
    Platform.runLater(() -> canvas.snapshot(null, this));
}
 
Example 5
Source File: RandomGeneratorPeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void paint(GraphicsContext graphics, CircuitState circuitState) {
	GuiUtils.drawName(graphics, this, getProperties().getValue(Properties.LABEL_LOCATION));
	
	graphics.setFill(Color.WHITE);
	graphics.setStroke(Color.BLACK);
	GuiUtils.drawShape(graphics::fillRect, this);
	GuiUtils.drawShape(graphics::strokeRect, this);
	
	graphics.setFont(GuiUtils.getFont(16, true));
	Bounds bounds = GuiUtils.getBounds(graphics.getFont(), "RNG");
	graphics.setFill(Color.BLACK);
	graphics.fillText("RNG",
	                  getScreenX() + (getScreenWidth() - bounds.getWidth()) * 0.5,
	                  getScreenY() + (getScreenHeight() + bounds.getHeight()) * 0.45);
	
	graphics.setStroke(Color.BLACK);
	GuiUtils.drawClockInput(graphics, clockConnection, Direction.SOUTH);
}
 
Example 6
Source File: ViewUtils.java    From JetUML with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draw pText in black with the given font, at point pX, pY.
 * 
 * @param pGraphics The graphics context.
 * @param pX The x-coordinate where to draw the text.
 * @param pY The y-coordinate where to draw the text.
 * @param pText The text to draw.
 * @param pFont The font to use.
 */
public static void drawText(GraphicsContext pGraphics, int pX, int pY, String pText, Font pFont)
{
	Font font = pGraphics.getFont();
	pGraphics.setFont(pFont);
	pGraphics.setFill(Color.BLACK);
	pGraphics.fillText(pText, pX + 0.5, pY + 0.5);
	pGraphics.setFont(font);
	pGraphics.setFill(Color.WHITE);
}
 
Example 7
Source File: Example2.java    From Introduction-to-JavaFX-for-Game-Development with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void start(Stage theStage) 
{
    theStage.setTitle( "Canvas Example" );
    
    Group root = new Group();
    Scene theScene = new Scene( root );
    theStage.setScene( theScene );
    
    Canvas canvas = new Canvas( 400, 200 );
    root.getChildren().add( canvas );
    
    GraphicsContext gc = canvas.getGraphicsContext2D();
    
    gc.setFill( Color.RED );
    gc.setStroke( Color.BLACK );
    gc.setLineWidth(2);
    Font theFont = Font.font( "Times New Roman", FontWeight.BOLD, 48 );
    gc.setFont( theFont );
    gc.fillText( "Hello, World!", 60, 50 );
    gc.strokeText( "Hello, World!", 60, 50 );
    
    Image earth = new Image( "earth.png" );
    gc.drawImage( earth, 180, 100 );
    
    theStage.show();
}
 
Example 8
Source File: Text.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void paint(GraphicsContext graphics, CircuitState state) {
	graphics.setFill(Color.BLACK);
	graphics.setStroke(Color.BLACK);
	
	graphics.setLineWidth(2);
	
	int x = getScreenX();
	int y = getScreenY();
	int width = getScreenWidth();
	int height = getScreenHeight();
	
	if(text.isEmpty()) {
		graphics.drawImage(textImage, x, y, width, height);
	} else {
		graphics.setFont(GuiUtils.getFont(13));
		for(int i = 0; i < lines.size(); i++) {
			String line = lines.get(i);
			Bounds bounds = GuiUtils.getBounds(graphics.getFont(), line, false);
			
			graphics.fillText(line,
			                  x + (width - bounds.getWidth()) * 0.5,
			                  y + 15 * (i + 1));
			
			if(entered && i == lines.size() - 1) {
				double lx = x + (width + bounds.getWidth()) * 0.5 + 3;
				double ly = y + 15 * (i + 1);
				graphics.strokeLine(lx, ly - 10, lx, ly);
			}
		}
	}
}
 
Example 9
Source File: DeckView.java    From Solitaire with GNU General Public License v2.0 5 votes vote down vote up
private Canvas createNewGameImage()
{
	double width = CardImages.getBack().getWidth();
	double height = CardImages.getBack().getHeight();
	Canvas canvas = new Canvas( width, height );
	GraphicsContext context = canvas.getGraphicsContext2D();
	
	// The reset image
	context.setStroke(Color.DARKGREEN);
	context.setLineWidth(IMAGE_NEW_LINE_WIDTH);
	context.strokeOval(width/4, height/2-width/4 + IMAGE_FONT_SIZE, width/2, width/2);

	// The text
	
	context.setTextAlign(TextAlignment.CENTER);
	context.setTextBaseline(VPos.CENTER);
	context.setFill(Color.DARKKHAKI);
	context.setFont(Font.font(Font.getDefault().getName(), IMAGE_FONT_SIZE));
	
	
	
	if( GameModel.instance().isCompleted() )
	{
		context.fillText("You won!", Math.round(width/2), IMAGE_FONT_SIZE);
	}
	else
	{
		context.fillText("Give up?", Math.round(width/2), IMAGE_FONT_SIZE);
	}
	context.setTextAlign(TextAlignment.CENTER);
	return canvas;
}
 
Example 10
Source File: GuiUtils.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void drawValue(GraphicsContext graphics, String string, int x, int y, int width) {
	Bounds bounds = GuiUtils.getBounds(graphics.getFont(), string, false);
	
	if(string.length() == 1) {
		graphics.fillText(string, x + (width - bounds.getWidth()) * 0.5, y + bounds.getHeight() * 0.75 + 1);
	} else {
		for(int i = 0, row = 1; i < string.length(); row++) {
			String sub = string.substring(i, i + Math.min(8, string.length() - i));
			i += sub.length();
			graphics.fillText(sub, x + 1, y + bounds.getHeight() * 0.75 * row + 1);
		}
	}
}
 
Example 11
Source File: ScaleBarOverlayRenderer.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
@Override
public synchronized void drawOverlays(GraphicsContext graphicsContext) {
	if (width > 0.0 && height > 0.0 && config.getIsShowing()) {
		double targetLength = Math.min(width, config.getTargetScaleBarLength());
		double[] onePixelWidth = {1.0, 0.0, 0.0};
		transform.applyInverse(onePixelWidth, onePixelWidth);
		final double globalCoordinateWidth = LinAlgHelpers.length(onePixelWidth);
		// length of scale bar in global coordinate system
		final double scaleBarWidth = targetLength * globalCoordinateWidth;
		final double pot = Math.floor( Math.log10( scaleBarWidth ) );
		final double l2 =  scaleBarWidth / Math.pow( 10, pot );
		final int fracs = ( int ) ( 0.1 * l2 * subdivPerPowerOfTen );
		final double scale1 = ( fracs > 0 ) ? Math.pow( 10, pot + 1 ) * fracs / subdivPerPowerOfTen : Math.pow( 10, pot );
		final double scale2 = ( fracs == 3 ) ? Math.pow( 10, pot + 1 ) : Math.pow( 10, pot + 1 ) * ( fracs + 1 ) / subdivPerPowerOfTen;

		final double lB1 = scale1 / globalCoordinateWidth;
		final double lB2 = scale2 / globalCoordinateWidth;

		final double scale;
		final double scaleBarLength;
		if (Math.abs(lB1 - targetLength) < Math.abs(lB2 - targetLength))
		{
			scale = scale1;
			scaleBarLength = lB1;
		}
		else
		{
			scale = scale2;
			scaleBarLength = lB2;
		}

		final double[] ratios = UNITS.stream().mapToDouble(unit -> config.getBaseUnit().getConverterTo(unit).convert(scale)).toArray();
		int firstSmallerThanZeroIndex = 0;
		for (; firstSmallerThanZeroIndex < ratios.length; ++firstSmallerThanZeroIndex) {
			if (ratios[firstSmallerThanZeroIndex] < 1.0)
				break;
		}
		final int unitIndex = Math.max(firstSmallerThanZeroIndex - 1, 0);
		final Unit<Length> targetUnit = UNITS.get(unitIndex);
		final double targetScale = config.getBaseUnit().getConverterTo(targetUnit).convert(scale);

		final double x = 20;
		final double y = height - 30;

		final DecimalFormat format = new DecimalFormat(String.format("0.%s", String.join("", Collections.nCopies(config.getNumDecimals(), "#"))));
		final String scaleBarText = format.format(targetScale) + targetUnit.toString();
		final Text text = new Text(scaleBarText);
		text.setFont(config.getOverlayFont());
		final Bounds bounds = text.getBoundsInLocal();
		final double tx = 20 + (scaleBarLength - bounds.getMaxX()) / 2;
		final double ty = y - 5;
		graphicsContext.setFill(config.getBackgroundColor());

		// draw background
		graphicsContext.fillRect(
				x - 7,
				ty - bounds.getHeight() - 3,
			 	scaleBarLength + 14,
				bounds.getHeight() + 25 );

		// draw scalebar
		graphicsContext.setFill(config.getForegroundColor());
		graphicsContext.fillRect(x, y, ( int ) scaleBarLength, 10);

		// draw label
		graphicsContext.setFont(config.getOverlayFont());
		graphicsContext.fillText(scaleBarText, tx, ty);
	}
}
 
Example 12
Source File: AmpSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void drawTickMarks(final GraphicsContext CTX) {
    double     sinValue;
    double     cosValue;
    double     orthText         = TickLabelOrientation.ORTHOGONAL == gauge.getTickLabelOrientation() ? 0.51 : 0.52;
    Point2D    center           = new Point2D(width * 0.5, height * 0.77);
    double     minorTickSpace   = gauge.getMinorTickSpace();
    double     minValue         = gauge.getMinValue();
    //double     maxValue         = gauge.getMaxValue();
    double     tmpAngleStep     = angleStep * minorTickSpace;
    int        decimals         = gauge.getTickLabelDecimals();
    BigDecimal minorTickSpaceBD = BigDecimal.valueOf(minorTickSpace);
    BigDecimal majorTickSpaceBD = BigDecimal.valueOf(gauge.getMajorTickSpace());
    BigDecimal mediumCheck2     = BigDecimal.valueOf(2 * minorTickSpace);
    BigDecimal mediumCheck5     = BigDecimal.valueOf(5 * minorTickSpace);
    BigDecimal counterBD        = BigDecimal.valueOf(minValue);
    double     counter          = minValue;

    Font tickLabelFont = Fonts.robotoCondensedRegular((decimals == 0 ? 0.045 : 0.038) * height);
    CTX.setFont(tickLabelFont);

    for (double angle = 0 ; Double.compare(-ANGLE_RANGE - tmpAngleStep, angle) < 0 ; angle -= tmpAngleStep) {
        sinValue = Math.sin(Math.toRadians(angle + START_ANGLE));
        cosValue = Math.cos(Math.toRadians(angle + START_ANGLE));

        Point2D innerPoint       = new Point2D(center.getX() + width * 0.41987097 * sinValue, center.getY() + width * 0.41987097 * cosValue);
        Point2D outerMinorPoint  = new Point2D(center.getX() + width * 0.45387097 * sinValue, center.getY() + width * 0.45387097 * cosValue);
        Point2D outerMediumPoint = new Point2D(center.getX() + width * 0.46387097 * sinValue, center.getY() + width * 0.46387097 * cosValue);
        Point2D outerPoint       = new Point2D(center.getX() + width * 0.48387097 * sinValue, center.getY() + width * 0.48387097 * cosValue);
        Point2D textPoint        = new Point2D(center.getX() + width * orthText * sinValue, center.getY() + width * orthText * cosValue);

        CTX.setStroke(gauge.getTickMarkColor());
        if (Double.compare(counterBD.remainder(majorTickSpaceBD).doubleValue(), 0.0) == 0) {
            // Draw major tickmark
            CTX.setLineWidth(height * 0.0055);
            CTX.strokeLine(innerPoint.getX(), innerPoint.getY(), outerPoint.getX(), outerPoint.getY());

            // Draw text
            CTX.save();
            CTX.translate(textPoint.getX(), textPoint.getY());
            switch(gauge.getTickLabelOrientation()) {
                case ORTHOGONAL:
                    if ((360 - START_ANGLE - angle) % 360 > 90 && (360 - START_ANGLE - angle) % 360 < 270) {
                        CTX.rotate((180 - START_ANGLE - angle) % 360);
                    } else {
                        CTX.rotate((360 - START_ANGLE - angle) % 360);
                    }
                    break;
                case TANGENT:
                    if ((360 - START_ANGLE - angle - 90) % 360 > 90 && (360 - START_ANGLE - angle - 90) % 360 < 270) {
                        CTX.rotate((90 - START_ANGLE - angle) % 360);
                    } else {
                        CTX.rotate((270 - START_ANGLE - angle) % 360);
                    }
                    break;
                case HORIZONTAL:
                default:
                    break;
            }
            CTX.setTextAlign(TextAlignment.CENTER);
            CTX.setTextBaseline(VPos.CENTER);
            CTX.setFill(gauge.getTickLabelColor());
            CTX.fillText(String.format(locale, "%." + decimals + "f", counter), 0, 0);
            CTX.restore();
        } else if (gauge.getMediumTickMarksVisible() &&
                   Double.compare(minorTickSpaceBD.remainder(mediumCheck2).doubleValue(), 0.0) != 0.0 &&
                   Double.compare(counterBD.remainder(mediumCheck5).doubleValue(), 0.0) == 0.0) {
            CTX.setLineWidth(height * 0.0035);
            CTX.strokeLine(innerPoint.getX(), innerPoint.getY(), outerMediumPoint.getX(), outerMediumPoint.getY());
        } else if (gauge.getMinorTickMarksVisible() && Double.compare(counterBD.remainder(minorTickSpaceBD).doubleValue(), 0.0) == 0) {
            CTX.setLineWidth(height * 0.00225);
            CTX.strokeLine(innerPoint.getX(), innerPoint.getY(), outerMinorPoint.getX(), outerMinorPoint.getY());
        }
        counterBD = counterBD.add(minorTickSpaceBD);
        counter   = counterBD.doubleValue();
    }
}
 
Example 13
Source File: MultiplexerPeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void paint(GraphicsContext graphics, CircuitState circuitState) {
	GuiUtils.drawName(graphics, this, getProperties().getValue(Properties.LABEL_LOCATION));
	
	Direction direction = getProperties().getValue(Properties.DIRECTION);
	
	int x = getScreenX();
	int y = getScreenY();
	int width = 3 * GuiUtils.BLOCK_SIZE;
	int height = (getComponent().getNumInputs() + 2) * GuiUtils.BLOCK_SIZE;
	
	int zeroXOffset = 0;
	
	switch(direction) {
		case NORTH:
			graphics.translate(x, y);
			graphics.rotate(270);
			graphics.translate(-x - width, -y);
		case EAST:
			zeroXOffset = 2;
			graphics.beginPath();
			graphics.moveTo(x, y);
			graphics.lineTo(x + width, y + Math.min(20, height * 0.2));
			graphics.lineTo(x + width, y + height - Math.min(20, height * 0.2));
			graphics.lineTo(x, y + height);
			graphics.closePath();
			break;
		case SOUTH:
			graphics.translate(x, y);
			graphics.rotate(270);
			graphics.translate(-x - width, -y);
		case WEST:
			zeroXOffset = width - 10;
			graphics.beginPath();
			graphics.moveTo(x + width, y);
			graphics.lineTo(x, y + Math.min(20, height * 0.2));
			graphics.lineTo(x, y + height - Math.min(20, height * 0.2));
			graphics.lineTo(x + width, y + height);
			graphics.closePath();
			break;
	}
	
	graphics.setFill(Color.WHITE);
	graphics.fill();
	graphics.setStroke(Color.BLACK);
	graphics.stroke();
	
	graphics.setFill(Color.DARKGRAY);
	graphics.fillText("0", x + zeroXOffset, y + 13);
}
 
Example 14
Source File: YOLO2_TF_Client.java    From SKIL_Examples with Apache License 2.0 4 votes vote down vote up
private void renderJavaFXStyle(GraphicsContext ctx) throws Exception {

        INDArray boundingBoxPriors = Nd4j.create(YOLO2.DEFAULT_PRIOR_BOXES);

        ctx.setLineWidth(3);
        ctx.setTextAlign(TextAlignment.LEFT);

        long start = System.nanoTime();
        for (int i = 0; i < 1; i++) {
            INDArray permuted = networkGlobalOutput.permute(0, 3, 1, 2);
            INDArray activated = YoloUtils.activate(boundingBoxPriors, permuted);
            List<DetectedObject> predictedObjects = YoloUtils.getPredictedObjects(boundingBoxPriors, activated, 0.6, 0.4);
            
            //System.out.println( "width: " + imageWidth );
            //System.out.println( "height: " + imageHeight );

            for (DetectedObject o : predictedObjects) {
                ClassPrediction classPrediction = labels.decodePredictions(o.getClassPredictions(), 1).get(0).get(0);
                String label = classPrediction.getLabel();
                long x = Math.round(imageWidth  * o.getCenterX() / gridWidth);
                long y = Math.round(imageHeight * o.getCenterY() / gridHeight);
                long w = Math.round(imageWidth  * o.getWidth()   / gridWidth);
                long h = Math.round(imageHeight * o.getHeight()  / gridHeight);

                System.out.println("\"" + label + "\" at [" + x + "," + y + ";" + w + "," + h + "], score = "
                                + o.getConfidence() * classPrediction.getProbability());

                double[] xy1 = o.getTopLeftXY();
                double[] xy2 = o.getBottomRightXY();
                int x1 = (int) Math.round(imageWidth  * xy1[0] / gridWidth);
                int y1 = (int) Math.round(imageHeight * xy1[1] / gridHeight);
                int x2 = (int) Math.round(imageWidth  * xy2[0] / gridWidth);
                int y2 = (int) Math.round(imageHeight * xy2[1] / gridHeight);

                int rectW = x2 - x1;
                int rectH = y2 - y1;
                //System.out.printf("%s - %d, %d, %d, %d \n", label, x1, x2, y1, y2);
                //System.out.println( "color: " + colors.get(label) );
                ctx.setStroke(colors.get(label));
                ctx.strokeRect(x1, y1, rectW, rectH);
                
                int labelWidth = label.length() * 10;
                int labelHeight = 14;
                
                ctx.setFill( colors.get(label) );
                ctx.strokeRect(x1, y1-labelHeight, labelWidth, labelHeight);
                ctx.fillRect(x1, y1 - labelHeight, labelWidth, labelHeight);
                ctx.setFill( Color.WHITE );
                ctx.fillText(label, x1 + 3, y1 - 3 );

            }

        }

        globalEndTime = System.nanoTime();
        long end = System.nanoTime();
        System.out.println("Rendering code took: " + (end - start) / 1000000 + " ms");

        System.out.println("Overall Program Time: " + (globalEndTime - globalStartTime) / 1000000 + " ms");

    }
 
Example 15
Source File: BitExtenderPeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void paint(GraphicsContext graphics, CircuitState circuitState) {
	GuiUtils.drawName(graphics, this, getProperties().getValue(Properties.LABEL_LOCATION));
	
	graphics.setStroke(Color.BLACK);
	graphics.setFill(Color.WHITE);
	GuiUtils.drawShape(graphics::fillRect, this);
	GuiUtils.drawShape(graphics::strokeRect, this);
	
	graphics.setFont(GuiUtils.getFont(12, true));
	graphics.setFill(Color.BLACK);
	
	graphics.fillText(String.valueOf(getComponent().getInputBitSize()),
	                    getScreenX() + 3, getScreenY() + getScreenHeight() * 0.5 + 5);
	
	
	String outputString = String.valueOf(getComponent().getOutputBitSize());
	Bounds outputBounds = GuiUtils.getBounds(graphics.getFont(), outputString);
	
	graphics.fillText(outputString,
	                  getScreenX() + getScreenWidth() - outputBounds.getWidth() - 3,
	                  getScreenY() + getScreenHeight() * 0.5 + 5);
	
	String typeString = "";
	switch(getComponent().getExtensionType()) {
		case ZERO:
			typeString = "0";
			break;
		case ONE:
			typeString = "1";
			break;
		case SIGN:
			typeString = "sign";
			break;
	}
	
	Bounds typeBounds = GuiUtils.getBounds(graphics.getFont(), typeString);
	graphics.fillText(typeString,
	                  getScreenX() + (getScreenWidth() - typeBounds.getWidth()) * 0.5,
	                  getScreenY() + typeBounds.getHeight());
	
	graphics.setFont(GuiUtils.getFont(10, true));
	String extendString = "extend";
	Bounds extendBounds = GuiUtils.getBounds(graphics.getFont(), extendString);
	graphics.fillText(extendString,
	                  getScreenX() + (getScreenWidth() - extendBounds.getWidth()) * 0.5,
	                  getScreenY() + getScreenHeight() - 5);
}
 
Example 16
Source File: PriorityEncoderPeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void paint(GraphicsContext graphics, CircuitState circuitState) {
	GuiUtils.drawName(graphics, this, getProperties().getValue(Properties.LABEL_LOCATION));

	Direction direction = getProperties().getValue(Properties.DIRECTION);
	graphics.translate(getScreenX(), getScreenY());

	int height;
	int width;

	int inputSideLength = ((1 << getComponent().getNumSelectBits()) + 1) * GuiUtils.BLOCK_SIZE;
	int enabledSideLength = ENABLED_INOUT_SIDE_LEN * GuiUtils.BLOCK_SIZE;

	double zeroX = GuiUtils.BLOCK_SIZE >> 1;
	double zeroY;

	if(direction == Direction.EAST || direction == Direction.WEST) {
		height = inputSideLength;
		width = enabledSideLength;
		zeroY = GuiUtils.BLOCK_SIZE * 1.5;
		if(direction == Direction.WEST) {
			zeroX = width - GuiUtils.BLOCK_SIZE;
		}
	} else {
		height = enabledSideLength;
		width = inputSideLength;
		zeroY = height - (GuiUtils.BLOCK_SIZE >> 1);
		if(direction == Direction.SOUTH) {
			zeroY = GuiUtils.BLOCK_SIZE * 1.5;
		}
	}

	graphics.setStroke(Color.BLACK);
	graphics.strokeRect(0, 0, width, height);

	graphics.setFill(Color.WHITE);
	graphics.fillRect(0, 0, width, height);

	graphics.setFill(Color.DARKGRAY);
	graphics.fillText("0", zeroX, zeroY);

	graphics.setFill(Color.BLACK);
	graphics.fillText("Pri", (width >> 1) - graphics.getFont().getSize(), (height >> 1) + 0.5 * GuiUtils.BLOCK_SIZE);
}
 
Example 17
Source File: ROMPeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void paint(GraphicsContext graphics, CircuitState circuitState) {
	GuiUtils.drawName(graphics, this, getProperties().getValue(Properties.LABEL_LOCATION));
	
	graphics.setFill(Color.WHITE);
	GuiUtils.drawShape(graphics::fillRect, this);
	
	graphics.setStroke(Color.BLACK);
	GuiUtils.drawShape(graphics::strokeRect, this);

	String address = circuitState.getLastReceived(getComponent().getPort(ROM.PORT_ADDRESS)).toHexString();
	String value = circuitState.getLastPushed(getComponent().getPort(ROM.PORT_DATA)).toHexString();
	
	int x = getScreenX();
	int y = getScreenY();
	int width = getScreenWidth();
	int height = getScreenHeight();
	
	graphics.setFont(GuiUtils.getFont(11, true));

	String text = "ROM";
	Bounds bounds = GuiUtils.getBounds(graphics.getFont(), text);
	graphics.setFill(Color.BLACK);
	graphics.fillText(text,
	                  x + (width - bounds.getWidth()) * 0.5,
	                  y + (height + bounds.getHeight()) * 0.2);
	
	// Draw address
	text = "A: " + address;
	double addrY = y + bounds.getHeight() + 12;
	graphics.fillText(text, x + 13, addrY);
	
	// Draw data afterward
	bounds = GuiUtils.getBounds(graphics.getFont(), text);
	graphics.fillText("D: " + value, x + 13, addrY + bounds.getHeight());
	
	graphics.setFill(Color.GRAY);
	graphics.setFont(GuiUtils.getFont(10));
	graphics.fillText("A", x + 3, y + height * 0.5 - 1);
	graphics.fillText("D", x + width - 9, y + height * 0.5 - 1);
	graphics.fillText("en", x + width * 0.5 - 11.5, y + height - 3.5);
}
 
Example 18
Source File: CustomPlainAmpSkin.java    From medusademo with Apache License 2.0 4 votes vote down vote up
private void drawTickMarks(final GraphicsContext CTX) {
    double  sinValue;
    double  cosValue;
    double  orthText       = TickLabelOrientation.ORTHOGONAL == gauge.getTickLabelOrientation() ? 0.61 : 0.62;
    Point2D center         = new Point2D(width * 0.5, height * 1.4);
    double  minorTickSpace = gauge.getMinorTickSpace();
    double  minValue       = gauge.getMinValue();
    //double     maxValue         = gauge.getMaxValue();
    double     tmpAngleStep     = angleStep * minorTickSpace;
    int        decimals         = gauge.getTickLabelDecimals();
    BigDecimal minorTickSpaceBD = BigDecimal.valueOf(minorTickSpace);
    BigDecimal majorTickSpaceBD = BigDecimal.valueOf(gauge.getMajorTickSpace());
    BigDecimal mediumCheck2     = BigDecimal.valueOf(2 * minorTickSpace);
    BigDecimal mediumCheck5     = BigDecimal.valueOf(5 * minorTickSpace);
    BigDecimal counterBD        = BigDecimal.valueOf(minValue);
    double     counter          = minValue;

    Font tickLabelFont = Fonts.robotoCondensedRegular((decimals == 0 ? 0.07 : 0.068) * height);
    CTX.setFont(tickLabelFont);

    for (double angle = 0 ; Double.compare(-ANGLE_RANGE - tmpAngleStep, angle) < 0 ; angle -= tmpAngleStep) {
        sinValue = Math.sin(Math.toRadians(angle + START_ANGLE));
        cosValue = Math.cos(Math.toRadians(angle + START_ANGLE));

        Point2D innerPoint       = new Point2D(center.getX() + width * 0.51987097 * sinValue, center.getY() + width * 0.51987097 * cosValue);
        Point2D outerMinorPoint  = new Point2D(center.getX() + width * 0.55387097 * sinValue, center.getY() + width * 0.55387097 * cosValue);
        Point2D outerMediumPoint = new Point2D(center.getX() + width * 0.56387097 * sinValue, center.getY() + width * 0.56387097 * cosValue);
        Point2D outerPoint       = new Point2D(center.getX() + width * 0.58387097 * sinValue, center.getY() + width * 0.58387097 * cosValue);
        Point2D textPoint        = new Point2D(center.getX() + width * orthText * sinValue, center.getY() + width * orthText * cosValue);

        CTX.setStroke(gauge.getTickMarkColor());
        if (Double.compare(counterBD.remainder(majorTickSpaceBD).doubleValue(), 0.0) == 0) {
            // Draw major tickmark
            CTX.setLineWidth(height * 0.0055);
            CTX.strokeLine(innerPoint.getX(), innerPoint.getY(), outerPoint.getX(), outerPoint.getY());

            // Draw text
            CTX.save();
            CTX.translate(textPoint.getX(), textPoint.getY());
            switch(gauge.getTickLabelOrientation()) {
                case ORTHOGONAL:
                    if ((360 - START_ANGLE - angle) % 360 > 90 && (360 - START_ANGLE - angle) % 360 < 270) {
                        CTX.rotate((180 - START_ANGLE - angle) % 360);
                    } else {
                        CTX.rotate((360 - START_ANGLE - angle) % 360);
                    }
                    break;
                case TANGENT:
                    if ((360 - START_ANGLE - angle - 90) % 360 > 90 && (360 - START_ANGLE - angle - 90) % 360 < 270) {
                        CTX.rotate((90 - START_ANGLE - angle) % 360);
                    } else {
                        CTX.rotate((270 - START_ANGLE - angle) % 360);
                    }
                    break;
                case HORIZONTAL:
                default:
                    break;
            }
            CTX.setTextAlign(TextAlignment.CENTER);
            CTX.setTextBaseline(VPos.CENTER);
            CTX.setFill(gauge.getTickLabelColor());
            CTX.fillText(String.format(locale, "%." + decimals + "f", counter), 0, 0);
            CTX.restore();
        } else if (gauge.getMediumTickMarksVisible() &&
                   Double.compare(minorTickSpaceBD.remainder(mediumCheck2).doubleValue(), 0.0) != 0.0 &&
                   Double.compare(counterBD.remainder(mediumCheck5).doubleValue(), 0.0) == 0.0) {
            CTX.setLineWidth(height * 0.0035);
            CTX.strokeLine(innerPoint.getX(), innerPoint.getY(), outerMediumPoint.getX(), outerMediumPoint.getY());
        } else if (gauge.getMinorTickMarksVisible() && Double.compare(counterBD.remainder(minorTickSpaceBD).doubleValue(), 0.0) == 0) {
            CTX.setLineWidth(height * 0.00225);
            CTX.strokeLine(innerPoint.getX(), innerPoint.getY(), outerMinorPoint.getX(), outerMinorPoint.getY());
        }
        counterBD = counterBD.add(minorTickSpaceBD);
        counter   = counterBD.doubleValue();
    }
}
 
Example 19
Source File: LabelledMarkerRenderer.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
/**
 * Draws vertical markers with vertical (default) labels attached to the top
 *
 * @param gc the graphics context from the Canvas parent
 * @param chart instance of the calling chart
 * @param dataSet instance of the data set that is supposed to be drawn
 * @param indexMin minimum index of data set to be drawn
 * @param indexMax maximum index of data set to be drawn
 */
protected void drawVerticalLabelledMarker(final GraphicsContext gc, final XYChart chart, final DataSet dataSet,
        final int indexMin, final int indexMax) {
    Axis xAxis = this.getFirstAxis(Orientation.HORIZONTAL);
    if (xAxis == null) {
        xAxis = chart.getFirstAxis(Orientation.HORIZONTAL);
    }
    if (xAxis == null) {
        if (LOGGER.isWarnEnabled()) {
            LOGGER.atWarn().addArgument(LabelledMarkerRenderer.class.getSimpleName()).log("{}::drawVerticalLabelledMarker(...) getFirstAxis(HORIZONTAL) returned null skip plotting");
        }
        return;
    }

    gc.save();
    setGraphicsContextAttributes(gc, dataSet.getStyle());
    gc.setTextAlign(TextAlignment.LEFT);

    final double height = chart.getCanvas().getHeight();
    double lastLabel = -Double.MAX_VALUE;
    double lastFontSize = 0;
    for (int i = indexMin; i < indexMax; i++) {
        final double screenX = (int) xAxis.getDisplayPosition(dataSet.get(DataSet.DIM_X, i));
        final String label = dataSet.getDataLabel(i);
        if (label == null) {
            continue;
        }

        final String pointStyle = dataSet.getStyle(i);

        if (pointStyle != null) {
            gc.save();
            setGraphicsContextAttributes(gc, pointStyle);
        }

        gc.strokeLine(screenX, 0, screenX, height);

        if (Math.abs(screenX - lastLabel) > lastFontSize && !label.isEmpty()) {
            gc.save();
            gc.setLineWidth(0.8);
            gc.setLineDashes(1.0);
            gc.translate(Math.ceil(screenX + 3), Math.ceil(0.01 * height));
            gc.rotate(+90);
            gc.fillText(label, 0.0, 0);
            gc.restore();
            lastLabel = screenX;
            lastFontSize = gc.getFont().getSize();
        }
        if (pointStyle != null) {
            gc.restore();
        }
    }
    gc.restore();
}
 
Example 20
Source File: LabelledMarkerRenderer.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
/**
 * Draws horizontal markers with horizontal (default) labels attached to the top
 *
 * @param gc the graphics context from the Canvas parent
 * @param chart instance of the calling chart
 * @param dataSet instance of the data set that is supposed to be drawn
 * @param indexMin minimum index of data set to be drawn
 * @param indexMax maximum index of data set to be drawn
 */
protected void drawHorizontalLabelledMarker(final GraphicsContext gc, final XYChart chart, final DataSet dataSet,
        final int indexMin, final int indexMax) {
    final Axis yAxis = this.getFirstAxis(Orientation.VERTICAL, chart);

    gc.save();
    setGraphicsContextAttributes(gc, dataSet.getStyle());
    gc.setTextAlign(TextAlignment.RIGHT);

    final double width = chart.getCanvas().getWidth();
    double lastLabel = -Double.MAX_VALUE;
    double lastFontSize = 0;
    for (int i = indexMin; i < indexMax; i++) {
        final double screenY = (int) yAxis.getDisplayPosition(dataSet.get(DataSet.DIM_Y, i));
        final String label = dataSet.getDataLabel(i);
        if (label == null) {
            continue;
        }

        final String pointStyle = dataSet.getStyle(i);
        if (pointStyle != null) {
            gc.save();
            setGraphicsContextAttributes(gc, pointStyle);
        }

        gc.strokeLine(0, screenY, width, screenY);

        if (Math.abs(screenY - lastLabel) > lastFontSize && !label.isEmpty()) {
            gc.save();
            gc.setLineWidth(0.8);
            gc.setLineDashes(1.0);
            gc.translate(Math.ceil(screenY + 3), Math.ceil(0.99 * width));
            gc.fillText(label, 0.0, 0);
            gc.restore();
            lastLabel = screenY;
            lastFontSize = gc.getFont().getSize();
        }

        if (pointStyle != null) {
            gc.restore();
        }
    }
    gc.restore();
}