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

The following examples show how to use javafx.scene.canvas.GraphicsContext#setStroke() . 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: AbstractNodeViewer.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Canvas createIcon(Node pNode)
{
	Rectangle bounds = getBounds(pNode);
	int width = bounds.getWidth();
	int height = bounds.getHeight();
	double scaleX = (BUTTON_SIZE - OFFSET)/ (double) width;
	double scaleY = (BUTTON_SIZE - OFFSET)/ (double) height;
	double scale = Math.min(scaleX, scaleY);
	Canvas canvas = new Canvas(BUTTON_SIZE, BUTTON_SIZE);
	GraphicsContext graphics = canvas.getGraphicsContext2D();
	graphics.scale(scale, scale);
	graphics.translate(Math.max((height - width) / 2, 0), Math.max((width - height) / 2, 0));
	graphics.setFill(Color.WHITE);
	graphics.setStroke(Color.BLACK);
	draw(pNode, canvas.getGraphicsContext2D());
	return canvas;
}
 
Example 2
Source File: NorGatePeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void paintGate(GraphicsContext graphics, CircuitState circuitState) {
	int x = getScreenX();
	int y = getScreenY();
	int width = 4 * GuiUtils.BLOCK_SIZE;
	int height = 4 * GuiUtils.BLOCK_SIZE;
	
	graphics.beginPath();
	graphics.moveTo(x, y + height);
	graphics.arc(x, y + height * 0.5, width * 0.25, height * 0.5, 270, 180);
	graphics.arcTo(x + width * 0.66, y, x + width, y + height * 1.3, width * 0.7);
	graphics.arcTo(x + width * 0.66, y + height, x, y + height, width * 0.7);
	graphics.closePath();
	
	graphics.setFill(Color.WHITE);
	graphics.setStroke(Color.BLACK);
	graphics.fill();
	graphics.stroke();
	
	graphics.fillOval(x + width * 0.8, y + height * 0.5 - width * 0.1, width * 0.2, width * 0.2);
	graphics.strokeOval(x + width * 0.8, y + height * 0.5 - width * 0.1, width * 0.2, width * 0.2);
}
 
Example 3
Source File: NotGatePeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void paintGate(GraphicsContext graphics, CircuitState circuitState) {
	int x = getScreenX();
	int y = getScreenY();
	int width = 3 * GuiUtils.BLOCK_SIZE;
	int height = 2 * GuiUtils.BLOCK_SIZE;
	
	graphics.beginPath();
	graphics.moveTo(x, y);
	graphics.lineTo(x, y + height);
	graphics.lineTo(x + width * 0.7, y + height * 0.5);
	graphics.closePath();
	
	graphics.setFill(Color.WHITE);
	graphics.setStroke(Color.BLACK);
	graphics.fill();
	graphics.stroke();
	
	graphics.fillOval(x + width * 0.7, y + height * 0.5 - width * 0.125, width * 0.25, width * 0.25);
	graphics.strokeOval(x + width * 0.7, y + height * 0.5 - width * 0.125, width * 0.25, width * 0.25);
}
 
Example 4
Source File: NandGatePeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void paintGate(GraphicsContext graphics, CircuitState circuitState) {
	int x = getScreenX();
	int y = getScreenY();
	int width = 4 * GuiUtils.BLOCK_SIZE;
	int height = 4 * GuiUtils.BLOCK_SIZE;
	
	graphics.beginPath();
	graphics.moveTo(x, y);
	graphics.lineTo(x, y + height);
	graphics.arc(x + width * 0.3, y + height * 0.5, width * 0.5, height * 0.5, 270, 180);
	graphics.closePath();
	
	graphics.setFill(Color.WHITE);
	graphics.setStroke(Color.BLACK);
	graphics.fill();
	graphics.stroke();
	
	graphics.fillOval(x + width * 0.8, y + height * 0.5 - width * 0.1, width * 0.2, width * 0.2);
	graphics.strokeOval(x + width * 0.8, y + height * 0.5 - width * 0.1, width * 0.2, width * 0.2);
}
 
Example 5
Source File: DebugDrawJavaFX.java    From jbox2d with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void drawTransform(Transform xf) {
  GraphicsContext g = getGraphics();
  getWorldToScreenToOut(xf.p, temp);
  temp2.setZero();
  float k_axisScale = 0.4f;

  Color c = cpool.getColor(1, 0, 0);
  g.setStroke(c);

  temp2.x = xf.p.x + k_axisScale * xf.q.c;
  temp2.y = xf.p.y + k_axisScale * xf.q.s;
  getWorldToScreenToOut(temp2, temp2);
  g.strokeLine(temp.x, temp.y, temp2.x, temp2.y);

  c = cpool.getColor(0, 1, 0);
  g.setStroke(c);
  temp2.x = xf.p.x + -k_axisScale * xf.q.s;
  temp2.y = xf.p.y + k_axisScale * xf.q.c;
  getWorldToScreenToOut(temp2, temp2);
  g.strokeLine(temp.x, temp.y, temp2.x, temp2.y);
}
 
Example 6
Source File: AndGatePeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void paintGate(GraphicsContext graphics, CircuitState circuitState) {
	int x = getScreenX();
	int y = getScreenY();
	int width = 4 * GuiUtils.BLOCK_SIZE;
	int height = 4 * GuiUtils.BLOCK_SIZE;
	
	graphics.beginPath();
	graphics.moveTo(x, y);
	graphics.lineTo(x, y + height);
	graphics.arc(x + width * 0.5, y + height * 0.5, width * 0.5, height * 0.5, 270, 180);
	graphics.closePath();
	
	graphics.setFill(Color.WHITE);
	graphics.setStroke(Color.BLACK);
	graphics.fill();
	graphics.stroke();
}
 
Example 7
Source File: SubtractorPeer.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 8
Source File: CallNodeViewer.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void draw(Node pNode, GraphicsContext pGraphics)
{
	if(((CallNode)pNode).isOpenBottom())
	{
		pGraphics.setStroke(Color.WHITE);
		ViewUtils.drawRectangle(pGraphics, getBounds(pNode));
		pGraphics.setStroke(Color.BLACK);
		final Rectangle bounds = getBounds(pNode);
		int x1 = bounds.getX();
		int x2 = bounds.getMaxX();
		int y1 = bounds.getY();
		int y3 = bounds.getMaxY();
		int y2 = y3 - CallNode.CALL_YGAP;
		ViewUtils.drawLine(pGraphics, x1, y1, x2, y1, LineStyle.SOLID);
		ViewUtils.drawLine(pGraphics, x1, y1, x1, y2, LineStyle.SOLID);
		ViewUtils.drawLine(pGraphics, x2, y1, x2, y2, LineStyle.SOLID);
		ViewUtils.drawLine(pGraphics, x1, y2, x1, y3, LineStyle.DOTTED);
		ViewUtils.drawLine(pGraphics, x2, y2, x2, y3, LineStyle.DOTTED);
	}
	else
	{
		ViewUtils.drawRectangle(pGraphics, getBounds(pNode));
	}
}
 
Example 9
Source File: MoleculeViewSkin.java    From openchemlib-js with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void drawBorder(GraphicsContext ctx, double w, double h)
{
    if (borderColor != null) {
        ctx.save();
        ctx.setStroke(borderColor);
        ctx.strokeRect(0, 0, w, h);
        ctx.restore();
    }
}
 
Example 10
Source File: SimpleCanvasComponent.java    From arma-dialog-creator with MIT License 5 votes vote down vote up
/** Will paint the {@link #border} if it isn't null. If the border is null, nothing will happen. */
protected void paintBorder(@NotNull GraphicsContext gc) {
	if (border != null) {
		gc.save();
		gc.setStroke(border.getColor());
		gc.setLineWidth(border.getThickness());
		strokeRectangle(gc);
		gc.restore();
	}
}
 
Example 11
Source File: ToolGraphics.java    From JetUML with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws a handle on pGraphics that is centered at the position
 * (pX, pY).
 * 
 * @param pGraphics The graphics context on which to draw the handle.
 * @param pX The x-coordinate of the center of the handle.
 * @param pY The y-coordinate of the center of the handle.
 */
private static void drawHandle(GraphicsContext pGraphics, int pX, int pY)
{
	Paint oldStroke = pGraphics.getStroke();
	Paint oldFill = pGraphics.getFill();
	pGraphics.setStroke(SELECTION_COLOR);
	pGraphics.strokeRect((int)(pX - HANDLE_SIZE / 2.0) + 0.5, (int)(pY - HANDLE_SIZE / 2.0)+ 0.5, HANDLE_SIZE, HANDLE_SIZE);
	pGraphics.setFill(SELECTION_FILL_COLOR);
	pGraphics.fillRect((int)(pX - HANDLE_SIZE / 2.0)+0.5, (int)(pY - HANDLE_SIZE / 2.0)+0.5, HANDLE_SIZE, HANDLE_SIZE);
	pGraphics.setStroke(oldStroke);
	pGraphics.setFill(oldFill);
}
 
Example 12
Source File: PinPeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void paint(GraphicsContext graphics, CircuitState circuitState) {
	GuiUtils.drawName(graphics, this, getProperties().getValue(Properties.LABEL_LOCATION));
	
	graphics.setFont(GuiUtils.getFont(16, true));
	Port port = getComponent().getPort(Pin.PORT);
	WireValue value = isInput() ? circuitState.getLastPushed(port)
	                            : circuitState.getLastReceived(port);
	if(circuitState.isShortCircuited(port.getLink())) {
		graphics.setFill(Color.RED);
	} else {
		if(value.getBitSize() == 1) {
			GuiUtils.setBitColor(graphics, value.getBit(0));
		} else {
			graphics.setFill(Color.WHITE);
		}
	}
	graphics.setStroke(Color.BLACK);
	
	if(isInput()) {
		GuiUtils.drawShape(graphics::fillRect, this);
		GuiUtils.drawShape(graphics::strokeRect, this);
	} else {
		graphics.fillRoundRect(getScreenX(), getScreenY(), getScreenWidth(), getScreenHeight(), 20, 20);
		graphics.strokeRoundRect(getScreenX(), getScreenY(), getScreenWidth(), getScreenHeight(), 20, 20);
	}
	
	graphics.setFill(port.getLink().getBitSize() > 1 ? Color.BLACK : Color.WHITE);
	GuiUtils.drawValue(graphics, value.toString(), getScreenX(), getScreenY(), getScreenWidth());
}
 
Example 13
Source File: LabelledMarkerRenderer.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
protected void setGraphicsContextAttributes(final GraphicsContext gc, final String style) {
    final Color strokeColor = StyleParser.getColorPropertyValue(style, XYChartCss.STROKE_COLOR);
    if (strokeColor == null) {
        gc.setStroke(strokeColorMarker);
    } else {
        gc.setStroke(strokeColor);
    }

    final Color fillColor = StyleParser.getColorPropertyValue(style, XYChartCss.FILL_COLOR);
    if (fillColor == null) {
        gc.setFill(strokeColorMarker);
    } else {
        gc.setFill(fillColor);
    }

    final Double strokeWidth = StyleParser.getFloatingDecimalPropertyValue(style, XYChartCss.STROKE_WIDTH);
    if (strokeWidth == null) {
        gc.setLineWidth(strokeLineWidthMarker);
    } else {
        gc.setLineWidth(strokeWidth);
    }

    final Font font = StyleParser.getFontPropertyValue(style);
    if (font == null) {
        gc.setFont(Font.font(LabelledMarkerRenderer.DEFAULT_FONT, LabelledMarkerRenderer.DEFAULT_FONT_SIZE));
    } else {
        gc.setFont(font);
    }

    final double[] dashPattern = StyleParser.getFloatingDecimalArrayPropertyValue(style,
            XYChartCss.STROKE_DASH_PATTERN);
    if (dashPattern == null) {
        gc.setLineDashes(strokeDashPattern);
    } else {
        gc.setLineDashes(dashPattern);
    }
}
 
Example 14
Source File: Tunnel.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) {
	Direction direction = getProperties().getValue(Properties.DIRECTION);
	
	boolean isIncompatible = isIncompatible();
	
	graphics.setStroke(Color.BLACK);
	graphics.setFill(isIncompatible ? Color.ORANGE : Color.WHITE);
	
	int block = GuiUtils.BLOCK_SIZE;
	int x = getScreenX();
	int y = getScreenY();
	int width = getScreenWidth();
	int height = getScreenHeight();
	
	int xOff = 0;
	int yOff = 0;
	
	switch(direction) {
		case EAST:
			xOff = -block;
			graphics.beginPath();
			graphics.moveTo(x + width, y + height * 0.5);
			graphics.lineTo(x + width - block, y + height);
			graphics.lineTo(x, y + height);
			graphics.lineTo(x, y);
			graphics.lineTo(x + width - block, y);
			graphics.closePath();
			break;
		case WEST:
			xOff = block;
			graphics.beginPath();
			graphics.moveTo(x, y + height * 0.5);
			graphics.lineTo(x + block, y);
			graphics.lineTo(x + width, y);
			graphics.lineTo(x + width, y + height);
			graphics.lineTo(x + block, y + height);
			graphics.closePath();
			break;
		case NORTH:
			yOff = block;
			graphics.beginPath();
			graphics.moveTo(x + width * 0.5, y);
			graphics.lineTo(x + width, y + block);
			graphics.lineTo(x + width, y + height);
			graphics.lineTo(x, y + height);
			graphics.lineTo(x, y + block);
			graphics.closePath();
			break;
		case SOUTH:
			yOff = -block;
			graphics.beginPath();
			graphics.moveTo(x + width * 0.5, y + height);
			graphics.lineTo(x, y + height - block);
			graphics.lineTo(x, y);
			graphics.lineTo(x + width, y);
			graphics.lineTo(x + width, y + height - block);
			graphics.closePath();
			break;
	}
	
	graphics.fill();
	graphics.stroke();
	
	if(!label.isEmpty()) {
		Bounds bounds = GuiUtils.getBounds(graphics.getFont(), label);
		graphics.setFill(Color.BLACK);
		graphics.fillText(label,
		                  x + xOff + ((width - xOff) - bounds.getWidth()) * 0.5,
		                  y + yOff + ((height - yOff) + bounds.getHeight()) * 0.4);
	}
	
	if(isIncompatible) {
		PortConnection port = getConnections().get(0);
		
		graphics.setFill(Color.BLACK);
		graphics.fillText(String.valueOf(bitSize),
		                  port.getScreenX() + 11,
		                  port.getScreenY() + 21);
		
		graphics.setStroke(Color.ORANGE);
		graphics.setFill(Color.ORANGE);
		graphics.strokeOval(port.getScreenX() - 2, port.getScreenY() - 2, 10, 10);
		graphics.fillText(String.valueOf(bitSize),
		                  port.getScreenX() + 10,
		                  port.getScreenY() + 20);
	}
}
 
Example 15
Source File: GaugeSkin.java    From Enzo with Apache License 2.0 4 votes vote down vote up
private final void drawSections(final GraphicsContext CTX) {
    final double xy        = (size - 0.83 * size) / 2;
    final double wh        = size * 0.83;
    final double MIN_VALUE = getSkinnable().getMinValue();
    final double MAX_VALUE = getSkinnable().getMaxValue();
    final double OFFSET = 90 - getSkinnable().getStartAngle();
    for (int i = 0 ; i < getSkinnable().getSections().size() ; i++) {
        final Section SECTION = getSkinnable().getSections().get(i);

        if (SECTION.getStart() > MAX_VALUE || SECTION.getStop() < MIN_VALUE) continue;

        final double SECTION_START_ANGLE;
        if (SECTION.getStart() > MAX_VALUE || SECTION.getStop() < MIN_VALUE) continue;

        if (SECTION.getStart() < MIN_VALUE && SECTION.getStop() < MAX_VALUE) {
            SECTION_START_ANGLE = MIN_VALUE * angleStep;
        } else {
            SECTION_START_ANGLE = (SECTION.getStart() - MIN_VALUE) * angleStep;
        }
        final double SECTION_ANGLE_EXTEND;
        if (SECTION.getStop() > MAX_VALUE) {
            SECTION_ANGLE_EXTEND = MAX_VALUE * angleStep;
        } else {
            SECTION_ANGLE_EXTEND = (SECTION.getStop() - SECTION.getStart()) * angleStep;
        }

        CTX.save();
        switch(i) {
            case 0: CTX.setStroke(getSkinnable().getSectionFill0()); break;
            case 1: CTX.setStroke(getSkinnable().getSectionFill1()); break;
            case 2: CTX.setStroke(getSkinnable().getSectionFill2()); break;
            case 3: CTX.setStroke(getSkinnable().getSectionFill3()); break;
            case 4: CTX.setStroke(getSkinnable().getSectionFill4()); break;
            case 5: CTX.setStroke(getSkinnable().getSectionFill5()); break;
            case 6: CTX.setStroke(getSkinnable().getSectionFill6()); break;
            case 7: CTX.setStroke(getSkinnable().getSectionFill7()); break;
            case 8: CTX.setStroke(getSkinnable().getSectionFill8()); break;
            case 9: CTX.setStroke(getSkinnable().getSectionFill9()); break;
        }
        CTX.setLineWidth(size * 0.037);
        CTX.setLineCap(StrokeLineCap.BUTT);
        CTX.strokeArc(xy, xy, wh, wh, -(OFFSET + SECTION_START_ANGLE), -SECTION_ANGLE_EXTEND, ArcType.OPEN);
        CTX.restore();
    }
}
 
Example 16
Source File: PlainAmpSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void drawSections(final GraphicsContext CTX) {
    final double                  x                 = -width * 0.03;
    final double                  y                 = height * 0.345;
    final double                  w                 = width * 1.06;
    final double                  h                 = height * 2.085;
    final double                  MIN_VALUE         = gauge.getMinValue();
    final double                  MAX_VALUE         = gauge.getMaxValue();
    final double                  OFFSET            = 90 - START_ANGLE;
    final ObservableList<Section> sections          = gauge.getSections();
    final boolean                 highlightSections = gauge.isHighlightSections();

    double value    = gauge.getCurrentValue();
    int    listSize = sections.size();
    for (int i = 0 ; i < listSize ; i++) {
        final Section SECTION = sections.get(i);
        final double  SECTION_START_ANGLE;
        if (Double.compare(SECTION.getStart(), MAX_VALUE) <= 0 && Double.compare(SECTION.getStop(), MIN_VALUE) >= 0) {
            if (SECTION.getStart() < MIN_VALUE && SECTION.getStop() < MAX_VALUE) {
                SECTION_START_ANGLE = 0;
            } else {
                SECTION_START_ANGLE = (SECTION.getStart() - MIN_VALUE) * angleStep;
            }
            final double SECTION_ANGLE_EXTEND;
            if (SECTION.getStop() > MAX_VALUE) {
                SECTION_ANGLE_EXTEND = (MAX_VALUE - SECTION.getStart()) * angleStep;
            } else {
                SECTION_ANGLE_EXTEND = (SECTION.getStop() - SECTION.getStart()) * angleStep;
            }

            CTX.save();
            if (highlightSections) {
                CTX.setStroke(SECTION.contains(value) ? SECTION.getHighlightColor() : SECTION.getColor());
            } else {
                CTX.setStroke(SECTION.getColor());
            }
            CTX.setLineWidth(height * 0.0415);
            CTX.setLineCap(StrokeLineCap.BUTT);
            CTX.strokeArc(x, y, w, h, -(OFFSET + SECTION_START_ANGLE), -SECTION_ANGLE_EXTEND, ArcType.OPEN);
            CTX.restore();
        }
    }
}
 
Example 17
Source File: BulletChartSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void drawTickMarks(final GraphicsContext CTX) {
    tickMarkCanvas.setCache(false);
    CTX.clearRect(0, 0, tickMarkCanvas.getWidth(), tickMarkCanvas.getHeight());
    CTX.setFill(gauge.getMajorTickMarkColor());

    List<Section> tickMarkSections         = gauge.getTickMarkSections();
    List<Section> tickLabelSections        = gauge.getTickLabelSections();
    Color         majorTickMarkColor       = gauge.getTickMarkColor();
    Color         tickLabelColor           = gauge.getTickLabelColor();
    boolean       smallRange               = Double.compare(gauge.getRange(), 10.0) <= 0;
    double        minValue                 = gauge.getMinValue();
    double        maxValue                 = gauge.getMaxValue();
    double        tmpStepSize              = smallRange ? stepSize / 10 : stepSize;
    Font          tickLabelFont            = Fonts.robotoRegular(0.1 * size);
    boolean       tickMarkSectionsVisible  = gauge.getTickMarkSectionsVisible();
    boolean       tickLabelSectionsVisible = gauge.getTickLabelSectionsVisible();
    double        offsetX                  = 0.18345865 * width;
    double        offsetY                  = 0.1 * height;
    double        innerPointX              = 0;
    double        innerPointY              = 0;
    double        outerPointX              = 0.07 * width;
    double        outerPointY              = 0.08 * height;
    double        textPointX               = Orientation.HORIZONTAL == orientation ? 0.55 * tickMarkCanvas.getWidth() : outerPointX + size * 0.05;
    double        textPointY               = 0.7 * tickMarkCanvas.getHeight();
    BigDecimal    minorTickSpaceBD         = BigDecimal.valueOf(gauge.getMinorTickSpace());
    BigDecimal    majorTickSpaceBD         = BigDecimal.valueOf(gauge.getMajorTickSpace());
    BigDecimal    counterBD                = BigDecimal.valueOf(gauge.getMinValue());
    double        counter                  = minValue;
    double        range                    = gauge.getRange();

    for (double i = 0 ; Double.compare(i, range) <= 0 ; i++) {
        if (Orientation.VERTICAL == orientation) {
            innerPointY = counter * tmpStepSize + offsetY;
            outerPointY = innerPointY;
            textPointY  = innerPointY;
        } else {
            innerPointX = counter * tmpStepSize + offsetX;
            outerPointX = innerPointX;
            textPointX  = innerPointX;
        }

        // Set the general tickmark color
        CTX.setStroke(gauge.getTickMarkColor());
        if (Double.compare(counterBD.remainder(majorTickSpaceBD).doubleValue(), 0.0) == 0) {
            // Draw major tick mark
            if (gauge.getMajorTickMarksVisible()) {
                CTX.setFill(tickMarkSectionsVisible ? Helper.getColorOfSection(tickMarkSections, counter, majorTickMarkColor) : majorTickMarkColor);
                CTX.setStroke(tickMarkSectionsVisible ? Helper.getColorOfSection(tickMarkSections, counter, majorTickMarkColor) : majorTickMarkColor);
                CTX.setLineWidth(1);
                CTX.strokeLine(innerPointX, innerPointY, outerPointX, outerPointY);
            }
            // Draw tick label text
            if (gauge.getTickLabelsVisible()) {
                CTX.save();
                CTX.translate(textPointX, textPointY);
                CTX.setFont(tickLabelFont);
                CTX.setTextAlign(Orientation.HORIZONTAL == orientation ? TextAlignment.CENTER : TextAlignment.LEFT);
                CTX.setTextBaseline(VPos.CENTER);
                CTX.setFill(tickLabelSectionsVisible ? Helper.getColorOfSection(tickLabelSections, counter, tickLabelColor) : tickLabelColor);
                if (Orientation.VERTICAL == orientation) {
                    CTX.fillText(Integer.toString((int) (maxValue - counter)), 0, 0);
                } else {
                    CTX.fillText(Integer.toString((int) counter), 0, 0);
                }
                CTX.restore();
            }
        }
        counterBD = counterBD.add(minorTickSpaceBD);
        counter   = counterBD.doubleValue();
        if (counter > maxValue) break;
    }

    tickMarkCanvas.setCache(true);
    tickMarkCanvas.setCacheHint(CacheHint.QUALITY);
}
 
Example 18
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 19
Source File: GanttTaskCell.java    From Open-Lowcode with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * draw all separators in the gantt task cell
 * 
 * @param gc                     graphics context
 * @param startdatedisplaywindow start date (first day) of the display window
 * @param enddatedisplaywindow   end date (last day) of the display window
 * @param ystarthour             start hour of the planning
 * @param ystartday              start day of the planning
 * @param yend                   end of the cell in pixel
 * @param totalwidth             total width in pixel
 * @param businesscalendar       business calendar to use for displaying of
 *                               opening hours
 * @param extraxoffset           extra offset in the display
 */
public static void drawSeparators(
		GraphicsContext gc,
		Date startdatedisplaywindow,
		Date enddatedisplaywindow,
		double ystarthour,
		double ystartday,
		double yend,
		double totalwidth,
		BusinessCalendar businesscalendar,
		float extraxoffset) {
	Date[] separatorstoconsider = DateUtils.getAllStartOfDays(startdatedisplaywindow, enddatedisplaywindow,
			businesscalendar);
	boolean isreduceddisplay = isReducedDisplay(separatorstoconsider);

	for (int i = 0; i < separatorstoconsider.length; i++) {
		if (isreduceddisplay) {
			gc.setLineWidth(0.5);

			gc.setStroke(GanttTaskCell.SCALE_LIGHT_GRAY);
		}
		if (!isreduceddisplay) {
			gc.setLineWidth(1);

			gc.setStroke(GanttTaskCell.SCALE_GRAY);
		}

		gc.setEffect(null);
		Date separatortoprint = separatorstoconsider[i];
		if (isMonday(separatortoprint)) {
			gc.setStroke(GanttTaskCell.SCALE_GRAY);
			if (!isreduceddisplay)
				gc.setLineWidth(2);
			if (isreduceddisplay)
				gc.setLineWidth(1);

		}
		double separatorratio = DateUtils.genericDateToCoordinates(separatortoprint, startdatedisplaywindow,
				enddatedisplaywindow, businesscalendar).getValue();
		gc.strokeLine((long) (separatorratio * totalwidth + extraxoffset), (long) ystartday,
				(long) (separatorratio * totalwidth + extraxoffset), (long) (yend));
		if (!isreduceddisplay)
			if (separatorstoconsider.length < 30) {
				for (int j = businesscalendar.getDaywindowhourstart() + 1; j < businesscalendar
						.getDaywindowhourend(); j++) {
					Date hour = new Date(separatortoprint.getTime()
							+ (j - businesscalendar.getDaywindowhourstart()) * 3600 * 1000);
					double hourratio = DateUtils.genericDateToCoordinates(hour, startdatedisplaywindow,
							enddatedisplaywindow, businesscalendar).getValue();
					gc.setStroke(GanttTaskCell.SCALE_LIGHT_GRAY);
					gc.setLineWidth(0.5);

					gc.setEffect(null);
					gc.strokeLine((long) (hourratio * totalwidth + extraxoffset), (long) (ystarthour),
							(long) (hourratio * totalwidth + extraxoffset), (long) (yend));

				}
			}
	}

}
 
Example 20
Source File: ShifterPeer.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void paint(GraphicsContext graphics, CircuitState state) {
	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.setFill(Color.BLACK);
	graphics.setLineWidth(1.5);
	
	int x = getScreenX();
	int y = getScreenY();
	int width = getScreenWidth();
	int height = getScreenHeight();
	
	ShiftType shiftType = getProperties().getValue("Shift Type");
	boolean rotateRight = false;
	switch(shiftType) {
		case ROTATE_LEFT:
			graphics.strokeLine(x + width - 5, y + height * 0.5, x + width - 5, y + height * 0.5 - 10);
			graphics.strokeLine(x + width - 15, y + height * 0.5 - 10, x + width - 5, y + height * 0.5 - 10);
		case LOGICAL_LEFT:
			graphics.strokeLine(x + width - 15, y + height * 0.5, x + width - 5, y + height * 0.5);
			graphics.strokeLine(x + width - 10, y + height * 0.5 - 5, x + width - 15, y + height * 0.5);
			graphics.strokeLine(x + width - 10, y + height * 0.5 + 5, x + width - 15, y + height * 0.5);
			break;
		case ROTATE_RIGHT:
			rotateRight = true;
			graphics.strokeLine(x + width - 15, y + height * 0.5, x + width - 15, y + height * 0.5 - 10);
			graphics.strokeLine(x + width - 15, y + height * 0.5 - 10, x + width - 5, y + height * 0.5 - 10);
		case ARITHMETIC_RIGHT:
			if(!rotateRight) {
				graphics.strokeLine(x + width - 20, y + height * 0.5, x + width - 18, y + height * 0.5);
			}
		case LOGICAL_RIGHT:
			graphics.strokeLine(x + width - 15, y + height * 0.5, x + width - 5, y + height * 0.5);
			graphics.strokeLine(x + width - 10, y + height * 0.5 - 5, x + width - 5, y + height * 0.5);
			graphics.strokeLine(x + width - 10, y + height * 0.5 + 5, x + width - 5, y + height * 0.5);
			break;
	}
}