001package com.hfg.xml.msofficexml.xlsx.spreadsheetml.style; 002 003import java.awt.Font; 004 005import com.hfg.xml.msofficexml.xlsx.Xlsx; 006import com.hfg.xml.msofficexml.xlsx.spreadsheetml.SsmlXML; 007import com.hfg.xml.msofficexml.xlsx.spreadsheetml.SsmlXMLTag; 008 009 010//------------------------------------------------------------------------------ 011/** 012 Represents an Office Open XML differential format (<ssml:dxf>) tag. 013 014 @author J. Alex Taylor, hairyfatguy.com 015 */ 016//------------------------------------------------------------------------------ 017// com.hfg XML/HTML Coding Library 018// 019// This library is free software; you can redistribute it and/or 020// modify it under the terms of the GNU Lesser General Public 021// License as published by the Free Software Foundation; either 022// version 2.1 of the License, or (at your option) any later version. 023// 024// This library is distributed in the hope that it will be useful, 025// but WITHOUT ANY WARRANTY; without even the implied warranty of 026// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 027// Lesser General Public License for more details. 028// 029// You should have received a copy of the GNU Lesser General Public 030// License along with this library; if not, write to the Free Software 031// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 032// 033// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 034// jataylor@hairyfatguy.com 035//------------------------------------------------------------------------------ 036 037public class SsmlDifferentialFormat extends SsmlXMLTag implements Cloneable 038{ 039 private Integer mIndex; 040 private SsmlFont mFont; 041 private SsmlFill mFill; 042 private SsmlBorder mBorder; 043 private SsmlNumberFormat mNumberFormat; 044 private SsmlStyleFormat mStyleFormat; 045 private SsmlAlignment mAlignmentTag; 046 047 //--------------------------------------------------------------------------- 048 public SsmlDifferentialFormat(Xlsx inXlsx) 049 { 050 this(inXlsx.getStylesPart()); 051 } 052 053 //--------------------------------------------------------------------------- 054 public SsmlDifferentialFormat(StylesPart inStylesPart) 055 { 056 super(SsmlXML.DIFFERENTIAL_FORMAT, inStylesPart.getParentDoc()); 057 // Register with the styles part 058 mIndex = inStylesPart.defineDifferentialFormat(this); 059 } 060 061 //########################################################################## 062 // PUBLIC METHODS 063 //########################################################################## 064 065 //--------------------------------------------------------------------------- 066 @Override 067 public SsmlDifferentialFormat clone() 068 { 069 SsmlDifferentialFormat clone = (SsmlDifferentialFormat) super.clone(); 070 071 // Register with the styles part 072 clone.mIndex = getParentDoc().getStylesPart().defineDifferentialFormat(clone); 073 074 return clone; 075 } 076 077 //--------------------------------------------------------------------------- 078 public Integer getIndex() 079 { 080 return mIndex; 081 } 082 083 //--------------------------------------------------------------------------- 084 public SsmlDifferentialFormat setFont(Font inValue) 085 { 086 return setFont(inValue != null ? new SsmlFont(inValue, getParentDoc()) : null); 087 } 088 089 //--------------------------------------------------------------------------- 090 public SsmlDifferentialFormat setFont(SsmlFont inValue) 091 { 092 mFont = inValue; 093 if (mFont != null) 094 { 095 addSubtag(mFont); 096 } 097 else 098 { 099 removeSubtagsByName(SsmlXML.FONT); 100 } 101 102 return this; 103 } 104 105 //--------------------------------------------------------------------------- 106 public SsmlFont getFont() 107 { 108 if (null == mFont) 109 { 110 setFont(new SsmlFont(getParentDoc())); 111 } 112 113 return mFont; 114 } 115 116 117 //--------------------------------------------------------------------------- 118 public SsmlDifferentialFormat setFill(SsmlFill inValue) 119 { 120 mFill = inValue; 121 if (mFill != null) 122 { 123 addSubtag(mFill); 124 } 125 else 126 { 127 removeSubtagsByName(SsmlXML.FILL); 128 } 129 130 return this; 131 } 132 133 //--------------------------------------------------------------------------- 134 public SsmlFill getFill() 135 { 136 if (null == mFill) 137 { 138 setFill(new SsmlFill(getParentDoc())); 139 } 140 141 return mFill; 142 } 143 144 //--------------------------------------------------------------------------- 145 public SsmlDifferentialFormat setBorder(SsmlBorder inValue) 146 { 147 mBorder = inValue; 148 if (mBorder != null) 149 { 150 addSubtag(mBorder); 151 } 152 else 153 { 154 removeSubtagsByName(SsmlXML.BORDER); 155 } 156 157 return this; 158 } 159 160 //--------------------------------------------------------------------------- 161 public SsmlBorder getBorder() 162 { 163 if (null == mBorder) 164 { 165 setBorder(new SsmlBorder(getParentDoc())); 166 } 167 168 return mBorder; 169 } 170 171 //--------------------------------------------------------------------------- 172 public SsmlDifferentialFormat setNumberFormat(SsmlNumberFormat inValue) 173 { 174 mNumberFormat = inValue; 175 if (mNumberFormat != null) 176 { 177 setAttribute(SsmlXML.NUM_FORMAT_ID_ATT, mNumberFormat.getIndex()); 178 setAttribute(SsmlXML.APPLY_NUM_FORMAT_ATT, "1"); 179 } 180 else 181 { 182 removeAttribute(SsmlXML.NUM_FORMAT_ID_ATT); 183 removeAttribute(SsmlXML.APPLY_NUM_FORMAT_ATT); 184 } 185 186 return this; 187 } 188 189 //--------------------------------------------------------------------------- 190 public SsmlNumberFormat getNumberFormat() 191 { 192 if (null == mNumberFormat) 193 { 194 setNumberFormat(new SsmlNumberFormat(getParentDoc())); 195 } 196 197 return mNumberFormat; 198 } 199 200 //--------------------------------------------------------------------------- 201 public SsmlDifferentialFormat setAlignment(SsmlAlignment inValue) 202 { 203 mAlignmentTag = inValue; 204 205 return this; 206 } 207 208 //--------------------------------------------------------------------------- 209 public SsmlAlignment getAlignment() 210 { 211 if (null == mAlignmentTag) 212 { 213 // Check it it has been added via addSubtag()... 214 mAlignmentTag = getOptionalSubtagByName(SsmlXML.ALIGNMENT); 215 216 if (null == mAlignmentTag) 217 { 218 mAlignmentTag = new SsmlAlignment(getParentDoc()); 219 addSubtag(mAlignmentTag); 220 } 221 } 222 223 return mAlignmentTag; 224 } 225 226}