本文整理匯總了Java中org.apache.batik.ext.awt.MultipleGradientPaint類的典型用法代碼示例。如果您正苦於以下問題:Java MultipleGradientPaint類的具體用法?Java MultipleGradientPaint怎麽用?Java MultipleGradientPaint使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MultipleGradientPaint類屬於org.apache.batik.ext.awt包,在下文中一共展示了MultipleGradientPaint類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: if
import org.apache.batik.ext.awt.MultipleGradientPaint; //導入依賴的package包/類
/**
* Converts the spreadMethod attribute.
*
* @param paintElement the paint Element with a spreadMethod
* @param s the spread method
* @param ctx the BridgeContext to use for error information
*/
protected static MultipleGradientPaint.CycleMethodEnum convertSpreadMethod
(Element paintElement, String s, BridgeContext ctx) {
if (SVG_REPEAT_VALUE.equals(s)) {
return MultipleGradientPaint.REPEAT;
}
if (SVG_REFLECT_VALUE.equals(s)) {
return MultipleGradientPaint.REFLECT;
}
if (SVG_PAD_VALUE.equals(s)) {
return MultipleGradientPaint.NO_CYCLE;
}
throw new BridgeException
(ctx, paintElement, ERR_ATTRIBUTE_VALUE_MALFORMED,
new Object[] {SVG_SPREAD_METHOD_ATTRIBUTE, s});
}
示例2: toString
import org.apache.batik.ext.awt.MultipleGradientPaint; //導入依賴的package包/類
/**
* 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();
}
示例3: calculateGradient
import org.apache.batik.ext.awt.MultipleGradientPaint; //導入依賴的package包/類
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();
}
示例4: convertColorInterpolation
import org.apache.batik.ext.awt.MultipleGradientPaint; //導入依賴的package包/類
/**
* Returns the color space for the specified element. Checks the
* 'color-interpolation' property
*
* @param e the element
*/
public static MultipleGradientPaint.ColorSpaceEnum
convertColorInterpolation(Element e) {
Value v = getComputedStyle(e, SVGCSSEngine.COLOR_INTERPOLATION_INDEX);
return (CSS_LINEARRGB_VALUE == v.getStringValue())
? MultipleGradientPaint.LINEAR_RGB
: MultipleGradientPaint.SRGB;
}
示例5: createPaint
import org.apache.batik.ext.awt.MultipleGradientPaint; //導入依賴的package包/類
/**
* Creates a <code>Paint</code> according to the specified parameters.
*
* @param ctx the bridge context to use
* @param paintElement the element that defines a Paint
* @param paintedElement the element referencing the paint
* @param paintedNode the graphics node on which the Paint will be applied
* @param opacity the opacity of the Paint to create
*/
public Paint createPaint(BridgeContext ctx,
Element paintElement,
Element paintedElement,
GraphicsNode paintedNode,
float opacity) {
String s;
// stop elements
List stops = extractStop(paintElement, opacity, ctx);
// if no stops are defined, painting is the same as 'none'
if (stops == null) {
return null;
}
int stopLength = stops.size();
// if one stops is defined, painting is the same as a single color
if (stopLength == 1) {
return ((Stop)stops.get(0)).color;
}
float [] offsets = new float[stopLength];
Color [] colors = new Color[stopLength];
Iterator iter = stops.iterator();
for (int i=0; iter.hasNext(); ++i) {
Stop stop = (Stop)iter.next();
offsets[i] = stop.offset;
colors[i] = stop.color;
}
// 'spreadMethod' attribute - default is pad
MultipleGradientPaint.CycleMethodEnum spreadMethod
= MultipleGradientPaint.NO_CYCLE;
s = SVGUtilities.getChainableAttributeNS
(paintElement, null, SVG_SPREAD_METHOD_ATTRIBUTE, ctx);
if (s.length() != 0) {
spreadMethod = convertSpreadMethod(paintElement, s, ctx);
}
// 'color-interpolation' CSS property
MultipleGradientPaint.ColorSpaceEnum colorSpace
= CSSUtilities.convertColorInterpolation(paintElement);
// 'gradientTransform' attribute - default is an Identity matrix
AffineTransform transform;
s = SVGUtilities.getChainableAttributeNS
(paintElement, null, SVG_GRADIENT_TRANSFORM_ATTRIBUTE, ctx);
if (s.length() != 0) {
transform = SVGUtilities.convertTransform
(paintElement, SVG_GRADIENT_TRANSFORM_ATTRIBUTE, s, ctx);
} else {
transform = new AffineTransform();
}
Paint paint = buildGradient(paintElement,
paintedElement,
paintedNode,
spreadMethod,
colorSpace,
transform,
colors,
offsets,
ctx);
return paint;
}
示例6: setGradient
import org.apache.batik.ext.awt.MultipleGradientPaint; //導入依賴的package包/類
/**
* Sets the gradient within this panel to the new gradient. This will delete
* the old gradient all of it's settings, resetting the slider, gradient
* type selection, and other gradient configuration options to match the
* new gradient.
*
* @param mgrad The desired gradient.
*/
public void setGradient(MultipleGradientPaint mgrad) {
if(gradient == mgrad) {
return;
}
float[] fracts = mgrad.getFractions();
Color[] colors = mgrad.getColors();
if(!thumbsMoving) {
// update the slider properly
if(slider.getModel().getThumbCount() !=
mgrad.getColors().length) {
// removing all thumbs;
while(slider.getModel().getThumbCount() > 0) {
slider.getModel().removeThumb(0);
}
// add them back
for(int i=0; i<fracts.length; i++) {
slider.getModel().addThumb(fracts[i],colors[i]);
}
} else {
for(int i=0; i<fracts.length; i++) {
slider.getModel().getThumbAt(i).setObject(colors[i]);
slider.getModel().getThumbAt(i).setPosition(fracts[i]);
}
}
} else {
log.fine("not updating because it's moving");
}
if(mgrad instanceof RadialGradientPaint) {
if(styleCombo.getSelectedItem() != GradientStyle.Radial) {
styleCombo.setSelectedItem(GradientStyle.Radial);
}
} else {
if(styleCombo.getSelectedItem() != GradientStyle.Linear) {
styleCombo.setSelectedItem(GradientStyle.Linear);
}
}
if(mgrad.getCycleMethod() == MultipleGradientPaint.REFLECT) {
this.reflectedRadio.setSelected(true);
gradientPreview.setReflected(true);
}
if(mgrad.getCycleMethod() == MultipleGradientPaint.REPEAT) {
this.repeatedRadio.setSelected(true);
gradientPreview.setRepeated(true);
}
gradientPreview.setGradient(mgrad);
//reflectedRadio.setSelected()
MultipleGradientPaint old = this.getGradient();
gradient = mgrad;
firePropertyChange("gradient",old,getGradient());
repaint();
}
示例7: getGradient
import org.apache.batik.ext.awt.MultipleGradientPaint; //導入依賴的package包/類
public MultipleGradientPaint getGradient() {
return this.gradient;
}
示例8: paintComponent
import org.apache.batik.ext.awt.MultipleGradientPaint; //導入依賴的package包/類
protected void paintComponent(Graphics gfx) {
Graphics2D g = (Graphics2D)gfx;
// get the list of colors
List<Thumb<Color>> stops = slider.getModel().getSortedThumbs();
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++;
}
// calculate the track area
int thumb_width = 12;
int track_width = slider.getWidth() - thumb_width;
g.translate(thumb_width / 2, 12);
Rectangle2D rect = new Rectangle(0, 0, track_width, 20);
// fill in the checker
g.setPaint(checker_paint);
g.fill(rect);
// fill in the gradient
Point2D start = new Point2D.Float(0,0);
Point2D end = new Point2D.Float(track_width,0);
MultipleGradientPaint paint = new org.apache.batik.ext.awt.LinearGradientPaint(
(float)start.getX(),
(float)start.getY(),
(float)end.getX(),
(float)end.getY(),
fractions,colors);
g.setPaint(paint);
g.fill(rect);
// draw a border
g.setColor(Color.black);
g.draw(rect);
g.translate(-thumb_width / 2, -12);
}
示例9: buildGradient
import org.apache.batik.ext.awt.MultipleGradientPaint; //導入依賴的package包/類
/**
* Builds a concrete gradient according to the specified parameters.
*
* @param paintElement the element that defines a Paint
* @param paintedElement the element referencing the paint
* @param paintedNode the graphics node on which the Paint will be applied
* @param spreadMethod the spread method
* @param colorSpace the color space (sRGB | LinearRGB)
* @param transform the gradient transform
* @param colors the colors of the gradient
* @param offsets the offsets
* @param ctx the bridge context to use
*/
protected abstract
Paint buildGradient(Element paintElement,
Element paintedElement,
GraphicsNode paintedNode,
MultipleGradientPaint.CycleMethodEnum spreadMethod,
MultipleGradientPaint.ColorSpaceEnum colorSpace,
AffineTransform transform,
Color [] colors,
float [] offsets,
BridgeContext ctx);
示例10: getGradient
import org.apache.batik.ext.awt.MultipleGradientPaint; //導入依賴的package包/類
/**
* Returns the MultipleGradientPaint currently choosen by the user.
* @return the currently selected gradient
*/
public MultipleGradientPaint getGradient() {
return gradient;
}