Skip to content

Commit

Permalink
convert bibtexkeypatterndlg to javafx as well (#4277)
Browse files Browse the repository at this point in the history
* onvert bibtex pattern dialog to javafx as well

* simplify call of keypattern dialog
base dialog is now by default resizable
  • Loading branch information
Siedlerchr authored and tobiasdiez committed Aug 22, 2018
1 parent bd5a440 commit 2dbb05e
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@

public class BibtexKeyPatternAction extends SimpleCommand {

private JabRefFrame frame;
private final JabRefFrame frame;

public BibtexKeyPatternAction(JabRefFrame frame) {
this.frame = frame;
}

@Override
public void execute() {
BibtexKeyPatternDialog bibtexKeyPatternDialog = new BibtexKeyPatternDialog(frame.getCurrentBasePanel());
bibtexKeyPatternDialog.setLocationRelativeTo(null);
bibtexKeyPatternDialog.setVisible(true);
new BibtexKeyPatternDialog(frame.getCurrentBasePanel()).showAndWait();
}
}
Original file line number Diff line number Diff line change
@@ -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<Void> {

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();
Expand All @@ -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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class CopyFilesDialogView extends BaseDialog<Void> {

public CopyFilesDialogView(BibDatabaseContext bibDatabaseContext, CopyFilesResultListDependency results) {
this.setTitle(Localization.lang("Result"));
this.setResizable(true);

this.getDialogPane().getButtonTypes().addAll(ButtonType.OK);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public class DocumentViewerView extends BaseDialog<Void> {
public DocumentViewerView() {
this.setTitle(Localization.lang("Document viewer"));
this.initModality(Modality.NONE);
this.setResizable(true);

ViewLoader.view(this)
.load()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public class ErrorConsoleView extends BaseDialog<Void> {

public ErrorConsoleView() {
this.setTitle(Localization.lang("Event log"));
this.setResizable(true);
this.initModality(Modality.NONE);

ViewLoader.view(this)
Expand Down Expand Up @@ -97,7 +96,7 @@ private Callback<ListView<LogEventViewModel>, ListCell<LogEventViewModel>> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public class ExternalFileTypeEditor extends BaseDialog<Void> {
public ExternalFileTypeEditor() {
this.setTitle(Localization.lang("Manage external file types"));
this.initModality(Modality.APPLICATION_MODAL);
this.setResizable(true);
this.getDialogPane().setPrefSize(600, 500);

init();
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/jabref/gui/help/AboutDialogView.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public class AboutDialogView extends BaseDialog<Void> {

public AboutDialogView() {
this.setTitle(Localization.lang("About JabRef"));
this.setResizable(true);

ViewLoader.view(this)
.load()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public class ManageJournalAbbreviationsView extends BaseDialog<Void> {

public ManageJournalAbbreviationsView() {
this.setTitle(Localization.lang("Journal abbreviations"));
this.setResizable(true);

ViewLoader.view(this)
.load()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class KeyBindingsDialogView extends BaseDialog<Void> {
public KeyBindingsDialogView() {
this.setTitle(Localization.lang("Key bindings"));
this.getDialogPane().setPrefSize(375, 475);
this.setResizable(true);

ViewLoader.view(this)
.load()
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/util/BaseDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected BaseDialog() {
});

setDialogIcon(IconTheme.getJabRefImageFX());

setResizable(true);
Globals.getThemeLoader().installBaseCss(getDialogPane().getScene(), Globals.prefs);
}

Expand Down

0 comments on commit 2dbb05e

Please sign in to comment.