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 listLevel = list.getListLevels().get(0);
listLevel.getFont().setColor(Color.RED);
listLevel.getFont().setSize(24.0);
listLevel.setNumberStyle(NumberStyle.ORDINAL_TEXT);
listLevel.setStartAt(21);
listLevel.setNumberFormat("\u0000");

listLevel.setNumberPosition(-36);
listLevel.setTextPosition(144.0);
listLevel.setTabPosition(144.0);

// Customize another list level
listLevel = list.getListLevels().get(1);
listLevel.setAlignment(ListLevelAlignment.RIGHT);
listLevel.setNumberStyle(NumberStyle.BULLET);
listLevel.getFont().setName("Wingdings");
listLevel.getFont().setColor(Color.BLUE);
listLevel.getFont().setSize(24.0);
listLevel.setNumberFormat("\uf0af"); // A bullet that looks like a star
listLevel.setTrailingCharacter(ListTrailingCharacter.SPACE);
listLevel.setNumberPosition(144.0);

// 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(getArtifactsDir() + "Lists.CreateCustomList.docx");

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
Assert.assertTrue(list1.isListStyleDefinition());
Assert.assertFalse(list1.isListStyleReference());
Assert.assertTrue(list1.isMultiLevel());
Assert.assertEquals(listStyle, list1.getStyle());

// Modify formatting of the list style to our liking
for (ListLevel level : list1.getListLevels()) {
    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
Assert.assertFalse(list2.isListStyleDefinition());
Assert.assertTrue(list2.isListStyleReference());
Assert.assertEquals(listStyle, list2.getStyle());

// 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(getArtifactsDir() + "Lists.CreateAndUseListStyle.docx");

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
        Assert.assertTrue(list1.isListStyleDefinition());
        Assert.assertFalse(list1.isListStyleReference());
        Assert.assertTrue(list1.isMultiLevel());
        Assert.assertEquals(listStyle, list1.getStyle());
        
        // Modify formatting of the list style to our liking
        for (ListLevel level : list1.getListLevels()) {
            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
        Assert.assertFalse(list2.isListStyleDefinition());
        Assert.assertTrue(list2.isListStyleReference());
        Assert.assertEquals(listStyle, list2.getStyle());
        
        // 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(getArtifactsDir() + "Lists.CreateAndUseListStyle.docx");
      • 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
        Assert.assertTrue(list1.isListStyleDefinition());
        Assert.assertFalse(list1.isListStyleReference());
        Assert.assertTrue(list1.isMultiLevel());
        Assert.assertEquals(listStyle, list1.getStyle());
        
        // Modify formatting of the list style to our liking
        for (ListLevel level : list1.getListLevels()) {
            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
        Assert.assertFalse(list2.isListStyleDefinition());
        Assert.assertTrue(list2.isListStyleReference());
        Assert.assertEquals(listStyle, list2.getStyle());
        
        // 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(getArtifactsDir() + "Lists.CreateAndUseListStyle.docx");

        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 listLevel = list.getListLevels().get(0);
        listLevel.getFont().setColor(Color.RED);
        listLevel.getFont().setSize(24.0);
        listLevel.setNumberStyle(NumberStyle.ORDINAL_TEXT);
        listLevel.setStartAt(21);
        listLevel.setNumberFormat("\u0000");
        
        listLevel.setNumberPosition(-36);
        listLevel.setTextPosition(144.0);
        listLevel.setTabPosition(144.0);
        
        // Customize another list level
        listLevel = list.getListLevels().get(1);
        listLevel.setAlignment(ListLevelAlignment.RIGHT);
        listLevel.setNumberStyle(NumberStyle.BULLET);
        listLevel.getFont().setName("Wingdings");
        listLevel.getFont().setColor(Color.BLUE);
        listLevel.getFont().setSize(24.0);
        listLevel.setNumberFormat("\uf0af"); // A bullet that looks like a star
        listLevel.setTrailingCharacter(ListTrailingCharacter.SPACE);
        listLevel.setNumberPosition(144.0);
        
        // 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(getArtifactsDir() + "Lists.CreateCustomList.docx");
    • 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();
        
        doc.save(getArtifactsDir() + "Lists.CreateListRestartAfterHigher.docx");