2 Copyright (C) 2003 Morten O. Alver
4 All programs in this directory and
5 subdirectories are published under the GNU General Public License as
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 Further information about the GNU GPL is available at:
24 http://www.gnu.org/copyleft/gpl.ja.html
27 Modified for use in JabRef.
31 package net.sf.jabref;
33 import java.awt.Color;
34 import java.awt.Dimension;
37 import java.io.IOException;
38 import java.io.InputStream;
39 import java.net.MalformedURLException;
41 import java.util.HashMap;
43 import java.util.Collections;
45 import javax.swing.ImageIcon;
46 import javax.swing.JLabel;
49 * Static variables for graphics files and keyboard shortcuts.
51 public class GUIGlobals {
55 frameTitle = "JabRef",
56 version = Globals.VERSION,
57 stringsTitle = "Strings for database",
58 //untitledStringsTitle = stringsTitle + Globals.lang("untitled"),
59 untitledTitle = "untitled",
60 helpTitle = "JabRef help",
61 TYPE_HEADER = "entrytype",
63 encPrefix = "Encoding: ", // Part of the signature in written bib files.
64 linuxDefaultLookAndFeel = "com.jgoodies.looks.plastic.Plastic3DLookAndFeel",
66 //linuxDefaultLookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel",
67 //linuxDefaultLookAndFeel = "org.jvnet.substance.skin.SubstanceCremeCoffeeLookAndFeel",
68 //linuxDefaultLookAndFeel = "org.jvnet.substance.skin.SubstanceNebulaLookAndFeel",
69 //linuxDefaultLookAndFeel = "org.jvnet.substance.skin.SubstanceBusinessLookAndFeel",
70 windowsDefaultLookAndFeel = "com.jgoodies.looks.windows.WindowsLookAndFeel";
72 public static Font CURRENTFONT,
77 // Signature written at the top of the .bib file.
78 public static final String SIGNATURE =
79 "This file was created with JabRef";
81 // Size of help window.
83 helpSize = new Dimension(700, 600),
84 aboutSize = new Dimension(600, 265),
85 searchPaneSize = new Dimension(430, 70),
86 searchFieldSize = new Dimension(215, 25);
88 // Divider size for BaseFrame split pane. 0 means non-resizable.
89 public static final int
90 SPLIT_PANE_DIVIDER_SIZE = 4,
91 SPLIT_PANE_DIVIDER_LOCATION = 145 + 15, // + 15 for possible scrollbar.
92 TABLE_ROW_PADDING = 4,
94 KEYBIND_COL_1 = 80, // Added to the font size when determining table
95 PREVIEW_PANEL_PADDING = 15, // Extra room given to the preview editor, in addition to its own
96 PREVIEW_PANEL_HEIGHT = 200,
97 MAX_CONTENT_SELECTOR_WIDTH = 240; // The max width of the combobox for content selectors.
98 // calculated preferred size
99 //public static final int[] PREVIEW_HEIGHT = {115, 300};
101 public static final double
102 VERTICAL_DIVIDER_LOCATION = 0.4;
105 public static String //configFile = "preferences.dat",
114 ex = imageSize + extension,
117 fontPath = "/images/font/";
119 static HashMap<String, JLabel> tableIcons = new HashMap<String, JLabel>(); // Contains table icon mappings. Set up
121 public static Color activeEditor = new Color(230, 230, 255);
123 static HashMap<String, String> iconMap;
125 public static JLabel getTableIcon(String fieldType) {
126 Object o = tableIcons.get(fieldType);
128 Globals.logger("Error: no table icon defined for type '"+fieldType+"'.");
130 } else return (JLabel)o;
134 //Help files (in HTML format):
136 baseFrameHelp = "BaseFrameHelp.html",
137 entryEditorHelp = "EntryEditorHelp.html",
138 stringEditorHelp = "StringEditorHelp.html",
139 helpContents = "Contents.html",
140 searchHelp = "SearchHelp.html",
141 groupsHelp = "GroupsHelp.html",
142 customEntriesHelp = "CustomEntriesHelp.html",
143 contentSelectorHelp = "ContentSelectorHelp.html",
144 labelPatternHelp = "LabelPatterns.html",
145 ownerHelp = "OwnerHelp.html",
146 timeStampHelp = "TimeStampHelp.html",
147 pdfHelp = "ExternalFiles.html",
148 exportCustomizationHelp = "CustomExports.html",
149 importCustomizationHelp = "CustomImports.html",
150 medlineHelp = "MedlineHelp.html",
151 citeSeerHelp = "CiteSeerHelp.html",
152 generalFieldsHelp = "GeneralFields.html",
153 aboutPage = "About.html",
154 shortPlainImport="ShortPlainImport.html",
155 importInspectionHelp = "ImportInspectionDialog.html",
156 shortIntegrityCheck="ShortIntegrityCheck.html",
157 shortAuxImport="ShortAuxImport.html",
158 remoteHelp = "RemoteHelp.html",
159 journalAbbrHelp = "JournalAbbreviations.html",
160 regularExpressionSearchHelp = "ExternalFiles.html#RegularExpressionSearch",
161 nameFormatterHelp = "CustomExports.html#NameFormatter",
162 previewHelp = "PreviewHelp.html";
166 lightGray = new Color(230, 30, 30), // Light gray background
167 validFieldColor = new Color(100, 100, 150), // Empty field, blue.
168 nullFieldColor = new Color(75, 130, 95), // Valid field, green.
169 invalidFieldColor = new Color(141, 0, 61), // Invalid field, red.
170 // invalidFieldColor = new Color(210, 70, 70), // Invalid field, red.
171 validFieldBackground = Color.white, // Valid field backgnd.
172 // invalidFieldBackground = new Color(210, 70, 70), // Invalid field backgnd.
173 invalidFieldBackground = new Color(255, 100, 100), // Invalid field backgnd.
174 gradientGray = new Color(112, 121, 165), // Title bar gradient color, sidepaneheader
175 gradientBlue = new Color(0, 27, 102), // Title bar gradient color, sidepaneheader
176 //activeTabbed = Color.black, // active Database (JTabbedPane)
177 //inActiveTabbed = Color.gray.darker(), // inactive Database
178 activeTabbed = validFieldColor.darker(), // active Database (JTabbedPane)
179 inActiveTabbed = Color.black, // inactive Database
180 infoField = new Color(254, 255, 225) // color for an info field
183 public static String META_FLAG = "jabref-meta: ";
184 public static String META_FLAG_OLD = "bibkeeper-meta: ";
185 public static String ENTRYTYPE_FLAG = "jabref-entrytype: ";
187 // some fieldname constants
188 public static final double
189 DEFAULT_FIELD_WEIGHT = 1,
190 MAX_FIELD_WEIGHT = 2;
192 // constants for editor types:
193 public static final int
197 public static final String FILE_FIELD = "file";
199 public static final double
204 public static final double PE_HEIGHT = 2;
206 // Size constants for EntryTypeForm; small, medium and large.
207 public static int[] FORM_WIDTH = new int[] { 500, 650, 820};
208 public static int[] FORM_HEIGHT = new int[] { 90, 110, 130};
210 // Constants controlling formatted bibtex output.
211 public static final int
213 LINE_LENGTH = 65; // Maximum
215 public static int DEFAULT_FIELD_LENGTH = 100,
216 NUMBER_COL_LENGTH = 32,
219 // Column widths for export customization dialog table:
220 public static final int
221 EXPORT_DIALOG_COL_0_WIDTH = 50,
222 EXPORT_DIALOG_COL_1_WIDTH = 200,
223 EXPORT_DIALOG_COL_2_WIDTH = 30;
225 // Column widths for import customization dialog table:
226 public static final int
227 IMPORT_DIALOG_COL_0_WIDTH = 200,
228 IMPORT_DIALOG_COL_1_WIDTH = 80,
229 IMPORT_DIALOG_COL_2_WIDTH = 200,
230 IMPORT_DIALOG_COL_3_WIDTH = 200;
232 public static final Map<String, String> LANGUAGES;
235 LANGUAGES = new HashMap<String, String>();
236 // LANGUAGES contains mappings for supported languages.
237 LANGUAGES.put("English", "en");
238 LANGUAGES.put("Deutsch", "de");
239 LANGUAGES.put("Fran\u00E7ais", "fr");
240 LANGUAGES.put("Italiano", "it");
241 LANGUAGES.put("Nederlands", "du");
242 LANGUAGES.put("Norsk", "no");
243 LANGUAGES.put("EspaƱol", "es");
244 LANGUAGES.put("Polski", "pl");
248 * Read either the default icon theme, or a custom one. If loading of the custom theme
249 * fails, try to fall back on the default theme.
251 public static void setUpIconTheme() {
252 String defaultPrefix = "/images/crystal_16/", prefix = defaultPrefix;
254 URL defaultResource = GUIGlobals.class.getResource(prefix+"Icons.properties");
255 URL resource = defaultResource;
257 if (Globals.prefs.getBoolean("useCustomIconTheme")) {
258 String filename = Globals.prefs.get("customIconThemeFile");
259 if (filename != null)
261 File file = new File(filename);
262 String parent = file.getParentFile().getAbsolutePath();
263 prefix = "file://"+parent+System.getProperty("file.separator");
264 resource = new URL("file://"+file.getAbsolutePath());
265 } catch (MalformedURLException e) {
270 iconMap = readIconThemeFile(resource, prefix);
271 } catch (IOException e) {
272 System.err.println(Globals.lang("Unable to read icon theme file")+" '"+
273 resource.toString()+"'");
274 // If we were trying to load a custom theme, try the default one as a fallback:
275 if (resource != defaultResource)
277 iconMap = readIconThemeFile(defaultResource, defaultPrefix);
278 } catch (IOException e2) {
279 System.err.println(Globals.lang("Unable to read default icon theme."));
288 * Looks up the URL for the image representing the given function, in the resource
289 * file listing images.
290 * @param name The name of the icon, such as "open", "save", "saveAs" etc.
291 * @return The URL to the actual image to use.
293 public static URL getIconUrl(String name) {
294 if (iconMap.containsKey(name)) {
295 String path = iconMap.get(name);
296 URL url = GUIGlobals.class.getResource(path);
298 // This may be a resource outside of the jar file, so we try a general URL:
301 } catch (MalformedURLException e) {
304 System.err.println(Globals.lang("Could not find image file")+" '"+path+"'");
311 * Constructs an ImageIcon for the given function, using the image specified in
312 * the resource files resource/Icons_en.properties.
313 * @param name The name of the icon, such as "open", "save", "saveAs" etc.
314 * @return The ImageIcon for the function.
316 public static ImageIcon getImage(String name) {
317 URL u = getIconUrl(name);
318 return u != null ? new ImageIcon(getIconUrl(name)) : null;
322 * Get a Map of all application icons mapped from their keys.
323 * @return A Map containing all icons used in the application.
325 public static Map<String, String> getAllIcons() {
326 return Collections.unmodifiableMap(iconMap);
330 * Read a typical java property file into a HashMap. Currently doesn't support escaping
331 * of the '=' character - it simply looks for the first '=' to determine where the key ends.
332 * Both the key and the value is trimmed for whitespace at the ends.
333 * @param file The URL to read information from.
334 * @param prefix A String to prefix to all values read. Can represent e.g. the directory
335 * where icon files are to be found.
336 * @return A HashMap containing all key-value pairs found.
337 * @throws IOException
339 private static HashMap<String, String> readIconThemeFile(URL file, String prefix) throws IOException {
340 HashMap<String, String> map = new HashMap<String, String>();
341 InputStream in = null;
343 in = file.openStream();
344 StringBuffer buffer = new StringBuffer();
346 while ((c = in.read()) != -1)
347 buffer.append((char)c);
348 String[] lines = buffer.toString().split("\n");
349 for (int i=0; i<lines.length; i++) {
350 String line = lines[i].trim();
351 int index = line.indexOf("=");
353 String key = line.substring(0, index).trim();
354 String value = prefix+line.substring(index+1).trim();
358 } catch (IOException ex) {
362 if (in != null) in.close();
363 } catch (IOException ex) {
364 ex.printStackTrace();
370 /** returns the path to language independent help files */
371 public static String getLocaleHelpPath()
373 JabRefPreferences prefs = JabRefPreferences.getInstance() ;
374 String middle = prefs.get("language")+"/";
375 if (middle.equals("en/")) middle = ""; // english in base help dir.
377 return (helpPre + middle );
382 * Perform initializations that are only used in graphical mode. This is to prevent
383 * the "Xlib: connection to ":0.0" refused by server" error when access to the X server
384 * on Un*x is unavailable.
386 public static void init() {
387 typeNameFont = new Font("arial", Font.ITALIC+Font.BOLD, 24);
388 fieldNameFont = new Font("arial", Font.ITALIC+Font.BOLD, 14);
390 lab = new JLabel(getImage("pdfSmall"));
391 lab.setToolTipText(Globals.lang("Open")+" PDF");
392 tableIcons.put("pdf", lab);
393 lab = new JLabel(getImage("wwwSmall"));
394 lab.setToolTipText(Globals.lang("Open")+" URL");
395 tableIcons.put("url", lab);
396 lab = new JLabel(getImage("citeseer"));
397 lab.setToolTipText(Globals.lang("Open")+" CiteSeer URL");
398 tableIcons.put("citeseerurl", lab);
399 lab = new JLabel(getImage("doiSmall"));
400 lab.setToolTipText(Globals.lang("Open")+" DOI "+Globals.lang("web link"));
401 tableIcons.put("doi", lab);
402 lab = new JLabel(getImage("psSmall"));
403 lab.setToolTipText(Globals.lang("Open")+" PS");
404 tableIcons.put("ps", lab);
405 lab = new JLabel(getImage("psSmall"));
406 lab.setToolTipText(Globals.lang("Open file"));
407 tableIcons.put(GUIGlobals.FILE_FIELD, lab);
410 //jabRefFont = new Font("arial", Font.ITALIC/*+Font.BOLD*/, 20);