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;
35 //import java.util.List;
37 import java.net.MalformedURLException;
39 import java.io.InputStream;
40 import java.io.IOException;
44 * Static variables for graphics files and keyboard shortcuts.
46 public class GUIGlobals {
50 frameTitle = "JabRef",
52 version = Globals.VERSION,
53 stringsTitle = "Strings for database",
54 //untitledStringsTitle = stringsTitle + Globals.lang("untitled"),
55 untitledTitle = "untitled",
56 helpTitle = "JabRef help",
57 TYPE_HEADER = "entrytype",
59 encPrefix = "Encoding: ", // Part of the signature in written bib files.
60 linuxDefaultLookAndFeel = "com.jgoodies.looks.plastic.Plastic3DLookAndFeel",
61 //"com.shfarr.ui.plaf.fh.FhLookAndFeel",
62 // "net.sourceforge.mlf.metouia.MetouiaLookAndFeel",
63 // "org.compiere.plaf.CompiereLookAndFeel",
64 windowsDefaultLookAndFeel = "com.jgoodies.looks.windows.WindowsLookAndFeel";
66 public static Font CURRENTFONT,
71 // Signature written at the top of the .bib file.
72 public static final String SIGNATURE =
73 "This file was created with JabRef";
75 // Size of help window.
77 helpSize = new Dimension(700, 600),
78 aboutSize = new Dimension(600, 265),
79 searchPaneSize = new Dimension(430, 70),
80 searchFieldSize = new Dimension(215, 25);
82 // Divider size for BaseFrame split pane. 0 means non-resizable.
83 public static final int
84 SPLIT_PANE_DIVIDER_SIZE = 4,
85 SPLIT_PANE_DIVIDER_LOCATION = 145 + 15, // + 15 for possible scrollbar.
86 TABLE_ROW_PADDING = 4,
88 KEYBIND_COL_1 = 80, // Added to the font size when determining table
89 PREVIEW_PANEL_PADDING = 15, // Extra room given to the preview editor, in addition to its own
90 PREVIEW_PANEL_HEIGHT = 200,
91 MAX_CONTENT_SELECTOR_WIDTH = 240; // The max width of the combobox for content selectors.
92 // calculated preferred size
93 //public static final int[] PREVIEW_HEIGHT = {115, 300};
95 public static final double
96 VERTICAL_DIVIDER_LOCATION = 0.4;
99 public static String //configFile = "preferences.dat",
108 ex = imageSize + extension,
111 fontPath = "/images/font/";
113 static HashMap tableIcons = new HashMap(); // Contains table icon mappings. Set up
115 public static Color activeEditor = new Color(230, 230, 255);
117 static HashMap iconMap;
119 public static JLabel getTableIcon(String fieldType) {
120 Object o = tableIcons.get(fieldType);
122 Globals.logger("Error: no table icon defined for type '"+fieldType+"'.");
124 } else return (JLabel)o;
128 //Help files (in HTML format):
130 baseFrameHelp = "BaseFrameHelp.html",
131 entryEditorHelp = "EntryEditorHelp.html",
132 stringEditorHelp = "StringEditorHelp.html",
133 helpContents = "Contents.html",
134 searchHelp = "SearchHelp.html",
135 groupsHelp = "GroupsHelp.html",
136 customEntriesHelp = "CustomEntriesHelp.html",
137 contentSelectorHelp = "ContentSelectorHelp.html",
138 labelPatternHelp = "LabelPatterns.html",
139 ownerHelp = "OwnerHelp.html",
140 timeStampHelp = "TimeStampHelp.html",
141 pdfHelp = "ExternalFiles.html",
142 exportCustomizationHelp = "CustomExports.html",
143 importCustomizationHelp = "CustomImports.html",
144 medlineHelp = "MedlineHelp.html",
145 citeSeerHelp = "CiteSeerHelp.html",
146 generalFieldsHelp = "GeneralFields.html",
147 // searchHelp = "SearchHelp.html",
148 aboutPage = "About.html",
149 shortPlainImport="ShortPlainImport.html",
150 importInspectionHelp = "ImportInspectionDialog.html",
151 shortIntegrityCheck="ShortIntegrityCheck.html",
152 shortAuxImport="ShortAuxImport.html",
153 remoteHelp = "RemoteHelp.html",
154 journalAbbrHelp = "JournalAbbreviations.html",
155 regularExpressionSearchHelp = "ExternalFiles.html#RegularExpressionSearch",
156 nameFormatterHelp = "CustomExports.html#NameFormatter",
157 previewHelp = "PreviewHelp.html";
161 lightGray = new Color(230, 30, 30), // Light gray background
162 validFieldColor = new Color(100, 100, 150), // Empty field, blue.
163 nullFieldColor = new Color(75, 130, 95), // Valid field, green.
164 invalidFieldColor = new Color(141, 0, 61), // Invalid field, red.
165 // invalidFieldColor = new Color(210, 70, 70), // Invalid field, red.
166 validFieldBackground = Color.white, // Valid field backgnd.
167 // invalidFieldBackground = new Color(210, 70, 70), // Invalid field backgnd.
168 invalidFieldBackground = new Color(255, 100, 100), // Invalid field backgnd.
169 gradientGray = new Color(112, 121, 165), // Title bar gradient color, sidepaneheader
170 gradientBlue = new Color(0, 27, 102), // Title bar gradient color, sidepaneheader
171 //activeTabbed = Color.black, // active Database (JTabbedPane)
172 //inActiveTabbed = Color.gray.darker(), // inactive Database
173 activeTabbed = validFieldColor.darker(), // active Database (JTabbedPane)
174 inActiveTabbed = Color.black, // inactive Database
175 infoField = new Color(254, 255, 225) // color for an info field
178 public static String META_FLAG = "jabref-meta: ";
179 public static String META_FLAG_OLD = "bibkeeper-meta: ";
180 public static String ENTRYTYPE_FLAG = "jabref-entrytype: ";
182 // some fieldname constants
183 public static final double
184 DEFAULT_FIELD_WEIGHT = 1,
185 MAX_FIELD_WEIGHT = 2;
187 // constants for editor types:
188 public static final int
192 public static final String FILE_FIELD = "file";
194 public static final double
199 public static final double PE_HEIGHT = 2;
201 // Size constants for EntryTypeForm; small, medium and large.
202 public static int[] FORM_WIDTH = new int[] { 500, 650, 820};
203 public static int[] FORM_HEIGHT = new int[] { 90, 110, 130};
205 // Constants controlling formatted bibtex output.
206 public static final int
208 LINE_LENGTH = 65; // Maximum
210 public static int DEFAULT_FIELD_LENGTH = 100,
211 NUMBER_COL_LENGTH = 32,
214 // Column widths for export customization dialog table:
215 public static final int
216 EXPORT_DIALOG_COL_0_WIDTH = 50,
217 EXPORT_DIALOG_COL_1_WIDTH = 200,
218 EXPORT_DIALOG_COL_2_WIDTH = 30;
220 // Column widths for import customization dialog table:
221 public static final int
222 IMPORT_DIALOG_COL_0_WIDTH = 200,
223 IMPORT_DIALOG_COL_1_WIDTH = 80,
224 IMPORT_DIALOG_COL_2_WIDTH = 200,
225 IMPORT_DIALOG_COL_3_WIDTH = 200;
227 public static final Map LANGUAGES;
230 LANGUAGES = new HashMap();
231 // LANGUAGES contains mappings for supported languages.
232 LANGUAGES.put("English", "en");
233 LANGUAGES.put("Deutsch", "de");
234 LANGUAGES.put("Fran\u00E7ais", "fr");
235 LANGUAGES.put("Italiano", "it");
236 LANGUAGES.put("Nederlands", "du");
237 LANGUAGES.put("Norsk", "no");
238 LANGUAGES.put("EspaƱol", "es");
242 * Read either the default icon theme, or a custom one. If loading of the custom theme
243 * fails, try to fall back on the default theme.
245 public static void setUpIconTheme() {
246 String defaultPrefix = "/images/crystal_16/", prefix = defaultPrefix;
248 URL defaultResource = GUIGlobals.class.getResource(prefix+"Icons.properties");
249 URL resource = defaultResource;
251 if (Globals.prefs.getBoolean("useCustomIconTheme")) {
252 String filename = Globals.prefs.get("customIconThemeFile");
253 if (filename != null)
255 File file = new File(filename);
256 String parent = file.getParentFile().getAbsolutePath();
257 prefix = "file://"+parent+System.getProperty("file.separator");
258 resource = new URL("file://"+file.getAbsolutePath());
259 } catch (MalformedURLException e) {
264 iconMap = readIconThemeFile(resource, prefix);
265 } catch (IOException e) {
266 System.err.println(Globals.lang("Unable to read icon theme file")+" '"+
267 resource.toString()+"'");
268 // If we were trying to load a custom theme, try the default one as a fallback:
269 if (resource != defaultResource)
271 iconMap = readIconThemeFile(defaultResource, defaultPrefix);
272 } catch (IOException e2) {
273 System.err.println(Globals.lang("Unable to read default icon theme."));
282 * Looks up the URL for the image representing the given function, in the resource
283 * file listing images.
284 * @param name The name of the icon, such as "open", "save", "saveAs" etc.
285 * @return The URL to the actual image to use.
287 public static URL getIconUrl(String name) {
288 if (iconMap.containsKey(name)) {
289 String path = (String)iconMap.get(name);
290 URL url = GUIGlobals.class.getResource(path);
292 // This may be a resource outside of the jar file, so we try a general URL:
295 } catch (MalformedURLException e) {
299 System.err.println(Globals.lang("Could not find image file")+" '"+path+"'");
306 * Constructs an ImageIcon for the given function, using the image specified in
307 * the resource files resource/Icons_en.properties.
308 * @param name The name of the icon, such as "open", "save", "saveAs" etc.
309 * @return The ImageIcon for the function.
311 public static ImageIcon getImage(String name) {
312 URL u = getIconUrl(name);
313 return u != null ? new ImageIcon(getIconUrl(name)) : null;
317 * Get a Map of all application icons mapped from their keys.
318 * @return A Map containing all icons used in the application.
320 public static Map getAllIcons() {
321 return Collections.unmodifiableMap(iconMap);
325 * Read a typical java property file into a HashMap. Currently doesn't support escaping
326 * of the '=' character - it simply looks for the first '=' to determine where the key ends.
327 * Both the key and the value is trimmed for whitespace at the ends.
328 * @param file The URL to read information from.
329 * @param prefix A String to prefix to all values read. Can represent e.g. the directory
330 * where icon files are to be found.
331 * @return A HashMap containing all key-value pairs found.
332 * @throws IOException
334 private static HashMap readIconThemeFile(URL file, String prefix) throws IOException {
335 HashMap map = new HashMap();
336 InputStream in = null;
338 in = file.openStream();
339 StringBuffer buffer = new StringBuffer();
341 while ((c = in.read()) != -1)
342 buffer.append((char)c);
343 String[] lines = buffer.toString().split("\n");
344 for (int i=0; i<lines.length; i++) {
345 String line = lines[i].trim();
346 int index = line.indexOf("=");
348 String key = line.substring(0, index).trim();
349 String value = prefix+line.substring(index+1).trim();
353 } catch (IOException ex) {
357 if (in != null) in.close();
358 } catch (IOException ex) {
359 ex.printStackTrace();
365 /** returns the path to language independent help files */
366 public static String getLocaleHelpPath()
368 JabRefPreferences prefs = JabRefPreferences.getInstance() ;
369 String middle = prefs.get("language")+"/";
370 if (middle.equals("en/")) middle = ""; // english in base help dir.
372 return (helpPre + middle );
377 * Perform initializations that are only used in graphical mode. This is to prevent
378 * the "Xlib: connection to ":0.0" refused by server" error when access to the X server
379 * on Un*x is unavailable.
381 public static void init() {
382 typeNameFont = new Font("arial", Font.ITALIC+Font.BOLD, 24);
383 fieldNameFont = new Font("arial", Font.ITALIC+Font.BOLD, 14);
385 lab = new JLabel(getImage("pdfSmall"));
386 lab.setToolTipText(Globals.lang("Open")+" PDF");
387 tableIcons.put("pdf", lab);
388 lab = new JLabel(getImage("wwwSmall"));
389 lab.setToolTipText(Globals.lang("Open")+" URL");
390 tableIcons.put("url", lab);
391 lab = new JLabel(getImage("citeseer"));
392 lab.setToolTipText(Globals.lang("Open")+" CiteSeer URL");
393 tableIcons.put("citeseerurl", lab);
394 lab = new JLabel(getImage("doiSmall"));
395 lab.setToolTipText(Globals.lang("Open")+" DOI "+Globals.lang("web link"));
396 tableIcons.put("doi", lab);
397 lab = new JLabel(getImage("psSmall"));
398 lab.setToolTipText(Globals.lang("Open")+" PS");
399 tableIcons.put("ps", lab);
400 lab = new JLabel(getImage("psSmall"));
401 lab.setToolTipText(Globals.lang("Open file"));
402 tableIcons.put(GUIGlobals.FILE_FIELD, lab);
405 //jabRefFont = new Font("arial", Font.ITALIC/*+Font.BOLD*/, 20);