001package com.hfg.xml.msofficexml.docx.wordprocessingml;
002
003import com.hfg.graphics.units.GfxSize;
004import com.hfg.graphics.units.GfxUnits;
005import com.hfg.graphics.units.Pixels;
006import com.hfg.xml.XMLTag;
007import com.hfg.xml.msofficexml.docx.Docx;
008import com.hfg.xml.msofficexml.docx.drawingml.DmlGraphic;
009import com.hfg.xml.msofficexml.docx.drawingml.DmlXML;
010
011/*
012Sequence [1..1]
013
014    1. wp:extent [1..1]    Drawing Object Size
015    2. wp:effectExtent [0..1]    Inline Wrapping Extent
016    3. wp:docPr [1..1]    Drawing Object Non-Visual Properties
017    4. wp:cNvGraphicFramePr [0..1]    Common DrawingML Non-Visual Properties
018    5. a:graphic [1..1]    Graphic Object
019
020 */
021public class WmlInline extends WmlXMLTag
022{
023   private XMLTag          mExtentTag;
024   private WmlEffectExtent mEffectExtentTag;
025   private DmlGraphic      mGraphicTag;
026   private WmlDrawingObjNonVisualProperties mDrawingObjNonVisualProperties;
027   private WmlCommonDrawingMLNonVisualProperties mCommonDrawingMLNonVisualProperties;
028
029   //---------------------------------------------------------------------------
030   public WmlInline(Docx inDocx)
031   {
032      super(WmlXML.INLINE, inDocx);
033      init();
034   }
035
036   //---------------------------------------------------------------------------
037   private void init()
038   {
039      setMarginLeft(new Pixels(0));
040      setMarginRight(new Pixels(0));
041      setMarginTop(new Pixels(0));
042      setMarginBottom(new Pixels(0));
043
044      getEffectExtent();
045
046   }
047
048
049   //---------------------------------------------------------------------------
050   /**
051    * Specifies the left margin for the drawing.
052    */
053   public WmlInline setMarginLeft(GfxSize inValue)
054   {
055      setAttribute(WmlXML.DIST_LEFT_ATT, inValue.toInt(GfxUnits.emus));
056
057      return this;
058   }
059
060   //---------------------------------------------------------------------------
061   /**
062    * Specifies the right margin for the drawing.
063    */
064   public WmlInline setMarginRight(GfxSize inValue)
065   {
066      setAttribute(WmlXML.DIST_RIGHT_ATT, inValue.toInt(GfxUnits.emus));
067
068      return this;
069   }
070
071   //---------------------------------------------------------------------------
072   /**
073    * Specifies the top margin for the drawing.
074    */
075   public WmlInline setMarginTop(GfxSize inValue)
076   {
077      setAttribute(WmlXML.DIST_TOP_ATT, inValue.toInt(GfxUnits.emus));
078
079      return this;
080   }
081
082   //---------------------------------------------------------------------------
083   /**
084    * Specifies the top margin for the drawing.
085    */
086   public WmlInline setMarginBottom(GfxSize inValue)
087   {
088      setAttribute(WmlXML.DIST_BOTTOM_ATT, inValue.toInt(GfxUnits.emus));
089
090      return this;
091   }
092
093   //---------------------------------------------------------------------------
094   /**
095    * Specifies the width of the drawing.
096    */
097   public WmlInline setWidth(GfxSize inValue)
098   {
099      getExtent().setAttribute(WmlXML.CX_ATT, inValue.toInt(GfxUnits.emus));
100
101      return this;
102   }
103
104   //---------------------------------------------------------------------------
105   /**
106    * Specifies the height of the drawing.
107    */
108   public WmlInline setHeight(GfxSize inValue)
109   {
110      getExtent().setAttribute(WmlXML.CY_ATT, inValue.toInt(GfxUnits.emus));
111
112      return this;
113   }
114
115   //---------------------------------------------------------------------------
116   /**
117    * Returns the graphic tag if one exists or else instantiates a new one.
118    * @return the graphic tag for this drawing
119    */
120   public DmlGraphic getGraphic()
121   {
122      if (null == mGraphicTag)
123      {
124         // Check if it has been added via addSubtag()...
125         mGraphicTag = getOptionalSubtagByName(DmlXML.GRAPHIC);
126         if (null == mGraphicTag)
127         {
128            mGraphicTag = new DmlGraphic(getParentDoc());
129            addSubtag(mGraphicTag);
130         }
131      }
132
133      return mGraphicTag;
134   }
135
136   //---------------------------------------------------------------------------
137   /**
138    * Returns the drawing obj non-visual properties tag if one exists or else instantiates a new one.
139    * @return the drawing obj non-visual properties tag for this inline
140    */
141   public WmlDrawingObjNonVisualProperties getDrawingObjNonVisualProperties()
142   {
143      if (null == mDrawingObjNonVisualProperties)
144      {
145         // Check if it has been added via addSubtag()...
146         mDrawingObjNonVisualProperties = getOptionalSubtagByName(WmlXML.DRAWING_OBJ_NON_VISUAL_PROPS);
147         if (null == mDrawingObjNonVisualProperties)
148         {
149            mDrawingObjNonVisualProperties = new WmlDrawingObjNonVisualProperties();
150            addSubtag(mDrawingObjNonVisualProperties);
151         }
152      }
153
154      return mDrawingObjNonVisualProperties;
155   }
156
157   //---------------------------------------------------------------------------
158   /**
159    * Returns the drawingML common non-visual properties tag if one exists or else instantiates a new one.
160    * @return the drawingML common non-visual properties tag for this inline
161    */
162   public WmlCommonDrawingMLNonVisualProperties getCommonDrawingMLNonVisualProperties()
163   {
164      if (null == mCommonDrawingMLNonVisualProperties)
165      {
166         // Check if it has been added via addSubtag()...
167         mCommonDrawingMLNonVisualProperties = getOptionalSubtagByName(WmlXML.COMMON_DRAWINGML_NON_VISUAL_PROPS);
168         if (null == mCommonDrawingMLNonVisualProperties)
169         {
170            mCommonDrawingMLNonVisualProperties = new WmlCommonDrawingMLNonVisualProperties();
171            addSubtag(mCommonDrawingMLNonVisualProperties);
172         }
173      }
174
175      return mCommonDrawingMLNonVisualProperties;
176   }
177
178   //---------------------------------------------------------------------------
179   /**
180    * Returns the effect extent tag if one exists or else instantiates a new one.
181    * @return the effect extent tag for this drawing
182    */
183   public XMLTag getEffectExtent()
184   {
185      if (null == mEffectExtentTag)
186      {
187         // Check if it has been added via addSubtag()...
188         mEffectExtentTag = getOptionalSubtagByName(WmlXML.EFFECT_EXTENT);
189         if (null == mEffectExtentTag)
190         {
191            mEffectExtentTag = new WmlEffectExtent();
192            addSubtag(mEffectExtentTag);
193         }
194      }
195
196      return mEffectExtentTag;
197   }
198
199   //---------------------------------------------------------------------------
200   /**
201    * Returns the extent tag if one exists or else instantiates a new one.
202    * @return the extent tag for this drawing
203    */
204   private XMLTag getExtent()
205   {
206      if (null == mExtentTag)
207      {
208         // Check if it has been added via addSubtag()...
209         mExtentTag = getOptionalSubtagByName(WmlXML.EXTENT);
210         if (null == mExtentTag)
211         {
212            mExtentTag = new XMLTag(WmlXML.EXTENT);
213            addSubtag(mExtentTag);
214         }
215      }
216
217      return mExtentTag;
218   }
219
220}