All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hfg.xml.msofficexml.docx.wordprocessingml.WmlAbstractNumbering Maven / Gradle / Ivy

There is a newer version: 20240423
Show newest version
package com.hfg.xml.msofficexml.docx.wordprocessingml;

import java.util.ArrayList;
import java.util.List;

import com.hfg.graphics.units.Twips;
import com.hfg.xml.XMLName;
import com.hfg.xml.XMLTag;
import com.hfg.xml.msofficexml.docx.Docx;
import com.hfg.xml.msofficexml.docx.wordprocessingml.style.WmlJustification;

//------------------------------------------------------------------------------
/**
 Represents an Office Open XML document abstract numbering (<w:abstractNum>) tag.

 @author J. Alex Taylor, hairyfatguy.com
 */
//------------------------------------------------------------------------------
// com.hfg XML/HTML Coding Library
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
// [email protected]
//------------------------------------------------------------------------------

public class WmlAbstractNumbering extends WmlXMLTag
{
   private static int sAbstractNumIdSrc = 1;

   private List   mLevelTags;

   //---------------------------------------------------------------------------
   public WmlAbstractNumbering(Docx inDocx)
   {
      super(WmlXML.ABSTRACT_NUM, inDocx);

      setAttribute(WmlXML.ABSTRACT_NUM_ID_ATT, sAbstractNumIdSrc++);
   }


   //---------------------------------------------------------------------------
   public int getId()
   {
      return Integer.parseInt(getAttributeValue(WmlXML.ABSTRACT_NUM_ID_ATT));
   }

   //---------------------------------------------------------------------------
   public WmlAbstractNumbering addLevel(WmlNumberingLevelDef inValue)
   {
      if (null == mLevelTags)
      {
         mLevelTags = new ArrayList<>(3);
         mLevelTags.add(inValue);
      }

      addSubtag(inValue);

      return this;
   }

   //---------------------------------------------------------------------------
   public WmlAbstractNumbering setMultiLevelType(WmlNumberingDefinitionType inValue)
   {
      XMLName tagName = WmlXML.MULTI_LEVEL_TYPE;
      XMLTag tag = getOptionalSubtagByName(tagName);
      if (null == tag)
      {
         tag = new WmlXMLTag(tagName, getParentDoc());
         addSubtag(tag);
      }

      tag.setAttribute(WmlXML.VALUE_ATT, inValue);

      return this;
   }

   //---------------------------------------------------------------------------
   public WmlAbstractNumbering setRestartNumberingAfterBreak(boolean inValue)
   {
      setAttribute(WmlXML.RESTART_NUM_AFTER_BREAK_ATT, inValue ? 1 : 0);

      return this;
   }

   //---------------------------------------------------------------------------
   /**
    * Returns the defined level objects.
    * @return a List of WmlLevel objects
    */
   public List getLevels()
   {
      if (null == mLevelTags)
      {
         // Check if it has been added via addSubtag()...
         mLevelTags = (List) (Object) getSubtagsByName(WmlXML.LEVEL);
      }

      return mLevelTags;
   }

   //---------------------------------------------------------------------------
   public static List generateDefaultValues(Docx inParentDoc)
   {
      List defaultValues = new ArrayList<>(5);


      WmlNumberingLevelDef level0 = new WmlNumberingLevelDef(inParentDoc)
            .setLevel(0)
            .setStartingValue(1)
            .setNumberingFormat(WmlNumberingFormat.decimal)
            .setLevelText("%1.")
            .setJustification(WmlJustification.left);
      level0.getParagraphProperties().getIndentation().setLeft(new Twips(720)).setHanging(new Twips(360));

      WmlNumberingLevelDef level1 = new WmlNumberingLevelDef(inParentDoc)
            .setLevel(1)
            .setStartingValue(1)
            .setNumberingFormat(WmlNumberingFormat.lowerLetter)
            .setLevelText("%2.")
            .setJustification(WmlJustification.left);
      level1.getParagraphProperties().getIndentation().setLeft(new Twips(1440)).setHanging(new Twips(360));

      WmlNumberingLevelDef level2 = new WmlNumberingLevelDef(inParentDoc)
            .setLevel(2)
            .setTentative(true)
            .setStartingValue(1)
            .setNumberingFormat(WmlNumberingFormat.lowerRoman)
            .setLevelText("%3.")
            .setJustification(WmlJustification.right);
      level2.getParagraphProperties().getIndentation().setLeft(new Twips(2160)).setHanging(new Twips(180));

      WmlNumberingLevelDef level3 = new WmlNumberingLevelDef(inParentDoc)
            .setLevel(3)
            .setTentative(true)
            .setStartingValue(1)
            .setNumberingFormat(WmlNumberingFormat.decimal)
            .setLevelText("%4.")
            .setJustification(WmlJustification.left);
      level3.getParagraphProperties().getIndentation().setLeft(new Twips(2880)).setHanging(new Twips(360));

      WmlNumberingLevelDef level4 = new WmlNumberingLevelDef(inParentDoc)
            .setLevel(4)
            .setTentative(true)
            .setStartingValue(1)
            .setNumberingFormat(WmlNumberingFormat.lowerLetter)
            .setLevelText("%5.")
            .setJustification(WmlJustification.left);
      level4.getParagraphProperties().getIndentation().setLeft(new Twips(3600)).setHanging(new Twips(360));

      WmlNumberingLevelDef level5 = new WmlNumberingLevelDef(inParentDoc)
            .setLevel(5)
            .setTentative(true)
            .setStartingValue(1)
            .setNumberingFormat(WmlNumberingFormat.lowerRoman)
            .setLevelText("%6.")
            .setJustification(WmlJustification.right);
      level5.getParagraphProperties().getIndentation().setLeft(new Twips(4320)).setHanging(new Twips(180));

      WmlNumberingLevelDef level6 = new WmlNumberingLevelDef(inParentDoc)
            .setLevel(6)
            .setTentative(true)
            .setStartingValue(1)
            .setNumberingFormat(WmlNumberingFormat.decimal)
            .setLevelText("%7.")
            .setJustification(WmlJustification.left);
      level6.getParagraphProperties().getIndentation().setLeft(new Twips(5040)).setHanging(new Twips(360));

      WmlNumberingLevelDef level7 = new WmlNumberingLevelDef(inParentDoc)
            .setLevel(7)
            .setTentative(true)
            .setStartingValue(1)
            .setNumberingFormat(WmlNumberingFormat.lowerLetter)
            .setLevelText("%8.")
            .setJustification(WmlJustification.left);
      level7.getParagraphProperties().getIndentation().setLeft(new Twips(5760)).setHanging(new Twips(360));

      WmlNumberingLevelDef level8 = new WmlNumberingLevelDef(inParentDoc)
            .setLevel(8)
            .setTentative(true)
            .setStartingValue(1)
            .setNumberingFormat(WmlNumberingFormat.lowerRoman)
            .setLevelText("%9.")
            .setJustification(WmlJustification.right);
      level8.getParagraphProperties().getIndentation().setLeft(new Twips(6480)).setHanging(new Twips(180));

      WmlAbstractNumbering value1 = new WmlAbstractNumbering(inParentDoc)
            .setMultiLevelType(WmlNumberingDefinitionType.hybridMultilevel)
            .addLevel(level0)
            .addLevel(level1)
            .addLevel(level2)
            .addLevel(level3)
            .addLevel(level4)
            .addLevel(level5)
            .addLevel(level6)
            .addLevel(level7)
            .addLevel(level8);

      defaultValues.add(value1);







      level0 = new WmlNumberingLevelDef(inParentDoc)
            .setLevel(0)
            .setStartingValue(1)
            .setNumberingFormat(WmlNumberingFormat.bullet)
            .setLevelText("\uF0B7")
            .setJustification(WmlJustification.left);
      level0.getParagraphProperties().getIndentation().setLeft(new Twips(720)).setHanging(new Twips(360));
      level0.getTextRunProperties().setFont("Symbol");

      level1 = new WmlNumberingLevelDef(inParentDoc)
            .setLevel(1)
            .setTentative(true)
            .setStartingValue(1)
            .setNumberingFormat(WmlNumberingFormat.bullet)
            .setLevelText("o")
            .setJustification(WmlJustification.left);
      level1.getParagraphProperties().getIndentation().setLeft(new Twips(1440)).setHanging(new Twips(360));
      level1.getTextRunProperties().setFont("Courier New");

      level2 = new WmlNumberingLevelDef(inParentDoc)
            .setLevel(2)
            .setTentative(true)
            .setStartingValue(1)
            .setNumberingFormat(WmlNumberingFormat.bullet)
            .setLevelText("\uF0A7")
            .setJustification(WmlJustification.left);
      level2.getParagraphProperties().getIndentation().setLeft(new Twips(2160)).setHanging(new Twips(360));
      level2.getTextRunProperties().setFont("Wingdings");

      level3 = new WmlNumberingLevelDef(inParentDoc)
            .setLevel(3)
            .setTentative(true)
            .setStartingValue(1)
            .setNumberingFormat(WmlNumberingFormat.bullet)
            .setLevelText("\uF0B7")
            .setJustification(WmlJustification.left);
      level3.getParagraphProperties().getIndentation().setLeft(new Twips(2880)).setHanging(new Twips(360));
      level3.getTextRunProperties().setFont("Symbol");

      level4 = new WmlNumberingLevelDef(inParentDoc)
            .setLevel(4)
            .setTentative(true)
            .setStartingValue(1)
            .setNumberingFormat(WmlNumberingFormat.bullet)
            .setLevelText("o")
            .setJustification(WmlJustification.left);
      level4.getParagraphProperties().getIndentation().setLeft(new Twips(3600)).setHanging(new Twips(360));
      level4.getTextRunProperties().setFont("Courier New");

      level5 = new WmlNumberingLevelDef(inParentDoc)
            .setLevel(5)
            .setTentative(true)
            .setStartingValue(1)
            .setNumberingFormat(WmlNumberingFormat.bullet)
            .setLevelText("\uF0A7")
            .setJustification(WmlJustification.left);
      level5.getParagraphProperties().getIndentation().setLeft(new Twips(4320)).setHanging(new Twips(360));
      level5.getTextRunProperties().setFont("Wingdings");


      level6 = new WmlNumberingLevelDef(inParentDoc)
            .setLevel(6)
            .setTentative(true)
            .setStartingValue(1)
            .setNumberingFormat(WmlNumberingFormat.bullet)
            .setLevelText("\uF0B7")
            .setJustification(WmlJustification.left);
      level6.getParagraphProperties().getIndentation().setLeft(new Twips(5040)).setHanging(new Twips(360));
      level6.getTextRunProperties().setFont("Symbol");

      level7 = new WmlNumberingLevelDef(inParentDoc)
            .setLevel(7)
            .setTentative(true)
            .setStartingValue(1)
            .setNumberingFormat(WmlNumberingFormat.bullet)
            .setLevelText("o")
            .setJustification(WmlJustification.left);
      level7.getParagraphProperties().getIndentation().setLeft(new Twips(5760)).setHanging(new Twips(360));
      level7.getTextRunProperties().setFont("Courier New");

      level8 = new WmlNumberingLevelDef(inParentDoc)
            .setLevel(8)
            .setTentative(true)
            .setStartingValue(1)
            .setNumberingFormat(WmlNumberingFormat.bullet)
            .setLevelText("\uF0A7")
            .setJustification(WmlJustification.left);
      level8.getParagraphProperties().getIndentation().setLeft(new Twips(6480)).setHanging(new Twips(360));
      level8.getTextRunProperties().setFont("Wingdings");

      WmlAbstractNumbering value2 = new WmlAbstractNumbering(inParentDoc)
            .setMultiLevelType(WmlNumberingDefinitionType.hybridMultilevel)
            .setRestartNumberingAfterBreak(false)
            .addLevel(level0)
            .addLevel(level1)
            .addLevel(level2)
            .addLevel(level3)
            .addLevel(level4)
            .addLevel(level5)
            .addLevel(level6)
            .addLevel(level7)
            .addLevel(level8);

      defaultValues.add(value2);



      
      return defaultValues;
   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy