/** * Returns true if the given MultipleGradientPaint instance can be * used by the accelerated OGLPaints.MultiGradient implementation. * A MultipleGradientPaint is considered valid if the following * conditions are met: * - the number of gradient "stops" is <= MAX_FRACTIONS * - the destination has support for fragment shaders */ @Override boolean isPaintValid(SunGraphics2D sg2d) { MultipleGradientPaint paint = (MultipleGradientPaint)sg2d.paint; // REMIND: ugh, this creates garbage; would be nicer if // we had a MultipleGradientPaint.getNumStops() method... if (paint.getFractions().length > MULTI_MAX_FRACTIONS) { return false; } OGLSurfaceData dstData = (OGLSurfaceData)sg2d.surfaceData; OGLGraphicsConfig gc = dstData.getOGLGraphicsConfig(); if (!gc.isCapPresent(CAPS_EXT_GRAD_SHADER)) { return false; } return true; }
/** * Returns true if the given MultipleGradientPaint instance can be * used by the accelerated D3DPaints.MultiGradient implementation. * A MultipleGradientPaint is considered valid if the following * conditions are met: * - the number of gradient "stops" is <= MAX_FRACTIONS * - the destination has support for fragment shaders */ @Override boolean isPaintValid(SunGraphics2D sg2d) { MultipleGradientPaint paint = (MultipleGradientPaint)sg2d.paint; // REMIND: ugh, this creates garbage; would be nicer if // we had a MultipleGradientPaint.getNumStops() method... if (paint.getFractions().length > MULTI_MAX_FRACTIONS_D3D) { return false; } D3DSurfaceData dstData = (D3DSurfaceData)sg2d.surfaceData; D3DGraphicsDevice gd = (D3DGraphicsDevice) dstData.getDeviceConfiguration().getDevice(); if (!gd.isCapPresent(CAPS_LCD_SHADER)) { return false; } return true; }
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(); }
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); }
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(); }
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(); }
public void setPaint(Paint paint) { if(paint == selectedPaint) { return; } Paint old = selectedPaint; selectedPaint = paint; if(paint instanceof Color) { tabbedPane.setSelectedComponent(colorPickerParent); colorPicker.setColor((Color)paint); alphaSlider.setValue(((Color)paint).getAlpha()); } if(paint instanceof MultipleGradientPaint) { tabbedPane.setSelectedComponent(gradientPicker); gradientPicker.setGradient((MultipleGradientPaint)paint); } firePropertyChange("paint", old, selectedPaint); }
/** * Creates a flat version of the current gradient. This is a linear gradient * from 0.0 to length,0. This gradient is suitable for drawing previews of * the real gradient. * * @param length * @return a gradient Paint with values between 0.0 and length */ private MultipleGradientPaint getFlatGradient(JXGradientChooser chooser, double length) { MultipleGradientPaint gp = chooser.getGradient(); // set up the data for the gradient float[] fractions = gp.getFractions(); Color[] colors = gp.getColors(); // fill in the gradient Point2D start = new Point2D.Float(0, 0); Point2D end = new Point2D.Float((float) length, 0); MultipleGradientPaint paint = new LinearGradientPaint( (float) start.getX(), (float) start.getY(), (float) end.getX(), (float) end.getY(), fractions, colors); return paint; }
/** * Creates a string representation of a {@code MultipleGradientPaint}. This * string is used for debugging purposes. Its contents cannot be guaranteed * between releases. * * @param paint * the {@code paint} to create a string for * @return a string representing the supplied {@code paint} */ public static String toString(MultipleGradientPaint paint) { StringBuffer buffer = new StringBuffer(); buffer.append(paint.getClass().getName()); Color[] colors = paint.getColors(); float[] values = paint.getFractions(); buffer.append("["); for(int i=0; i<colors.length; i++) { buffer.append("#").append(Integer.toHexString(colors[i].getRGB())); buffer.append(":"); buffer.append(values[i]); buffer.append(", "); } buffer.append("]"); return buffer.toString(); }
public MultipleGradientPaint calculateGradient() { List<Thumb<Color>> stops = getStops(); int len = stops.size(); // set up the data for the gradient float[] fractions = new float[len]; Color[] colors = new Color[len]; int i = 0; for (Thumb<Color> thumb : stops) { colors[i] = (Color)thumb.getObject(); fractions[i] = thumb.getPosition(); i++; } // get the final gradient this.setGradient(calculateGradient(fractions, colors)); return getGradient(); }
private BufferedImage createGradientImage(Color... colors) { final float[] fractions = new float[colors.length]; final float step = 1.0F / colors.length; for (int i = 0; i < colors.length; i++) { fractions[i] = i * step; } final LinearGradientPaint gradient = new LinearGradientPaint(0, 0, 256, 1, fractions, colors, MultipleGradientPaint.CycleMethod.REPEAT); final BufferedImage bi = new BufferedImage(256, 1, BufferedImage.TYPE_INT_ARGB); final Graphics2D g = bi.createGraphics(); try { g.setPaint(gradient); g.fillRect(0, 0, 256, 1); } finally { g.dispose(); } return bi; }
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)); }
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)); }
public LinearGradientPaint getPaint(float startX, float endX, boolean quadratic) { if (dirtyPaint || colorPoints == null || colorsQuadratic == null || colorsLinear == null) { rebuildPaint(); } return new LinearGradientPaint(startX, 0f, endX, 0f, colorPoints, quadratic ? colorsQuadratic : colorsLinear, MultipleGradientPaint.CycleMethod.NO_CYCLE); }
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"); }
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; }