Class GradientUIResource

java.lang.Object
com.github.tadukoo.view.paint.gradient.GradientUIResource
All Implemented Interfaces:
Gradient, PaintUIResource, SizablePaint, UIResource

public class GradientUIResource extends Object implements PaintUIResource, Gradient
GradientUIResource is simply a LinearGradient wrapped as a PaintUIResource so that it can be used in Tadukoo Look & Feel (or other custom Look & Feels if desired).
Since:
Alpha v.0.2
Version:
Alpha v.0.3
Author:
Logan Ferree (Tadukoo)
  • Field Details

    • gradient

      private final Gradient gradient
      The Gradient contained in this Gradient UI resource
  • Constructor Details

    • GradientUIResource

      public GradientUIResource(Gradient gradient)
      Constructs a Gradient UI Resource using the given Gradient.
      Parameters:
      gradient - The Gradient to use for this Gradient UI Resource
  • Method Details

    • getColors

      public Color[] getColors()
      Specified by:
      getColors in interface Gradient
      Returns:
      The Colors involved in this Gradient
    • getFractions

      public float[] getFractions()
      Specified by:
      getFractions in interface Gradient
      Returns:
      The fractions involved in this Gradient
    • getCycleMethod

      public MultipleGradientPaint.CycleMethod getCycleMethod()
      Specified by:
      getCycleMethod in interface Gradient
      Returns:
      The cycle method involved in the Gradient
    • getColorSpace

      public MultipleGradientPaint.ColorSpaceType getColorSpace()
      Specified by:
      getColorSpace in interface Gradient
      Returns:
      The color space involved in the Gradient
    • getGradientTransform

      public AffineTransform getGradientTransform()
      Specified by:
      getGradientTransform in interface Gradient
      Returns:
      The AffineTransform involved in the Gradient
    • getPaint

      public Paint getPaint(Dimension size)
      Creates a Paint to be used based on the size of the object to be painted. The size is given because in the case of Gradients, it determines where the points are placed.
      Specified by:
      getPaint in interface SizablePaint
      Parameters:
      size - The Dimensions of the object to be painted
      Returns:
      A Paint
    • getColorUIResource

      public ColorUIResource getColorUIResource()
      Makes a ColorUIResource out of the first Color in this Gradient. There are some UI situations where we can't avoid using a Color instead of a general Paint if we want to support everything, so we need to return a plain Color in some cases.
      Specified by:
      getColorUIResource in interface PaintUIResource
      Returns:
      The first Color in the Gradient as a ColorUIResource
    • getMetalGradientList

      public List<Object> getMetalGradientList()
      Metal Look and Feel has a trash way of handling gradients. Basically it takes 3 colors and 2 fractions, but with the 3 colors, it repeats color 1 and does 1, 2, 1, 3. The fractions represent the 2 middle points, but the 2nd point is calculated as mid1 * 2 + mid2.

      If there are 4 colors or more, we send colors 1, 2, and either 3 or 4. Color 3 is sent if it's different than color 1 (because if it's the same, Metal already handles it with its 1, 2, 1, 3 garbage).
      3 colors get sent in their given order, and we can't help that 1 is repeated.

      If there are 3 fractions or more, we send fraction 2 as midpoint1, and fraction 3 as midpoint2, after subtracting midpoint1 * 2 from it.

      If there are only 2 colors, we send color 1, 2, and 2 again. For the fractions, we send fraction 2 as midpoint 1 and put in 0 for midpoint 2.
      Specified by:
      getMetalGradientList in interface PaintUIResource
      Returns:
      The garbage List that Metal Look and Feel expects for gradients that matches best to the one defined here