~ubuntu-branches/ubuntu/natty/jabref/natty

« back to all changes in this revision

Viewing changes to src/java/net/sf/jabref/Globals.java

  • Committer: Bazaar Package Importer
  • Author(s): gregor herrmann
  • Date: 2007-11-16 18:38:18 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071116183818-20x934jdsju14618
Tags: 2.3-2
* Add /usr/lib/jvm/java-7-icedtea to wrapper script. Doesn't work on
  Debian yet but helps Ubuntu users (TODO: add dependency on
  icedtea-java7-jre (not yet in Debian)).
* Reformat wrapper script.
* debian/rules: re-arrange targets and their dependencies.

Show diffs side-by-side

added added

removed removed

Lines of Context:
98
98
                // Charset.availableCharsets().keySet().toArray(new
99
99
                // String[]{});
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;
105
106
 
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" };
109
110
 
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>();
112
113
        static {
113
114
                MONTH_STRINGS.put("jan", "January");
114
115
                MONTH_STRINGS.put("feb", "February");
125
126
 
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]);
132
133
                        }
133
134
                }
134
 
                ENCODINGS = (String[]) encodings.toArray(new String[0]);
 
135
                ENCODINGS = encodings.toArray(new String[0]);
135
136
 
136
 
        }
 
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");
 
165
    }
137
166
 
138
167
        public static GlobalFocusListener focusListener = new GlobalFocusListener();
139
168
 
152
181
        public static final String NEWLINE = System.getProperty("line.separator");
153
182
    public static final int NEWLINE_LENGTH = System.getProperty("line.separator").length();
154
183
 
155
 
        /**
 
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;
 
188
    /**
156
189
         * true if we have unix newlines
157
190
         */
158
191
        public static final boolean UNIX_NEWLINE = NEWLINE.equals("\n");
163
196
        // string. Used when writing database to file.
164
197
 
165
198
        public static void logger(String s) {
166
 
                Logger.global.info(s);
 
199
                logger.info(s);
167
200
        }
168
201
 
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);
171
204
        }
172
205
 
173
206
        // should be only called once
174
207
        public static void turnOnConsoleLogging() {
175
 
                Logger.global.addHandler(consoleHandler);
 
208
                logger.addHandler(consoleHandler);
176
209
 
177
210
        }
178
211
 
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();
183
216
                /*
185
218
                 * catch (IOException e) { //can't open log file so use console
186
219
                 * e.printStackTrace(); }
187
220
                 */
188
 
                Logger.global.addHandler(handler);
 
221
                logger.addHandler(handler);
189
222
 
190
223
                handler.setFilter(new Filter() { // select what gets logged
191
224
                                public boolean isLoggable(LogRecord record) {
208
241
        public static String lang(String key, String[] params) {
209
242
                String translation = null;
210
243
                try {
211
 
                        if (Globals.messages != null) {
 
244
                        if (Globals.messages != null) 
212
245
                                translation = Globals.messages.getString(key.replaceAll(" ", "_"));
213
 
                        }
214
246
                } catch (MissingResourceException ex) {
215
 
                        translation = key;
216
 
 
217
 
                        // Thread.dumpStack(); // For debugging
218
247
                        //logger("Warning: could not get translation for \"" + key + "\"");
219
248
                }
 
249
                if (translation == null)
 
250
                        translation = key;
 
251
 
220
252
                if ((translation != null) && (translation.length() != 0)) {
221
253
                        translation = translation.replaceAll("_", " ");
222
254
                        StringBuffer sb = new StringBuffer();
282
314
                } catch (MissingResourceException ex) {
283
315
                        translation = key;
284
316
 
285
 
                        // System.err.println("Warning: could not get menu item translation
286
 
                        // for \""
287
 
                        // + key + "\"");
 
317
                        //System.err.println("Warning: could not get menu item translation for \""
 
318
                        //+ key + "\"");
288
319
 
289
320
                }
290
321
                if ((translation != null) && (translation.length() != 0)) {
377
408
         * @param directory
378
409
         * @param extension
379
410
         * @param updateWorkingdirectory
380
 
         * @return
 
411
         * @return an array of selected file paths, or an empty array if no selection is made.
381
412
         */
382
413
        public static String[] getMultipleFiles(JFrame owner, File directory, String extension,
383
414
                boolean updateWorkingdirectory) {
389
420
                        off = new OpenFileFilter(extension);
390
421
 
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);
393
424
 
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,
408
 
                        false);
409
 
        }
410
 
 
 
439
                        false, null);
 
440
        }
 
441
 
 
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,
 
445
                        false, accessory);
 
446
        }
 
447
 
 
448
        
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);
415
453
        }
416
454
 
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,
420
 
                        true);
 
458
                        true, null);
421
459
        }
422
460
 
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);
427
465
        }
428
466
 
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) {
431
470
 
432
471
                OpenFileFilter off = null;
433
472
 
437
476
                        off = new OpenFileFilter(extension);
438
477
 
439
478
                return (String) getNewFileImpl(owner, directory, extension, description, off, dialogType,
440
 
                        updateWorkingDirectory, dirOnly, false);
 
479
                        updateWorkingDirectory, dirOnly, false, accessory);
441
480
        }
442
481
 
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) {
446
485
 
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")) {
448
489
 
449
490
                        return getNewFileForMac(owner, directory, extension, dialogType,
450
491
                                updateWorkingDirectory, dirOnly, off);
451
492
                }
452
493
 
453
 
                JFileChooser fc = null;
 
494
                JFileChooser fc;
454
495
                try {
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
533
576
                }
534
577
 
535
578
                fc.setVisible(true); // fc.show(); -> deprecated since 1.5
536
 
 
 
579
        
537
580
                if (fc.getFile() != null) {
538
581
                        Globals.prefs.put("workingDirectory", fc.getDirectory() + fc.getFile());
539
582
                        return fc.getDirectory() + fc.getFile();
544
587
 
545
588
        public static String SPECIAL_COMMAND_CHARS = "\"`^~'c";
546
589
 
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>();
 
593
 
550
594
        static {
551
595
 
552
596
                // System.out.println(journalAbbrev.getAbbreviatedName("Journal of Fish
718
762
                HTMLCHARS.put("vC", "&#268;"); // "Ccaron"
719
763
                HTMLCHARS.put("vc", "&#269;"); // "ccaron"
720
764
                HTMLCHARS.put("vD", "&#270;"); // "Dcaron"
721
 
                // Symbol #271 (d�) has no special Latex command
 
765
                // Symbol #271 (d�) has no special Latex command
722
766
                HTMLCHARS.put("DJ", "&#272;"); // "Dstrok"
723
767
                HTMLCHARS.put("dj", "&#273;"); // "dstrok"
724
768
                HTMLCHARS.put("=E", "&#274;"); // "Emacr"
764
808
                HTMLCHARS.put("'l", "&#314;"); // "lacute"
765
809
                HTMLCHARS.put("cL", "&#315;"); // "Lcedil"
766
810
                HTMLCHARS.put("cl", "&#316;"); // "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", "&#319;"); // "Lmidot"
770
814
                HTMLCHARS.put("lmidot", "&#320;"); // "lmidot"
771
815
                HTMLCHARS.put("L", "&#321;"); // "Lstrok"
776
820
                HTMLCHARS.put("cn", "&#326;"); // "ncedil"
777
821
                HTMLCHARS.put("vN", "&#327;"); // "Ncaron"
778
822
                HTMLCHARS.put("vn", "&#328;"); // "ncaron"
779
 
                // Symbol #329 (�n) has no special Latex command
 
823
                // Symbol #329 (�n) has no special Latex command
780
824
                HTMLCHARS.put("NG", "&#330;"); // "ENG"
781
825
                HTMLCHARS.put("ng", "&#331;"); // "eng"
782
826
                HTMLCHARS.put("=O", "&#332;"); // "Omacr"
804
848
                HTMLCHARS.put("cT", "&#354;"); // "Tcedil"
805
849
                HTMLCHARS.put("ct", "&#355;"); // "tcedil"
806
850
                HTMLCHARS.put("vT", "&#356;"); // "Tcaron"
807
 
                // Symbol #357 (t�) has no special Latex command
 
851
                // Symbol #357 (t�) has no special Latex command
808
852
                HTMLCHARS.put("Tstrok", "&#358;"); // "Tstrok"
809
853
                HTMLCHARS.put("tstrok", "&#359;"); // "tstrok"
810
854
                HTMLCHARS.put("~U", "&#360;"); // "Utilde"
831
875
                HTMLCHARS.put("vZ", "&#381;"); // "Zcaron"
832
876
                HTMLCHARS.put("vz", "&#382;"); // "zcaron"
833
877
                // Symbol #383 (f) has no special Latex command
 
878
        HTMLCHARS.put("%", "%"); // percent sign
834
879
 
835
 
                XML_CHARS.put("\\{\\\\\\\"\\{a\\}\\}", "&#x00E4;");
 
880
        XML_CHARS.put("\\{\\\\\\\"\\{a\\}\\}", "&#x00E4;");
836
881
                XML_CHARS.put("\\{\\\\\\\"\\{A\\}\\}", "&#x00C4;");
837
882
                XML_CHARS.put("\\{\\\\\\\"\\{e\\}\\}", "&#x00EB;");
838
883
                XML_CHARS.put("\\{\\\\\\\"\\{E\\}\\}", "&#x00CB;");
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"