com.aspose.words
Class TabStop

java.lang.Object
    extended by com.aspose.words.TabStop
All Implemented Interfaces:
java.lang.Cloneable

public class TabStop 
extends java.lang.Object

Represents a single custom tab stop. The TabStop object is a member of the TabStopCollection collection.

Normally, a tab stop specifies a position where a tab stop exists. But because tab stops can be inherited from parent styles, it might be needed for the child object to define explicitly that there is no tab stop at a given position. To clear an inherited tab stop at a given position, create a TabStop object and set Alignment to TabAlignment.Clear.

For more information see TabStopCollection.

Example:

Shows how to modify the position of the right tab stop in TOC related paragraphs.
Document doc = new Document(getMyDir() + "Table of contents.docx");

// Iterate through all paragraphs in the document
for (Paragraph para : (Iterable<Paragraph>) doc.getChildNodes(NodeType.PARAGRAPH, true)) {
    // Check if this paragraph is formatted using the TOC result based styles. This is any style between TOC and TOC9
    if (para.getParagraphFormat().getStyle().getStyleIdentifier() >= StyleIdentifier.TOC_1
            && para.getParagraphFormat().getStyle().getStyleIdentifier() <= StyleIdentifier.TOC_9) {
        // Get the first tab used in this paragraph, this should be the tab used to align the page numbers
        TabStop tab = para.getParagraphFormat().getTabStops().get(0);
        // Remove the old tab from the collection
        para.getParagraphFormat().getTabStops().removeByPosition(tab.getPosition());
        // Insert a new tab using the same properties but at a modified position
        // We could also change the separators used (dots) by passing a different Leader type
        para.getParagraphFormat().getTabStops().add(tab.getPosition() - 50, tab.getAlignment(), tab.getLeader());
    }
}

doc.save(getArtifactsDir() + "Styles.ChangeTocsTabStops.docx");
See Also:
ParagraphFormat, TabStopCollection, Document.DefaultTabStop

Constructor Summary
TabStop(double position)
           Initializes a new instance of this class.
TabStop(double position, int alignment, int leader)
           Initializes a new instance of this class.
 
Property Getters/Setters Summary
intgetAlignment()
voidsetAlignment(int value)
           Gets or sets the alignment of text at this tab stop. The value of the property is TabAlignment integer constant.
booleanisClear()
           Returns true if this tab stop clears any existing tab stops in this position.
intgetLeader()
voidsetLeader(int value)
           Gets or sets the type of the leader line displayed under the tab character. The value of the property is TabLeader integer constant.
doublegetPosition()
           Gets the position of the tab stop in points.
 
Method Summary
booleanequals(TabStop rhs)
           Compares with the specified TabStop.
 

Constructor Detail

TabStop

public TabStop(double position)
Initializes a new instance of this class.

Example:

Shows how to add tab stops to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Access the collection of tab stops and add some tab stops to it
TabStopCollection tabStops = builder.getParagraphFormat().getTabStops();

// 72 points is one "inch" on the Microsoft Word tab stop ruler
tabStops.add(new TabStop(72.0));
tabStops.add(new TabStop(432.0, TabAlignment.RIGHT, TabLeader.DASHES));

Assert.assertEquals(tabStops.getCount(), 2);
Assert.assertFalse(tabStops.get(0).isClear());
Assert.assertFalse(tabStops.get(0).equals(tabStops.get(1)));

builder.writeln("Start\tTab 1\tTab 2");

// Get the collection of paragraphs that we've created
ParagraphCollection paragraphs = doc.getFirstSection().getBody().getParagraphs();
Assert.assertEquals(paragraphs.getCount(), 2);

// Each paragraph gets its own TabStopCollection which gets values from the DocumentBuilder's collection
Assert.assertEquals(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops());
Assert.assertNotSame(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops());
Assert.assertNotEquals(paragraphs.get(0).getParagraphFormat().getTabStops().hashCode(),
        paragraphs.get(1).getParagraphFormat().getTabStops().hashCode());

// A TabStopCollection can point us to TabStops before and after certain positions
Assert.assertEquals(72.0, tabStops.before(100.0).getPosition());
Assert.assertEquals(432.0, tabStops.after(100.0).getPosition());

doc.save(getArtifactsDir() + "TabStopCollection.TabStops.docx");

TabStop

public TabStop(double position, int alignment, int leader)
Initializes a new instance of this class.
Parameters:
position - The position of the tab stop in points.
alignment - A TabAlignment value that specifies the alignment of text at this tab stop.
leader - A TabLeader value that specifies the type of the leader line displayed under the tab character.

Example:

Shows how to add tab stops to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Access the collection of tab stops and add some tab stops to it
TabStopCollection tabStops = builder.getParagraphFormat().getTabStops();

// 72 points is one "inch" on the Microsoft Word tab stop ruler
tabStops.add(new TabStop(72.0));
tabStops.add(new TabStop(432.0, TabAlignment.RIGHT, TabLeader.DASHES));

Assert.assertEquals(tabStops.getCount(), 2);
Assert.assertFalse(tabStops.get(0).isClear());
Assert.assertFalse(tabStops.get(0).equals(tabStops.get(1)));

builder.writeln("Start\tTab 1\tTab 2");

// Get the collection of paragraphs that we've created
ParagraphCollection paragraphs = doc.getFirstSection().getBody().getParagraphs();
Assert.assertEquals(paragraphs.getCount(), 2);

// Each paragraph gets its own TabStopCollection which gets values from the DocumentBuilder's collection
Assert.assertEquals(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops());
Assert.assertNotSame(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops());
Assert.assertNotEquals(paragraphs.get(0).getParagraphFormat().getTabStops().hashCode(),
        paragraphs.get(1).getParagraphFormat().getTabStops().hashCode());

// A TabStopCollection can point us to TabStops before and after certain positions
Assert.assertEquals(72.0, tabStops.before(100.0).getPosition());
Assert.assertEquals(432.0, tabStops.after(100.0).getPosition());

doc.save(getArtifactsDir() + "TabStopCollection.TabStops.docx");

Property Getters/Setters Detail

getAlignment/setAlignment

public int getAlignment() / public void setAlignment(int value)
Gets or sets the alignment of text at this tab stop. The value of the property is TabAlignment integer constant.

Example:

Shows how to modify the position of the right tab stop in TOC related paragraphs.
Document doc = new Document(getMyDir() + "Table of contents.docx");

// Iterate through all paragraphs in the document
for (Paragraph para : (Iterable<Paragraph>) doc.getChildNodes(NodeType.PARAGRAPH, true)) {
    // Check if this paragraph is formatted using the TOC result based styles. This is any style between TOC and TOC9
    if (para.getParagraphFormat().getStyle().getStyleIdentifier() >= StyleIdentifier.TOC_1
            && para.getParagraphFormat().getStyle().getStyleIdentifier() <= StyleIdentifier.TOC_9) {
        // Get the first tab used in this paragraph, this should be the tab used to align the page numbers
        TabStop tab = para.getParagraphFormat().getTabStops().get(0);
        // Remove the old tab from the collection
        para.getParagraphFormat().getTabStops().removeByPosition(tab.getPosition());
        // Insert a new tab using the same properties but at a modified position
        // We could also change the separators used (dots) by passing a different Leader type
        para.getParagraphFormat().getTabStops().add(tab.getPosition() - 50, tab.getAlignment(), tab.getLeader());
    }
}

doc.save(getArtifactsDir() + "Styles.ChangeTocsTabStops.docx");

isClear

public boolean isClear()
Returns true if this tab stop clears any existing tab stops in this position.

Example:

Shows how to add tab stops to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Access the collection of tab stops and add some tab stops to it
TabStopCollection tabStops = builder.getParagraphFormat().getTabStops();

// 72 points is one "inch" on the Microsoft Word tab stop ruler
tabStops.add(new TabStop(72.0));
tabStops.add(new TabStop(432.0, TabAlignment.RIGHT, TabLeader.DASHES));

Assert.assertEquals(tabStops.getCount(), 2);
Assert.assertFalse(tabStops.get(0).isClear());
Assert.assertFalse(tabStops.get(0).equals(tabStops.get(1)));

builder.writeln("Start\tTab 1\tTab 2");

// Get the collection of paragraphs that we've created
ParagraphCollection paragraphs = doc.getFirstSection().getBody().getParagraphs();
Assert.assertEquals(paragraphs.getCount(), 2);

// Each paragraph gets its own TabStopCollection which gets values from the DocumentBuilder's collection
Assert.assertEquals(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops());
Assert.assertNotSame(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops());
Assert.assertNotEquals(paragraphs.get(0).getParagraphFormat().getTabStops().hashCode(),
        paragraphs.get(1).getParagraphFormat().getTabStops().hashCode());

// A TabStopCollection can point us to TabStops before and after certain positions
Assert.assertEquals(72.0, tabStops.before(100.0).getPosition());
Assert.assertEquals(432.0, tabStops.after(100.0).getPosition());

doc.save(getArtifactsDir() + "TabStopCollection.TabStops.docx");

getLeader/setLeader

public int getLeader() / public void setLeader(int value)
Gets or sets the type of the leader line displayed under the tab character. The value of the property is TabLeader integer constant.

Example:

Shows how to modify the position of the right tab stop in TOC related paragraphs.
Document doc = new Document(getMyDir() + "Table of contents.docx");

// Iterate through all paragraphs in the document
for (Paragraph para : (Iterable<Paragraph>) doc.getChildNodes(NodeType.PARAGRAPH, true)) {
    // Check if this paragraph is formatted using the TOC result based styles. This is any style between TOC and TOC9
    if (para.getParagraphFormat().getStyle().getStyleIdentifier() >= StyleIdentifier.TOC_1
            && para.getParagraphFormat().getStyle().getStyleIdentifier() <= StyleIdentifier.TOC_9) {
        // Get the first tab used in this paragraph, this should be the tab used to align the page numbers
        TabStop tab = para.getParagraphFormat().getTabStops().get(0);
        // Remove the old tab from the collection
        para.getParagraphFormat().getTabStops().removeByPosition(tab.getPosition());
        // Insert a new tab using the same properties but at a modified position
        // We could also change the separators used (dots) by passing a different Leader type
        para.getParagraphFormat().getTabStops().add(tab.getPosition() - 50, tab.getAlignment(), tab.getLeader());
    }
}

doc.save(getArtifactsDir() + "Styles.ChangeTocsTabStops.docx");

getPosition

public double getPosition()
Gets the position of the tab stop in points.

Example:

Shows how to modify the position of the right tab stop in TOC related paragraphs.
Document doc = new Document(getMyDir() + "Table of contents.docx");

// Iterate through all paragraphs in the document
for (Paragraph para : (Iterable<Paragraph>) doc.getChildNodes(NodeType.PARAGRAPH, true)) {
    // Check if this paragraph is formatted using the TOC result based styles. This is any style between TOC and TOC9
    if (para.getParagraphFormat().getStyle().getStyleIdentifier() >= StyleIdentifier.TOC_1
            && para.getParagraphFormat().getStyle().getStyleIdentifier() <= StyleIdentifier.TOC_9) {
        // Get the first tab used in this paragraph, this should be the tab used to align the page numbers
        TabStop tab = para.getParagraphFormat().getTabStops().get(0);
        // Remove the old tab from the collection
        para.getParagraphFormat().getTabStops().removeByPosition(tab.getPosition());
        // Insert a new tab using the same properties but at a modified position
        // We could also change the separators used (dots) by passing a different Leader type
        para.getParagraphFormat().getTabStops().add(tab.getPosition() - 50, tab.getAlignment(), tab.getLeader());
    }
}

doc.save(getArtifactsDir() + "Styles.ChangeTocsTabStops.docx");

Method Detail

equals

public boolean equals(TabStop rhs)
Compares with the specified TabStop.

Example:

Shows how to add tab stops to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Access the collection of tab stops and add some tab stops to it
TabStopCollection tabStops = builder.getParagraphFormat().getTabStops();

// 72 points is one "inch" on the Microsoft Word tab stop ruler
tabStops.add(new TabStop(72.0));
tabStops.add(new TabStop(432.0, TabAlignment.RIGHT, TabLeader.DASHES));

Assert.assertEquals(tabStops.getCount(), 2);
Assert.assertFalse(tabStops.get(0).isClear());
Assert.assertFalse(tabStops.get(0).equals(tabStops.get(1)));

builder.writeln("Start\tTab 1\tTab 2");

// Get the collection of paragraphs that we've created
ParagraphCollection paragraphs = doc.getFirstSection().getBody().getParagraphs();
Assert.assertEquals(paragraphs.getCount(), 2);

// Each paragraph gets its own TabStopCollection which gets values from the DocumentBuilder's collection
Assert.assertEquals(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops());
Assert.assertNotSame(paragraphs.get(0).getParagraphFormat().getTabStops(), paragraphs.get(1).getParagraphFormat().getTabStops());
Assert.assertNotEquals(paragraphs.get(0).getParagraphFormat().getTabStops().hashCode(),
        paragraphs.get(1).getParagraphFormat().getTabStops().hashCode());

// A TabStopCollection can point us to TabStops before and after certain positions
Assert.assertEquals(72.0, tabStops.before(100.0).getPosition());
Assert.assertEquals(432.0, tabStops.after(100.0).getPosition());

doc.save(getArtifactsDir() + "TabStopCollection.TabStops.docx");

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