1 19 20 package jxl.write.biff; 21 22 import common.Logger; 23 24 import jxl.biff.XFRecord; 25 import jxl.write.WritableFont; 26 import jxl.write.WritableCellFormat; 27 import jxl.write.WritableWorkbook; 28 import jxl.write.NumberFormats; 29 import jxl.write.DateFormat; 30 import jxl.write.DateFormats; 31 32 37 class Styles 38 { 39 42 private static Logger logger = Logger.getLogger(Styles.class); 43 44 47 private WritableFont arial10pt; 48 49 52 private WritableFont hyperlinkFont; 53 54 57 private WritableCellFormat normalStyle; 58 59 62 private WritableCellFormat hyperlinkStyle; 63 64 67 private WritableCellFormat hiddenStyle; 68 69 72 private WritableCellFormat defaultDateFormat; 73 74 77 public Styles() 78 { 79 arial10pt = null; 80 hyperlinkFont = null; 81 normalStyle = null; 82 hyperlinkStyle = null; 83 hiddenStyle = null; 84 } 85 86 private synchronized void initNormalStyle() 87 { 88 normalStyle = new WritableCellFormat(getArial10Pt(), 89 NumberFormats.DEFAULT); 90 normalStyle.setFont(getArial10Pt()); 91 } 92 93 public WritableCellFormat getNormalStyle() 94 { 95 if (normalStyle == null) 96 { 97 initNormalStyle(); 98 } 99 100 return normalStyle; 101 } 102 103 private synchronized void initHiddenStyle() 104 { 105 hiddenStyle = new WritableCellFormat 106 (getArial10Pt(), new DateFormat(";;;")); 107 } 108 109 public WritableCellFormat getHiddenStyle() 110 { 111 if (hiddenStyle == null) 112 { 113 initHiddenStyle(); 114 } 115 116 return hiddenStyle; 117 } 118 119 private synchronized void initHyperlinkStyle() 120 { 121 hyperlinkStyle = new WritableCellFormat(getHyperlinkFont(), 122 NumberFormats.DEFAULT); 123 } 124 125 public WritableCellFormat getHyperlinkStyle() 126 { 127 if (hyperlinkStyle == null) 128 { 129 initHyperlinkStyle(); 130 } 131 132 return hyperlinkStyle; 133 } 134 135 private synchronized void initArial10Pt() 136 { 137 arial10pt = new WritableFont(WritableWorkbook.ARIAL_10_PT); 138 } 139 140 public WritableFont getArial10Pt() 141 { 142 if (arial10pt == null) 143 { 144 initArial10Pt(); 145 } 146 147 return arial10pt; 148 } 149 150 private synchronized void initHyperlinkFont() 151 { 152 hyperlinkFont = new WritableFont(WritableWorkbook.HYPERLINK_FONT); 153 } 154 155 public WritableFont getHyperlinkFont() 156 { 157 if (hyperlinkFont == null) 158 { 159 initHyperlinkFont(); 160 } 161 162 return hyperlinkFont; 163 } 164 165 private synchronized void initDefaultDateFormat() 166 { 167 defaultDateFormat = new WritableCellFormat(DateFormats.DEFAULT); 168 } 169 170 public WritableCellFormat getDefaultDateFormat() 171 { 172 if (defaultDateFormat == null) 173 { 174 initDefaultDateFormat(); 175 } 176 177 return defaultDateFormat; 178 } 179 180 190 public XFRecord getFormat(XFRecord wf) 191 { 192 XFRecord format = wf; 193 194 if (format == WritableWorkbook.NORMAL_STYLE) 197 { 198 format = getNormalStyle(); 199 } 200 else if (format == WritableWorkbook.HYPERLINK_STYLE) 201 { 202 format = getHyperlinkStyle(); 203 } 204 else if (format == WritableWorkbook.HIDDEN_STYLE) 205 { 206 format = getHiddenStyle(); 207 } 208 else if (format == DateRecord.defaultDateFormat) 209 { 210 format = getDefaultDateFormat(); 211 } 212 213 if (format.getFont() == WritableWorkbook.ARIAL_10_PT) 215 { 216 format.setFont(getArial10Pt()); 217 } 218 else if (format.getFont() == WritableWorkbook.HYPERLINK_FONT) 219 { 220 format.setFont(getHyperlinkFont()); 221 } 222 223 return format; 224 } 225 } 226 | Popular Tags |