1
13 package gate.util;
14
15 import java.awt.Font;
16 import java.awt.font.TextAttribute;
17 import java.util.*;
18
22 public class OptionsMap extends HashMap {
23
24
27 public Object put(Object key, Object value){
28 if(value instanceof Font){
29 Font font = (Font)value;
30 String family = font.getFamily();
31 int size = font.getSize();
32 boolean italic = font.isItalic();
33 boolean bold = font.isBold();
34 value = family + "#" + size + "#" + italic + "#" + bold;
35 }
36
37 Object res = super.put(key, value.toString());
38 return res;
39 }
40
41
45 public Integer getInt(Object key){
46 String stringValue = getString(key);
47 Integer value = null;
48 try{
49 value = Integer.decode(stringValue);
50 }catch(Exception e){};
51 return value;
52 }
53
54
58 public Boolean getBoolean(Object key){
59 String stringValue = getString(key);
60 Boolean value = null;
61 try{
62 value = Boolean.valueOf(stringValue);
63 }catch(Exception e){};
64 return value;
65 }
66
67
71 public String getString(Object key){
72 String stringValue = null;
73 try{
74 stringValue = (String)get(key);
75 }catch(Exception e){};
76 return stringValue;
77 }
78
79
83 public Font getFont(Object key){
84 String stringValue = null;
85 try{
86 stringValue = (String)get(key);
87 }catch(Exception e){};
88 if(stringValue == null) return null;
89 StringTokenizer strTok = new StringTokenizer(stringValue, "#", false);
90 String family = strTok.nextToken();
91 int size = Integer.parseInt(strTok.nextToken());
92 boolean italic = Boolean.valueOf(strTok.nextToken()).booleanValue();
93 boolean bold = Boolean.valueOf(strTok.nextToken()).booleanValue();
94
95 Map fontAttrs = new HashMap();
96 fontAttrs.put(TextAttribute.FAMILY, family);
97 fontAttrs.put(TextAttribute.SIZE, new Float(size));
98 if(bold) fontAttrs.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
99 else fontAttrs.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_REGULAR);
100 if(italic) fontAttrs.put(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE);
101 else fontAttrs.put(TextAttribute.POSTURE, TextAttribute.POSTURE_REGULAR);
102
103 return new Font(fontAttrs);
104 }
105
106
107
108 }