Implemented some of the import/export functionality. Major refactoring of datasource...
[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 CODE_PREFERENCE = "code";
49 //public static final NomenclaturalCode CODE_PREFERENCE_ICBN = NomenclaturalCode.ICBN();
50 //public static final NomenclaturalCode CODE_PREFERENCE_ICZN = NomenclaturalCode.ICZN();
51 //public static final NomenclaturalCode DEFAULT_CODE_PREFERENCE = CODE_PREFERENCE_ICZN;
52 public static final String CODE_PREFERENCE_ICBN = "ICBN";
53 public static final String CODE_PREFERENCE_ICZN = "ICZN";
54 public static final String DEFAULT_CODE_PREFERENCE = CODE_PREFERENCE_ICBN;
55 public static final String INITIALIZED = "initialized";
56 public static final String INITIALIZE_W_TESTDATA = "init_w_testdata";
57
58 /* ***************************************************************************************
59 STRINGS
60 ************************************************************************************** */
61 public static final String MISAPPLIED_NAME = "misappliedname";
62 public static final String BASIONYM = "basionym";
63 public static final String SYNONYM = "synonym";
64 public static final String HOMOTYPIC_SYNONYM = "homotypic_synonym";
65 public static final String HETEROTYPIC_SYNONYM = "heterotypic_synonym";
66 public static final String NAMERELATION = "namerelation";
67 public static final String TAXON = "taxon";
68 public static final String HOMOTYPIC_GROUP = "homotypicgroup";
69 public static final String QUICK_NAME_TAXON = "quick_name_taxon";
70 public static final String PROPERTY_SHEET_CHANGE = "property_sheet_change";
71 public static final String REFRESH_NAMEVIEWER = "refresh_name_viewer";
72
73 /* ***************************************************************************************
74 FONTS
75 ************************************************************************************** */
76 public static final String MENU_ITEM_ITALICS_FONT = "menu_item_italics_font";
77 public static final String ACCEPTED_TAXON_FONT = "accepted_taxon_font";
78 public static final String SYNONYM_FONT = "synonym_font";
79 public static final String MISAPPLIEDNAME_FONT = "misappliedname_font";
80 public static final String CONCEPT_FONT = "concept_font";
81 public static final String DATASOURCE_FONT = "datasource_font";
82 public static final String CHOOSE_NAME_TEXT_FONT = "choose_name_text_font";
83 public static final String FONT_DEFAULT_PROMPT = "default_prompt_font";
84
85 /* ***************************************************************************************
86 COLORS
87 ************************************************************************************** */
88 public static final String COLOR_COMPOSITE_BACKGROUND = "group_gray_background_color";
89 public static final String PROP_SHEET_RED = "property_sheet_red";
90 public static final String SEARCH_VIEW_FOREGROUND = "search_view_foreground";
91 public static final String SEARCH_VIEW_FOCUS = "search_view_focus";
92 public static final String COLOR_COMPOSITE_SELECTED = "color_list_selection";
93 public static final String COLOR_LIST_BACKGROUND = "color_list_background";
94
95
96 /***************************************************************************
97 * FONT REGISTRY
98 **************************************************************************/
99 private FontRegistry fontRegistry;
100
101 private FontRegistry getFontRegistry() {
102 if (fontRegistry == null) {
103 fontRegistry = new FontRegistry(Display.getCurrent());
104
105 fontRegistry.put(DATASOURCE_FONT,
106 new FontData[] { new FontData("Arial", 8, SWT.NONE) });
107 fontRegistry.put(MENU_ITEM_ITALICS_FONT,
108 new FontData[] { new FontData("Arial", 9, SWT.ITALIC) });
109 fontRegistry.put(ACCEPTED_TAXON_FONT,
110 new FontData[] { new FontData("Georgia", 12, SWT.NONE) });
111 fontRegistry.put(SYNONYM_FONT,
112 new FontData[] { new FontData("Georgia", 10, SWT.NONE) });
113 fontRegistry.put(MISAPPLIEDNAME_FONT,
114 new FontData[] { new FontData("Georgia", 10, SWT.NONE) });
115 fontRegistry.put(CONCEPT_FONT,
116 new FontData[] { new FontData("Georgia", 10, SWT.NONE) });
117 fontRegistry.put(CHOOSE_NAME_TEXT_FONT,
118 new FontData[] { new FontData("Arial", 12, SWT.BOLD) });
119 fontRegistry.put(FONT_DEFAULT_PROMPT,
120 new FontData[] { new FontData("Georgia", 10, SWT.ITALIC) });
121 }
122 return fontRegistry;
123 }
124
125 public static Font getFont(String key) {
126 return getInstance().getFontRegistry().get(key);
127 }
128
129 /**
130 * @param font
131 */
132 public static Font italicizeFont(Font font) {
133 FontData fontData = font.getFontData()[0];
134 fontData.setStyle(fontData.getStyle() | SWT.ITALIC);
135 Font italFont = new Font(Display.getDefault(), fontData);
136
137 int i = 0;
138 String fontName = "italic";
139 Set<?> keySet = getInstance().getFontRegistry().getKeySet();
140 while (keySet.contains(fontName + i)) {
141 i++;
142 }
143 getInstance().getFontRegistry().put(fontName + i, italFont.getFontData());
144
145 return italFont;
146 }
147
148 /***************************************************************************
149 * COLOR MAP
150 **************************************************************************/
151 private static HashMap<String, Color> colorRegistry;
152
153 public static Color getColor(String key) {
154 return getInstance().getColorRegistry().get(key);
155 }
156
157 private HashMap<String, Color> getColorRegistry() {
158 if (colorRegistry == null) {
159 colorRegistry = new HashMap<String, Color>();
160
161 RGB currentLineRGB = PreferenceConverter.getColor(
162 EditorsUI.getPreferenceStore(), "currentLineColor");
163 Color currentLineColor = new Color(null, currentLineRGB);
164
165 colorRegistry.put(COLOR_COMPOSITE_BACKGROUND,
166 new Color(null, 250, 250, 250));
167 colorRegistry.put(PROP_SHEET_RED,
168 new Color(null, 255, 0, 0));
169 colorRegistry.put(SEARCH_VIEW_FOREGROUND,
170 new Color(null, 192, 192, 192));
171 colorRegistry.put(SEARCH_VIEW_FOCUS,
172 new Color(null, 0, 0, 0));
173 // colorRegistry.put(COLOR_COMPOSITE_SELECTED,
174 // Display.getDefault().getSystemColor(SWT.COLOR_LIST_SELECTION));
175 colorRegistry.put(COLOR_COMPOSITE_SELECTED,
176 currentLineColor);
177 colorRegistry.put(COLOR_LIST_BACKGROUND,
178 Display.getDefault().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
179 }
180 EditorsUI.getPreferenceStore();
181 return colorRegistry;
182 }
183 }