98
98
// Charset.availableCharsets().keySet().toArray(new
100
100
new String[] { "ISO8859_1", "UTF8", "UTF-16", "ASCII", "Cp1250", "Cp1251", "Cp1252",
101
"Cp1253", "Cp1254", "Cp1257", "JIS", "SJIS",
101
"Cp1253", "Cp1254", "Cp1257", "SJIS",
102
102
"EUC_JP", // Added Japanese encodings.
103
103
"Big5", "Big5_HKSCS", "GBK", "ISO8859_2", "ISO8859_3", "ISO8859_4", "ISO8859_5",
104
104
"ISO8859_6", "ISO8859_7", "ISO8859_8", "ISO8859_9", "ISO8859_13", "ISO8859_15" };
105
public static Map<String,String> ENCODING_NAMES_LOOKUP;
106
// String array that maps from month number to month string label:
107
// String array that maps from month number to month string label:
107
108
public static String[] MONTHS = new String[] { "jan", "feb", "mar", "apr", "may", "jun", "jul",
108
109
"aug", "sep", "oct", "nov", "dec" };
110
111
// Map that maps from month string labels to
111
public static Map MONTH_STRINGS = new HashMap();
112
public static Map<String, String> MONTH_STRINGS = new HashMap<String, String>();
113
114
MONTH_STRINGS.put("jan", "January");
114
115
MONTH_STRINGS.put("feb", "February");
126
127
// Build list of encodings, by filtering out all that are not supported
127
128
// on this system:
128
List encodings = new ArrayList();
129
List<String> encodings = new ArrayList<String>();
129
130
for (int i = 0; i < ALL_ENCODINGS.length; i++) {
130
131
if (Charset.isSupported(ALL_ENCODINGS[i])) {
131
132
encodings.add(ALL_ENCODINGS[i]);
134
ENCODINGS = (String[]) encodings.toArray(new String[0]);
135
ENCODINGS = encodings.toArray(new String[0]);
137
// Build a map for translating Java encoding names into common encoding names:
138
ENCODING_NAMES_LOOKUP = new HashMap<String,String>();
139
ENCODING_NAMES_LOOKUP.put("Cp1250", "windows-1250");
140
ENCODING_NAMES_LOOKUP.put("Cp1251", "windows-1251");
141
ENCODING_NAMES_LOOKUP.put("Cp1252", "windows-1252");
142
ENCODING_NAMES_LOOKUP.put("Cp1253", "windows-1253");
143
ENCODING_NAMES_LOOKUP.put("Cp1254", "windows-1254");
144
ENCODING_NAMES_LOOKUP.put("Cp1257", "windows-1257");
145
ENCODING_NAMES_LOOKUP.put("ISO8859_1", "ISO-8859-1");
146
ENCODING_NAMES_LOOKUP.put("ISO8859_2", "ISO-8859-2");
147
ENCODING_NAMES_LOOKUP.put("ISO8859_3", "ISO-8859-3");
148
ENCODING_NAMES_LOOKUP.put("ISO8859_4", "ISO-8859-4");
149
ENCODING_NAMES_LOOKUP.put("ISO8859_5", "ISO-8859-5");
150
ENCODING_NAMES_LOOKUP.put("ISO8859_6", "ISO-8859-6");
151
ENCODING_NAMES_LOOKUP.put("ISO8859_7", "ISO-8859-7");
152
ENCODING_NAMES_LOOKUP.put("ISO8859_8", "ISO-8859-8");
153
ENCODING_NAMES_LOOKUP.put("ISO8859_9", "ISO-8859-9");
154
ENCODING_NAMES_LOOKUP.put("ISO8859_13", "ISO-8859-13");
155
ENCODING_NAMES_LOOKUP.put("ISO8859_15", "ISO-8859-15");
156
ENCODING_NAMES_LOOKUP.put("KOI8_R", "KOI8-R");
157
ENCODING_NAMES_LOOKUP.put("UTF8", "UTF-8");
158
ENCODING_NAMES_LOOKUP.put("UTF-16", "UTF-16");
159
ENCODING_NAMES_LOOKUP.put("SJIS", "Shift_JIS");
160
ENCODING_NAMES_LOOKUP.put("GBK", "GBK");
161
ENCODING_NAMES_LOOKUP.put("Big5_HKSCS", "Big5-HKSCS");
162
ENCODING_NAMES_LOOKUP.put("Big5", "Big5");
163
ENCODING_NAMES_LOOKUP.put("EUC_JP", "EUC-JP");
164
ENCODING_NAMES_LOOKUP.put("ASCII", "US-ASCII");
138
167
public static GlobalFocusListener focusListener = new GlobalFocusListener();
152
181
public static final String NEWLINE = System.getProperty("line.separator");
153
182
public static final int NEWLINE_LENGTH = System.getProperty("line.separator").length();
184
// Instantiate logger:
185
// TODO: Doesn't work in Java 5:
186
// private static Logger logger = Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
187
private static Logger logger = Logger.global;
156
189
* true if we have unix newlines
158
191
public static final boolean UNIX_NEWLINE = NEWLINE.equals("\n");
163
196
// string. Used when writing database to file.
165
198
public static void logger(String s) {
166
Logger.global.info(s);
169
202
public static void turnOffLogging() { // only log exceptions
170
Logger.global.setLevel(java.util.logging.Level.SEVERE);
203
logger.setLevel(java.util.logging.Level.SEVERE);
173
206
// should be only called once
174
207
public static void turnOnConsoleLogging() {
175
Logger.global.addHandler(consoleHandler);
208
logger.addHandler(consoleHandler);
179
212
public static void turnOnFileLogging() {
180
Logger.global.setLevel(java.util.logging.Level.ALL);
213
logger.setLevel(java.util.logging.Level.ALL);
181
214
java.util.logging.Handler handler;
182
215
handler = new ConsoleHandler();
208
241
public static String lang(String key, String[] params) {
209
242
String translation = null;
211
if (Globals.messages != null) {
244
if (Globals.messages != null)
212
245
translation = Globals.messages.getString(key.replaceAll(" ", "_"));
214
246
} catch (MissingResourceException ex) {
217
// Thread.dumpStack(); // For debugging
218
247
//logger("Warning: could not get translation for \"" + key + "\"");
249
if (translation == null)
220
252
if ((translation != null) && (translation.length() != 0)) {
221
253
translation = translation.replaceAll("_", " ");
222
254
StringBuffer sb = new StringBuffer();
389
420
off = new OpenFileFilter(extension);
391
422
Object files = getNewFileImpl(owner, directory, extension, null, off,
392
JFileChooser.OPEN_DIALOG, updateWorkingdirectory, false, true);
423
JFileChooser.OPEN_DIALOG, updateWorkingdirectory, false, true, null);
394
425
if (files instanceof String[]) {
395
426
return (String[]) files;
405
436
public static String getNewFile(JFrame owner, File directory, String extension, int dialogType,
406
437
boolean updateWorkingDirectory) {
407
438
return getNewFile(owner, directory, extension, null, dialogType, updateWorkingDirectory,
442
public static String getNewFile(JFrame owner, File directory, String extension, int dialogType,
443
boolean updateWorkingDirectory, JComponent accessory) {
444
return getNewFile(owner, directory, extension, null, dialogType, updateWorkingDirectory,
411
449
public static String getNewFile(JFrame owner, File directory, String extension,
412
450
String description, int dialogType, boolean updateWorkingDirectory) {
413
451
return getNewFile(owner, directory, extension, description, dialogType,
414
updateWorkingDirectory, false);
452
updateWorkingDirectory, false, null);
417
455
public static String getNewDir(JFrame owner, File directory, String extension, int dialogType,
418
456
boolean updateWorkingDirectory) {
419
457
return getNewFile(owner, directory, extension, null, dialogType, updateWorkingDirectory,
423
461
public static String getNewDir(JFrame owner, File directory, String extension,
424
462
String description, int dialogType, boolean updateWorkingDirectory) {
425
463
return getNewFile(owner, directory, extension, description, dialogType,
426
updateWorkingDirectory, true);
464
updateWorkingDirectory, true, null);
429
467
private static String getNewFile(JFrame owner, File directory, String extension,
430
String description, int dialogType, boolean updateWorkingDirectory, boolean dirOnly) {
468
String description, int dialogType, boolean updateWorkingDirectory, boolean dirOnly,
469
JComponent accessory) {
432
471
OpenFileFilter off = null;
437
476
off = new OpenFileFilter(extension);
439
478
return (String) getNewFileImpl(owner, directory, extension, description, off, dialogType,
440
updateWorkingDirectory, dirOnly, false);
479
updateWorkingDirectory, dirOnly, false, accessory);
443
482
private static Object getNewFileImpl(JFrame owner, File directory, String extension,
444
483
String description, OpenFileFilter off, int dialogType, boolean updateWorkingDirectory,
445
boolean dirOnly, boolean multipleSelection) {
484
boolean dirOnly, boolean multipleSelection, JComponent accessory) {
447
if (ON_MAC && prefs.getBoolean("useNativeFileDialogOnMac")) {
486
// Added the !dirOnly condition below as a workaround to the native file dialog
487
// not supporting directory selection:
488
if (!dirOnly && prefs.getBoolean("useNativeFileDialogOnMac")) {
449
490
return getNewFileForMac(owner, directory, extension, dialogType,
450
491
updateWorkingDirectory, dirOnly, off);
453
JFileChooser fc = null;
455
496
fc = new JabRefFileChooser(directory);
497
if (accessory != null)
498
fc.setAccessory(accessory);
456
499
} catch (InternalError errl) {
457
500
// This try/catch clause was added because a user reported an
458
501
// InternalError getting thrown on WinNT, presumably because of a
545
588
public static String SPECIAL_COMMAND_CHARS = "\"`^~'c";
547
public static HashMap HTML_CHARS = new HashMap(), HTMLCHARS = new HashMap(),
548
XML_CHARS = new HashMap(), ASCII2XML_CHARS = new HashMap(), UNICODE_CHARS = new HashMap(),
549
RTFCHARS = new HashMap(), URL_CHARS = new HashMap();
590
public static HashMap<String, String> HTML_CHARS = new HashMap<String, String>(), HTMLCHARS = new HashMap<String, String>(),
591
XML_CHARS = new HashMap<String, String>(), ASCII2XML_CHARS = new HashMap<String, String>(), UNICODE_CHARS = new HashMap<String, String>(),
592
RTFCHARS = new HashMap<String, String>(), URL_CHARS = new HashMap<String,String>();
552
596
// System.out.println(journalAbbrev.getAbbreviatedName("Journal of Fish
718
762
HTMLCHARS.put("vC", "Č"); // "Ccaron"
719
763
HTMLCHARS.put("vc", "č"); // "ccaron"
720
764
HTMLCHARS.put("vD", "Ď"); // "Dcaron"
721
// Symbol #271 (d�) has no special Latex command
765
// Symbol #271 (d�) has no special Latex command
722
766
HTMLCHARS.put("DJ", "Đ"); // "Dstrok"
723
767
HTMLCHARS.put("dj", "đ"); // "dstrok"
724
768
HTMLCHARS.put("=E", "Ē"); // "Emacr"
764
808
HTMLCHARS.put("'l", "ĺ"); // "lacute"
765
809
HTMLCHARS.put("cL", "Ļ"); // "Lcedil"
766
810
HTMLCHARS.put("cl", "ļ"); // "lcedil"
767
// Symbol #317 (L�) has no special Latex command
768
// Symbol #318 (l�) has no special Latex command
811
// Symbol #317 (L�) has no special Latex command
812
// Symbol #318 (l�) has no special Latex command
769
813
HTMLCHARS.put("Lmidot", "Ŀ"); // "Lmidot"
770
814
HTMLCHARS.put("lmidot", "ŀ"); // "lmidot"
771
815
HTMLCHARS.put("L", "Ł"); // "Lstrok"
776
820
HTMLCHARS.put("cn", "ņ"); // "ncedil"
777
821
HTMLCHARS.put("vN", "Ň"); // "Ncaron"
778
822
HTMLCHARS.put("vn", "ň"); // "ncaron"
779
// Symbol #329 (�n) has no special Latex command
823
// Symbol #329 (�n) has no special Latex command
780
824
HTMLCHARS.put("NG", "Ŋ"); // "ENG"
781
825
HTMLCHARS.put("ng", "ŋ"); // "eng"
782
826
HTMLCHARS.put("=O", "Ō"); // "Omacr"
804
848
HTMLCHARS.put("cT", "Ţ"); // "Tcedil"
805
849
HTMLCHARS.put("ct", "ţ"); // "tcedil"
806
850
HTMLCHARS.put("vT", "Ť"); // "Tcaron"
807
// Symbol #357 (t�) has no special Latex command
851
// Symbol #357 (t�) has no special Latex command
808
852
HTMLCHARS.put("Tstrok", "Ŧ"); // "Tstrok"
809
853
HTMLCHARS.put("tstrok", "ŧ"); // "tstrok"
810
854
HTMLCHARS.put("~U", "Ũ"); // "Utilde"
831
875
HTMLCHARS.put("vZ", "Ž"); // "Zcaron"
832
876
HTMLCHARS.put("vz", "ž"); // "zcaron"
833
877
// Symbol #383 (f) has no special Latex command
878
HTMLCHARS.put("%", "%"); // percent sign
835
XML_CHARS.put("\\{\\\\\\\"\\{a\\}\\}", "ä");
880
XML_CHARS.put("\\{\\\\\\\"\\{a\\}\\}", "ä");
836
881
XML_CHARS.put("\\{\\\\\\\"\\{A\\}\\}", "Ä");
837
882
XML_CHARS.put("\\{\\\\\\\"\\{e\\}\\}", "ë");
838
883
XML_CHARS.put("\\{\\\\\\\"\\{E\\}\\}", "Ë");
1195
1240
RTFCHARS.put("vC", "\\u268C"); // "Ccaron"
1196
1241
RTFCHARS.put("vc", "\\u269c"); // "ccaron"
1197
1242
RTFCHARS.put("vD", "\\u270D"); // "Dcaron"
1198
// Symbol #271 (d�) has no special Latex command
1243
// Symbol #271 (d�) has no special Latex command
1199
1244
RTFCHARS.put("DJ", "\\u272D"); // "Dstrok"
1200
1245
RTFCHARS.put("dj", "\\u273d"); // "dstrok"
1201
1246
RTFCHARS.put("=E", "\\u274E"); // "Emacr"
1241
1286
RTFCHARS.put("'l", "\\u314l"); // "lacute"
1242
1287
RTFCHARS.put("cL", "\\u315L"); // "Lcedil"
1243
1288
RTFCHARS.put("cl", "\\u316l"); // "lcedil"
1244
// Symbol #317 (L�) has no special Latex command
1245
// Symbol #318 (l�) has no special Latex command
1289
// Symbol #317 (L�) has no special Latex command
1290
// Symbol #318 (l�) has no special Latex command
1246
1291
RTFCHARS.put("Lmidot", "\\u319L"); // "Lmidot"
1247
1292
RTFCHARS.put("lmidot", "\\u320l"); // "lmidot"
1248
1293
RTFCHARS.put("L", "\\u321L"); // "Lstrok"
1253
1298
RTFCHARS.put("cn", "\\u326n"); // "ncedil"
1254
1299
RTFCHARS.put("vN", "\\u327N"); // "Ncaron"
1255
1300
RTFCHARS.put("vn", "\\u328n"); // "ncaron"
1256
// Symbol #329 (�n) has no special Latex command
1301
// Symbol #329 (�n) has no special Latex command
1257
1302
RTFCHARS.put("NG", "\\u330G"); // "ENG"
1258
1303
RTFCHARS.put("ng", "\\u331g"); // "eng"
1259
1304
RTFCHARS.put("=O", "\\u332O"); // "Omacr"
1281
1326
RTFCHARS.put("cT", "\\u354T"); // "Tcedil"
1282
1327
RTFCHARS.put("ct", "\\u355t"); // "tcedil"
1283
1328
RTFCHARS.put("vT", "\\u356T"); // "Tcaron"
1284
// Symbol #357 (t�) has no special Latex command
1329
// Symbol #357 (t�) has no special Latex command
1285
1330
RTFCHARS.put("Tstrok", "\\u358T"); // "Tstrok"
1286
1331
RTFCHARS.put("tstrok", "\\u359t"); // "tstrok"
1287
1332
RTFCHARS.put("~U", "\\u360U"); // "Utilde"