Java Code Examples for java.awt.MultipleGradientPaint.CycleMethod

The following are Jave code examples for showing how to use CycleMethod of the java.awt.MultipleGradientPaint class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: iSeleda   File: GradientTool.java   Source Code and License Vote up 6 votes
public static void drawGradient(ImageLayer layer, GradientType gradientType, GradientColorType colorType, MultipleGradientPaint.CycleMethod cycleMethod, Composite composite, UserDrag userDrag, boolean invert) {
    if (userDrag.isClick()) {
        return;
    }

    TmpDrawingLayer tmpDrawingLayer = layer.createTmpDrawingLayer(composite, true);
    Graphics2D g = tmpDrawingLayer.getGraphics();
    // repeated gradients are still jaggy
    g.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON);

    Color[] colors = {colorType.getStartColor(invert), colorType.getEndColor(invert)};
    Paint gradient = gradientType.getGradient(userDrag, colors, cycleMethod);

    g.setPaint(gradient);

    int width = tmpDrawingLayer.getWidth();
    int height = tmpDrawingLayer.getHeight();
    g.fillRect(0, 0, width, height);
    g.dispose();
    layer.mergeTmpDrawingImageDown();
}
 
Example 2
Project: iSeleda   File: DiamondGradientPaint.java   Source Code and License Vote up 6 votes
private DiamondGradientPaintContext(UserDrag userDrag, Color startColor, Color endColor, ColorModel cm, MultipleGradientPaint.CycleMethod cycleMethod) {
    this.userDrag = userDrag;
    this.cycleMethod = cycleMethod;

    startAlpha = startColor.getAlpha();
    startRed = startColor.getRed();
    startGreen = startColor.getGreen();
    startBlue = startColor.getBlue();

    endAlpha = endColor.getAlpha();
    endRed = endColor.getRed();
    endGreen = endColor.getGreen();
    endBlue = endColor.getBlue();

    this.cm = cm;

    dragDist = userDrag.getDistance();
    double dragDistSqr = dragDist * dragDist;
    dragRelDX = (float) (userDrag.getDX() / dragDistSqr);
    dragRelDY = (float) (userDrag.getDY() / dragDistSqr);
}
 
Example 3
Project: iSeleda   File: AngleGradientPaint.java   Source Code and License Vote up 6 votes
private AngleGradientPaintContext(UserDrag userDrag, Color startColor, Color endColor, ColorModel cm, MultipleGradientPaint.CycleMethod cycleMethod) {
    this.userDrag = userDrag;
    this.cycleMethod = cycleMethod;

    startAlpha = startColor.getAlpha();
    startRed = startColor.getRed();
    startGreen = startColor.getGreen();
    startBlue = startColor.getBlue();

    endAlpha = endColor.getAlpha();
    endRed = endColor.getRed();
    endGreen = endColor.getGreen();
    endBlue = endColor.getBlue();

    this.cm = cm;
    drawAngle = userDrag.getDrawAngle();
}
 
Example 4
Project: iSeleda   File: SpiralGradientPaint.java   Source Code and License Vote up 6 votes
private SpiralGradientPaintContext(boolean clockwise, UserDrag userDrag, Color startColor, Color endColor, ColorModel cm, MultipleGradientPaint.CycleMethod cycleMethod) {
    this.clockwise = clockwise;
    this.userDrag = userDrag;
    this.cycleMethod = cycleMethod;

    startAlpha = startColor.getAlpha();
    startRed = startColor.getRed();
    startGreen = startColor.getGreen();
    startBlue = startColor.getBlue();

    endAlpha = endColor.getAlpha();
    endRed = endColor.getRed();
    endGreen = endColor.getGreen();
    endBlue = endColor.getBlue();

    this.cm = cm;
    drawAngle = userDrag.getDrawAngle() + Math.PI;  // between 0 and 2*PI

    dragDistance = userDrag.getDistance();
}
 
Example 5
Project: griffon2   File: LinearGradientPaintPropertyEditor.java   Source Code and License Vote up 6 votes
private void handleAsMap(Map<?, ?> map) {
    if(map.isEmpty()) {
        super.setValueInternal(null);
        return;
    }

    float x1 = (Float) getMapValue(map, "x1", 0f);
    float y1 = (Float) getMapValue(map, "y1", 0f);
    float x2 = (Float) getMapValue(map, "x2", 0f);
    float y2 = (Float) getMapValue(map, "y2", 0f);
    MultipleGradientPaint.CycleMethod cyclicMethod = MultipleGradientPaint.CycleMethod.NO_CYCLE;

    float[] fractions = parseFractions(map, map.get("fractions"));
    Color[] colors = parseColors(map, map.get("colors"));
    if (fractions.length != colors.length) {
        throw illegalValue(map, LinearGradientPaint.class);
    }
    Object cyclicValue = map.get("cycle");
    if (null != cyclicValue) {
        cyclicMethod = parseCyclicMethod(map, String.valueOf(cyclicValue));
    }

    super.setValueInternal(new LinearGradientPaint(x1, y1, x2, y2, fractions, colors, cyclicMethod));
}
 
Example 6
Project: griffon2   File: RadialGradientPaintPropertyEditor.java   Source Code and License Vote up 6 votes
private void handleAsMap(Map<?, ?> map) {
    if(map.isEmpty()) {
        super.setValueInternal(null);
        return;
    }

    float cx = (Float) getMapValue(map, "cx", 0f);
    float cy = (Float) getMapValue(map, "cy", 0f);
    float radius = (Float) getMapValue(map, "radius", 0f);
    float fx = (Float) getMapValue(map, "fx", 0f);
    float fy = (Float) getMapValue(map, "fy", 0f);
    MultipleGradientPaint.CycleMethod cyclicMethod = MultipleGradientPaint.CycleMethod.NO_CYCLE;

    float[] fractions = parseFractions(map, map.get("fractions"));
    Color[] colors = parseColors(map, map.get("colors"));
    if (fractions.length != colors.length) {
        throw illegalValue(map, RadialGradientPaint.class);
    }
    Object cyclicValue = map.get("cycle");
    if (null != cyclicValue) {
        cyclicMethod = parseCyclicMethod(map, String.valueOf(cyclicValue));
    }

    super.setValueInternal(new RadialGradientPaint(cx, cy, radius, fx, fy, fractions, colors, cyclicMethod));
}
 
Example 7
Project: iSeleda   File: GradientTool.java   Source Code and License Vote up 5 votes
private static MultipleGradientPaint.CycleMethod getCycleMethodFromString(String s) {
    switch (s) {
        case NO_CYCLE_AS_STRING:
            return NO_CYCLE;
        case REFLECT_AS_STRING:
            return REFLECT;
        case REPEAT_AS_STRING:
            return REPEAT;
    }
    throw new IllegalStateException("should not get here");
}
 
Example 8
Project: iSeleda   File: SpiralGradientPaint.java   Source Code and License Vote up 5 votes
public SpiralGradientPaint(boolean clockwise, UserDrag userDrag, Color startColor, Color endColor, MultipleGradientPaint.CycleMethod cycleMethod) {
    this.clockwise = clockwise;
    this.userDrag = userDrag;
    this.startColor = startColor;
    this.endColor = endColor;
    this.cycleMethod = cycleMethod;
}
 
Example 9
Project: griffon2   File: LinearGradientPaintPropertyEditor.java   Source Code and License Vote up 5 votes
private void handleAsString(String str) {
    if (isBlank(str)) {
        super.setValueInternal(null);
        return;
    }

    float x1 = 0;
    float y1 = 0;
    float x2 = 0;
    float y2 = 0;
    float[] fractions = null;
    Color[] colors = null;
    MultipleGradientPaint.CycleMethod cyclicMethod = MultipleGradientPaint.CycleMethod.NO_CYCLE;
    String[] parts = str.split(",");
    switch (parts.length) {
        case 7:
            cyclicMethod = parseCyclicMethod(str, parts[6]);
        case 6:
            x1 = parseValue(parts[0]);
            y1 = parseValue(parts[1]);
            x2 = parseValue(parts[2]);
            y2 = parseValue(parts[3]);
            fractions = parseFractions(str, parts[4].trim());
            colors = parseColors(str, parts[5].trim());
            if (fractions.length != colors.length) {
                throw illegalValue(str, LinearGradientPaint.class);
            }
            super.setValueInternal(new LinearGradientPaint(x1, y1, x2, y2, fractions, colors, cyclicMethod));
            break;
        default:
            throw illegalValue(str, LinearGradientPaint.class);
    }
}
 
Example 10
Project: griffon2   File: LinearGradientPaintPropertyEditor.java   Source Code and License Vote up 5 votes
private void handleAsList(List<?> list) {
    if(list.isEmpty()) {
        super.setValueInternal(null);
        return;
    }

    float x1 = 0;
    float y1 = 0;
    float x2 = 0;
    float y2 = 0;
    float[] fractions = null;
    Color[] colors = null;
    MultipleGradientPaint.CycleMethod cyclicMethod = MultipleGradientPaint.CycleMethod.NO_CYCLE;
    switch (list.size()) {
        case 7:
            cyclicMethod = parseCyclicMethod(list, String.valueOf(list.get(6)).trim());
        case 6:
            x1 = parseValue(list.get(0));
            y1 = parseValue(list.get(1));
            x2 = parseValue(list.get(2));
            y2 = parseValue(list.get(3));
            fractions = parseFractions(list, list.get(4));
            colors = parseColors(list, list.get(5));
            if (fractions.length != colors.length) {
                throw illegalValue(list, LinearGradientPaint.class);
            }
            super.setValueInternal(new LinearGradientPaint(x1, y1, x2, y2, fractions, colors, cyclicMethod));
            break;
        default:
            throw illegalValue(list, LinearGradientPaint.class);
    }
}
 
Example 11
Project: griffon2   File: LinearGradientPaintPropertyEditor.java   Source Code and License Vote up 5 votes
private MultipleGradientPaint.CycleMethod parseCyclicMethod(Object source, String str) {
    try {
        Field cyclicMethodField = MultipleGradientPaint.CycleMethod.class.getDeclaredField(str.toUpperCase().trim());
        return (MultipleGradientPaint.CycleMethod) cyclicMethodField.get(null);
    } catch (NoSuchFieldException | IllegalAccessException e) {
        throw illegalValue(source, LinearGradientPaint.class, e);
    }
}
 
Example 12
Project: griffon2   File: RadialGradientPaintPropertyEditor.java   Source Code and License Vote up 5 votes
private void handleAsString(String str) {
    if (isBlank(str)) {
        super.setValueInternal(null);
        return;
    }

    float cx = 0;
    float cy = 0;
    float radius = 0;
    float fx = 0;
    float fy = 0;
    float[] fractions = null;
    Color[] colors = null;
    MultipleGradientPaint.CycleMethod cyclicMethod = MultipleGradientPaint.CycleMethod.NO_CYCLE;
    String[] parts = str.split(",");
    switch (parts.length) {
        case 8:
            cyclicMethod = parseCyclicMethod(str, parts[7]);
        case 7:
            cx = parseValue(parts[0]);
            cy = parseValue(parts[1]);
            radius = parseValue(parts[2]);
            fx = parseValue(parts[3]);
            fy = parseValue(parts[4]);
            fractions = parseFractions(str, parts[5].trim());
            colors = parseColors(str, parts[6].trim());
            if (fractions.length != colors.length) {
                throw illegalValue(str, RadialGradientPaint.class);
            }
            super.setValueInternal(new RadialGradientPaint(cx, cy, radius, fx, fy, fractions, colors, cyclicMethod));
            break;
        default:
            throw illegalValue(str, RadialGradientPaint.class);
    }
}
 
Example 13
Project: griffon2   File: RadialGradientPaintPropertyEditor.java   Source Code and License Vote up 5 votes
private void handleAsList(List<?> list) {
    if(list.isEmpty()) {
        super.setValueInternal(null);
        return;
    }

    float cx = 0;
    float cy = 0;
    float radius = 0;
    float fx = 0;
    float fy = 0;
    float[] fractions = null;
    Color[] colors = null;
    MultipleGradientPaint.CycleMethod cyclicMethod = MultipleGradientPaint.CycleMethod.NO_CYCLE;
    switch (list.size()) {
        case 8:
            cyclicMethod = parseCyclicMethod(list, String.valueOf(list.get(7)).trim());
        case 7:
            cx = parseValue(list.get(0));
            cy = parseValue(list.get(1));
            radius = parseValue(list.get(2));
            fx = parseValue(list.get(3));
            fy = parseValue(list.get(4));
            fractions = parseFractions(list, list.get(5));
            colors = parseColors(list, list.get(6));
            if (fractions.length != colors.length) {
                throw illegalValue(list, RadialGradientPaint.class);
            }
            super.setValueInternal(new RadialGradientPaint(cx, cy, radius, fx, fy, fractions, colors, cyclicMethod));
            break;
        default:
            throw illegalValue(list, RadialGradientPaint.class);
    }
}
 
Example 14
Project: griffon2   File: RadialGradientPaintPropertyEditor.java   Source Code and License Vote up 5 votes
private MultipleGradientPaint.CycleMethod parseCyclicMethod(Object source, String str) {
    try {
        Field cyclicMethodField = MultipleGradientPaint.CycleMethod.class.getDeclaredField(str.toUpperCase().trim());
        return (MultipleGradientPaint.CycleMethod) cyclicMethodField.get(null);
    } catch (NoSuchFieldException | IllegalAccessException e) {
        throw illegalValue(source, RadialGradientPaint.class, e);
    }
}
 
Example 15
Project: iSeleda   File: DiamondGradientPaint.java   Source Code and License Vote up 4 votes
public DiamondGradientPaint(UserDrag userDrag, Color startColor, Color endColor, MultipleGradientPaint.CycleMethod cycleMethod) {
    this.userDrag = userDrag;
    this.startColor = startColor;
    this.endColor = endColor;
    this.cycleMethod = cycleMethod;
}
 
Example 16
Project: iSeleda   File: AngleGradientPaint.java   Source Code and License Vote up 4 votes
public AngleGradientPaint(UserDrag userDrag, Color startColor, Color endColor, MultipleGradientPaint.CycleMethod cycleMethod) {
    this.userDrag = userDrag;
    this.startColor = startColor;
    this.endColor = endColor;
    this.cycleMethod = cycleMethod;
}
 
Example 17
Project: mars-sim   File: GradientWrapper.java   Source Code and License Vote up 4 votes
public GradientWrapper(float startX, float startY, float endX, float endY, float[] fractions, Color[] colors, MultipleGradientPaint.CycleMethod cycleMethod) {
    GRADIENT = new LinearGradientPaint(new Point2D.Float(startX, startY), new Point2D.Float(endX, endY), fractions, colors, cycleMethod);
    copyArrays(fractions, colors);
}
 
Example 18
Project: mars-sim   File: GradientWrapper.java   Source Code and License Vote up 4 votes
public GradientWrapper(Point2D start, Point2D end, float[] fractions, Color[] colors, MultipleGradientPaint.CycleMethod cycleMethod) {
    GRADIENT = new LinearGradientPaint(start, end, fractions, colors, cycleMethod, java.awt.MultipleGradientPaint.ColorSpaceType.SRGB, new AffineTransform());
    copyArrays(fractions, colors);
}
 
Example 19
Project: mars-sim   File: GradientWrapper.java   Source Code and License Vote up 4 votes
public GradientWrapper(Point2D start, Point2D end, float[] fractions, Color[] colors, MultipleGradientPaint.CycleMethod cycleMethod, MultipleGradientPaint.ColorSpaceType colorSpace, AffineTransform gradientTransform) {
    GRADIENT = new LinearGradientPaint(start, end, fractions, colors, cycleMethod, colorSpace, gradientTransform);
    copyArrays(fractions, colors);
}