com.aspose.words
Class GradientStop

java.lang.Object
    extended by com.aspose.words.GradientStop

public class GradientStop 
extends java.lang.Object

Represents one gradient stop.

To learn more, visit the Working with Graphic Elements documentation article.


Constructor Summary
GradientStop(java.awt.Color color, double position)
           Initializes a new instance of the GradientStop class.
GradientStop(java.awt.Color color, double position, double transparency)
           Initializes a new instance of the GradientStop class.
 
Property Getters/Setters Summary
java.awt.ColorgetColor()
voidsetColor(java.awt.Color value)
           Gets or sets a value representing the color of the gradient stop.
doublegetPosition()
voidsetPosition(double value)
           Gets or sets a value representing the position of a stop within the gradient expressed as a percent in range 0.0 to 1.0.
doublegetTransparency()
voidsetTransparency(double value)
           Gets or sets a value representing the transparency of the gradient fill expressed as a percent in range 0.0 to 1.0.
 
Method Summary
voidremove()
           Removes the gradient stop from the parent GradientStopCollection.
 

Constructor Detail

GradientStop

public GradientStop(java.awt.Color color, double position)
Initializes a new instance of the GradientStop class.
Parameters:
color - Represents the color of the gradient stop.
position - Represents the position of a stop within the gradient expressed as a percent in range 0.0 to 1.0.

Example:

Shows how to add gradient stops to the gradient fill.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Shape shape = builder.insertShape(ShapeType.RECTANGLE, 80.0, 80.0);
shape.getFill().twoColorGradient(Color.green, Color.RED, GradientStyle.HORIZONTAL, GradientVariant.VARIANT_2);

// Get gradient stops collection.
GradientStopCollection gradientStops = shape.getFill().getGradientStops();

// Change first gradient stop.
gradientStops.get(0).setColor(Color.yellow);
gradientStops.get(0).setPosition(0.1);
gradientStops.get(0).setTransparency(0.25);

// Add new gradient stop to the end of collection.
GradientStop gradientStop = new GradientStop(Color.blue, 0.5);
gradientStops.add(gradientStop);

// Remove gradient stop at index 1.
gradientStops.removeAt(1);
// And insert new gradient stop at the same index 1.
gradientStops.insert(1, new GradientStop(Color.pink, 0.75, 0.3));

// Remove last gradient stop in the collection.
gradientStop = gradientStops.get(2);
gradientStops.remove(gradientStop);

Assert.assertEquals(2, gradientStops.getCount());

Assert.assertEquals(Color.yellow.getRGB(), gradientStops.get(0).getColor().getRGB());
Assert.assertEquals(0.1d, gradientStops.get(0).getPosition(), 0.01d);
Assert.assertEquals(0.25d, gradientStops.get(0).getTransparency(), 0.01d);

Assert.assertEquals(Color.pink.getRGB(), gradientStops.get(1).getColor().getRGB());
Assert.assertEquals(0.75d, gradientStops.get(1).getPosition(), 0.01d);
Assert.assertEquals(0.3d, gradientStops.get(1).getTransparency(), 0.01d);

// Use the compliance option to define the shape using DML
// if you want to get "GradientStops" property after the document saves.
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(); { saveOptions.setCompliance(OoxmlCompliance.ISO_29500_2008_STRICT); }

doc.save(getArtifactsDir() + "Shape.GradientStops.docx", saveOptions);

GradientStop

public GradientStop(java.awt.Color color, double position, double transparency)
Initializes a new instance of the GradientStop class.
Parameters:
color - Represents the color of the gradient stop.
position - Represents the position of a stop within the gradient expressed as a percent in range 0.0 to 1.0.
transparency - Represents the transparency of a stop within the gradient expressed as a percent in range 0.0 to 1.0.

Example:

Shows how to add gradient stops to the gradient fill.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Shape shape = builder.insertShape(ShapeType.RECTANGLE, 80.0, 80.0);
shape.getFill().twoColorGradient(Color.green, Color.RED, GradientStyle.HORIZONTAL, GradientVariant.VARIANT_2);

// Get gradient stops collection.
GradientStopCollection gradientStops = shape.getFill().getGradientStops();

// Change first gradient stop.
gradientStops.get(0).setColor(Color.yellow);
gradientStops.get(0).setPosition(0.1);
gradientStops.get(0).setTransparency(0.25);

// Add new gradient stop to the end of collection.
GradientStop gradientStop = new GradientStop(Color.blue, 0.5);
gradientStops.add(gradientStop);

// Remove gradient stop at index 1.
gradientStops.removeAt(1);
// And insert new gradient stop at the same index 1.
gradientStops.insert(1, new GradientStop(Color.pink, 0.75, 0.3));

// Remove last gradient stop in the collection.
gradientStop = gradientStops.get(2);
gradientStops.remove(gradientStop);

Assert.assertEquals(2, gradientStops.getCount());

Assert.assertEquals(Color.yellow.getRGB(), gradientStops.get(0).getColor().getRGB());
Assert.assertEquals(0.1d, gradientStops.get(0).getPosition(), 0.01d);
Assert.assertEquals(0.25d, gradientStops.get(0).getTransparency(), 0.01d);

Assert.assertEquals(Color.pink.getRGB(), gradientStops.get(1).getColor().getRGB());
Assert.assertEquals(0.75d, gradientStops.get(1).getPosition(), 0.01d);
Assert.assertEquals(0.3d, gradientStops.get(1).getTransparency(), 0.01d);

// Use the compliance option to define the shape using DML
// if you want to get "GradientStops" property after the document saves.
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(); { saveOptions.setCompliance(OoxmlCompliance.ISO_29500_2008_STRICT); }

doc.save(getArtifactsDir() + "Shape.GradientStops.docx", saveOptions);

Property Getters/Setters Detail

getColor/setColor

public java.awt.Color getColor() / public void setColor(java.awt.Color value)
Gets or sets a value representing the color of the gradient stop.

Example:

Shows how to add gradient stops to the gradient fill.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Shape shape = builder.insertShape(ShapeType.RECTANGLE, 80.0, 80.0);
shape.getFill().twoColorGradient(Color.green, Color.RED, GradientStyle.HORIZONTAL, GradientVariant.VARIANT_2);

// Get gradient stops collection.
GradientStopCollection gradientStops = shape.getFill().getGradientStops();

// Change first gradient stop.
gradientStops.get(0).setColor(Color.yellow);
gradientStops.get(0).setPosition(0.1);
gradientStops.get(0).setTransparency(0.25);

// Add new gradient stop to the end of collection.
GradientStop gradientStop = new GradientStop(Color.blue, 0.5);
gradientStops.add(gradientStop);

// Remove gradient stop at index 1.
gradientStops.removeAt(1);
// And insert new gradient stop at the same index 1.
gradientStops.insert(1, new GradientStop(Color.pink, 0.75, 0.3));

// Remove last gradient stop in the collection.
gradientStop = gradientStops.get(2);
gradientStops.remove(gradientStop);

Assert.assertEquals(2, gradientStops.getCount());

Assert.assertEquals(Color.yellow.getRGB(), gradientStops.get(0).getColor().getRGB());
Assert.assertEquals(0.1d, gradientStops.get(0).getPosition(), 0.01d);
Assert.assertEquals(0.25d, gradientStops.get(0).getTransparency(), 0.01d);

Assert.assertEquals(Color.pink.getRGB(), gradientStops.get(1).getColor().getRGB());
Assert.assertEquals(0.75d, gradientStops.get(1).getPosition(), 0.01d);
Assert.assertEquals(0.3d, gradientStops.get(1).getTransparency(), 0.01d);

// Use the compliance option to define the shape using DML
// if you want to get "GradientStops" property after the document saves.
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(); { saveOptions.setCompliance(OoxmlCompliance.ISO_29500_2008_STRICT); }

doc.save(getArtifactsDir() + "Shape.GradientStops.docx", saveOptions);

getPosition/setPosition

public double getPosition() / public void setPosition(double value)
Gets or sets a value representing the position of a stop within the gradient expressed as a percent in range 0.0 to 1.0.

Example:

Shows how to add gradient stops to the gradient fill.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Shape shape = builder.insertShape(ShapeType.RECTANGLE, 80.0, 80.0);
shape.getFill().twoColorGradient(Color.green, Color.RED, GradientStyle.HORIZONTAL, GradientVariant.VARIANT_2);

// Get gradient stops collection.
GradientStopCollection gradientStops = shape.getFill().getGradientStops();

// Change first gradient stop.
gradientStops.get(0).setColor(Color.yellow);
gradientStops.get(0).setPosition(0.1);
gradientStops.get(0).setTransparency(0.25);

// Add new gradient stop to the end of collection.
GradientStop gradientStop = new GradientStop(Color.blue, 0.5);
gradientStops.add(gradientStop);

// Remove gradient stop at index 1.
gradientStops.removeAt(1);
// And insert new gradient stop at the same index 1.
gradientStops.insert(1, new GradientStop(Color.pink, 0.75, 0.3));

// Remove last gradient stop in the collection.
gradientStop = gradientStops.get(2);
gradientStops.remove(gradientStop);

Assert.assertEquals(2, gradientStops.getCount());

Assert.assertEquals(Color.yellow.getRGB(), gradientStops.get(0).getColor().getRGB());
Assert.assertEquals(0.1d, gradientStops.get(0).getPosition(), 0.01d);
Assert.assertEquals(0.25d, gradientStops.get(0).getTransparency(), 0.01d);

Assert.assertEquals(Color.pink.getRGB(), gradientStops.get(1).getColor().getRGB());
Assert.assertEquals(0.75d, gradientStops.get(1).getPosition(), 0.01d);
Assert.assertEquals(0.3d, gradientStops.get(1).getTransparency(), 0.01d);

// Use the compliance option to define the shape using DML
// if you want to get "GradientStops" property after the document saves.
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(); { saveOptions.setCompliance(OoxmlCompliance.ISO_29500_2008_STRICT); }

doc.save(getArtifactsDir() + "Shape.GradientStops.docx", saveOptions);

getTransparency/setTransparency

public double getTransparency() / public void setTransparency(double value)
Gets or sets a value representing the transparency of the gradient fill expressed as a percent in range 0.0 to 1.0.

Example:

Shows how to add gradient stops to the gradient fill.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Shape shape = builder.insertShape(ShapeType.RECTANGLE, 80.0, 80.0);
shape.getFill().twoColorGradient(Color.green, Color.RED, GradientStyle.HORIZONTAL, GradientVariant.VARIANT_2);

// Get gradient stops collection.
GradientStopCollection gradientStops = shape.getFill().getGradientStops();

// Change first gradient stop.
gradientStops.get(0).setColor(Color.yellow);
gradientStops.get(0).setPosition(0.1);
gradientStops.get(0).setTransparency(0.25);

// Add new gradient stop to the end of collection.
GradientStop gradientStop = new GradientStop(Color.blue, 0.5);
gradientStops.add(gradientStop);

// Remove gradient stop at index 1.
gradientStops.removeAt(1);
// And insert new gradient stop at the same index 1.
gradientStops.insert(1, new GradientStop(Color.pink, 0.75, 0.3));

// Remove last gradient stop in the collection.
gradientStop = gradientStops.get(2);
gradientStops.remove(gradientStop);

Assert.assertEquals(2, gradientStops.getCount());

Assert.assertEquals(Color.yellow.getRGB(), gradientStops.get(0).getColor().getRGB());
Assert.assertEquals(0.1d, gradientStops.get(0).getPosition(), 0.01d);
Assert.assertEquals(0.25d, gradientStops.get(0).getTransparency(), 0.01d);

Assert.assertEquals(Color.pink.getRGB(), gradientStops.get(1).getColor().getRGB());
Assert.assertEquals(0.75d, gradientStops.get(1).getPosition(), 0.01d);
Assert.assertEquals(0.3d, gradientStops.get(1).getTransparency(), 0.01d);

// Use the compliance option to define the shape using DML
// if you want to get "GradientStops" property after the document saves.
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(); { saveOptions.setCompliance(OoxmlCompliance.ISO_29500_2008_STRICT); }

doc.save(getArtifactsDir() + "Shape.GradientStops.docx", saveOptions);

Method Detail

remove

public void remove()
Removes the gradient stop from the parent GradientStopCollection.

Example:

Shows how to add gradient stops to the gradient fill.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Shape shape = builder.insertShape(ShapeType.RECTANGLE, 80.0, 80.0);
shape.getFill().twoColorGradient(Color.green, Color.RED, GradientStyle.HORIZONTAL, GradientVariant.VARIANT_2);

// Get gradient stops collection.
GradientStopCollection gradientStops = shape.getFill().getGradientStops();

// Change first gradient stop.
gradientStops.get(0).setColor(Color.yellow);
gradientStops.get(0).setPosition(0.1);
gradientStops.get(0).setTransparency(0.25);

// Add new gradient stop to the end of collection.
GradientStop gradientStop = new GradientStop(Color.blue, 0.5);
gradientStops.add(gradientStop);

// Remove gradient stop at index 1.
gradientStops.removeAt(1);
// And insert new gradient stop at the same index 1.
gradientStops.insert(1, new GradientStop(Color.pink, 0.75, 0.3));

// Remove last gradient stop in the collection.
gradientStop = gradientStops.get(2);
gradientStops.remove(gradientStop);

Assert.assertEquals(2, gradientStops.getCount());

Assert.assertEquals(Color.yellow.getRGB(), gradientStops.get(0).getColor().getRGB());
Assert.assertEquals(0.1d, gradientStops.get(0).getPosition(), 0.01d);
Assert.assertEquals(0.25d, gradientStops.get(0).getTransparency(), 0.01d);

Assert.assertEquals(Color.pink.getRGB(), gradientStops.get(1).getColor().getRGB());
Assert.assertEquals(0.75d, gradientStops.get(1).getPosition(), 0.01d);
Assert.assertEquals(0.3d, gradientStops.get(1).getTransparency(), 0.01d);

// Use the compliance option to define the shape using DML
// if you want to get "GradientStops" property after the document saves.
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(); { saveOptions.setCompliance(OoxmlCompliance.ISO_29500_2008_STRICT); }

doc.save(getArtifactsDir() + "Shape.GradientStops.docx", saveOptions);

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.