If the object stored under key is a Font then returns its value otherwise returns null. @param key key associated to the value to retrieve @return the associated font
(Object key)
| 148 | * @return the associated font |
| 149 | */ |
| 150 | public Font getFont(Object key) { |
| 151 | try { |
| 152 | String stringValue = (String) get(key); |
| 153 | if (stringValue == null) { return null; } |
| 154 | StringTokenizer strTok = new StringTokenizer(stringValue, "#", false); |
| 155 | String family = strTok.nextToken(); |
| 156 | int size = Integer.parseInt(strTok.nextToken()); |
| 157 | boolean italic = Boolean.valueOf(strTok.nextToken()); |
| 158 | boolean bold = Boolean.valueOf(strTok.nextToken()); |
| 159 | HashMap<TextAttribute, Serializable> fontAttrs = |
| 160 | new HashMap<TextAttribute, Serializable>(); |
| 161 | fontAttrs.put(TextAttribute.FAMILY, family); |
| 162 | fontAttrs.put(TextAttribute.SIZE, (float) size); |
| 163 | if(bold) fontAttrs.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD); |
| 164 | else fontAttrs.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_REGULAR); |
| 165 | if(italic) fontAttrs.put( |
| 166 | TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE); |
| 167 | else fontAttrs.put(TextAttribute.POSTURE, TextAttribute.POSTURE_REGULAR); |
| 168 | return new Font(fontAttrs); |
| 169 | } catch (Exception e) { |
| 170 | return null; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * If the object stored under key is a set then returns its value |
no test coverage detected