Skip to content

Commit

Permalink
Remove customjfx (#3779)
Browse files Browse the repository at this point in the history
* Get rid of customjfx hack
Big step towards jdk9 compatibility
No longer needed
CodeArea still does not work

* Remove TextArea and rework Edit Preamble Dialog to javafx to be on the safe side with customjfxpanel

* Remove basePanel from Preamble Change

* fix non in fx thread issue
  • Loading branch information
Siedlerchr authored Mar 11, 2018
1 parent b028c9c commit d31f2d8
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 467 deletions.
Binary file removed lib/customjfx-1.0.0.jar
Binary file not shown.
56 changes: 13 additions & 43 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.Set;
import java.util.stream.Collectors;

import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
Expand Down Expand Up @@ -61,7 +60,6 @@
import org.jabref.gui.externalfiletype.ExternalFileMenuItem;
import org.jabref.gui.externalfiletype.ExternalFileType;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
import org.jabref.gui.fieldeditors.FieldEditor;
import org.jabref.gui.filelist.AttachFileAction;
import org.jabref.gui.filelist.FileListEntry;
import org.jabref.gui.filelist.FileListTableModel;
Expand Down Expand Up @@ -177,9 +175,6 @@ public class BasePanel extends StackPane implements ClipboardOwner {
// Used to track whether the base has changed since last save.
private BibEntry showing;

// in switching between entries.
private PreambleEditor preambleEditor;
// Keeps track of the preamble dialog if it is open.
private StringDialog stringDialog;
private SuggestionProviders suggestionProviders;

Expand Down Expand Up @@ -361,17 +356,6 @@ private void setupActions() {

actions.put(Actions.SELECT_ALL, (BaseAction) mainTable.getSelectionModel()::selectAll);

// The action for opening the preamble editor
actions.put(Actions.EDIT_PREAMBLE, (BaseAction) () -> {
if (preambleEditor == null) {
PreambleEditor form = new PreambleEditor(frame, BasePanel.this, bibDatabaseContext.getDatabase());
form.setVisible(true);
preambleEditor = form;
} else {
preambleEditor.setVisible(true);
}
});

// The action for opening the string editor
actions.put(Actions.EDIT_STRINGS, (BaseAction) () -> {
if (stringDialog == null) {
Expand Down Expand Up @@ -519,7 +503,8 @@ public void update() {
.openConsole(frame.getCurrentBasePanel().getBibDatabaseContext().getDatabaseFile().orElse(null)));

actions.put(Actions.PULL_CHANGES_FROM_SHARED_DATABASE, (BaseAction) () -> {
DatabaseSynchronizer dbmsSynchronizer = frame.getCurrentBasePanel().getBibDatabaseContext()
DatabaseSynchronizer dbmsSynchronizer = frame.getCurrentBasePanel()
.getBibDatabaseContext()
.getDBMSSynchronizer();
dbmsSynchronizer.pullChanges();
});
Expand Down Expand Up @@ -875,7 +860,8 @@ private boolean saveDatabase(File file, boolean selectedOnly, Charset enc,
SaveSession session;
final String SAVE_DATABASE = Localization.lang("Save library");
try {
SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs).withEncoding(enc)
SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs)
.withEncoding(enc)
.withSaveType(saveType);
BibtexDatabaseWriter<SaveSession> databaseWriter = new BibtexDatabaseWriter<>(
FileSaveSession::new);
Expand Down Expand Up @@ -1066,7 +1052,8 @@ private void createMainTable() {
mainTable.addSelectionListener(listEvent -> Globals.stateManager.setSelectedEntries(mainTable.getSelectedEntries()));

// Update entry editor and preview according to selected entries
mainTable.addSelectionListener(event -> mainTable.getSelectedEntries().stream()
mainTable.addSelectionListener(event -> mainTable.getSelectedEntries()
.stream()
.findFirst()
.ifPresent(entry -> {
preview.setEntry(entry);
Expand Down Expand Up @@ -1231,12 +1218,6 @@ private void instantiateSearchAutoCompleter() {
}
}

public void updatePreamble() {
if (preambleEditor != null) {
preambleEditor.updatePreamble();
}
}

public void assureStringDialogNotEditing() {
if (stringDialog != null) {
stringDialog.assureNotEditing();
Expand Down Expand Up @@ -1478,10 +1459,6 @@ public BibDatabase getDatabase() {
return bibDatabaseContext.getDatabase();
}

public void preambleEditorClosing() {
preambleEditor = null;
}

public void stringsClosing() {
stringDialog = null;
}
Expand Down Expand Up @@ -1844,16 +1821,6 @@ private class UndoAction implements BaseAction {
@Override
public void action() {
try {
JComponent focused = Globals.getFocusListener().getFocused();
if ((focused != null) && (focused instanceof FieldEditor) && focused.hasFocus()) {
// User is currently editing a field:
// Check if it is the preamble:

FieldEditor fieldEditor = (FieldEditor) focused;
if ((preambleEditor != null) && (fieldEditor.equals(preambleEditor.getFieldEditor()))) {
preambleEditor.storeCurrentEdit();
}
}
getUndoManager().undo();
markBaseChanged();
frame.output(Localization.lang("Undo"));
Expand Down Expand Up @@ -1891,9 +1858,11 @@ public void action() {

List<LinkedFile> files = bes.get(0).getFiles();

Optional<LinkedFile> linkedFile = files.stream().filter(file -> (FieldName.URL.equalsIgnoreCase(file.getFileType())
|| FieldName.PS.equalsIgnoreCase(file.getFileType())
|| FieldName.PDF.equalsIgnoreCase(file.getFileType()))).findFirst();
Optional<LinkedFile> linkedFile = files.stream()
.filter(file -> (FieldName.URL.equalsIgnoreCase(file.getFileType())
|| FieldName.PS.equalsIgnoreCase(file.getFileType())
|| FieldName.PDF.equalsIgnoreCase(file.getFileType())))
.findFirst();

if (linkedFile.isPresent()) {

Expand Down Expand Up @@ -1954,7 +1923,8 @@ public void action() throws SaveException {
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder()
.withDefaultExtension(FileType.BIBTEX_DB)
.addExtensionFilter(FileType.BIBTEX_DB)
.withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build();
.withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY))
.build();

Optional<Path> chosenFile = dialogService.showFileSaveDialog(fileDialogConfiguration);
if (chosenFile.isPresent()) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ private MenuBar createMenu() {
new SeparatorMenuItem(),

factory.createMenuItem(StandardActions.LIBRARY_PROPERTIES, new LibraryPropertiesAction(this)),
factory.createMenuItem(StandardActions.EDIT_PREAMBLE, new OldDatabaseCommandWrapper(Actions.EDIT_PREAMBLE, this, Globals.stateManager)),
factory.createMenuItem(StandardActions.EDIT_PREAMBLE, new PreambleEditor(this)),
factory.createMenuItem(StandardActions.EDIT_STRINGS, new OldDatabaseCommandWrapper(Actions.EDIT_STRINGS, this, Globals.stateManager))

);
Expand Down
212 changes: 27 additions & 185 deletions src/main/java/org/jabref/gui/PreambleEditor.java
Original file line number Diff line number Diff line change
@@ -1,214 +1,56 @@
package org.jabref.gui;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JPanel;
import javax.swing.LayoutFocusTraversalPolicy;
import javax.swing.text.JTextComponent;

import org.jabref.Globals;
import org.jabref.gui.actions.Actions;
import org.jabref.gui.fieldeditors.FieldEditor;
import org.jabref.gui.fieldeditors.TextArea;
import org.jabref.gui.keyboard.KeyBinding;
import java.util.Optional;

import javafx.scene.control.ButtonType;
import javafx.scene.control.DialogPane;
import javafx.scene.control.TextArea;

import org.jabref.gui.actions.SimpleCommand;
import org.jabref.gui.undo.UndoablePreambleChange;
import org.jabref.gui.util.WindowLocation;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.database.BibDatabase;
import org.jabref.preferences.JabRefPreferences;

class PreambleEditor extends JabRefDialog {
// A reference to the entry this object works on.
private final BibDatabase database;
private final BasePanel panel;

private final FieldEditor editor;

private final UndoAction undoAction = new UndoAction();
private final StoreFieldAction storeFieldAction = new StoreFieldAction();
private final RedoAction redoAction = new RedoAction();
// The action concerned with closing the window.
private final CloseAction closeAction = new CloseAction();

public PreambleEditor(JabRefFrame baseFrame, BasePanel panel, BibDatabase database) {
super(null, PreambleEditor.class);
this.panel = panel;
this.database = database;

addWindowListener(new WindowAdapter() {

@Override
public void windowClosing(WindowEvent e) {
closeAction.actionPerformed(null);
}

@Override
public void windowOpened(WindowEvent e) {
editor.requestFocus();
}
});
setFocusTraversalPolicy(new LayoutFocusTraversalPolicy() {

@Override
protected boolean accept(Component c) {
return super.accept(c) && (c instanceof FieldEditor);
}
});

JPanel pan = new JPanel();
GridBagLayout gbl = new GridBagLayout();
pan.setLayout(gbl);
GridBagConstraints con = new GridBagConstraints();
con.fill = GridBagConstraints.BOTH;
con.weighty = 1;
con.insets = new Insets(10, 5, 10, 5);
class PreambleEditor extends SimpleCommand {

editor = new TextArea(Localization.lang("Preamble"), database.getPreamble().orElse(""));

// TODO: Reenable this
//setupJTextComponent((TextArea) editor);

//gbl.setConstraints(editor.getLabel(), con);
//pan.add(editor.getLabel());

con.weightx = 1;

gbl.setConstraints(editor.getPane(), con);
pan.add(editor.getPane());

Container conPane = getContentPane();
conPane.add(pan, BorderLayout.CENTER);
setTitle(Localization.lang("Edit preamble"));

WindowLocation pw = new WindowLocation(this, JabRefPreferences.PREAMBLE_POS_X, JabRefPreferences.PREAMBLE_POS_Y,
JabRefPreferences.PREAMBLE_SIZE_X, JabRefPreferences.PREAMBLE_SIZE_Y);
pw.displayWindowAtStoredLocation();
}

private void setupJTextComponent(JTextComponent ta) {
// Set up key bindings and focus listener for the FieldEditor.
ta.getInputMap().put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
ta.getActionMap().put("close", closeAction);
ta.getInputMap().put(Globals.getKeyPrefs().getKey(KeyBinding.PREAMBLE_EDITOR_STORE_CHANGES), "store");
ta.getActionMap().put("store", storeFieldAction);

ta.getInputMap().put(Globals.getKeyPrefs().getKey(KeyBinding.UNDO), "undo");
ta.getActionMap().put(Actions.UNDO, undoAction);
ta.getInputMap().put(Globals.getKeyPrefs().getKey(KeyBinding.REDO), "redo");
ta.getActionMap().put(Actions.REDO, redoAction);

ta.addFocusListener(new FieldListener());
}

public void updatePreamble() {
editor.setText(database.getPreamble().orElse(""));
}
private final TextArea editor = new TextArea();

public FieldEditor getFieldEditor() {
return editor;
}
private final JabRefFrame frame;

public void storeCurrentEdit() {
storeFieldAction.actionPerformed(null);
public PreambleEditor(JabRefFrame frame) {
this.frame = frame;
}

private class FieldListener extends FocusAdapter {
@Override
public void execute() {
BasePanel panel = frame.getCurrentBasePanel();
BibDatabase database = frame.getCurrentBasePanel().getDatabase();

/*
* Focus listener that fires the storeFieldAction when a TextArea
* loses focus.
*/
@Override
public void focusLost(FocusEvent e) {
if (!e.isTemporary()) {
storeFieldAction.actionPerformed(new ActionEvent(e.getSource(), 0, ""));
}
}
DialogPane pane = new DialogPane();

}
editor.setText(frame.getCurrentBasePanel()
.getDatabase()
.getPreamble()
.orElse(""));
pane.setContent(editor);

class StoreFieldAction extends AbstractAction {
Optional<ButtonType> pressedButton = frame.getDialogService().showCustomDialogAndWait(Localization.lang("Edit Preamble"), pane, ButtonType.APPLY, ButtonType.CANCEL);

public StoreFieldAction() {
super("Store field value");
putValue(Action.SHORT_DESCRIPTION, "Store field value");
}

@Override
public void actionPerformed(ActionEvent e) {
if (pressedButton.isPresent() && pressedButton.get().equals(ButtonType.APPLY)) {
String toSet = editor.getText();

// We check if the field has changed, since we don't want to mark the
// base as changed unless we have a real change.
if (!database.getPreamble().orElse("").equals(toSet)) {

panel.getUndoManager().addEdit(
new UndoablePreambleChange(database, panel, database.getPreamble().orElse(null), toSet));
new UndoablePreambleChange(database, database.getPreamble().orElse(null), toSet));
database.setPreamble(toSet);
//if ((toSet == null) || toSet.isEmpty()) {
// editor.setLabelColor(GUIGlobals.NULL_FIELD_COLOR);
//} else {
// editor.setLabelColor(GUIGlobals.ENTRY_EDITOR_LABEL_COLOR);
//}
editor.setValidBackgroundColor();
if (editor.hasFocus()) {
editor.setActiveBackgroundColor();
}

panel.markBaseChanged();
}

}
}

class UndoAction extends AbstractAction {

public UndoAction() {
super("Undo", IconTheme.JabRefIcons.UNDO.getIcon());
putValue(Action.SHORT_DESCRIPTION, "Undo");
}

@Override
public void actionPerformed(ActionEvent e) {
panel.runCommand(Actions.UNDO);
}
}

class RedoAction extends AbstractAction {

public RedoAction() {
super("Redo", IconTheme.JabRefIcons.REDO.getIcon());
putValue(Action.SHORT_DESCRIPTION, "Redo");
}

@Override
public void actionPerformed(ActionEvent e) {
panel.runCommand(Actions.REDO);
}
}

class CloseAction extends AbstractAction {

public CloseAction() {
super(Localization.lang("Close window"));
}

@Override
public void actionPerformed(ActionEvent e) {
storeFieldAction.actionPerformed(null);
panel.preambleEditorClosing();
dispose();
}
}

}
Loading

0 comments on commit d31f2d8

Please sign in to comment.