GradientStopCollection
Inheritance: java.lang.Object
All Implemented Interfaces: java.lang.Iterable
public class GradientStopCollection implements Iterable
Contains a collection of GradientStop objects.
To learn more, visit the Working with Graphic Elements documentation article.
Remarks:
You do not create instances of this class directly. Use the Fill.getGradientStops() property to access gradient stops of fill objects.
Examples:
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(new Color((255), (255), (0)), gradientStops.get(0).getBaseColor());
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);
Methods
Method | Description |
---|---|
add(GradientStop gradientStop) | Adds a specified GradientStop to a gradient. |
get(int index) | Gets a GradientStop object in the collection. |
getCount() | Gets an integer value indicating the number of items in the collection. |
insert(int index, GradientStop gradientStop) | Inserts a GradientStop to the collection at a specified index. |
iterator() | Returns an enumerator that iterates through the collection. |
remove(GradientStop gradientStop) | Removes a specified GradientStop from the collection. |
removeAt(int index) | Removes a GradientStop from the collection at a specified index. |
set(int index, GradientStop value) | Sets a GradientStop object in the collection. |
add(GradientStop gradientStop)
public GradientStop add(GradientStop gradientStop)
Adds a specified GradientStop to a gradient.
Examples:
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(new Color((255), (255), (0)), gradientStops.get(0).getBaseColor());
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);
Parameters:
Parameter | Type | Description |
---|---|---|
gradientStop | GradientStop |
Returns: GradientStop
get(int index)
public GradientStop get(int index)
Gets a GradientStop object in the collection.
Examples:
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(new Color((255), (255), (0)), gradientStops.get(0).getBaseColor());
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);
Parameters:
Parameter | Type | Description |
---|---|---|
index | int |
Returns: GradientStop - A GradientStop object in the collection.
getCount()
public int getCount()
Gets an integer value indicating the number of items in the collection.
Examples:
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(new Color((255), (255), (0)), gradientStops.get(0).getBaseColor());
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);
Returns: int - An integer value indicating the number of items in the collection.
insert(int index, GradientStop gradientStop)
public GradientStop insert(int index, GradientStop gradientStop)
Inserts a GradientStop to the collection at a specified index.
Examples:
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(new Color((255), (255), (0)), gradientStops.get(0).getBaseColor());
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);
Parameters:
Parameter | Type | Description |
---|---|---|
index | int | |
gradientStop | GradientStop |
Returns: GradientStop
iterator()
public Iterator iterator()
Returns an enumerator that iterates through the collection.
Returns: java.util.Iterator
remove(GradientStop gradientStop)
public boolean remove(GradientStop gradientStop)
Removes a specified GradientStop from the collection.
Examples:
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(new Color((255), (255), (0)), gradientStops.get(0).getBaseColor());
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);
Parameters:
Parameter | Type | Description |
---|---|---|
gradientStop | GradientStop |
Returns: boolean - true if gradient stop was successfully removed, otherwise false .
removeAt(int index)
public GradientStop removeAt(int index)
Removes a GradientStop from the collection at a specified index.
Examples:
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(new Color((255), (255), (0)), gradientStops.get(0).getBaseColor());
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);
Parameters:
Parameter | Type | Description |
---|---|---|
index | int |
Returns: GradientStop - Removed GradientStop.
set(int index, GradientStop value)
public void set(int index, GradientStop value)
Sets a GradientStop object in the collection.
Examples:
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(new Color((255), (255), (0)), gradientStops.get(0).getBaseColor());
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);
Parameters:
Parameter | Type | Description |
---|---|---|
index | int | |
value | GradientStop | A GradientStop object in the collection. |