Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Globals #74

Merged
merged 24 commits into from
Jul 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ef9af29
Delete unused variable STANDARD_EXPORT_COUNT
lenhard Jul 29, 2015
8a37c11
Move METADATA_LINE_LENGTH to MetaData
lenhard Jul 29, 2015
46edd29
Move highlightColor to LayoutEntry
lenhard Jul 29, 2015
7c9db63
Move additionalFields to BibtexFields and resort members in Globals
lenhard Jul 29, 2015
de65d08
Inline locale to the only method where it is used
lenhard Jul 29, 2015
7d221fe
Move Layout_PREFIX to ExportFormat
lenhard Jul 29, 2015
8b26c04
Move ARXIV_LOOKUP_PREFIX to Util
lenhard Jul 29, 2015
3cdad30
Move SKIP_WORDS to LabelPatternUtil
lenhard Jul 29, 2015
6ecfc10
Move SEPARATING_CHARS to DefaultAutoCompleter
lenhard Jul 29, 2015
953040c
Move SEPARATING_CHARS_NOSPACE to Util
lenhard Jul 29, 2015
42a5269
Remove unnecessary UNIX_NEWLINE
lenhard Jul 29, 2015
465f26b
Use varargs to remove overloaded lang methods
lenhard Jul 29, 2015
423b545
Remove URL_CHARS since they are not used anywhere
lenhard Jul 29, 2015
8e8ef06
Move getShortcutMask to JabRefPreferences
lenhard Jul 29, 2015
399465c
Fix formatting issues (via auto-format)
lenhard Jul 29, 2015
2b055d8
Extract html map from Globals
lenhard Jul 29, 2015
733c54c
Extract XML char map from Globals
lenhard Jul 29, 2015
2722562
Move ASCII2XML_CHARS to XMLCharFormatter
lenhard Jul 29, 2015
55ae2fe
Extract map of unicode chars from Globals
lenhard Jul 29, 2015
a86b9a6
Turn char maps into constants
lenhard Jul 29, 2015
51b6365
Extract rtf char map from Globals
lenhard Jul 29, 2015
c1ebdc1
Reduce visibility of char maps
lenhard Jul 29, 2015
af253ce
Merge branch 'master' into refactor-Globals
lenhard Jul 29, 2015
bff0d3e
Undo rename of Formatter classes since they might be loaded by forName()
lenhard Jul 29, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/main/java/net/sf/jabref/BibtexFields.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class BibtexFields
{
public class BibtexFields {

public static final String KEY_FIELD = "bibtexkey";

Expand All @@ -53,7 +52,12 @@ public class BibtexFields
public static final String MARKED = "__markedentry";
public static final String OWNER = "owner";
public static final String TIMESTAMP = "timestamp"; // it's also definied at the JabRefPreferences class
private static final String ENTRYTYPE = "entrytype";
private static final String ENTRYTYPE = "entrytype";

/*
* some extra field definitions
*/
private static final String ADDITIONAL_FIELDS = "/resource/fields/fields.xml";

public static final String// Using this when I have no database open or when I read
// non bibtex file formats (used by the ImportFormatReader.java)
Expand Down Expand Up @@ -241,7 +245,7 @@ private BibtexFields()
add(dummy);

// read external field definitions
readXML(Globals.additionalFields);
readXML(ADDITIONAL_FIELDS);

// collect all public fields for the PUBLIC_FIELDS array
Vector<String> pFields = new Vector<String>(fieldSet.size());
Expand Down
951 changes: 29 additions & 922 deletions src/main/java/net/sf/jabref/Globals.java

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion src/main/java/net/sf/jabref/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package net.sf.jabref;

import java.awt.Color;
import java.awt.Toolkit;
import java.awt.event.InputEvent;
import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -346,6 +347,8 @@ public class JabRefPreferences {

public String WRAPPED_USERNAME;
public final String MARKING_WITH_NUMBER_PATTERN;

private int SHORTCUT_MASK = -1;

private final Preferences prefs;

Expand Down Expand Up @@ -1147,8 +1150,20 @@ private KeyStroke getKeyForMac(KeyStroke ks) {
modifiers = modifiers | InputEvent.ALT_MASK;
}

return KeyStroke.getKeyStroke(keyCode, Globals.getShortcutMask() + modifiers);
return KeyStroke.getKeyStroke(keyCode, getShortcutMask() + modifiers);
}
}

private int getShortcutMask() {
if (SHORTCUT_MASK == -1) {
try {
SHORTCUT_MASK = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
} catch (Throwable ignored) {

}
}

return SHORTCUT_MASK;
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/net/sf/jabref/MetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class MetaData implements Iterable<String> {

private static final String PREFIX_KEYPATTERN = "keypattern_";
private static final String KEYPATTERNDEFAULT = "keypatterndefault";

private static final int METADATA_LINE_LENGTH = 70; // The line length used to wrap metadata.

private final HashMap<String, Vector<String>> metaData = new HashMap<String, Vector<String>>();
private GroupTreeNode groupsRoot = null;
Expand Down Expand Up @@ -263,7 +265,7 @@ public void writeMetaData(Writer out) throws IOException {
sb.append(StringUtil.quote(orderedData.elementAt(j), ";", '\\')).append(";");
}
sb.append("}");
wrapStringBuffer(sb, Globals.METADATA_LINE_LENGTH);
wrapStringBuffer(sb, METADATA_LINE_LENGTH);
sb.append(Globals.NEWLINE);
sb.append(Globals.NEWLINE);

Expand All @@ -290,7 +292,7 @@ public void writeMetaData(Writer out) throws IOException {
while (tok.hasMoreTokens()) {
StringBuffer s =
new StringBuffer(StringUtil.quote(tok.nextToken(), ";", '\\') + ";");
wrapStringBuffer(s, Globals.METADATA_LINE_LENGTH);
wrapStringBuffer(s, METADATA_LINE_LENGTH);
sb.append(s);
sb.append(Globals.NEWLINE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
class DefaultAutoCompleter extends AbstractAutoCompleter {

private final String fieldName;

private final String SEPARATING_CHARS = ";,\n ";

/**
* @see AutoCompleterFactory
Expand All @@ -50,7 +52,7 @@ public void addBibtexEntry(BibtexEntry entry) {

String fieldValue = entry.getField(fieldName);
if (fieldValue != null) {
StringTokenizer tok = new StringTokenizer(fieldValue, Globals.SEPARATING_CHARS);
StringTokenizer tok = new StringTokenizer(fieldValue, SEPARATING_CHARS);
while (tok.hasMoreTokens()) {
String word = tok.nextToken();
addWordToIndex(word);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/sf/jabref/export/ExportFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class ExportFormat implements IExportFormat {

private FileFilter fileFilter;
private boolean customExport = false;

private final String LAYOUT_PREFIX = "/resource/layout/";

/**
* Initialize another export format based on templates stored in dir with
Expand Down Expand Up @@ -136,7 +136,7 @@ Reader getReader(String filename) throws IOException {
if (customExport) {
dir = "";
} else {
dir = Globals.LAYOUT_PREFIX
dir = LAYOUT_PREFIX
+ (directory == null ? "" : directory + '/');
}
return FileActions.getReader(dir + filename);
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/net/sf/jabref/export/layout/LayoutEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ class LayoutEntry {
private final String classPrefix;

private ArrayList<String> invalidFormatter = null;


// used at highlighting in preview area.
// Color chosen similar to JTextComponent.getSelectionColor(), which is
// used at highlighting words at the editor
public static final String HIGHLIGHT_COLOR = "#3399FF";

public LayoutEntry(StringInt si, String classPrefix_) throws Exception {
type = si.i;
Expand Down Expand Up @@ -536,7 +540,7 @@ private String highlightWords(String text, ArrayList<String> toHighlight) {
Matcher matcher = Globals.getPatternForWords(toHighlight).matcher(text);

if (Character.isLetterOrDigit(text.charAt(0))) {
String hlColor = Globals.highlightColor;
String hlColor = HIGHLIGHT_COLOR;
StringBuffer sb = new StringBuffer();
boolean foundSomething = false;

Expand Down
16 changes: 9 additions & 7 deletions src/main/java/net/sf/jabref/export/layout/format/HTMLChars.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
package net.sf.jabref.export.layout.format;

import net.sf.jabref.Globals;
import net.sf.jabref.util.StringUtil;
import net.sf.jabref.export.layout.LayoutFormatter;
import net.sf.jabref.util.StringUtil;

/**
* This formatter escapes characters so they are suitable for HTML.
*/
public class HTMLChars implements LayoutFormatter {

private static final HtmlCharsMap HTML_CHARS = new HtmlCharsMap();

@Override
public String format(String field) {
Expand All @@ -45,7 +47,7 @@ public String format(String field) {
if (incommand) {
/* Close Command */
String command = currentCommand.toString();
Object result = Globals.HTMLCHARS.get(command);
Object result = HTML_CHARS.get(command);
if (result != null) {
sb.append((String) result);
} else {
Expand Down Expand Up @@ -86,7 +88,7 @@ public String format(String field) {
combody = field.substring(i, i + 1);
// System.out.println("... "+combody);
}
Object result = Globals.HTMLCHARS.get(command + combody);
Object result = HTML_CHARS.get(command + combody);

if (result != null) {
sb.append((String) result);
Expand All @@ -98,7 +100,7 @@ public String format(String field) {
// Are we already at the end of the string?
if ((i + 1) == field.length()) {
String command = currentCommand.toString();
Object result = Globals.HTMLCHARS.get(command);
Object result = HTML_CHARS.get(command);
/* If found, then use translated version. If not,
* then keep
* the text of the parameter intact.
Expand Down Expand Up @@ -142,7 +144,7 @@ public String format(String field) {
argument = part;
if (argument != null) {
// handle common case of general latex command
Object result = Globals.HTMLCHARS.get(command + argument);
Object result = HTML_CHARS.get(command + argument);
// System.out.print("command: "+command+", arg: "+argument);
// System.out.print(", result: ");
// If found, then use translated version. If not, then keep
Expand All @@ -158,15 +160,15 @@ public String format(String field) {
// This end brace terminates a command. This can be the case in
// constructs like {\aa}. The correct behaviour should be to
// substitute the evaluated command and swallow the brace:
Object result = Globals.HTMLCHARS.get(command);
Object result = HTML_CHARS.get(command);
if (result != null) {
sb.append((String) result);
} else {
// If the command is unknown, just print it:
sb.append(command);
}
} else {
Object result = Globals.HTMLCHARS.get(command);
Object result = HTML_CHARS.get(command);
if (result != null) {
sb.append((String) result);
} else {
Expand Down
Loading