com.aspose.words

Class TabStopCollection

  • All Implemented Interfaces:
    java.lang.Cloneable
    public class TabStopCollection 
    extends InternableComplexAttr

A collection of TabStop objects that represent custom tabs for a paragraph or a style.

In Microsoft Word documents, a tab stop can be defined in the properties of a paragraph style or directly in the properties of a paragraph. A style can be based on another style. Therefore, the complete set of tab stops for a given object is a combination of tab stops defined directly on this object and tab stops inherited from the parent styles.

In Aspose.Words, when you obtain a TabStops collection for a paragraph or a style, it contains only the custom tab stops defined directly for this paragraph or style. The collection does not include tab stops defined in the parent styles or default tab stops.

See Also:
ParagraphFormat, TabStop, Document.DefaultTabStop

Property Getters/Setters Summary
intgetCount()
Gets the number of tab stops in the collection.
TabStopget(double position)
Gets a tab stop at the specified position.
TabStopget(int index)
Gets a tab stop at the given index.
 
Method Summary
voidadd(TabStop tabStop)
Adds or replaces a tab stop in the collection.
voidadd(double position, int alignment, int leader)
Adds or replaces a tab stop in the collection.
TabStopafter(double position)
Gets a first tab stop to the right of the specified position.
TabStopbefore(double position)
Gets a first tab stop to the left of the specified position.
voidclear()
Deletes all tab stop positions.
booleanequals(java.lang.Object obj)
Determines whether the specified object is equal in value to the current object.
intgetIndexByPosition(double position)
Gets the index of a tab stop with the specified position in points.
doublegetPositionByIndex(int index)
Gets the position (in points) of the tab stop at the specified index.
inthashCode()
Serves as a hash function for this type.
voidremoveByIndex(int index)
Removes a tab stop at the specified index from the collection.
voidremoveByPosition(double position)
Removes a tab stop at the specified position from the collection.
 

    • Property Getters/Setters Detail

      • getCount

        public int getCount()
        
        Gets the number of tab stops in the collection.
      • get

        public TabStop get(double position)
        
        Gets a tab stop at the specified position. Returns null if no tab stop is found at the specified position.
        Parameters:
        position - The position (in points) of the tab stop.
      • get

        public TabStop get(int index)
        
        Gets a tab stop at the given index.
        Parameters:
        index - An index into the collection of tab stops.
    • Method Detail

      • add

        public void add(TabStop tabStop)
        Adds or replaces a tab stop in the collection.

        If a tab stop already exists at the specified position, it is replaced.

        Parameters:
        tabStop - A tab stop object to add.

        Example:

        Shows how to create tab stops and add them to a document.
        Document doc = new Document(getMyDir() + "Document.doc");
        Paragraph paragraph = (Paragraph) doc.getChild(NodeType.PARAGRAPH, 0, true);
        
        // Create a TabStop object and add it to the document.
        TabStop tabStop = new TabStop(ConvertUtil.inchToPoint(3.0), TabAlignment.LEFT, TabLeader.DASHES);
        paragraph.getParagraphFormat().getTabStops().add(tabStop);
        
        // Add a tab stop without explicitly creating new TabStop objects.
        paragraph.getParagraphFormat().getTabStops().add(ConvertUtil.millimeterToPoint(100.0), TabAlignment.LEFT, TabLeader.DASHES);
        
        // Add tab stops at 5 cm to all paragraphs.
        for (Paragraph para : (Iterable<Paragraph>) doc.getChildNodes(NodeType.PARAGRAPH, true))
        {
            para.getParagraphFormat().getTabStops().add(ConvertUtil.millimeterToPoint(50.0), TabAlignment.LEFT, TabLeader.DASHES);
        }
        
        doc.save(getMyDir() + "\\Artifacts\\Document.AddedTabStops.doc");
      • add

        public void add(double position, int alignment, int leader)
        Adds or replaces a tab stop in the collection.

        If a tab stop already exists at the specified position, it is replaced.

        Parameters:
        position - A position (in points) where to add the tab stop.
        alignment - A TabAlignment value that specifies the alignment of text at the tab stop.
        leader - A TabLeader value that specifies the type of the leader line displayed under the tab character.

        Example:

        Shows how to create tab stops and add them to a document.
        Document doc = new Document(getMyDir() + "Document.doc");
        Paragraph paragraph = (Paragraph) doc.getChild(NodeType.PARAGRAPH, 0, true);
        
        // Create a TabStop object and add it to the document.
        TabStop tabStop = new TabStop(ConvertUtil.inchToPoint(3.0), TabAlignment.LEFT, TabLeader.DASHES);
        paragraph.getParagraphFormat().getTabStops().add(tabStop);
        
        // Add a tab stop without explicitly creating new TabStop objects.
        paragraph.getParagraphFormat().getTabStops().add(ConvertUtil.millimeterToPoint(100.0), TabAlignment.LEFT, TabLeader.DASHES);
        
        // Add tab stops at 5 cm to all paragraphs.
        for (Paragraph para : (Iterable<Paragraph>) doc.getChildNodes(NodeType.PARAGRAPH, true))
        {
            para.getParagraphFormat().getTabStops().add(ConvertUtil.millimeterToPoint(50.0), TabAlignment.LEFT, TabLeader.DASHES);
        }
        
        doc.save(getMyDir() + "\\Artifacts\\Document.AddedTabStops.doc");
      • after

        public TabStop after(double position)
        Gets a first tab stop to the right of the specified position.

        Skips tab stops with Alignment set to TabAlignment.Bar.

        Parameters:
        position - The reference position (in points).
        Returns:
        A tab stop object or null if a suitable tab stop was not found.
      • before

        public TabStop before(double position)
        Gets a first tab stop to the left of the specified position.

        Skips tab stops with Alignment set to TabAlignment.Bar.

        Parameters:
        position - The reference position (in points).
        Returns:
        A tab stop object or null if a suitable tab stop was not found.
      • clear

        public void clear()
        Deletes all tab stop positions.

        Example:

        Shows how to remove all tab stops from a document.
        Document doc = new Document(getMyDir() + "Document.TableOfContents.doc");
        
        // Clear all tab stops from every paragraph.
        for (Paragraph para : (Iterable<Paragraph>) doc.getChildNodes(NodeType.PARAGRAPH, true))
        {
            para.getParagraphFormat().getTabStops().clear();
        }
        
        doc.save(getMyDir() + "\\Artifacts\\Document.AllTabStopsRemoved.doc");
      • equals

        public boolean equals(java.lang.Object obj)
        Determines whether the specified object is equal in value to the current object.
      • getIndexByPosition

        public int getIndexByPosition(double position)
        Gets the index of a tab stop with the specified position in points.

        Example:

        Shows how to look up a position to see if a tab stop exists there, and if so, obtain its index.
        Document doc = new Document(getMyDir() + "Document.doc");
        Paragraph paragraph = (Paragraph) doc.getChild(NodeType.PARAGRAPH, 0, true);
        
        paragraph.getParagraphFormat().getTabStops().add(ConvertUtil.millimeterToPoint(30.0), TabAlignment.LEFT, TabLeader.DASHES);
        
        // An output of -1 signifies that there is no tab stop at that position.
        System.out.println(paragraph.getParagraphFormat().getTabStops().getIndexByPosition(ConvertUtil.millimeterToPoint(30.0))); // 0
        System.out.println(paragraph.getParagraphFormat().getTabStops().getIndexByPosition(ConvertUtil.millimeterToPoint(60.0))); // -1
      • getPositionByIndex

        public double getPositionByIndex(int index)
        Gets the position (in points) of the tab stop at the specified index.
        Parameters:
        index - An index into the collection of tab stops.
        Returns:
        The position of the tab stop.

        Example:

        Shows how to find a tab stop by it's index and get its position.
        Document doc = new Document(getMyDir() + "Document.doc");
        Paragraph paragraph = (Paragraph) doc.getChild(NodeType.PARAGRAPH, 0, true);
        
        paragraph.getParagraphFormat().getTabStops().add(ConvertUtil.millimeterToPoint(30.0), TabAlignment.LEFT, TabLeader.DASHES);
        paragraph.getParagraphFormat().getTabStops().add(ConvertUtil.millimeterToPoint(60.0), TabAlignment.LEFT, TabLeader.DASHES);
        
        System.out.println(MessageFormat.format("Tab stop at index {0} of the first paragraph is at {1} points.", 1, paragraph.getParagraphFormat().getTabStops().getPositionByIndex(1)));
      • hashCode

        public int hashCode()
        Serves as a hash function for this type.
      • removeByIndex

        public void removeByIndex(int index)
        Removes a tab stop at the specified index from the collection.
        Parameters:
        index - An index into the collection of tab stops.

        Example:

        Shows how to select a tab stop in a document by its index and remove it.
        Document doc = new Document(getMyDir() + "Document.doc");
        Paragraph paragraph = (Paragraph) doc.getChild(NodeType.PARAGRAPH, 0, true);
        
        paragraph.getParagraphFormat().getTabStops().add(ConvertUtil.millimeterToPoint(30.0), TabAlignment.LEFT, TabLeader.DASHES);
        paragraph.getParagraphFormat().getTabStops().add(ConvertUtil.millimeterToPoint(60.0), TabAlignment.LEFT, TabLeader.DASHES);
        
        // Tab stop placed at 30 mm is removed
        paragraph.getParagraphFormat().getTabStops().removeByIndex(0);
        
        System.out.println(paragraph.getParagraphFormat().getTabStops().getCount());
        
        doc.save(getMyDir() + "\\Artifacts\\Document.RemovedTabStopsByIndex.doc");
      • removeByPosition

        public void removeByPosition(double position)
        Removes a tab stop at the specified position from the collection.
        Parameters:
        position - The position (in points) of the tab stop to remove.

        Example:

        Shows how to modify the position of the right tab stop in TOC related paragraphs.
        Document doc = new Document(getMyDir() + "Document.TableOfContents.doc");
        
        // 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(getMyDir() + "\\Artifacts\\Document.TableOfContentsTabStops.doc");