Java Color Darker withAlphaAdjustingDarkness(Color c, double d)

Here you can find the source of withAlphaAdjustingDarkness(Color c, double d)

Description

with Alpha Adjusting Darkness

License

Apache License

Declaration

public static Color withAlphaAdjustingDarkness(Color c, double d) 

Method Source Code


//package com.java2s;
/*/*from  www.  ja  va 2  s .  c o  m*/
 * Copyright 2000-2012 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.awt.*;

public class Main {
    public static Color withAlphaAdjustingDarkness(Color c, double d) {
        return shift(withAlpha(c, d), d);
    }

    private static int shift(int colorComponent, double d) {
        final int n = (int) (colorComponent * d);
        return n > 255 ? 255 : n < 0 ? 0 : n;
    }

    public static Color shift(Color c, double d) {
        return new Color(shift(c.getRed(), d), shift(c.getGreen(), d), shift(c.getBlue(), d), c.getAlpha());
    }

    public static Color withAlpha(Color c, double a) {
        return toAlpha(c, (int) (255 * a));
    }

    public static Color toAlpha(Color color, int a) {
        Color c = color != null ? color : Color.black;
        return new Color(c.getRed(), c.getGreen(), c.getBlue(), a);
    }
}

Related

  1. initializePattern(Color light, Color dark)
  2. makeDarker(final Color color, final double percentage)
  3. reallyDark(Color c)
  4. setColorsDarkTheme()
  5. slightlyDarker(Color color)