(no commit message)
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / model / Resources.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.taxeditor.model;
11
12 import java.util.HashMap;
13 import java.util.Set;
14
15 import org.eclipse.jface.preference.PreferenceConverter;
16 import org.eclipse.jface.resource.FontRegistry;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.graphics.Color;
19 import org.eclipse.swt.graphics.Font;
20 import org.eclipse.swt.graphics.FontData;
21 import org.eclipse.swt.graphics.RGB;
22 import org.eclipse.swt.widgets.Display;
23 import org.eclipse.ui.editors.text.EditorsUI;
24
25
26 /**
27 * @author n.hoffmann
28 * @created 18.03.2009
29 * @version 1.0
30 *
31 * @deprecated migrate to org.eclipse.ui.themes or at least handle this a little bit more eclipse like
32 */
33 public class Resources {
34
35 private static Resources instance;
36
37 public static Resources getInstance(){
38 if(instance == null){
39 instance = new Resources();
40 }
41 return instance;
42 }
43
44
45 /* ***************************************************************************************
46 PREFERENCES
47 ************************************************************************************** */
48 public static final String INITIALIZED = "initialized";
49 public static final String INITIALIZE_W_TESTDATA = "init_w_testdata";
50
51 /* ***************************************************************************************
52 STRINGS
53 ************************************************************************************** */
54 public static final String MISAPPLIED_NAME = "misappliedname";
55 public static final String BASIONYM = "basionym";
56 public static final String SYNONYM = "synonym";
57 public static final String HOMOTYPIC_SYNONYM = "homotypic_synonym";
58 public static final String HETEROTYPIC_SYNONYM = "heterotypic_synonym";
59 public static final String NAMERELATION = "namerelation";
60 public static final String TAXON = "taxon";
61 public static final String HOMOTYPIC_GROUP = "homotypicgroup";
62 public static final String QUICK_NAME_TAXON = "quick_name_taxon";
63 public static final String PROPERTY_SHEET_CHANGE = "property_sheet_change";
64 public static final String REFRESH_NAMEVIEWER = "refresh_name_viewer";
65
66 /* ***************************************************************************************
67 FONTS
68 ************************************************************************************** */
69 public static final String MENU_ITEM_ITALICS_FONT = "menu_item_italics_font";
70 public static final String ACCEPTED_TAXON_FONT = "accepted_taxon_font";
71 public static final String SYNONYM_FONT = "synonym_font";
72 public static final String MISAPPLIEDNAME_FONT = "misappliedname_font";
73 public static final String CONCEPT_FONT = "concept_font";
74 public static final String DATASOURCE_FONT = "datasource_font";
75 public static final String CHOOSE_NAME_TEXT_FONT = "choose_name_text_font";
76 public static final String FONT_DEFAULT_PROMPT = "default_prompt_font";
77
78 /* ***************************************************************************************
79 COLORS
80 ************************************************************************************** */
81 public static final String COLOR_COMPOSITE_BACKGROUND = "group_gray_background_color";
82 public static final String PROP_SHEET_RED = "property_sheet_red";
83 public static final String SEARCH_VIEW_FOREGROUND = "search_view_foreground";
84 public static final String SEARCH_VIEW_FOCUS = "search_view_focus";
85 public static final String COLOR_COMPOSITE_SELECTED = "color_list_selection";
86 public static final String COLOR_LIST_BACKGROUND = "color_list_background";
87
88
89 /***************************************************************************
90 * FONT REGISTRY
91 **************************************************************************/
92 private FontRegistry fontRegistry;
93
94 private FontRegistry getFontRegistry() {
95 if (fontRegistry == null) {
96 fontRegistry = new FontRegistry(Display.getCurrent());
97
98 fontRegistry.put(DATASOURCE_FONT,
99 new FontData[] { new FontData("Arial", 8, SWT.NONE) });
100 fontRegistry.put(MENU_ITEM_ITALICS_FONT,
101 new FontData[] { new FontData("Arial", 9, SWT.ITALIC) });
102 fontRegistry.put(ACCEPTED_TAXON_FONT,
103 new FontData[] { new FontData("Georgia", 12, SWT.NONE) });
104 fontRegistry.put(SYNONYM_FONT,
105 new FontData[] { new FontData("Georgia", 10, SWT.NONE) });
106 fontRegistry.put(MISAPPLIEDNAME_FONT,
107 new FontData[] { new FontData("Georgia", 10, SWT.NONE) });
108 fontRegistry.put(CONCEPT_FONT,
109 new FontData[] { new FontData("Georgia", 10, SWT.NONE) });
110 fontRegistry.put(CHOOSE_NAME_TEXT_FONT,
111 new FontData[] { new FontData("Arial", 12, SWT.BOLD) });
112 fontRegistry.put(FONT_DEFAULT_PROMPT,
113 new FontData[] { new FontData("Georgia", 10, SWT.ITALIC) });
114 }
115 return fontRegistry;
116 }
117
118 public static Font getFont(String key) {
119 return getInstance().getFontRegistry().get(key);
120 }
121
122 /**
123 * @param font
124 */
125 public static Font italicizeFont(Font font) {
126 FontData fontData = font.getFontData()[0];
127 fontData.setStyle(fontData.getStyle() | SWT.ITALIC);
128 Font italFont = new Font(Display.getDefault(), fontData);
129
130 int i = 0;
131 String fontName = "italic";
132 Set<?> keySet = getInstance().getFontRegistry().getKeySet();
133 while (keySet.contains(fontName + i)) {
134 i++;
135 }
136 getInstance().getFontRegistry().put(fontName + i, italFont.getFontData());
137
138 return italFont;
139 }
140
141 /***************************************************************************
142 * COLOR MAP
143 **************************************************************************/
144 private static HashMap<String, Color> colorRegistry;
145
146 public static Color getColor(String key) {
147 return getInstance().getColorRegistry().get(key);
148 }
149
150 private HashMap<String, Color> getColorRegistry() {
151 if (colorRegistry == null) {
152 colorRegistry = new HashMap<String, Color>();
153
154 RGB currentLineRGB = PreferenceConverter.getColor(
155 EditorsUI.getPreferenceStore(), "currentLineColor");
156 Color currentLineColor = new Color(null, currentLineRGB);
157
158 colorRegistry.put(COLOR_COMPOSITE_BACKGROUND,
159 new Color(null, 250, 250, 250));
160 colorRegistry.put(PROP_SHEET_RED,
161 new Color(null, 255, 0, 0));
162 colorRegistry.put(SEARCH_VIEW_FOREGROUND,
163 new Color(null, 192, 192, 192));
164 colorRegistry.put(SEARCH_VIEW_FOCUS,
165 new Color(null, 0, 0, 0));
166 // colorRegistry.put(COLOR_COMPOSITE_SELECTED,
167 // Display.getDefault().getSystemColor(SWT.COLOR_LIST_SELECTION));
168 colorRegistry.put(COLOR_COMPOSITE_SELECTED,
169 currentLineColor);
170 colorRegistry.put(COLOR_LIST_BACKGROUND,
171 Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
172 }
173 EditorsUI.getPreferenceStore();
174 return colorRegistry;
175 }
176 }