Class ConicalGradientPaint

  • All Implemented Interfaces:
    java.awt.Paint, java.awt.Transparency

    public final class ConicalGradientPaint
    extends java.lang.Object
    implements java.awt.Paint
    A paint class that creates conical gradients around a given center point It could be used in the same way as LinearGradientPaint and RadialGradientPaint and follows the same syntax. You could use floats from 0.0 to 1.0 for the fractions which is standard but it's also possible to use angles from 0.0 to 360 degrees which is most of the times much easier to handle. Gradients always start at the top with a clockwise direction and you could rotate the gradient around the center by given offset. The offset could also be defined from -0.5 to +0.5 or -180 to +180 degrees. If you would like to use degrees instead of values from 0 to 1 you have to use the full constructor and set the USE_DEGREES variable to true. Contributed under the BSD license by Gerrit Grunwald. Original code from https://www.jug-muenster.de/java2d-conical-gradient-paint-674/
    • Constructor Summary

      Constructors 
      Constructor Description
      ConicalGradientPaint​(boolean USE_DEGREES, java.awt.geom.Point2D CENTER, float GIVEN_OFFSET, float[] GIVEN_FRACTIONS, java.awt.Color[] GIVEN_COLORS)  
      ConicalGradientPaint​(java.awt.geom.Point2D CENTER, float[] GIVEN_FRACTIONS, java.awt.Color[] GIVEN_COLORS)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.awt.PaintContext createContext​(java.awt.image.ColorModel COLOR_MODEL, java.awt.Rectangle DEVICE_BOUNDS, java.awt.geom.Rectangle2D USER_BOUNDS, java.awt.geom.AffineTransform TRANSFORM, java.awt.RenderingHints HINTS)  
      java.awt.Color getColorFromFraction​(java.awt.Color START_COLOR, java.awt.Color DESTINATION_COLOR, int RANGE, int VALUE)
      With the START_COLOR at the beginning and the DESTINATION_COLOR at the end of the given RANGE the method will calculate and return the color that equals the given VALUE.
      int getTransparency()  
      private java.util.HashMap<java.lang.Float,​java.awt.Color> recalculate​(java.util.List<java.lang.Float> FRACTION_LIST, java.util.List<java.awt.Color> COLOR_LIST, float OFFSET)
      Recalculates the fractions in the FRACTION_LIST and their associated colors in the COLOR_LIST with a given OFFSET.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • CENTER

        private final java.awt.geom.Point2D CENTER
      • FRACTION_ANGLES

        private final double[] FRACTION_ANGLES
      • RED_STEP_LOOKUP

        private final double[] RED_STEP_LOOKUP
      • GREEN_STEP_LOOKUP

        private final double[] GREEN_STEP_LOOKUP
      • BLUE_STEP_LOOKUP

        private final double[] BLUE_STEP_LOOKUP
      • ALPHA_STEP_LOOKUP

        private final double[] ALPHA_STEP_LOOKUP
      • COLORS

        private final java.awt.Color[] COLORS
    • Constructor Detail

      • ConicalGradientPaint

        public ConicalGradientPaint​(java.awt.geom.Point2D CENTER,
                                    float[] GIVEN_FRACTIONS,
                                    java.awt.Color[] GIVEN_COLORS)
                             throws java.lang.IllegalArgumentException
        Throws:
        java.lang.IllegalArgumentException
      • ConicalGradientPaint

        public ConicalGradientPaint​(boolean USE_DEGREES,
                                    java.awt.geom.Point2D CENTER,
                                    float GIVEN_OFFSET,
                                    float[] GIVEN_FRACTIONS,
                                    java.awt.Color[] GIVEN_COLORS)
                             throws java.lang.IllegalArgumentException
        Throws:
        java.lang.IllegalArgumentException
    • Method Detail

      • recalculate

        private java.util.HashMap<java.lang.Float,​java.awt.Color> recalculate​(java.util.List<java.lang.Float> FRACTION_LIST,
                                                                                    java.util.List<java.awt.Color> COLOR_LIST,
                                                                                    float OFFSET)
        Recalculates the fractions in the FRACTION_LIST and their associated colors in the COLOR_LIST with a given OFFSET. Because the conical gradients always starts with 0 at the top and clockwise direction you could rotate the defined conical gradient from -180 to 180 degrees which equals values from -0.5 to +0.5
        Parameters:
        FRACTION_LIST -
        COLOR_LIST -
        OFFSET -
        Returns:
      • getColorFromFraction

        public java.awt.Color getColorFromFraction​(java.awt.Color START_COLOR,
                                                   java.awt.Color DESTINATION_COLOR,
                                                   int RANGE,
                                                   int VALUE)
        With the START_COLOR at the beginning and the DESTINATION_COLOR at the end of the given RANGE the method will calculate and return the color that equals the given VALUE. e.g. a START_COLOR of BLACK (R:0, G:0, B:0, A:255) and a DESTINATION_COLOR of WHITE(R:255, G:255, B:255, A:255) with a given RANGE of 100 and a given VALUE of 50 will return the color that is exactly in the middle of the gradient between black and white which is gray(R:128, G:128, B:128, A:255) So this method is really useful to calculate colors in gradients between two given colors.
        Parameters:
        START_COLOR -
        DESTINATION_COLOR -
        RANGE -
        VALUE -
        Returns:
      • createContext

        public java.awt.PaintContext createContext​(java.awt.image.ColorModel COLOR_MODEL,
                                                   java.awt.Rectangle DEVICE_BOUNDS,
                                                   java.awt.geom.Rectangle2D USER_BOUNDS,
                                                   java.awt.geom.AffineTransform TRANSFORM,
                                                   java.awt.RenderingHints HINTS)
        Specified by:
        createContext in interface java.awt.Paint
      • getTransparency

        public int getTransparency()
        Specified by:
        getTransparency in interface java.awt.Transparency