]> source.dussan.org Git - poi.git/commitdiff
New HSSF example.
authorMark Beardsley <msb@apache.org>
Tue, 4 Aug 2009 15:35:04 +0000 (15:35 +0000)
committerMark Beardsley <msb@apache.org>
Tue, 4 Aug 2009 15:35:04 +0000 (15:35 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@800845 13f79535-47bb-0310-9956-ffa450edef68

src/examples/src/org/apache/poi/hssf/usermodel/examples/InCellLists.java [new file with mode: 0644]

diff --git a/src/examples/src/org/apache/poi/hssf/usermodel/examples/InCellLists.java b/src/examples/src/org/apache/poi/hssf/usermodel/examples/InCellLists.java
new file mode 100644 (file)
index 0000000..3ecd30e
--- /dev/null
@@ -0,0 +1,569 @@
+/* ====================================================================\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+\r
+\r
+package org.apache.poi.hssf.usermodel.examples;\r
+\r
+import java.io.File;\r
+import java.io.FileOutputStream;\r
+import java.io.FileNotFoundException;\r
+import java.io.IOException;\r
+import java.util.ArrayList;\r
+\r
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;\r
+import org.apache.poi.hssf.usermodel.HSSFSheet;\r
+import org.apache.poi.hssf.usermodel.HSSFRow;\r
+import org.apache.poi.hssf.usermodel.HSSFCell;\r
+import org.apache.poi.hssf.usermodel.HSSFCellStyle;\r
+import org.apache.poi.hssf.usermodel.HSSFDataFormat;\r
+import org.apache.poi.hssf.usermodel.HSSFRichTextString;\r
+\r
+/**\r
+ * This class contains code that demonstrates how to insert plain, numbered\r
+ * and bulleted lists into an Excel spreadsheet cell.\r
+ *\r
+ * Look at the code contained in the demonstrateMethodCalls() method. It calls\r
+ * other methods that create plain, numbered and bulleted single and\r
+ * multi-level lists. The demonstrateMethodCalls() method appears at the top\r
+ * of the class definition.\r
+ *\r
+ * Though different methods are provided to construct single and multi-level\r
+ * plain, numbered and bulleted lists, close examination will reveal that they\r
+ * are not strictly necessary. If the inputs to the listInCell() and\r
+ * multilLevelListInCell() methods are constructed to include the bullet\r
+ * character or the item numbers then these methods alone may be sufficient.\r
+ *\r
+ * @author Mark Beardsley [msb at apache.org]\r
+ */\r
+public class InCellLists {\r
+\r
+    // This character looks like a solid, black, loser case letter 'o'\r
+    // positioned up from the base line of the text.\r
+    private static final char BULLET_CHARACTER = '\u2022';\r
+\r
+    // The tab character - \t - cannot be used to create a tab space\r
+    // within a cell as it is rendered as a square. Therefore, four\r
+    // spaces are used to simulate that character.\r
+    private static final String TAB = "    ";\r
+\r
+    /**\r
+     * Call each of the list creation methods.\r
+     *\r
+     * @param outputFilename A String that encapsulates the name of and path to\r
+     *                       the Excel spreadsheet file this code will create.\r
+     */\r
+    public void demonstrateMethodCalls(String outputFilename) {\r
+        HSSFWorkbook workbook = null;\r
+        HSSFSheet sheet = null;\r
+        HSSFRow row = null;\r
+        HSSFCell cell = null;\r
+        File outputFile = null;\r
+        FileOutputStream fos = null;\r
+        ArrayList<MultiLevelListItem> multiLevelListItems = null;\r
+        ArrayList<String> listItems = null;\r
+        String listItem = null;\r
+        try {\r
+            workbook = new HSSFWorkbook();\r
+            sheet = workbook.createSheet("In Cell Lists");\r
+            row = sheet.createRow(0);\r
+\r
+            // Create a cell at A1 and insert a single, bulleted, item into\r
+            // that cell.\r
+            cell = row.createCell(0);\r
+            this.bulletedItemInCell(workbook, "List Item", cell);\r
+\r
+            // Create a cell at A2 and insert a plain list - that is one\r
+            // whose items are neither bulleted or numbered - into that cell.\r
+            row = sheet.createRow(1);\r
+            cell = row.createCell(0);\r
+            listItems = new ArrayList<String>();\r
+            listItems.add("List Item One.");\r
+            listItems.add("List Item Two.");\r
+            listItems.add("List Item Three.");\r
+            listItems.add("List Item Four.");\r
+            this.listInCell(workbook, listItems, cell);\r
+            // The row height and cell width are set here to ensure that the\r
+            // list may be seen.\r
+            row.setHeight((short)1100);\r
+            sheet.setColumnWidth(0, 9500);\r
+\r
+            // Create a cell at A3 and insert a numbered list into that cell.\r
+            // Note that a couple of items have been added to the listItems\r
+            // ArrayList\r
+            row = sheet.createRow(2);\r
+            cell = row.createCell(0);\r
+            listItems.add("List Item Five.");\r
+            listItems.add("List Item Six.");\r
+            this.numberedListInCell(workbook, listItems, cell, 1, 2);\r
+            row.setHeight((short)1550);\r
+\r
+            // Create a cell at A4 and insert a numbered list into that cell.\r
+            // Note that a couple of items have been added to the listItems\r
+            // ArrayList\r
+            row = sheet.createRow(3);\r
+            cell = row.createCell(0);\r
+            listItems.add("List Item Seven.");\r
+            listItems.add("List Item Eight.");\r
+            listItems.add("List Item Nine.");\r
+            listItems.add("List Item Ten.");\r
+            this.bulletedListInCell(workbook, listItems, cell);\r
+            row.setHeight((short)2550);\r
+\r
+            // Insert a plain, multi-level list into cell A5. Note that\r
+            // the major difference here is that the list items are passed as\r
+            // an ArrayList of MultiLevelListItems. Note that an ArrayList\r
+            // of instances of an inner class was used here in preference to\r
+            // a Hashtable or HashMap as the ArrayList will preserve the\r
+            // ordering of the items added to it; the first item added will\r
+            // be the first item recovered and the last item added, the last\r
+            // item recovered.\r
+            row = sheet.createRow(4);\r
+            cell = row.createCell(0);\r
+            multiLevelListItems = new ArrayList<MultiLevelListItem>();\r
+            listItems = new ArrayList<String>();\r
+            listItems.add("ML List Item One - Sub Item One.");\r
+            listItems.add("ML List Item One - Sub Item Two.");\r
+            listItems.add("ML List Item One - Sub Item Three.");\r
+            listItems.add("ML List Item One - Sub Item Four.");\r
+            multiLevelListItems.add(new MultiLevelListItem("List Item One.", listItems));\r
+            // Passing either null or an empty ArrayList will signal that\r
+            // there are no lower level items associated with the top level\r
+            // item\r
+            multiLevelListItems.add(new MultiLevelListItem("List Item Two.", null));\r
+            multiLevelListItems.add(new MultiLevelListItem("List Item Three.", null));\r
+            listItems = new ArrayList<String>();\r
+            listItems.add("ML List Item Four - Sub Item One.");\r
+            listItems.add("ML List Item Four - Sub Item Two.");\r
+            listItems.add("ML List Item Four - Sub Item Three.");\r
+            multiLevelListItems.add(new MultiLevelListItem("List Item Four.", listItems));\r
+            this.multiLevelListInCell(workbook, multiLevelListItems, cell);\r
+            row.setHeight((short)2800);\r
+\r
+            // Insert a numbered multi-level list into cell A6. Note that the\r
+            // same ArrayList as constructed for the above plain multi-level\r
+            // list example will be re-used\r
+            row = sheet.createRow(5);\r
+            cell = row.createCell(0);\r
+            this.multiLevelNumberedListInCell(workbook, multiLevelListItems,\r
+                                              cell, 1, 1, 1, 2);\r
+            row.setHeight((short)2800);\r
+\r
+            // Insert a numbered multi-level list into cell A7. Note that the\r
+            // same ArrayList as constructed for the plain multi-level list\r
+            // example will be re-used\r
+            row = sheet.createRow(6);\r
+            cell = row.createCell(0);\r
+            this.multiLevelBulletedListInCell(workbook, multiLevelListItems, cell);\r
+            row.setHeight((short)2800);\r
+\r
+            // Save the completed workbook\r
+            outputFile = new File(outputFilename);\r
+            fos = new FileOutputStream(outputFile);\r
+            workbook.write(fos);\r
+        }\r
+        catch(FileNotFoundException fnfEx) {\r
+            System.out.println("Caught a: " + fnfEx.getClass().getName());\r
+            System.out.println("Message: " + fnfEx.getMessage());\r
+            System.out.println("Stacktrace follows...........");\r
+            fnfEx.printStackTrace(System.out);\r
+        }\r
+        catch(IOException ioEx) {\r
+            System.out.println("Caught a: " + ioEx.getClass().getName());\r
+            System.out.println("Message: " + ioEx.getMessage());\r
+            System.out.println("Stacktrace follows...........");\r
+            ioEx.printStackTrace(System.out);\r
+        }\r
+        finally {\r
+            if(fos != null) {\r
+                try {\r
+                    fos.close();\r
+                }\r
+                catch(IOException ioEx) {\r
+\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Inserts a single bulleted item into a cell.\r
+     *\r
+     * @param workbook A reference to the HSSFWorkbook that 'contains' the\r
+     *                 cell.\r
+     * @param listItem An instance of the String class encapsulating the\r
+     *                 items text.\r
+     * @param cell An instance of the HSSFCell class that encapsulates a\r
+     *             reference to the spreadsheet cell into which the list item\r
+     *             will be written.\r
+     */\r
+    public void bulletedItemInCell(HSSFWorkbook workbook, String listItem, HSSFCell cell) {\r
+        // A format String must be built to ensure that the contents of the\r
+        // cell appear as a bulleted item.\r
+        HSSFDataFormat format = workbook.createDataFormat();\r
+        String formatString = InCellLists.BULLET_CHARACTER + " @";\r
+        int formatIndex = format.getFormat(formatString);\r
+\r
+        // Construct an HSSFCellStyle and set it's data formt to use the\r
+        // object created above.\r
+        HSSFCellStyle bulletStyle = workbook.createCellStyle();\r
+        bulletStyle.setDataFormat((short)formatIndex);\r
+\r
+        // Set the cells contents and style.\r
+        cell.setCellValue(new HSSFRichTextString(listItem));\r
+        cell.setCellStyle(bulletStyle);\r
+    }\r
+\r
+    /**\r
+     * Inserts a list of plain items - that is items that are neither\r
+     * numbered or bulleted - into a single cell.\r
+     *\r
+     * @param workbook A reference to the HSSFWorkbook that 'contains' the\r
+     *                 cell.\r
+     * @param listItems An ArrayList whose elements encapsulate the text for\r
+     *                  the list's items.\r
+     * @param cell An instance of the HSSFCell class that encapsulates a\r
+     *             reference to the spreadsheet cell into which the list\r
+     *             will be written.\r
+     */\r
+    public void listInCell(HSSFWorkbook workbook, ArrayList<String> listItems, HSSFCell cell) {\r
+        StringBuffer buffer = new StringBuffer();\r
+        HSSFCellStyle wrapStyle = workbook.createCellStyle();\r
+        wrapStyle.setWrapText(true);\r
+        for(String listItem : listItems) {\r
+            buffer.append(listItem);\r
+            buffer.append("\n");\r
+        }\r
+        // The StringBuffer's contents are the source for the contents\r
+        // of the cell.\r
+        cell.setCellValue(new HSSFRichTextString(buffer.toString().trim()));\r
+        cell.setCellStyle(wrapStyle);\r
+    }\r
+\r
+    /**\r
+     * Inserts a numbered list into a single cell.\r
+     *\r
+     * @param workbook A reference to the HSSFWorkbook that 'contains' the\r
+     *                 cell.\r
+     * @param listItems An ArrayList whose elements encapsulate the text for\r
+     *                  the lists items.\r
+     * @param cell An instance of the HSSFCell class that encapsulates a\r
+     *             reference to the spreadsheet cell into which the list\r
+     *             will be written.\r
+     * @param startingValue A primitive int containing the number for the first\r
+     *                      item in the list.\r
+     * @param increment A primitive int containing the value that should be used\r
+     *                  to calculate subsequent item numbers.\r
+     */\r
+    public void numberedListInCell(HSSFWorkbook workbook,\r
+                                   ArrayList<String> listItems,\r
+                                   HSSFCell cell,\r
+                                   int startingValue,\r
+                                   int increment) {\r
+        StringBuffer buffer = new StringBuffer();\r
+        int itemNumber = startingValue;\r
+        // Note that again, an HSSFCellStye object is required and that\r
+        // it's wrap text property should be set to 'true'\r
+        HSSFCellStyle wrapStyle = workbook.createCellStyle();\r
+        wrapStyle.setWrapText(true);\r
+        // Note that the basic method is identical to the listInCell() method\r
+        // with one difference; a number prefixed to the items text.\r
+        for(String listItem : listItems) {\r
+            buffer.append(String.valueOf(itemNumber) + ". ");\r
+            buffer.append(listItem);\r
+            buffer.append("\n");\r
+            itemNumber += increment;\r
+        }\r
+        // The StringBuffer's contents are the source for the contents\r
+        // of the cell.\r
+        cell.setCellValue(new HSSFRichTextString(buffer.toString().trim()));\r
+        cell.setCellStyle(wrapStyle);\r
+    }\r
+\r
+    /**\r
+     * Insert a bulleted list into a cell.\r
+     *\r
+     * @param workbook A reference to the HSSFWorkbook that 'contains' the\r
+     *                 cell.\r
+     * @param listItems An ArrayList whose elements encapsulate the text for\r
+     *                  the lists items.\r
+     * @param cell An instance of the HSSFCell class that encapsulates a\r
+     *             reference to the spreadsheet cell into which the list\r
+     *             will be written.\r
+     */\r
+    public void bulletedListInCell(HSSFWorkbook workbook,\r
+                                   ArrayList<String> listItems,\r
+                                   HSSFCell cell) {\r
+        StringBuffer buffer = new StringBuffer();\r
+        // Note that again, an HSSFCellStye object is required and that\r
+        // it's wrap text property should be set to 'true'\r
+        HSSFCellStyle wrapStyle = workbook.createCellStyle();\r
+        wrapStyle.setWrapText(true);\r
+        // Note that the basic method is identical to the listInCell() method\r
+        // with one difference; the bullet character prefixed to the items text.\r
+        for(String listItem : listItems) {\r
+            buffer.append(InCellLists.BULLET_CHARACTER + " ");\r
+            buffer.append(listItem);\r
+            buffer.append("\n");\r
+        }\r
+        // The StringBuffer's contents are the source for the contents\r
+        // of the cell.\r
+        cell.setCellValue(new HSSFRichTextString(buffer.toString().trim()));\r
+        cell.setCellStyle(wrapStyle);\r
+    }\r
+\r
+    /**\r
+     * Insert a multi-level list into a cell.\r
+     *\r
+     * @param workbook A reference to the HSSFWorkbook that 'contains' the\r
+     *                 cell.\r
+     * @param multiLevelListItems An ArrayList whose elements contain instances\r
+     *                            of the MultiLevelListItem class. Each element\r
+     *                            encapsulates the text for the high level item\r
+     *                            along with an ArrayList. Each element of this\r
+     *                            ArrayList encapsulates the text for a lower\r
+     *                            level item.\r
+     * @param cell An instance of the HSSFCell class that encapsulates a\r
+     *             reference to the spreadsheet cell into which the list\r
+     *             will be written.\r
+     */\r
+    public void multiLevelListInCell(HSSFWorkbook workbook,\r
+                                     ArrayList<MultiLevelListItem> multiLevelListItems,\r
+                                     HSSFCell cell) {\r
+        StringBuffer buffer = new StringBuffer();\r
+        ArrayList<String> lowerLevelItems = null;\r
+        // Note that again, an HSSFCellStye object is required and that\r
+        // it's wrap text property should be set to 'true'\r
+        HSSFCellStyle wrapStyle = workbook.createCellStyle();\r
+        wrapStyle.setWrapText(true);\r
+        // Step through the ArrayList of MultilLevelListItem instances.\r
+        for(MultiLevelListItem multiLevelListItem : multiLevelListItems) {\r
+            // For each element in the ArrayList, get the text for the high\r
+            // level list item......\r
+            buffer.append(multiLevelListItem.getItemText());\r
+            buffer.append("\n");\r
+            // and then an ArrayList whose elements encapsulate the text\r
+            // for the lower level list items.\r
+            lowerLevelItems = multiLevelListItem.getLowerLevelItems();\r
+            if(!(lowerLevelItems == null) && !(lowerLevelItems.isEmpty())) {\r
+                for(String item : lowerLevelItems) {\r
+                    buffer.append(InCellLists.TAB);\r
+                    buffer.append(item);\r
+                    buffer.append("\n");\r
+                }\r
+            }\r
+        }\r
+        // The StringBuffer's contents are the source for the contents\r
+        // of the cell.\r
+        cell.setCellValue(new HSSFRichTextString(buffer.toString().trim()));\r
+        cell.setCellStyle(wrapStyle);\r
+    }\r
+\r
+    /**\r
+     * Insert a multi-level list into a cell.\r
+     *\r
+     * @param workbook A reference to the HSSFWorkbook that 'contains' the\r
+     *                 cell.\r
+     * @param multiLevelListItems An ArrayList whose elements contain instances\r
+     *                            of the MultiLevelListItem class. Each element\r
+     *                            encapsulates the text for the high level item\r
+     *                            along with an ArrayList. Each element of this\r
+     *                            ArrayList encapsulates the text for a lower\r
+     *                            level item.\r
+     * @param cell An instance of the HSSFCell class that encapsulates a\r
+     *             reference to the spreadsheet cell into which the list\r
+     *             will be written.\r
+     * @param highLevelStartingValue A primitive int containing the number\r
+     *                               for the first high level item in the list.\r
+     * @param highLevelIncrement A primitive int containing the value that\r
+     *                           should be used to calculate the number of\r
+     *                           subsequent high level item.\r
+     * @param lowLevelStartingValue A primitive int will containing the number\r
+     *                              for the first low level item associated\r
+     *                              with a high level item.\r
+     * @param lowLevelIncrement A primitive int containing the value that\r
+     *                          should be used to calculate the number of\r
+     *                          subsequent low level item.\r
+     */\r
+    public void multiLevelNumberedListInCell(HSSFWorkbook workbook,\r
+                                             ArrayList<MultiLevelListItem> multiLevelListItems,\r
+                                             HSSFCell cell,\r
+                                             int highLevelStartingValue,\r
+                                             int highLevelIncrement,\r
+                                             int lowLevelStartingValue,\r
+                                             int lowLevelIncrement) {\r
+        StringBuffer buffer = new StringBuffer();\r
+        int highLevelItemNumber = highLevelStartingValue;\r
+        int lowLevelItemNumber = 0;\r
+        ArrayList<String> lowerLevelItems = null;\r
+        // Note that again, an HSSFCellStye object is required and that\r
+        // it's wrap text property should be set to 'true'\r
+        HSSFCellStyle wrapStyle = workbook.createCellStyle();\r
+        wrapStyle.setWrapText(true);\r
+        // Step through the ArrayList of MultilLevelListItem instances.\r
+        for(MultiLevelListItem multiLevelListItem : multiLevelListItems) {\r
+            // For each element in the ArrayList, get the text for the high\r
+            // level list item......\r
+            buffer.append(String.valueOf(highLevelItemNumber));\r
+            buffer.append(". ");\r
+            buffer.append(multiLevelListItem.getItemText());\r
+            buffer.append("\n");\r
+            // and then an ArrayList whose elements encapsulate the text\r
+            // for the lower level list items.\r
+            lowerLevelItems = multiLevelListItem.getLowerLevelItems();\r
+            if(!(lowerLevelItems == null) && !(lowerLevelItems.isEmpty())) {\r
+                lowLevelItemNumber = lowLevelStartingValue;\r
+                for(String item : lowerLevelItems) {\r
+                    buffer.append(InCellLists.TAB);\r
+                    buffer.append(String.valueOf(highLevelItemNumber));\r
+                    buffer.append(".");\r
+                    buffer.append(String.valueOf(lowLevelItemNumber));\r
+                    buffer.append(" ");\r
+                    buffer.append(item);\r
+                    buffer.append("\n");\r
+                    lowLevelItemNumber += lowLevelIncrement;\r
+                }\r
+            }\r
+            highLevelItemNumber += highLevelIncrement;\r
+        }\r
+        // The StringBuffer's contents are the source for the contents\r
+        // of the cell.\r
+        cell.setCellValue(new HSSFRichTextString(buffer.toString().trim()));\r
+        cell.setCellStyle(wrapStyle);\r
+    }\r
+\r
+    /**\r
+     * Insert a bulleted multi-level list into a cell.\r
+     *\r
+     * @param workbook A reference to the HSSFWorkbook that 'contains' the\r
+     *                 cell.\r
+     * @param multiLevelListItems An ArrayList whose elements contain instances\r
+     *                            of the MultiLevelListItem class. Each element\r
+     *                            encapsulates the text for the high level item\r
+     *                            along with an ArrayList. Each element of this\r
+     *                            ArrayList encapsulates the text for a lower\r
+     *                            level item.\r
+     * @param cell An instance of the HSSFCell class that encapsulates a\r
+     *             reference to the spreadsheet cell into which the list\r
+     *             will be written.\r
+     */\r
+    public void multiLevelBulletedListInCell(HSSFWorkbook workbook,\r
+                                             ArrayList<MultiLevelListItem> multiLevelListItems,\r
+                                             HSSFCell cell) {\r
+        StringBuffer buffer = new StringBuffer();\r
+        ArrayList<String> lowerLevelItems = null;\r
+        // Note that again, an HSSFCellStye object is required and that\r
+        // it's wrap text property should be set to 'true'\r
+        HSSFCellStyle wrapStyle = workbook.createCellStyle();\r
+        wrapStyle.setWrapText(true);\r
+        // Step through the ArrayList of MultilLevelListItem instances.\r
+        for(MultiLevelListItem multiLevelListItem : multiLevelListItems) {\r
+            // For each element in the ArrayList, get the text for the high\r
+            // level list item......\r
+            buffer.append(InCellLists.BULLET_CHARACTER);\r
+            buffer.append(" ");\r
+            buffer.append(multiLevelListItem.getItemText());\r
+            buffer.append("\n");\r
+            // and then an ArrayList whose elements encapsulate the text\r
+            // for the lower level list items.\r
+            lowerLevelItems = multiLevelListItem.getLowerLevelItems();\r
+            if(!(lowerLevelItems == null) && !(lowerLevelItems.isEmpty())) {\r
+                for(String item : lowerLevelItems) {\r
+                    buffer.append(InCellLists.TAB);\r
+                    buffer.append(InCellLists.BULLET_CHARACTER);\r
+                    buffer.append(" ");\r
+                    buffer.append(item);\r
+                    buffer.append("\n");\r
+                }\r
+            }\r
+        }\r
+        // The StringBuffer's contents are the source for the contents\r
+        // of the cell.\r
+        cell.setCellValue(new HSSFRichTextString(buffer.toString().trim()));\r
+        cell.setCellStyle(wrapStyle);\r
+    }\r
+\r
+    /**\r
+     * The main entry point to the program. Demonstrates how to call the method\r
+     * that will create an Excel workbook containing many different sorts of\r
+     * lists.\r
+     *\r
+     * @param args the command line arguments.\r
+     */\r
+    public static void main(String[] args) {\r
+        new InCellLists().demonstrateMethodCalls("C:/temp/Latest In Cell List.xls");\r
+    }\r
+\r
+    /**\r
+     * An instance of this inner class models an item or element in a\r
+     * multi-level list. Each multi-level list item consists of the text for the\r
+     * high level items and an ArrayList containing the text for each of the\r
+     * associated lower level items. When written into a cell, each multi-level\r
+     * list item will have this general appearance.\r
+     *\r
+     *     Item One\r
+     *         Sub Item One.\r
+     *         Sub Item Two.\r
+     *     Item Two\r
+     *         Sub Item One.\r
+     *         Sub Item Two.\r
+     *     etc.\r
+     *\r
+     * It would be quite possible to modify this class to model much more\r
+     * complex list structures descending through two, three or even more\r
+     * levels.\r
+     */\r
+    public final class MultiLevelListItem {\r
+\r
+        private String itemText = null;\r
+        private ArrayList<String> lowerLevelItems = null;\r
+\r
+        /**\r
+         * Create a new instance of the MultiLevelListItem class using the\r
+         * following parameters.\r
+         *\r
+         * @param itemText A String that encapsulates the text for the high\r
+         *                 level list item.\r
+         * @param lowerLevelItems An ArrayList whose elements encapsulate the\r
+         *                        text for the associated lower level list\r
+         *                        items.\r
+         */\r
+        public MultiLevelListItem(String itemText, ArrayList<String> lowerLevelItems) {\r
+            this.itemText = itemText;\r
+            this.lowerLevelItems = lowerLevelItems;\r
+        }\r
+\r
+        /**\r
+         * Get the text for the high level list item.\r
+         *\r
+         * @return A String that encapsulates the text for the high level list\r
+         *         item.\r
+         */\r
+        public String getItemText() {\r
+            return(this.itemText);\r
+        }\r
+\r
+        /**\r
+         * Get the text for the associated lower level list items.\r
+         *\r
+         * @return An ArrayList whose elements each encapsulate the text for a\r
+         *         single associated lower level list item.\r
+         */\r
+        public ArrayList<String> getLowerLevelItems() {\r
+            return(this.lowerLevelItems);\r
+        }\r
+    }\r
+}\r