Java Color Darker darker(Color col, double FACTOR)

Here you can find the source of darker(Color col, double FACTOR)

Description

Makes the color darker

License

Open Source License

Parameter

Parameter Description
col a parameter
FACTOR 0 for black, 1 for no change

Declaration

public static Color darker(Color col, double FACTOR) 

Method Source Code

//package com.java2s;
/*// w ww. jav a  2s.co  m
 * Spirit, a study/biosample management tool for research.
 * Copyright (C) 2018 Idorsia Pharmaceuticals Ltd., Hegenheimermattweg 91,
 * CH-4123 Allschwil, Switzerland.
 *
 * This program 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.
 *
 * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>
 *
 * @author Joel Freyss
 */

import java.awt.Color;

import java.util.HashMap;

import java.util.Map;

public class Main {
    private static Map<Integer, Color> colorMap = new HashMap<Integer, Color>();

    /**
     * Makes the color darker
     * @param col
     * @param FACTOR 0 for black, 1 for no change
     * @return
     */
    public static Color darker(Color col, double FACTOR) {
        return getColor(Math.max((int) (col.getRed() * FACTOR), 0), Math.max((int) (col.getGreen() * FACTOR), 0),
                Math.max((int) (col.getBlue() * FACTOR), 0));
    }

    /**
     * Get Colors from (small) cache
     */
    public static Color getColor(int r, int g, int b) {
        return getColor(r, g, b, 255);
    }

    public static Color getColor(Color color, int alpha) {
        return getColor(color.getRed(), color.getGreen(), color.getBlue(), alpha);
    }

    public static Color getColor(int r, int g, int b, int alpha) {
        int rgb = ((alpha & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | ((b & 0xFF) << 0);
        return getColor(rgb);
    }

    public static Color getColor(int rgb) {
        Color res = colorMap.get(rgb);
        if (res == null) {
            if (colorMap.size() > 1000)
                colorMap.clear();
            res = new Color(rgb, true);
            colorMap.put(rgb, res);
        }
        return res;

    }
}

Related

  1. darker(Color c)
  2. darker(Color c, double factor)
  3. darker(Color c, double p)
  4. darker(Color c, double p)
  5. darker(Color c, float factor)
  6. darker(Color color)
  7. darker(Color color)
  8. darker(Color color, double factor)
  9. darker(Color color, double fraction)