compare JavaFX RGB Color - Java JavaFX

Java examples for JavaFX:Color

Description

compare JavaFX RGB Color

Demo Code

/*//  w  w  w .j a v a2 s  . c o m
 * Copyright year Yuliyan Rusev - Inspix
 *
 * ColorHelpers.java is part of ColorSwapper.
 *
 *  ColorSwapper is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
 *
 * ColorSwapper is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with Foobar. If not, see http://www.gnu.org/licenses/.
 *
 */
//package com.java2s;
import javafx.scene.paint.Color;
import java.util.Comparator;

public class Main{
    public static Comparator<Color> rgbComparator = ((o1, o2) -> {

        double r1 = o1.getRed();
        double r2 = o2.getRed();
        double g1 = o1.getGreen();
        double g2 = o2.getGreen();
        double b1 = o1.getBlue();
        double b2 = o2.getBlue();

        if (r1 != r2) {
            return r1 < r2 ? -1 : 1;
        }
        if (g1 != g2) {
            return g1 < g2 ? -1 : 1;
        }
        if (b1 != b2) {
            return b1 < b2 ? -1 : 1;
        }
        return 0;
    });
    public static int compareRGB(Color color1, Color color2) {
        return rgbComparator.compare(color1, color2);
    }
}

Related Tutorials