1 package org
.argeo
.cms
.ui
.eclipse
.forms
;
3 import java
.util
.HashMap
;
5 import org
.eclipse
.jface
.resource
.DeviceResourceException
;
6 import org
.eclipse
.jface
.resource
.FontDescriptor
;
7 import org
.eclipse
.jface
.resource
.JFaceResources
;
8 import org
.eclipse
.jface
.resource
.LocalResourceManager
;
9 import org
.eclipse
.swt
.SWT
;
10 import org
.eclipse
.swt
.graphics
.Device
;
11 import org
.eclipse
.swt
.graphics
.Font
;
12 import org
.eclipse
.swt
.graphics
.FontData
;
13 //import org.eclipse.swt.internal.graphics.Graphics;
14 import org
.eclipse
.swt
.widgets
.Display
;
16 public class FormFonts
{
17 private static FormFonts instance
;
19 public static FormFonts
getInstance() {
21 instance
= new FormFonts();
25 private LocalResourceManager resources
;
26 private HashMap descriptors
;
31 private class BoldFontDescriptor
extends FontDescriptor
{
32 private FontData
[] fFontData
;
34 BoldFontDescriptor(Font font
) {
35 // RAP [if] Changes due to different way of creating fonts
36 // fFontData = font.getFontData();
37 // for (int i = 0; i < fFontData.length; i++) {
38 // fFontData[i].setStyle(fFontData[i].getStyle() | SWT.BOLD);
40 FontData fontData
= font
.getFontData()[0];
41 // Font boldFont = Graphics.getFont( fontData.getName(),
42 // fontData.getHeight(),
43 // fontData.getStyle() | SWT.BOLD );
44 Font boldFont
= new Font(Display
.getCurrent(), fontData
.getName(), fontData
.getHeight(),
45 fontData
.getStyle() | SWT
.BOLD
);
46 fFontData
= boldFont
.getFontData();
49 public boolean equals(Object obj
) {
50 if (obj
instanceof BoldFontDescriptor
) {
51 BoldFontDescriptor desc
= (BoldFontDescriptor
) obj
;
52 if (desc
.fFontData
.length
!= fFontData
.length
)
54 for (int i
= 0; i
< fFontData
.length
; i
++)
55 if (!fFontData
[i
].equals(desc
.fFontData
[i
]))
62 public int hashCode() {
64 for (int i
= 0; i
< fFontData
.length
; i
++)
65 hash
= hash
* 7 + fFontData
[i
].hashCode();
69 public Font
createFont(Device device
) throws DeviceResourceException
{
70 // RAP [if] Changes due to different way of creating fonts
71 return new Font(device
, fFontData
[0]);
72 // return Graphics.getFont( fFontData[ 0 ] );
75 public void destroyFont(Font previouslyCreatedFont
) {
76 // RAP [if] unnecessary
77 // previouslyCreatedFont.dispose();
81 public Font
getBoldFont(Display display
, Font font
) {
83 BoldFontDescriptor desc
= new BoldFontDescriptor(font
);
84 Font result
= getResourceManager().createFont(desc
);
85 descriptors
.put(result
, desc
);
89 public boolean markFinished(Font boldFont
) {
91 BoldFontDescriptor desc
= (BoldFontDescriptor
) descriptors
.get(boldFont
);
93 getResourceManager().destroyFont(desc
);
94 if (getResourceManager().find(desc
) == null) {
95 descriptors
.remove(boldFont
);
101 // if the image was not found, dispose of it for the caller
102 // RAP [if] unnecessary
103 // boldFont.dispose();
107 private LocalResourceManager
getResourceManager() {
108 if (resources
== null)
109 resources
= new LocalResourceManager(JFaceResources
.getResources());
113 private void checkHashMaps() {
114 if (descriptors
== null)
115 descriptors
= new HashMap();
118 private void validateHashMaps() {
119 if (descriptors
.size() == 0)