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

Ported the KeyBindings dialog to JavaFX #1390

Merged
merged 2 commits into from
Jun 27, 2016
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ to [sourceforge feature requests](https://sourceforge.net/p/jabref/features/) by
- Added an option in the about dialog to easily copy the version information of JabRef
- Integrity check table can be sorted by clicking on column headings
- Add tab which shows the MathSciNet review website if the `MRNumber` field is present.
- Partly switched to new UI technology (JavaFX). Redesigned key bindings dialog.

### Fixed
- Fixed [#473](https://github.com/JabRef/jabref/issues/473): Values in an entry containing symbols like ' are now properly escaped for exporting to the database
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/net/sf/jabref/gui/FXAlert.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@
import java.awt.event.WindowEvent;

import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Alert;
import javafx.scene.image.Image;
import javafx.stage.Stage;

import net.sf.jabref.Globals;
import net.sf.jabref.JabRefGUI;
import net.sf.jabref.gui.keyboard.KeyBinding;
import net.sf.jabref.gui.keyboard.KeyBindingPreferences;

/**
* This class shall provide a super class for future dialogs implemented in java fx.
Expand Down Expand Up @@ -67,6 +71,7 @@ public void windowGainedFocus(WindowEvent e) {
}
};


public FXAlert(AlertType type, String title, Image image) {
this(type, title);
setDialogIcon(image);
Expand All @@ -89,6 +94,13 @@ public FXAlert(AlertType type) {
fxDialogWindow.setOnHiding(evt -> setSwingWindowsEnabledAndFocusable(true));

fxDialogWindow.setOnCloseRequest(evt -> this.close());

fxDialogWindow.getScene().setOnKeyPressed(evt -> {
KeyBindingPreferences keyPreferences = Globals.getKeyPrefs();
if (keyPreferences.checkKeyCombinationEquality(KeyBinding.CLOSE_DIALOG, evt)) {
fxDialogWindow.close();
}
});
}

public void setDialogStyle(String pathToStyleSheet) {
Expand Down
135 changes: 135 additions & 0 deletions src/main/java/net/sf/jabref/gui/FXDialogs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/* Copyright (C) 2016 JabRef contributors.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package net.sf.jabref.gui;

import java.util.Optional;

import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonType;
import javafx.scene.control.DialogPane;

/**
* This class provides static methods to create default
* JavaFX dialogs which will also work on top of swing
* windows. The created dialogs are instances of the
* {@link FXAlert} class. The available dialogs in this class
* are useful for displaying small information graphic dialogs
* rather than complex windows. For more complex dialogs it is
* advised to rather create a new sub class of {@link FXAlert}.
*
*/
public abstract class FXDialogs {

/**
* This will create and display a new information dialog.
* It will include a blue information icon on the left and
* a single OK Button. To create a information dialog with custom
* buttons see also {@link #showCustomButtonDialogAndWait(AlertType, String, String, ButtonType...)}
*
* @param title as String
* @param content as String
*/
public static void showInformationDialogAndWait(String title, String content) {
FXAlert alert = createDialog(AlertType.INFORMATION, title, content);
alert.showAndWait();
}

/**
* This will create and display a new information dialog.
* It will include a yellow warning icon on the left and
* a single OK Button. To create a warning dialog with custom
* buttons see also {@link #showCustomButtonDialogAndWait(AlertType, String, String, ButtonType...)}
*
* @param title as String
* @param content as String
*/
public static void showWarningDialogAndWait(String title, String content) {
FXAlert alert = createDialog(AlertType.WARNING, title, content);
alert.showAndWait();
}

/**
* This will create and display a new error dialog.
* It will include a red error icon on the left and
* a single OK Button. To create a error dialog with custom
* buttons see also {@link #showCustomButtonDialogAndWait(AlertType, String, String, ButtonType...)}
*
* @param title as String
* @param content as String
*/
public static void showErrorDialogAndWait(String title, String content) {
FXAlert alert = createDialog(AlertType.ERROR, title, content);
alert.showAndWait();
}

/**
* This will create and display a new confirmation dialog.
* It will include a blue question icon on the left and
* a OK and Cancel Button. To create a confirmation dialog with custom
* buttons see also {@link #showCustomButtonDialogAndWait(AlertType, String, String, ButtonType...)}
*
* @param title as String
* @param content as String
* @return Optional with the pressed Button as ButtonType
*/
public static Optional<ButtonType> showConfirmationDialogAndWait(String title, String content) {
FXAlert alert = createDialog(AlertType.CONFIRMATION, title, content);
return alert.showAndWait();
}

/**
* This will create and display a new dialog of the specified
* {@link AlertType} but with user defined buttons as optional
* {@link ButtonType}s.
*
* @param type as {@link AlertType}
* @param title as String
* @param content as String
* @param buttonTypes
* @return Optional with the pressed Button as ButtonType
*/
public static Optional<ButtonType> showCustomButtonDialogAndWait(AlertType type, String title, String content,
ButtonType... buttonTypes) {
FXAlert alert = createDialog(type, title, content);
alert.getButtonTypes().setAll(buttonTypes);
return alert.showAndWait();
}

/**
* This will create and display a new dialog showing a custom {@link DialogPane}
* and using custom {@link ButtonType}s.
*
* @param title as String
* @param contentPane as DialogPane
* @param buttonTypes as ButtonType
* @return Optional with the pressed Button as ButtonType
*/
public static Optional<ButtonType> showCustomDialogAndWait(String title, DialogPane contentPane,
ButtonType... buttonTypes) {
FXAlert alert = new FXAlert(AlertType.NONE, title);
alert.setDialogPane(contentPane);
alert.getButtonTypes().setAll(buttonTypes);
return alert.showAndWait();
}

private static FXAlert createDialog(AlertType type, String title, String content) {
FXAlert alert = new FXAlert(type, title);
alert.setHeaderText(null);
alert.setContentText(content);
return alert;
}

}
4 changes: 4 additions & 0 deletions src/main/java/net/sf/jabref/gui/IconTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class IconTheme {

public static Font FONT;
public static Font FONT_16;
public static javafx.scene.text.Font FX_FONT;

/* Colors */

Expand All @@ -70,6 +71,9 @@ public class IconTheme {
try (InputStream stream = FontBasedIcon.class.getResourceAsStream("/fonts/materialdesignicons-webfont.ttf")) {
FONT = Font.createFont(Font.TRUETYPE_FONT, stream);
FONT_16 = FONT.deriveFont(Font.PLAIN, 16f);
try (InputStream stream2 = FontBasedIcon.class.getResourceAsStream("/fonts/materialdesignicons-webfont.ttf")) {
FX_FONT = javafx.scene.text.Font.loadFont(stream2, DEFAULT_SIZE);
}
} catch (FontFormatException | IOException e) {
LOGGER.warn("Error loading font", e);
}
Expand Down
24 changes: 3 additions & 21 deletions src/main/java/net/sf/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@
import net.sf.jabref.gui.help.HelpFiles;
import net.sf.jabref.gui.journals.ManageJournalsAction;
import net.sf.jabref.gui.keyboard.KeyBinding;
import net.sf.jabref.gui.keyboard.KeyBindingRepository;
import net.sf.jabref.gui.keyboard.KeyBindingsDialog;
import net.sf.jabref.gui.keyboard.KeyBindingAction;
import net.sf.jabref.gui.menus.ChangeEntryTypeMenu;
import net.sf.jabref.gui.menus.FileHistoryMenu;
import net.sf.jabref.gui.menus.RightClickMenu;
Expand Down Expand Up @@ -206,7 +205,7 @@ public class JabRefFrame extends JFrame implements OutputPrinter {
private final OpenDatabaseAction open = new OpenDatabaseAction(this, true);
private final EditModeAction editModeAction = new EditModeAction();
private final AbstractAction quit = new CloseAction();
private final AbstractAction selectKeys = new SelectKeysAction();
private final AbstractAction keyBindingAction = new KeyBindingAction();
private final AbstractAction newBibtexDatabaseAction = new NewDatabaseAction(this, BibDatabaseMode.BIBTEX);
private final AbstractAction newBiblatexDatabaseAction = new NewDatabaseAction(this, BibDatabaseMode.BIBLATEX);
private final AbstractAction newSubDatabaseAction = new NewSubDatabaseAction(this);
Expand Down Expand Up @@ -1341,7 +1340,7 @@ private void fillMenu() {
options.add(customFileTypesAction);
options.add(manageJournals);
options.add(manageSelectors);
options.add(selectKeys);
options.add(keyBindingAction);
mb.add(options);

helpMenu.add(help);
Expand Down Expand Up @@ -1664,23 +1663,6 @@ public void createDisabledIconsForMenuEntries(MenuElement menuElement) {
}
}

private class SelectKeysAction extends AbstractAction {

public SelectKeysAction() {
super(Localization.lang("Customize key bindings"));
this.putValue(Action.SMALL_ICON, IconTheme.JabRefIcon.KEY_BINDINGS.getSmallIcon());
}

@Override
public void actionPerformed(ActionEvent e) {
KeyBindingsDialog d = new KeyBindingsDialog(new KeyBindingRepository(Globals.getKeyPrefs().getKeyBindings()));
d.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
d.pack(); //setSize(300,500);
d.setLocationRelativeTo(JabRefFrame.this);
d.setVisible(true);
}
}

/**
* The action concerned with closing the window.
*/
Expand Down
Loading