From 2dbb05ebbaa2d8f986d5fc948bb486df79291a7f Mon Sep 17 00:00:00 2001 From: Christoph Date: Wed, 22 Aug 2018 17:18:16 +0200 Subject: [PATCH] convert bibtexkeypatterndlg to javafx as well (#4277) * onvert bibtex pattern dialog to javafx as well * simplify call of keypattern dialog base dialog is now by default resizable --- .../gui/actions/BibtexKeyPatternAction.java | 6 +- .../BibtexKeyPatternDialog.java | 76 +++---------------- .../gui/copyfiles/CopyFilesDialogView.java | 1 - .../documentviewer/DocumentViewerView.java | 1 - .../gui/errorconsole/ErrorConsoleView.java | 3 +- .../ExternalFileTypeEditor.java | 1 - .../org/jabref/gui/help/AboutDialogView.java | 1 - .../ManageJournalAbbreviationsView.java | 1 - .../gui/keyboard/KeyBindingsDialogView.java | 1 - .../java/org/jabref/gui/util/BaseDialog.java | 2 +- 10 files changed, 15 insertions(+), 78 deletions(-) diff --git a/src/main/java/org/jabref/gui/actions/BibtexKeyPatternAction.java b/src/main/java/org/jabref/gui/actions/BibtexKeyPatternAction.java index 71c125f9659..7eaae3af4df 100644 --- a/src/main/java/org/jabref/gui/actions/BibtexKeyPatternAction.java +++ b/src/main/java/org/jabref/gui/actions/BibtexKeyPatternAction.java @@ -5,7 +5,7 @@ public class BibtexKeyPatternAction extends SimpleCommand { - private JabRefFrame frame; + private final JabRefFrame frame; public BibtexKeyPatternAction(JabRefFrame frame) { this.frame = frame; @@ -13,8 +13,6 @@ public BibtexKeyPatternAction(JabRefFrame frame) { @Override public void execute() { - BibtexKeyPatternDialog bibtexKeyPatternDialog = new BibtexKeyPatternDialog(frame.getCurrentBasePanel()); - bibtexKeyPatternDialog.setLocationRelativeTo(null); - bibtexKeyPatternDialog.setVisible(true); + new BibtexKeyPatternDialog(frame.getCurrentBasePanel()).showAndWait(); } } diff --git a/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternDialog.java b/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternDialog.java index 7fc92b94f67..647c54a1fc0 100644 --- a/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternDialog.java +++ b/src/main/java/org/jabref/gui/bibtexkeypattern/BibtexKeyPatternDialog.java @@ -1,40 +1,20 @@ package org.jabref.gui.bibtexkeypattern; -import java.awt.BorderLayout; -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.awt.event.WindowEvent; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.BorderFactory; -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JPanel; -import javax.swing.WindowConstants; - -import javafx.embed.swing.JFXPanel; -import javafx.scene.Scene; +import javafx.scene.control.ButtonType; import org.jabref.Globals; import org.jabref.gui.BasePanel; -import org.jabref.gui.JabRefDialog; -import org.jabref.gui.customjfx.CustomJFXPanel; -import org.jabref.gui.keyboard.KeyBinder; -import org.jabref.logic.l10n.Localization; +import org.jabref.gui.util.BaseDialog; import org.jabref.model.bibtexkeypattern.AbstractBibtexKeyPattern; import org.jabref.model.metadata.MetaData; -import com.jgoodies.forms.builder.ButtonBarBuilder; - -public class BibtexKeyPatternDialog extends JabRefDialog { +public class BibtexKeyPatternDialog extends BaseDialog { private final MetaData metaData; private final BasePanel panel; private final BibtexKeyPatternPanel bibtexKeyPatternPanel; public BibtexKeyPatternDialog(BasePanel panel) { - super(Localization.lang("BibTeX key patterns"), true, BibtexKeyPatternDialog.class); this.bibtexKeyPatternPanel = new BibtexKeyPatternPanel(panel); this.panel = panel; this.metaData = panel.getBibDatabaseContext().getMetaData(); @@ -44,53 +24,19 @@ public BibtexKeyPatternDialog(BasePanel panel) { } private void init() { - getContentPane().setLayout(new BorderLayout()); - JFXPanel bibPanel = CustomJFXPanel.wrap(new Scene(bibtexKeyPatternPanel)); - getContentPane().add(bibPanel, BorderLayout.CENTER); - - JButton ok = new JButton(Localization.lang("OK")); - JButton cancel = new JButton(); // label of "cancel" is set later as the label is overwritten by assigning an action to the button - - JPanel lower = new JPanel(); - lower.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); - ButtonBarBuilder bb = new ButtonBarBuilder(lower); - bb.addGlue(); - bb.addButton(ok); - bb.addButton(cancel); - bb.addGlue(); - - getContentPane().add(lower, BorderLayout.SOUTH); - this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - getContentPane().setPreferredSize(new Dimension(500, 600)); - pack(); + this.getDialogPane().setContent(bibtexKeyPatternPanel.getPanel()); + this.getDialogPane().getButtonTypes().addAll(ButtonType.APPLY, ButtonType.CANCEL); - ok.addActionListener(e -> { - metaData.setCiteKeyPattern(bibtexKeyPatternPanel.getKeyPatternAsDatabaseBibtexKeyPattern()); - panel.markNonUndoableBaseChanged(); - dispose(); - }); - - final JDialog dialog = this; - - Action cancelAction = new AbstractAction() { - - @Override - public void actionPerformed(ActionEvent e) { - dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING)); + this.setResultConverter(button -> { + if (button == ButtonType.APPLY) { + metaData.setCiteKeyPattern(bibtexKeyPatternPanel.getKeyPatternAsDatabaseBibtexKeyPattern()); + panel.markNonUndoableBaseChanged(); } - }; - cancel.setAction(cancelAction); - cancel.setText(Localization.lang("Cancel")); - KeyBinder.bindCloseDialogKeyToCancelAction(this.getRootPane(), cancelAction); - } + return null; + }); - @Override - public void setVisible(boolean visible) { - if (visible) { - super.setVisible(visible); - } } } diff --git a/src/main/java/org/jabref/gui/copyfiles/CopyFilesDialogView.java b/src/main/java/org/jabref/gui/copyfiles/CopyFilesDialogView.java index bbf813c4c14..eff25118bdb 100644 --- a/src/main/java/org/jabref/gui/copyfiles/CopyFilesDialogView.java +++ b/src/main/java/org/jabref/gui/copyfiles/CopyFilesDialogView.java @@ -26,7 +26,6 @@ public class CopyFilesDialogView extends BaseDialog { public CopyFilesDialogView(BibDatabaseContext bibDatabaseContext, CopyFilesResultListDependency results) { this.setTitle(Localization.lang("Result")); - this.setResizable(true); this.getDialogPane().getButtonTypes().addAll(ButtonType.OK); diff --git a/src/main/java/org/jabref/gui/documentviewer/DocumentViewerView.java b/src/main/java/org/jabref/gui/documentviewer/DocumentViewerView.java index 60ef762d9bc..0f7383989b5 100644 --- a/src/main/java/org/jabref/gui/documentviewer/DocumentViewerView.java +++ b/src/main/java/org/jabref/gui/documentviewer/DocumentViewerView.java @@ -41,7 +41,6 @@ public class DocumentViewerView extends BaseDialog { public DocumentViewerView() { this.setTitle(Localization.lang("Document viewer")); this.initModality(Modality.NONE); - this.setResizable(true); ViewLoader.view(this) .load() diff --git a/src/main/java/org/jabref/gui/errorconsole/ErrorConsoleView.java b/src/main/java/org/jabref/gui/errorconsole/ErrorConsoleView.java index d45adf100c9..fe1d592fe23 100644 --- a/src/main/java/org/jabref/gui/errorconsole/ErrorConsoleView.java +++ b/src/main/java/org/jabref/gui/errorconsole/ErrorConsoleView.java @@ -47,7 +47,6 @@ public class ErrorConsoleView extends BaseDialog { public ErrorConsoleView() { this.setTitle(Localization.lang("Event log")); - this.setResizable(true); this.initModality(Modality.NONE); ViewLoader.view(this) @@ -97,7 +96,7 @@ private Callback, ListCell> creat public void updateItem(LogEventViewModel event, boolean empty) { super.updateItem(event, empty); - if (event == null || empty) { + if ((event == null) || empty) { setGraphic(null); } else { icon = event.getIcon().getGraphicNode(); diff --git a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java index 868b38bf896..ce1192c5d47 100644 --- a/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java +++ b/src/main/java/org/jabref/gui/externalfiletype/ExternalFileTypeEditor.java @@ -53,7 +53,6 @@ public class ExternalFileTypeEditor extends BaseDialog { public ExternalFileTypeEditor() { this.setTitle(Localization.lang("Manage external file types")); this.initModality(Modality.APPLICATION_MODAL); - this.setResizable(true); this.getDialogPane().setPrefSize(600, 500); init(); diff --git a/src/main/java/org/jabref/gui/help/AboutDialogView.java b/src/main/java/org/jabref/gui/help/AboutDialogView.java index 5fbb6f857c7..f1356fd9684 100644 --- a/src/main/java/org/jabref/gui/help/AboutDialogView.java +++ b/src/main/java/org/jabref/gui/help/AboutDialogView.java @@ -28,7 +28,6 @@ public class AboutDialogView extends BaseDialog { public AboutDialogView() { this.setTitle(Localization.lang("About JabRef")); - this.setResizable(true); ViewLoader.view(this) .load() diff --git a/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsView.java b/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsView.java index 42611dccbed..1a0457af443 100644 --- a/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsView.java +++ b/src/main/java/org/jabref/gui/journals/ManageJournalAbbreviationsView.java @@ -52,7 +52,6 @@ public class ManageJournalAbbreviationsView extends BaseDialog { public ManageJournalAbbreviationsView() { this.setTitle(Localization.lang("Journal abbreviations")); - this.setResizable(true); ViewLoader.view(this) .load() diff --git a/src/main/java/org/jabref/gui/keyboard/KeyBindingsDialogView.java b/src/main/java/org/jabref/gui/keyboard/KeyBindingsDialogView.java index 5e834ea9087..c58665b93e2 100644 --- a/src/main/java/org/jabref/gui/keyboard/KeyBindingsDialogView.java +++ b/src/main/java/org/jabref/gui/keyboard/KeyBindingsDialogView.java @@ -39,7 +39,6 @@ public class KeyBindingsDialogView extends BaseDialog { public KeyBindingsDialogView() { this.setTitle(Localization.lang("Key bindings")); this.getDialogPane().setPrefSize(375, 475); - this.setResizable(true); ViewLoader.view(this) .load() diff --git a/src/main/java/org/jabref/gui/util/BaseDialog.java b/src/main/java/org/jabref/gui/util/BaseDialog.java index 73c157838df..44a4a116a62 100644 --- a/src/main/java/org/jabref/gui/util/BaseDialog.java +++ b/src/main/java/org/jabref/gui/util/BaseDialog.java @@ -20,7 +20,7 @@ protected BaseDialog() { }); setDialogIcon(IconTheme.getJabRefImageFX()); - + setResizable(true); Globals.getThemeLoader().installBaseCss(getDialogPane().getScene(), Globals.prefs); }