Java Code Examples for javafx.scene.paint.Color#equals()

The following examples show how to use javafx.scene.paint.Color#equals() . 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: Model.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** Called by items to set their initial color
 *  @return 'Next' suggested item color
 */
private Color getNextItemColor()
{
    boolean already_used;
    Color color;
    int attempts = 10;
    do
    {
        -- attempts;
        color = default_colors.next();
        already_used = false;
        for (ModelItem item : items)
            if (color.equals(item.getPaintColor()))
            {
                already_used = true;
                break;
            }
    }
    while (attempts > 0  &&  already_used);
    return color;
}
 
Example 2
Source File: DisintegrationApp.java    From FXTutorials with MIT License 6 votes vote down vote up
private void disintegrate(Image image) {
    PixelReader pixelReader = image.getPixelReader();

    for (int y = 0; y < image.getHeight(); y++) {
        for (int x = 0; x < image.getWidth(); x++) {
            Color color = pixelReader.getColor(x, y);

            if (!color.equals(Color.TRANSPARENT)) {
                Particle p = new Particle(x + 700, y + 50, color);
                particles.add(p);
            }
        }
    }

    fullSize = particles.size();
}
 
Example 3
Source File: LogLine.java    From LogFX with GNU General Public License v3.0 6 votes vote down vote up
BackgroundTransition( Color targetColor ) {
    List<BackgroundFill> fills = getBackground().getFills();
    if ( !fills.isEmpty() && fills.get( 0 ).getFill() instanceof Color ) {
        this.originalColor = ( Color ) fills.get( 0 ).getFill();
    } else {
        this.originalColor = targetColor.invert();
    }

    if ( targetColor.equals( originalColor ) ) {
        this.targetColor = targetColor.invert();
    } else {
        this.targetColor = targetColor;
    }

    setCycleDuration( Duration.millis( 650 ) );
    setInterpolator( Interpolator.EASE_OUT );
    setCycleCount( 6 );
    setAutoReverse( true );
    setOnFinished( event -> setBackground( FxUtils.simpleBackground( originalColor ) ) );
}
 
Example 4
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static boolean isColorMatch2(Color color1, Color color2, int distance2) {
    if (color1.equals(color2)) {
        return true;
    } else if (distance2 == 0) {
        return false;
    }
    return calculateColorDistance2(color1, color2) <= distance2;

}
 
Example 5
Source File: PlotPart.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** @param color Color to use for this part */
public void setColor(final Color color)
{
    Objects.requireNonNull(color);
    synchronized (this)
    {
        if (color.equals(this.color))
            return;
        this.color = color;
    }
    requestRefresh();
}
 
Example 6
Source File: ModelItem.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** @param new_col New color for this item */
public void setColor(final Color new_col)
{
    if (new_col.equals(color))
        return;
    color = new_col;
    fireItemLookChanged();
}
 
Example 7
Source File: ImageMaskController.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public boolean drawMaskLine(double strokeWidth, Color strokeColor, boolean dotted, float opacity) {
    maskPane.getChildren().removeAll(maskLineLines);
    maskLineLines.clear();
    polygonP1.setOpacity(0);
    int size = maskLineData.getSize();
    if (size == 0) {
        return true;
    }

    double xRatio = imageView.getBoundsInParent().getWidth() / getImageWidth();
    double yRatio = imageView.getBoundsInParent().getHeight() / getImageHeight();
    double drawStrokeWidth = strokeWidth * xRatio;
    if (size == 1) {
        polygonP1.setOpacity(1);
        DoublePoint p1 = maskLineData.get(0);
        int anchorHW = AppVariables.getUserConfigInt("AnchorWidth", 10) / 2;
        polygonP1.setLayoutX(imageView.getLayoutX() + p1.getX() * xRatio - anchorHW);
        polygonP1.setLayoutY(imageView.getLayoutY() + p1.getY() * yRatio - anchorHW);
    } else if (size > 1) {
        double lastx = -1, lasty = -1, thisx, thisy;
        for (DoublePoint p : maskLineData.getPoints()) {
            thisx = p.getX() * xRatio;
            thisy = p.getY() * yRatio;
            if (lastx >= 0) {
                Line line = new Line(lastx, lasty, thisx, thisy);
                if (strokeColor.equals(Color.TRANSPARENT)) {
                    // Have not found how to make line as transparent. For display only.
                    line.setStroke(Color.WHITE);
                } else {
                    line.setStroke(strokeColor);
                }
                line.setStrokeWidth(drawStrokeWidth);
                line.getStrokeDashArray().clear();
                if (dotted) {
                    line.getStrokeDashArray().addAll(drawStrokeWidth * 1d, drawStrokeWidth * 3d);
                }
                line.setOpacity(opacity);
                maskLineLines.add(line);
                maskPane.getChildren().add(line);
                line.setLayoutX(imageView.getLayoutX());
                line.setLayoutY(imageView.getLayoutY());
            }
            lastx = thisx;
            lasty = thisy;
        }
    }
    return true;
}
 
Example 8
Source File: ImageMaskController.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public boolean drawMaskPenLines(double strokeWidth, Color strokeColor, boolean dotted, float opacity) {
    for (List<Line> penline : maskPenLines) {
        maskPane.getChildren().removeAll(penline);
    }
    maskPenLines.clear();
    polygonP1.setOpacity(0);
    int size = maskPenData.getPointsSize();
    if (size == 0) {
        return true;
    }
    double xRatio = imageView.getBoundsInParent().getWidth() / getImageWidth();
    double yRatio = imageView.getBoundsInParent().getHeight() / getImageHeight();
    double drawStrokeWidth = strokeWidth * xRatio;
    if (size == 1) {
        polygonP1.setOpacity(1);
        DoublePoint p1 = maskPenData.getPoint(0);
        int anchorHW = AppVariables.getUserConfigInt("AnchorWidth", 10) / 2;
        polygonP1.setLayoutX(imageView.getLayoutX() + p1.getX() * xRatio - anchorHW);
        polygonP1.setLayoutY(imageView.getLayoutY() + p1.getY() * yRatio - anchorHW);
    } else if (size > 1) {
        double lastx, lasty = -1, thisx, thisy;
        for (List<DoublePoint> lineData : maskPenData.getLines()) {
            List<Line> penLine = new ArrayList<>();
            lastx = -1;
            for (DoublePoint p : lineData) {
                thisx = p.getX() * xRatio;
                thisy = p.getY() * yRatio;
                if (lastx >= 0) {
                    Line line = new Line(lastx, lasty, thisx, thisy);
                    if (strokeColor.equals(Color.TRANSPARENT)) {
                        // Have not found how to make line as transparent. For display only.
                        line.setStroke(Color.WHITE);
                    } else {
                        line.setStroke(strokeColor);
                    }
                    line.setStrokeWidth(drawStrokeWidth);
                    line.getStrokeDashArray().clear();
                    if (dotted) {
                        line.getStrokeDashArray().addAll(drawStrokeWidth * 1d, drawStrokeWidth * 3d);
                    }
                    line.setOpacity(opacity);
                    penLine.add(line);
                    maskPane.getChildren().add(line);
                    line.setLayoutX(imageView.getLayoutX());
                    line.setLayoutY(imageView.getLayoutY());
                }
                lastx = thisx;
                lasty = thisy;
            }
            maskPenLines.add(penLine);
        }

    }
    return true;
}
 
Example 9
Source File: SettingsController.java    From MyBox with Apache License 2.0 4 votes vote down vote up
@Override
public boolean setColor(Control control, Color color) {
    if (control == null || color == null) {
        return false;
    }
    try {
        if (settingsAnchorColorButton.equals(control)) {
            strokeRect.setFill(color);
            FxmlControl.setTooltip(strokeRect, new Tooltip(FxmlColor.colorNameDisplay(color)));
            AppVariables.setUserConfigValue("StrokeColor", color.toString());
            if (parentController != null) {
                parentController.setMaskStroke();
            }

        } else if (settingsStrokeColorButton.equals(control)) {
            anchorRect.setFill(color);
            FxmlControl.setTooltip(anchorRect, new Tooltip(FxmlColor.colorNameDisplay(color)));
            AppVariables.setUserConfigValue("AnchorColor", color.toString());
            if (parentController != null) {
                parentController.setMaskStroke();
            }

        } else if (settingsAlphaColorButton.equals(control)) {
            alphaRect.setFill(color);
            FxmlControl.setTooltip(alphaRect, new Tooltip(FxmlColor.colorNameDisplay(color)));
            AppVariables.setUserConfigValue("AlphaAsColor", color.toString());
            if (!color.equals(Color.WHITE)) {
                alphaLabel.setText(message("AlphaReplaceComments"));
                alphaLabel.setStyle(FxmlControl.darkRedText);
            } else {
                alphaLabel.setText("");
            }

        }
        popSuccessful();
        return true;
    } catch (Exception e) {
        logger.debug(e.toString());
        popError(e.toString());
        return false;
    }
}
 
Example 10
Source File: MatrixIcon.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
public String getCode() {
    StringBuilder code = new StringBuilder().append("MatrixIcon icon = new MatrixIcon();").append("\n");
    int startIndex       = -1;
    int endIndex         = -1;
    Color lastPixelColor = null;
    for (int y = 0 ; y < 8 ; y++) {
        for (int x = 0 ; x < 8 ; x++) {
            Color currentPixelColor = getPixelAt(x, y).getColor();
            Color nextPixelColor    = x == 7 ? null : getPixelAt(x + 1, y).getColor();
            if (currentPixelColor.equals(nextPixelColor)) {
                if (startIndex == -1) {
                    startIndex = x;
                }
            } else if (x == 7) {
                if (currentPixelColor.equals(lastPixelColor)) {
                    if (startIndex > -1) {
                        endIndex = x;
                        code.append("icon.fillPixels(").append(startIndex).append(", ").append(endIndex).append(", ").append(y).append(", Color.web(\"").append(currentPixelColor.toString().replace("0x", "#")).append("\"));\n");
                    } else {
                        code.append("icon.setPixel(").append(x).append(", ").append(y).append(", Color.web(\"").append(currentPixelColor.toString().replace("0x", "#")).append("\"));\n");
                    }
                } else {
                    code.append("icon.setPixel(").append(x).append(", ").append(y).append(", Color.web(\"").append(currentPixelColor.toString().replace("0x", "#")).append("\"));\n");
                }
            } else {
                endIndex = x;
                if (startIndex == -1) {
                    code.append("icon.setPixel(").append(x).append(", ").append(y).append(", Color.web(\"").append(currentPixelColor.toString().replace("0x", "#")).append("\"));\n");
                } else {
                    code.append("icon.fillPixels(").append(startIndex).append(", ").append(endIndex).append(", ").append(y).append(", Color.web(\"").append(currentPixelColor.toString().replace("0x", "#")).append("\"));\n");
                    startIndex = -1;
                    endIndex   = -1;
                }
            }
            lastPixelColor = currentPixelColor;
        }
        startIndex     = -1;
        endIndex       = -1;
        lastPixelColor = null;
    }
    return code.toString();
}
 
Example 11
Source File: ImageUtil.java    From Augendiagnose with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Retrieve an overlay image, warped due to pupil size and position.
 *
 * @param overlayType
 *            The overlay type.
 * @param side
 *            The side of the eye.
 * @param color
 *            The overlay color.
 * @param pupilXOffset
 *            The horizontal offset of the pupil.
 * @param pupilYOffset
 *            The vertical offset of the pupil.
 * @param pupilSize
 *            The relative size of the pupil.
 * @return The overlay image.
 */
private static Image getOverlayImage(final int overlayType, final RightLeft side, final Color color,
		final float pupilXOffset, final float pupilYOffset, final float pupilSize) {
	if (mCachedOverlayType != null && overlayType == mCachedOverlayType // BOOLEAN_EXPRESSION_COMPLEXITY
			&& side == mCachedOverlaySide && color.equals(mCachedOverlayColor)
			&& pupilXOffset == mCachedPupilXOffset && pupilYOffset == mCachedPupilYOffset && pupilSize == mCachedPupilSize) {
		return mCachedOverlay;
	}

	Image originalImage = getOverlayImage(overlayType, side, color);
	Canvas canvas = new Canvas(OVERLAY_SIZE, OVERLAY_SIZE);

	int overlayHalfSize = OVERLAY_SIZE / 2;
	int irisRadius = (int) (OVERLAY_CIRCLE_RATIO * overlayHalfSize);
	long irisRadiusSquare = irisRadius * irisRadius;
	float pupilXCenter = OVERLAY_SIZE * OVERLAY_CIRCLE_RATIO * pupilXOffset / (1 - pupilSize);
	float pupilYCenter = OVERLAY_SIZE * OVERLAY_CIRCLE_RATIO * pupilYOffset / (1 - pupilSize);
	float origPupilSize = ORIG_PUPIL_SIZES[overlayType];
	float linTransM = pupilSize == 1 ? 0 : (1 - origPupilSize) / (1 - pupilSize);
	float linTransB = 1 - linTransM;

	FloatMap floatMap = new FloatMap(OVERLAY_SIZE, OVERLAY_SIZE);
	for (int x = 0; x < OVERLAY_SIZE; x++) {
		int xPos = x - overlayHalfSize;
		float xPosP = xPos - pupilXCenter;

		for (int y = 0; y < OVERLAY_SIZE; y++) {
			int yPos = y - overlayHalfSize;
			float yPosP = yPos - pupilYCenter;

			long centerDistSquare = xPos * xPos + yPos * yPos;
			float pupilCenterDistSquare = xPosP * xPosP + yPosP * yPosP;

			if (centerDistSquare >= irisRadiusSquare) {
				floatMap.setSamples(x, y, 0, 0);
			}
			else if (pupilCenterDistSquare == 0) {
				floatMap.setSamples(x, y, -xPos / OVERLAY_SIZE, -yPos / OVERLAY_SIZE);
			}
			else {
				// Determine corresponding iris boundary point via quadratic equation
				float plusMinusTerm = (float) Math.sqrt(2 * xPosP * yPosP * pupilXCenter * pupilYCenter
						+ irisRadius * irisRadius * pupilCenterDistSquare
						- (pupilXCenter * pupilXCenter * yPosP * yPosP)
						- (pupilYCenter * pupilYCenter * xPosP * xPosP));

				float xBound = (yPosP * yPosP * pupilXCenter - yPosP * xPosP * pupilYCenter + xPosP * plusMinusTerm) / pupilCenterDistSquare;
				float yBound = (xPosP * xPosP * pupilYCenter - xPosP * yPosP * pupilXCenter + yPosP * plusMinusTerm) / pupilCenterDistSquare;

				// distance of the current point from the center - 1 corresponds to iris boundary
				float relativeDistance = (float) Math.sqrt(pupilCenterDistSquare
						/ ((xBound - pupilXCenter) * (xBound - pupilXCenter) + (yBound - pupilYCenter) * (yBound - pupilYCenter)));

				float sourceRelativeDistance = linTransM * relativeDistance + linTransB;
				if (relativeDistance < pupilSize) {
					sourceRelativeDistance -= linTransB * Math.pow(1 - relativeDistance / pupilSize, 1.1f); // MAGIC_NUMBER
				}

				float sourceX = xBound * sourceRelativeDistance;
				float sourceY = yBound * sourceRelativeDistance;

				floatMap.setSamples(x, y, (sourceX - xPos) / OVERLAY_SIZE, (sourceY - yPos) / OVERLAY_SIZE);
			}

		}
	}
	DisplacementMap displacementMap = new DisplacementMap(floatMap);
	canvas.getGraphicsContext2D().setEffect(displacementMap);
	canvas.getGraphicsContext2D().drawImage(originalImage, 0, 0, OVERLAY_SIZE, OVERLAY_SIZE);

	SnapshotParameters parameters = new SnapshotParameters();
	parameters.setFill(Color.TRANSPARENT);

	mCachedOverlay = canvas.snapshot(parameters, null);
	mCachedOverlayType = overlayType;
	mCachedOverlaySide = side;
	mCachedOverlayColor = color;
	mCachedPupilSize = pupilSize;
	mCachedPupilXOffset = pupilXOffset;
	mCachedPupilYOffset = pupilYOffset;
	return mCachedOverlay;
}