com.aspose.words

Class ListLevelCollection

  • java.lang.Object
    • com.aspose.words.ListLevelCollection
  • All Implemented Interfaces:
    java.lang.Cloneable, java.lang.Iterable
    public class ListLevelCollection 
    extends java.lang.Object

A collection of list formatting for each level in a list.

Example:

Shows how to apply custom list formatting to paragraphs when using DocumentBuilder.
Document doc = new Document();

// Create a list based on one of the Microsoft Word list templates.
List list = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);

// Completely customize one list level.
ListLevel level1 = list.getListLevels().get(0);
level1.getFont().setColor(Color.RED);
level1.getFont().setSize(24);
level1.setNumberStyle(NumberStyle.ORDINAL_TEXT);
level1.setStartAt(21);
level1.setNumberFormat("\u0000");

level1.setNumberPosition(-36);
level1.setTextPosition(144);
level1.setTabPosition(144);

// Completely customize yet another list level.
ListLevel level2 = list.getListLevels().get(1);
level2.setAlignment(ListLevelAlignment.RIGHT);
level2.setNumberStyle(NumberStyle.BULLET);
level2.getFont().setName("Wingdings");
level2.getFont().setColor(Color.BLUE);
level2.getFont().setSize(24);
level2.setNumberFormat("\uf0af");    // A bullet that looks like some sort of a star.
level2.setTrailingCharacter(ListTrailingCharacter.SPACE);
level2.setNumberPosition(144);

// Now add some text that uses the list that we created.
// It does not matter when to customize the list - before or after adding the paragraphs.
DocumentBuilder builder = new DocumentBuilder(doc);

builder.getListFormat().setList(list);
builder.writeln("The quick brown fox...");
builder.writeln("The quick brown fox...");

builder.getListFormat().listIndent();
builder.writeln("jumped over the lazy dog.");
builder.writeln("jumped over the lazy dog.");

builder.getListFormat().listOutdent();
builder.writeln("The quick brown fox...");

builder.getListFormat().removeNumbers();

builder.getDocument().save(getMyDir() + "\\Artifacts\\Lists.CreateCustomList.doc");

Example:

Shows how to create a list style and use it in a document.
Document doc = new Document();

// Create a new list style.
// List formatting associated with this list style is default numbered.
Style listStyle = doc.getStyles().add(StyleType.LIST, "MyListStyle");

// This list defines the formatting of the list style.
// Note this list can not be used directly to apply formatting to paragraphs (see below).
List list1 = listStyle.getList();

// Check some basic rules about the list that defines a list style.
System.out.println("IsListStyleDefinition: " + list1.isListStyleDefinition()); // Will be true
System.out.println("IsListStyleReference: " + list1.isListStyleReference()); // Will be false
System.out.println("IsMultiLevel: " + list1.isMultiLevel()); // Will be true
System.out.println("List style has been set: " + (listStyle == list1.getStyle())); // Are equal

// Modify formatting of the list style to our liking.
for (int i = 0; i < list1.getListLevels().getCount(); i++)
{
    ListLevel level = list1.getListLevels().get(i);
    level.getFont().setName("Verdana");
    level.getFont().setColor(Color.BLUE);
    level.getFont().setBold(true);
}

// Add some text to our document and use the list style.
DocumentBuilder builder = new DocumentBuilder(doc);

builder.writeln("Using list style first time:");

// This creates a list based on the list style.
List list2 = doc.getLists().add(listStyle);

// Check some basic rules about the list that references a list style.
System.out.println("IsListStyleDefinition: " + list2.isListStyleDefinition()); // Will be false
System.out.println("IsListStyleReference: " + list2.isListStyleReference()); // Will be true
System.out.println("List Style has been set: " + (listStyle == list2.getStyle())); // Are equal

// Apply the list that references the list style.
builder.getListFormat().setList(list2);
builder.writeln("Item 1");
builder.writeln("Item 2");
builder.getListFormat().removeNumbers();

builder.writeln("Using list style second time:");

// Create and apply another list based on the list style.
List list3 = doc.getLists().add(listStyle);
builder.getListFormat().setList(list3);
builder.writeln("Item 1");
builder.writeln("Item 2");
builder.getListFormat().removeNumbers();

builder.getDocument().save(getMyDir() + "\\Artifacts\\Lists.CreateAndUseListStyle.doc");

Property Getters/Setters Summary
intgetCount()
Gets the number of levels in this list.
ListLevelget(int index)
void
set(intindex, ListLevel value)
           Gets a list level by index.
 
Method Summary
java.util.Iterator<ListLevel>iterator()
Gets the enumerator object that will enumerate levels in this list.
 

    • Property Getters/Setters Detail

      • getCount

        public int getCount()
        
        Gets the number of levels in this list.

        There could be 1 or 9 levels in a list.

        Example:

        Shows how to create a list style and use it in a document.
        Document doc = new Document();
        
        // Create a new list style.
        // List formatting associated with this list style is default numbered.
        Style listStyle = doc.getStyles().add(StyleType.LIST, "MyListStyle");
        
        // This list defines the formatting of the list style.
        // Note this list can not be used directly to apply formatting to paragraphs (see below).
        List list1 = listStyle.getList();
        
        // Check some basic rules about the list that defines a list style.
        System.out.println("IsListStyleDefinition: " + list1.isListStyleDefinition()); // Will be true
        System.out.println("IsListStyleReference: " + list1.isListStyleReference()); // Will be false
        System.out.println("IsMultiLevel: " + list1.isMultiLevel()); // Will be true
        System.out.println("List style has been set: " + (listStyle == list1.getStyle())); // Are equal
        
        // Modify formatting of the list style to our liking.
        for (int i = 0; i < list1.getListLevels().getCount(); i++)
        {
            ListLevel level = list1.getListLevels().get(i);
            level.getFont().setName("Verdana");
            level.getFont().setColor(Color.BLUE);
            level.getFont().setBold(true);
        }
        
        // Add some text to our document and use the list style.
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.writeln("Using list style first time:");
        
        // This creates a list based on the list style.
        List list2 = doc.getLists().add(listStyle);
        
        // Check some basic rules about the list that references a list style.
        System.out.println("IsListStyleDefinition: " + list2.isListStyleDefinition()); // Will be false
        System.out.println("IsListStyleReference: " + list2.isListStyleReference()); // Will be true
        System.out.println("List Style has been set: " + (listStyle == list2.getStyle())); // Are equal
        
        // Apply the list that references the list style.
        builder.getListFormat().setList(list2);
        builder.writeln("Item 1");
        builder.writeln("Item 2");
        builder.getListFormat().removeNumbers();
        
        builder.writeln("Using list style second time:");
        
        // Create and apply another list based on the list style.
        List list3 = doc.getLists().add(listStyle);
        builder.getListFormat().setList(list3);
        builder.writeln("Item 1");
        builder.writeln("Item 2");
        builder.getListFormat().removeNumbers();
        
        builder.getDocument().save(getMyDir() + "\\Artifacts\\Lists.CreateAndUseListStyle.doc");
      • get/set

        public ListLevel get(int index) / public void set(int index, ListLevel value)
        
        Gets a list level by index.

        Example:

        Shows how to create a list style and use it in a document.
        Document doc = new Document();
        
        // Create a new list style.
        // List formatting associated with this list style is default numbered.
        Style listStyle = doc.getStyles().add(StyleType.LIST, "MyListStyle");
        
        // This list defines the formatting of the list style.
        // Note this list can not be used directly to apply formatting to paragraphs (see below).
        List list1 = listStyle.getList();
        
        // Check some basic rules about the list that defines a list style.
        System.out.println("IsListStyleDefinition: " + list1.isListStyleDefinition()); // Will be true
        System.out.println("IsListStyleReference: " + list1.isListStyleReference()); // Will be false
        System.out.println("IsMultiLevel: " + list1.isMultiLevel()); // Will be true
        System.out.println("List style has been set: " + (listStyle == list1.getStyle())); // Are equal
        
        // Modify formatting of the list style to our liking.
        for (int i = 0; i < list1.getListLevels().getCount(); i++)
        {
            ListLevel level = list1.getListLevels().get(i);
            level.getFont().setName("Verdana");
            level.getFont().setColor(Color.BLUE);
            level.getFont().setBold(true);
        }
        
        // Add some text to our document and use the list style.
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.writeln("Using list style first time:");
        
        // This creates a list based on the list style.
        List list2 = doc.getLists().add(listStyle);
        
        // Check some basic rules about the list that references a list style.
        System.out.println("IsListStyleDefinition: " + list2.isListStyleDefinition()); // Will be false
        System.out.println("IsListStyleReference: " + list2.isListStyleReference()); // Will be true
        System.out.println("List Style has been set: " + (listStyle == list2.getStyle())); // Are equal
        
        // Apply the list that references the list style.
        builder.getListFormat().setList(list2);
        builder.writeln("Item 1");
        builder.writeln("Item 2");
        builder.getListFormat().removeNumbers();
        
        builder.writeln("Using list style second time:");
        
        // Create and apply another list based on the list style.
        List list3 = doc.getLists().add(listStyle);
        builder.getListFormat().setList(list3);
        builder.writeln("Item 1");
        builder.writeln("Item 2");
        builder.getListFormat().removeNumbers();
        
        builder.getDocument().save(getMyDir() + "\\Artifacts\\Lists.CreateAndUseListStyle.doc");

        Example:

        Shows how to apply custom list formatting to paragraphs when using DocumentBuilder.
        Document doc = new Document();
        
        // Create a list based on one of the Microsoft Word list templates.
        List list = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
        
        // Completely customize one list level.
        ListLevel level1 = list.getListLevels().get(0);
        level1.getFont().setColor(Color.RED);
        level1.getFont().setSize(24);
        level1.setNumberStyle(NumberStyle.ORDINAL_TEXT);
        level1.setStartAt(21);
        level1.setNumberFormat("\u0000");
        
        level1.setNumberPosition(-36);
        level1.setTextPosition(144);
        level1.setTabPosition(144);
        
        // Completely customize yet another list level.
        ListLevel level2 = list.getListLevels().get(1);
        level2.setAlignment(ListLevelAlignment.RIGHT);
        level2.setNumberStyle(NumberStyle.BULLET);
        level2.getFont().setName("Wingdings");
        level2.getFont().setColor(Color.BLUE);
        level2.getFont().setSize(24);
        level2.setNumberFormat("\uf0af");    // A bullet that looks like some sort of a star.
        level2.setTrailingCharacter(ListTrailingCharacter.SPACE);
        level2.setNumberPosition(144);
        
        // Now add some text that uses the list that we created.
        // It does not matter when to customize the list - before or after adding the paragraphs.
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        builder.getListFormat().setList(list);
        builder.writeln("The quick brown fox...");
        builder.writeln("The quick brown fox...");
        
        builder.getListFormat().listIndent();
        builder.writeln("jumped over the lazy dog.");
        builder.writeln("jumped over the lazy dog.");
        
        builder.getListFormat().listOutdent();
        builder.writeln("The quick brown fox...");
        
        builder.getListFormat().removeNumbers();
        
        builder.getDocument().save(getMyDir() + "\\Artifacts\\Lists.CreateCustomList.doc");
    • Method Detail

      • iterator

        public java.util.Iterator<ListLevel> iterator()
        Gets the enumerator object that will enumerate levels in this list.

        Example:

        Shows how to create a list with some advanced formatting.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        
        List list = doc.getLists().add(ListTemplate.NUMBER_DEFAULT);
        
        // Level 1 labels will be "Appendix A", continuous and linked to the Heading 1 paragraph style.
        list.getListLevels().get(0).setNumberFormat("Appendix \u0000");
        list.getListLevels().get(0).setNumberStyle(NumberStyle.UPPERCASE_LETTER);
        list.getListLevels().get(0).setLinkedStyle(doc.getStyles().get("Heading 1"));
        
        // Level 2 labels will be "Section (1.01)" and restarting after Level 2 item appears.
        list.getListLevels().get(1).setNumberFormat("Section (\u0000.\u0001)");
        list.getListLevels().get(1).setNumberStyle(NumberStyle.LEADING_ZERO);
        // Notice the higher level uses UppercaseLetter numbering, but we want arabic number
        // of the higher levels to appear in this level, therefore set this property.
        list.getListLevels().get(1).isLegal(true);
        list.getListLevels().get(1).setRestartAfterLevel(0);
        
        // Level 3 labels will be "-I-" and restarting after Level 2 item appears.
        list.getListLevels().get(2).setNumberFormat("-\u0002-");
        list.getListLevels().get(2).setNumberStyle(NumberStyle.UPPERCASE_ROMAN);
        list.getListLevels().get(2).setRestartAfterLevel(1);
        
        // Make labels of all list levels bold.
        for (ListLevel level : list.getListLevels())
            level.getFont().setBold(true);
        
        // Apply list formatting to the current paragraph.
        builder.getListFormat().setList(list);
        
        // Exercise the 3 levels we created two times.
        for (int n = 0; n < 2; n++)
        {
            for (int i = 0; i < 3; i++)
            {
                builder.getListFormat().setListLevelNumber(i);
                builder.writeln("Level " + i);
            }
        }
        
        builder.getListFormat().removeNumbers();
        
        builder.getDocument().save(getMyDir() + "\\Artifacts\\Lists.CreateListRestartAfterHigher.doc");