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

Remove gui globals #6103

Merged
merged 3 commits into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions src/main/java/org/jabref/Globals.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
import com.microsoft.applicationinsights.telemetry.SessionState;
import kong.unirest.Unirest;

/**
* @deprecated try to use {@link StateManager} and {@link org.jabref.preferences.PreferencesService}
*/
@Deprecated
public class Globals {

/**
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/jabref/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import javafx.stage.Stage;

import org.jabref.gui.BasePanel;
import org.jabref.gui.GUIGlobals;
import org.jabref.gui.JabRefFrame;
import org.jabref.gui.dialogs.BackupUIManager;
import org.jabref.gui.help.VersionWorker;
Expand Down Expand Up @@ -57,7 +56,7 @@ public JabRefGUI(Stage mainStage, List<ParserResult> databases, boolean isBlank)
}

private void openWindow(Stage mainStage) {
GUIGlobals.init();
IconTheme.loadFonts();

LOGGER.debug("Initializing frame");
mainFrame.init();
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public String getTabTitle() {
String changeFlag = isModified() && !isAutosaveEnabled ? "*" : "";
title.append(this.bibDatabaseContext.getDatabaseFile().get().getName()).append(changeFlag);
} else {
title.append(GUIGlobals.UNTITLED_TITLE);
title.append(Localization.lang("untitled"));

if (getDatabase().hasEntries()) {
// if the database is not empty and no file is assigned,
Expand Down Expand Up @@ -290,17 +290,11 @@ public void editEntryAndFocusField(BibEntry entry, Field field) {
});
}

public void updateTableFont() {
mainTable.updateFont();
}

private void createMainTable() {
bibDatabaseContext.getDatabase().registerListener(SpecialFieldDatabaseChangeListener.INSTANCE);

mainTable = new MainTable(tableModel, frame, this, bibDatabaseContext, preferences.getTablePreferences(), externalFileTypes, preferences.getKeyBindings());

mainTable.updateFont();

// Add the listener that binds selection to state manager (TODO: should be replaced by proper JavaFX binding as soon as table is implemented in JavaFX)
mainTable.addSelectionListener(listEvent -> Globals.stateManager.setSelectedEntries(mainTable.getSelectedEntries()));

Expand Down Expand Up @@ -567,7 +561,7 @@ public synchronized void markChangedOrUnChanged() {
if (getBibDatabaseContext().getDatabaseFile().isPresent()) {
frame.setTabTitle(this, getTabTitle(), getBibDatabaseContext().getDatabaseFile().get().getAbsolutePath());
} else {
frame.setTabTitle(this, GUIGlobals.UNTITLED_TITLE, null);
frame.setTabTitle(this, Localization.lang("untitled"), null);
}
}
frame.setWindowTitle();
Expand Down
55 changes: 0 additions & 55 deletions src/main/java/org/jabref/gui/GUIGlobals.java

This file was deleted.

44 changes: 2 additions & 42 deletions src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,18 +243,6 @@ private void initKeyBindings() {
tabbedPane.getSelectionModel().selectPrevious();
event.consume();
break;
case INCREASE_TABLE_FONT_SIZE:
increaseTableFontSize();
event.consume();
break;
case DECREASE_TABLE_FONT_SIZE:
decreaseTableFontSize();
event.consume();
break;
case DEFAULT_TABLE_FONT_SIZE:
setDefaultTableFontSize();
event.consume();
break;
case SEARCH:
getGlobalSearchBar().focus();
break;
Expand Down Expand Up @@ -320,7 +308,7 @@ public void setWindowTitle() {
String databaseFile = panel.getBibDatabaseContext()
.getDatabaseFile()
.map(File::getPath)
.orElse(GUIGlobals.UNTITLED_TITLE);
.orElse(Localization.lang("untitled"));
//setTitle(FRAME_TITLE + " - " + databaseFile + changeFlag + modeInfo);
} else if (panel.getBibDatabaseContext().getLocation() == DatabaseLocation.SHARED) {
//setTitle(FRAME_TITLE + " - " + panel.getBibDatabaseContext().getDBMSSynchronizer().getDBName() + " ["
Expand Down Expand Up @@ -1134,7 +1122,7 @@ private boolean confirmClose(BasePanel panel) {
.getDatabasePath()
.map(Path::toAbsolutePath)
.map(Path::toString)
.orElse(GUIGlobals.UNTITLED_TITLE);
.orElse(Localization.lang("untitled"));

ButtonType saveChanges = new ButtonType(Localization.lang("Save changes"), ButtonBar.ButtonData.YES);
ButtonType discardChanges = new ButtonType(Localization.lang("Discard changes"), ButtonBar.ButtonData.NO);
Expand Down Expand Up @@ -1229,34 +1217,6 @@ public DialogService getDialogService() {
return dialogService;
}

private void setDefaultTableFontSize() {
GUIGlobals.setFont(Globals.prefs.getIntDefault(JabRefPreferences.FONT_SIZE));
for (BasePanel basePanel : getBasePanelList()) {
basePanel.updateTableFont();
}
dialogService.notify(Localization.lang("Table font size is %0", String.valueOf(GUIGlobals.currentFont.getSize())));
}

private void increaseTableFontSize() {
GUIGlobals.setFont(GUIGlobals.currentFont.getSize() + 1);
for (BasePanel basePanel : getBasePanelList()) {
basePanel.updateTableFont();
}
dialogService.notify(Localization.lang("Table font size is %0", String.valueOf(GUIGlobals.currentFont.getSize())));
}

private void decreaseTableFontSize() {
double currentSize = GUIGlobals.currentFont.getSize();
if (currentSize < 2) {
return;
}
GUIGlobals.setFont(currentSize - 1);
for (BasePanel basePanel : getBasePanelList()) {
basePanel.updateTableFont();
}
dialogService.notify(Localization.lang("Table font size is %0", String.valueOf(GUIGlobals.currentFont.getSize())));
}

/**
* The action concerned with closing the window.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/jabref/gui/StateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import javafx.collections.ObservableMap;
import javafx.scene.Node;

import org.jabref.gui.util.CustomLocalDragboard;
import org.jabref.gui.util.OptionalObjectProperty;
import org.jabref.logic.search.SearchQuery;
import org.jabref.model.database.BibDatabaseContext;
Expand All @@ -32,6 +33,7 @@
*/
public class StateManager {

private final CustomLocalDragboard localDragboard = new CustomLocalDragboard();
private final OptionalObjectProperty<BibDatabaseContext> activeDatabase = OptionalObjectProperty.empty();
private final ReadOnlyListWrapper<GroupTreeNode> activeGroups = new ReadOnlyListWrapper<>(FXCollections.observableArrayList());
private final ObservableList<BibEntry> selectedEntries = FXCollections.observableArrayList();
Expand All @@ -44,6 +46,10 @@ public StateManager() {
activeGroups.bind(Bindings.valueAt(selectedGroups, activeDatabase.orElse(null)));
}

public CustomLocalDragboard getLocalDragboard() {
return localDragboard;
}

public OptionalObjectProperty<BibDatabaseContext> activeDatabaseProperty() {
return activeDatabase;
}
Expand Down
9 changes: 0 additions & 9 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.jabref.Globals;
import org.jabref.gui.BasePanel;
import org.jabref.gui.DialogService;
import org.jabref.gui.GUIGlobals;
import org.jabref.gui.StateManager;
import org.jabref.gui.bibtexkeypattern.GenerateBibtexKeySingleAction;
import org.jabref.gui.entryeditor.fileannotationtab.FileAnnotationTab;
Expand All @@ -39,7 +38,6 @@
import org.jabref.gui.menus.ChangeEntryTypeMenu;
import org.jabref.gui.mergeentries.FetchAndMergeEntry;
import org.jabref.gui.undo.CountingUndoManager;
import org.jabref.gui.util.ColorUtil;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.TaskExecutor;
import org.jabref.logic.TypedBibEntry;
Expand Down Expand Up @@ -103,13 +101,6 @@ public EntryEditor(BasePanel panel, ExternalFileTypes externalFileTypes) {
this.fileLinker = new ExternalFilesEntryLinker(externalFileTypes, preferencesService.getFilePreferences(),
databaseContext);

if (GUIGlobals.currentFont != null) {
setStyle(String.format("text-area-background: %s;text-area-foreground: %s;text-area-highlight: %s;",
ColorUtil.toHex(GUIGlobals.validFieldBackgroundColor),
ColorUtil.toHex(GUIGlobals.editorTextColor),
ColorUtil.toHex(GUIGlobals.activeBackgroundColor)));
}

EasyBind.subscribe(tabbed.getSelectionModel().selectedItemProperty(), tab -> {
EntryEditorTab activeTab = (EntryEditorTab) tab;
if (activeTab != null) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/jabref/gui/groups/GroupTreeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

import org.jabref.gui.DialogService;
import org.jabref.gui.DragAndDropDataFormats;
import org.jabref.gui.GUIGlobals;
import org.jabref.gui.StateManager;
import org.jabref.gui.util.BindingsHelper;
import org.jabref.gui.util.ControlHelper;
Expand Down Expand Up @@ -77,7 +76,7 @@ public class GroupTreeView {

@FXML
public void initialize() {
this.localDragboard = GUIGlobals.localDragboard;
this.localDragboard = stateManager.getLocalDragboard();
viewModel = new GroupTreeViewModel(stateManager, dialogService, preferencesService, taskExecutor, localDragboard);

// Set-up groups tree
Expand Down
20 changes: 8 additions & 12 deletions src/main/java/org/jabref/gui/icon/IconTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
import javafx.scene.control.ToggleButton;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;

import org.jabref.preferences.JabRefPreferences;
import javafx.scene.text.Font;

import de.jensd.fx.glyphs.GlyphIcons;
import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon;
Expand All @@ -27,22 +26,21 @@

public class IconTheme {

public static final Color DEFAULT_DISABLED_COLOR = JabRefPreferences.getInstance().getColor(JabRefPreferences.ICON_DISABLED_COLOR);
public static final javafx.scene.paint.Color SELECTED_COLOR = javafx.scene.paint.Color.web("#50618F");
public static final Color DEFAULT_DISABLED_COLOR = Color.web("#c8c8c8");
public static final Color SELECTED_COLOR = Color.web("#50618F");
private static final String DEFAULT_ICON_PATH = "/images/external/red.png";
private static final Logger LOGGER = LoggerFactory.getLogger(IconTheme.class);
private static final Map<String, String> KEY_TO_ICON = readIconThemeFile(
IconTheme.class.getResource("/images/Icons.properties"), "/images/external/");
private static final Map<String, String> KEY_TO_ICON = readIconThemeFile(IconTheme.class.getResource("/images/Icons.properties"), "/images/external/");

public static void loadFonts() {
try (InputStream stream = getMaterialDesignIconsStream()) {
javafx.scene.text.Font.loadFont(stream, 7);
Font.loadFont(stream, 7);
} catch (IOException e) {
LOGGER.error("Error loading Material Design Icons TTF font", e);
}

try (InputStream stream = getJabRefMaterialDesignIconsStream()) {
javafx.scene.text.Font.loadFont(stream, 7);
Font.loadFont(stream, 7);
} catch (IOException e) {
LOGGER.error("Error loading custom font for custom JabRef icons", e);
}
Expand Down Expand Up @@ -86,7 +84,7 @@ public static URL getIconUrl(String name) {
String key = Objects.requireNonNull(name, "icon name");
if (!KEY_TO_ICON.containsKey(key)) {
LOGGER.warn("Could not find icon url by name " + name + ", so falling back on default icon "
+ DEFAULT_ICON_PATH);
+ DEFAULT_ICON_PATH);
}
String path = KEY_TO_ICON.getOrDefault(key, DEFAULT_ICON_PATH);
return Objects.requireNonNull(IconTheme.class.getResource(path), "Path must not be null for key " + key);
Expand All @@ -110,7 +108,7 @@ private static Map<String, String> readIconThemeFile(URL url, String prefix) {
Map<String, String> result = new HashMap<>();

try (BufferedReader in = new BufferedReader(
new InputStreamReader(url.openStream(), StandardCharsets.ISO_8859_1))) {
new InputStreamReader(url.openStream(), StandardCharsets.ISO_8859_1))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason this is not utf 8?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea...

String line;
while ((line = in.readLine()) != null) {
if (!line.contains("=")) {
Expand Down Expand Up @@ -345,13 +343,11 @@ public ToggleButton asToggleButton() {
@Override
public JabRefIcon withColor(Color color) {
return icon.withColor(color);

}

@Override
public JabRefIcon disabled() {
return icon.disabled();
}
}

}
3 changes: 0 additions & 3 deletions src/main/java/org/jabref/gui/keyboard/KeyBinding.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public enum KeyBinding {
CUT("Cut", Localization.lang("Cut"), "ctrl+X", KeyBindingCategory.EDIT),
//We have to put Entry Editor Previous before, because otherwise the decrease font size is found first
ENTRY_EDITOR_PREVIOUS_PANEL_2("Entry editor, previous panel 2", Localization.lang("Entry editor, previous panel 2"), "ctrl+MINUS", KeyBindingCategory.VIEW),
DECREASE_TABLE_FONT_SIZE("Decrease table font size", Localization.lang("Decrease table font size"), "ctrl+MINUS", KeyBindingCategory.VIEW),
DELETE_ENTRY("Delete entry", Localization.lang("Delete entry"), "DELETE", KeyBindingCategory.BIBTEX),
DEFAULT_DIALOG_ACTION("Execute default action in dialog", Localization.lang("Execute default action in dialog"), "ctrl+ENTER", KeyBindingCategory.VIEW),
DOWNLOAD_FULL_TEXT("Download full text documents", Localization.lang("Download full text documents"), "alt+F7", KeyBindingCategory.QUALITY),
Expand All @@ -43,8 +42,6 @@ public enum KeyBinding {
HELP("Help", Localization.lang("Help"), "F1", KeyBindingCategory.FILE),
IMPORT_INTO_CURRENT_DATABASE("Import into current library", Localization.lang("Import into current library"), "ctrl+I", KeyBindingCategory.FILE),
IMPORT_INTO_NEW_DATABASE("Import into new library", Localization.lang("Import into new library"), "ctrl+alt+I", KeyBindingCategory.FILE),
INCREASE_TABLE_FONT_SIZE("Increase table font size", Localization.lang("Increase table font size"), "ctrl+PLUS", KeyBindingCategory.VIEW),
DEFAULT_TABLE_FONT_SIZE("Default table font size", Localization.lang("Default table font size"), "ctrl+0", KeyBindingCategory.VIEW),
NEW_ARTICLE("New article", Localization.lang("New article"), "ctrl+shift+A", KeyBindingCategory.BIBTEX),
NEW_BOOK("New book", Localization.lang("New book"), "ctrl+shift+B", KeyBindingCategory.BIBTEX),
NEW_ENTRY("New entry", Localization.lang("New entry"), "ctrl+N", KeyBindingCategory.BIBTEX),
Expand Down
12 changes: 2 additions & 10 deletions src/main/java/org/jabref/gui/maintable/MainTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.jabref.Globals;
import org.jabref.gui.BasePanel;
import org.jabref.gui.DragAndDropDataFormats;
import org.jabref.gui.GUIGlobals;
import org.jabref.gui.JabRefFrame;
import org.jabref.gui.externalfiles.ImportHandler;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
Expand Down Expand Up @@ -56,7 +55,7 @@ public class MainTable extends TableView<BibEntryTableViewModel> {

private final MainTableDataModel model;
private final ImportHandler importHandler;
private final CustomLocalDragboard localDragboard = GUIGlobals.localDragboard;
private final CustomLocalDragboard localDragboard;

public MainTable(MainTableDataModel model, JabRefFrame frame,
BasePanel panel, BibDatabaseContext database,
Expand All @@ -76,6 +75,7 @@ public MainTable(MainTableDataModel model, JabRefFrame frame,
Globals.getFileUpdateMonitor(),
undoManager,
Globals.stateManager);
localDragboard = Globals.stateManager.getLocalDragboard();

this.getColumns().addAll(new MainTableColumnFactory(database, preferences.getColumnPreferences(), externalFileTypes, panel.getUndoManager(), frame.getDialogService()).createColumns());

Expand Down Expand Up @@ -325,12 +325,4 @@ private Optional<BibEntryTableViewModel> findEntry(BibEntry entry) {
.filter(viewModel -> viewModel.getEntry().equals(entry))
.findFirst();
}

/**
* Repaints the table with the most recent font configuration
*/
public void updateFont() {
// TODO: Font & padding customization
// setFont(GUIGlobals.currentFont);
}
}
Loading