| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
package org.wiztools.xml2spreadsheet.jxlimpl; |
| 11 |
|
|
| 12 |
|
import java.lang.reflect.Field; |
| 13 |
|
import java.util.HashMap; |
| 14 |
|
import java.util.Map; |
| 15 |
|
import jxl.format.Colour; |
| 16 |
|
import org.wiztools.xml2spreadsheet.exception.OperationException; |
| 17 |
|
import org.wiztools.xml2spreadsheet.exception.XML2XLSFatalException; |
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
public class JXLColor { |
| 24 |
|
|
| 25 |
|
private static JXLColor jxlc; |
| 26 |
|
|
| 27 |
|
private Map<String, Colour> colorMap; |
| 28 |
|
|
| 29 |
|
|
| 30 |
9 |
private JXLColor() { |
| 31 |
9 |
colorMap = new HashMap<String, Colour>(); |
| 32 |
9 |
Field[] arr = Colour.class.getFields(); |
| 33 |
|
try{ |
| 34 |
576 |
for(Field f: arr){ |
| 35 |
|
|
| 36 |
567 |
if(f.getType().getName().equals(Colour.class.getName())){ |
| 37 |
567 |
Colour color = (Colour)f.get(null); |
| 38 |
|
|
| 39 |
567 |
colorMap.put(f.getName().toLowerCase(), color); |
| 40 |
|
} |
| 41 |
|
} |
| 42 |
|
} |
| 43 |
0 |
catch(IllegalAccessException iae){ |
| 44 |
|
|
| 45 |
0 |
iae.printStackTrace(); |
| 46 |
9 |
} |
| 47 |
9 |
} |
| 48 |
|
|
| 49 |
|
public static JXLColor getInstance(){ |
| 50 |
54 |
if(jxlc == null){ |
| 51 |
9 |
jxlc = new JXLColor(); |
| 52 |
|
} |
| 53 |
54 |
return jxlc; |
| 54 |
|
} |
| 55 |
|
|
| 56 |
|
public Colour getColor(String colorStr) throws OperationException{ |
| 57 |
54 |
colorStr = colorStr.toLowerCase(); |
| 58 |
54 |
Colour c = colorMap.get(colorStr); |
| 59 |
54 |
if(c == null){ |
| 60 |
0 |
throw new OperationException("Color not found in the map: "+colorStr); |
| 61 |
|
} |
| 62 |
54 |
return c; |
| 63 |
|
} |
| 64 |
|
} |