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 obsolete swing components in Preferences and OpenOffice #4740

Merged
merged 7 commits into from
Mar 10, 2019
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 src/main/java/org/jabref/gui/FXDialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public <T> Optional<T> showChoiceDialogAndWait(String title, String content, Str
ButtonType okButtonType = new ButtonType(okButtonLabel, ButtonBar.ButtonData.OK_DONE);
choiceDialog.getDialogPane().getButtonTypes().setAll(ButtonType.CANCEL, okButtonType);
choiceDialog.setHeaderText(title);
choiceDialog.setTitle(title);
choiceDialog.setContentText(content);
return choiceDialog.showAndWait();

Expand Down
10 changes: 0 additions & 10 deletions src/main/java/org/jabref/gui/help/HelpAction.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jabref.gui.help;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.util.HashSet;
import java.util.Set;
Expand All @@ -9,7 +8,6 @@

import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.KeyStroke;

import org.jabref.Globals;
Expand Down Expand Up @@ -60,14 +58,6 @@ public HelpAction(HelpFile helpPage) {
this(Localization.lang("Help"), Localization.lang("Help"), helpPage, IconTheme.JabRefIcons.HELP.getSmallIcon());
}

public JButton getHelpButton() {
JButton button = new JButton(this);
button.setText(null);
button.setPreferredSize(new Dimension(24, 24));
button.setToolTipText(getValue(Action.SHORT_DESCRIPTION).toString());
return button;
}

public static void openHelpPage(HelpFile helpPage) {
String lang = Globals.prefs.get(JabRefPreferences.LANGUAGE);
StringBuilder sb = new StringBuilder("https://help.jabref.org/");
Expand Down
184 changes: 94 additions & 90 deletions src/main/java/org/jabref/gui/openoffice/OOBibBase.java

Large diffs are not rendered by default.

99 changes: 52 additions & 47 deletions src/main/java/org/jabref/gui/openoffice/OpenOfficePanel.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public AppearancePrefsTab(DialogService dialogService, JabRefPreferences prefs)
container.getChildren().addAll(overrideFonts, fontSizeContainer, fontTweaksLAF, lightTheme, darkTheme);
}

@Override
public Node getBuilder() {
return container;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public BibtexKeyPatternPrefTab(JabRefPreferences prefs, BasePanel panel) {
*/
@Override
public void storeSettings() {

// Set the default value:
Globals.prefs.put(JabRefPreferences.DEFAULT_BIBTEX_KEY_PATTERN, defaultPat.getText());
Globals.prefs.putBoolean(JabRefPreferences.WARN_BEFORE_OVERWRITING_KEY, warnBeforeOverwriting.isSelected());
Expand Down Expand Up @@ -98,6 +97,7 @@ private void appendKeyGeneratorSettings() {
warnBeforeOverwriting.setDisable(dontOverwrite.isSelected()));
}

@Override
public Node getBuilder() {
return builder;
}
Expand Down
45 changes: 25 additions & 20 deletions src/main/java/org/jabref/gui/preferences/FileTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import javafx.scene.layout.Pane;

import org.jabref.gui.DialogService;
import org.jabref.gui.actions.ActionFactory;
import org.jabref.gui.actions.StandardActions;
import org.jabref.gui.help.HelpAction;
import org.jabref.gui.util.DirectoryDialogConfiguration;
import org.jabref.logic.help.HelpFile;
Expand Down Expand Up @@ -52,22 +54,26 @@ class FileTab extends Pane implements PrefsTab {
private final CheckBox allowFileAutoOpenBrowse;
private final RadioButton useRegExpComboBox;
private final RadioButton matchExactKeyOnly = new RadioButton(
Localization.lang("Autolink only files that match the BibTeX key"));
Localization.lang("Autolink only files that match the BibTeX key"));
private final RadioButton matchStartsWithKey = new RadioButton(
Localization.lang("Autolink files with names starting with the BibTeX key"));
Localization.lang("Autolink files with names starting with the BibTeX key"));
private final TextField regExpTextField;

public FileTab(DialogService dialogService, JabRefPreferences prefs) {
this.dialogService = dialogService;
this.prefs = prefs;

ActionFactory factory = new ActionFactory(prefs.getKeyBindingRepository());

fileDir = new TextField();

bibLocAsPrimaryDir = new CheckBox(Localization.lang("Use the BIB file location as primary file directory"));
bibLocAsPrimaryDir.setAccessibleText(Localization.lang("When downloading files, or moving linked files to the "
+ "file directory, prefer the BIB file location rather than the file directory set above"));
+ "file directory, prefer the BIB file location rather than the file directory set above"));
runAutoFileSearch = new CheckBox(
Localization.lang("When opening file link, search for matching file if no link is defined"));
Localization.lang("When opening file link, search for matching file if no link is defined"));
allowFileAutoOpenBrowse = new CheckBox(
Localization.lang("Automatically open browse dialog when creating new file link"));
Localization.lang("Automatically open browse dialog when creating new file link"));
regExpTextField = new TextField();
useRegExpComboBox = new RadioButton(Localization.lang("Use regular expression search"));
useRegExpComboBox.setOnAction(e -> regExpTextField.setEditable(useRegExpComboBox.isSelected()));
Expand All @@ -92,13 +98,13 @@ public FileTab(DialogService dialogService, JabRefPreferences prefs) {
Label general = new Label(Localization.lang("General"));
general.getStyleClass().add("sectionHeader");
builder.add(general, 1, 1);
builder.add(openLast, 1, 2);
builder.add(openLast, 1, 2);
builder.add(backup, 1, 3);
Label label = new Label(Localization.lang("Do not wrap the following fields when saving") + ":");
builder.add(label, 1, 4);
final ToggleGroup resolveGroup = new ToggleGroup();
builder.add(nonWrappableFields, 2, 4);
builder.add(resolveStringsStandard, 1, 5);
builder.add(resolveStringsStandard, 1, 5);
builder.add(resolveStringsAll, 1, 6);
builder.add(doNotResolveStringsFor, 2, 6);
resolveStringsStandard.setToggleGroup(resolveGroup);
Expand All @@ -122,25 +128,23 @@ public FileTab(DialogService dialogService, JabRefPreferences prefs) {
browse.setPrefSize(80, 20);
browse.setOnAction(e -> {
DirectoryDialogConfiguration dirDialogConfiguration = new DirectoryDialogConfiguration.Builder()
.withInitialDirectory(Paths.get(fileDir.getText())).build();
.withInitialDirectory(Paths.get(fileDir.getText())).build();
dialogService.showDirectorySelectionDialog(dirDialogConfiguration)
.ifPresent(f -> fileDir.setText(f.toString()));
});
builder.add(browse, 3, 12);
builder.add(bibLocAsPrimaryDir, 1, 13);
final ToggleGroup autolinkGroup = new ToggleGroup();
builder.add(matchStartsWithKey, 1, 14);
builder.add(matchExactKeyOnly, 1, 15);
builder.add(matchStartsWithKey, 1, 14);
builder.add(matchExactKeyOnly, 1, 15);
builder.add(useRegExpComboBox, 1, 16);
builder.add(regExpTextField, 2, 16);
matchStartsWithKey.setToggleGroup(autolinkGroup);
matchExactKeyOnly.setToggleGroup(autolinkGroup);
useRegExpComboBox.setToggleGroup(autolinkGroup);

Button help = new Button("?");
help.setOnAction(event -> new HelpAction(Localization.lang("Help on regular expression search"),
HelpFile.REGEX_SEARCH).getHelpButton().doClick());

Button help = factory.createIconButton(StandardActions.HELP, new HelpAction(Localization.lang("Help on regular expression search"),
HelpFile.REGEX_SEARCH).getCommand());
builder.add(help, 3, 16);
builder.add(runAutoFileSearch, 1, 17);
builder.add(allowFileAutoOpenBrowse, 1, 18);
Expand All @@ -151,10 +155,10 @@ public FileTab(DialogService dialogService, JabRefPreferences prefs) {
Label autosave = new Label(Localization.lang("Autosave"));
autosave.getStyleClass().add("sectionHeader");
builder.add(autosave, 1, 20);
builder.add(localAutoSave, 1, 21);
Button help1 = new Button("?");
help1.setOnAction(event -> new HelpAction(HelpFile.AUTOSAVE).getHelpButton().doClick());
builder.add(help1, 2, 21);
builder.add(localAutoSave, 1, 21);

Button helpAutosave = factory.createIconButton(StandardActions.HELP, new HelpAction(HelpFile.AUTOSAVE).getCommand());
builder.add(helpAutosave, 2, 21);
}

@Override
Expand Down Expand Up @@ -194,6 +198,7 @@ public void setValues() {
localAutoSave.setSelected(prefs.getBoolean(JabRefPreferences.LOCAL_AUTO_SAVE));
}

@Override
public Node getBuilder() {
return builder;
}
Expand Down Expand Up @@ -247,8 +252,8 @@ public boolean validateSettings() {
boolean valid = Files.exists(path) && Files.isDirectory(path);
if (!valid) {
dialogService.showErrorDialogAndWait(
String.format("%s -> %s %n %n %s: %n %s", Localization.lang("File"),
Localization.lang("Main file directory"), Localization.lang("Directory not found"), path));
String.format("%s -> %s %n %n %s: %n %s", Localization.lang("File"),
Localization.lang("Main file directory"), Localization.lang("Directory not found"), path));
}
return valid;
}
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/org/jabref/gui/preferences/GeneralTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import javafx.scene.shape.Line;

import org.jabref.gui.DialogService;
import org.jabref.gui.actions.ActionFactory;
import org.jabref.gui.actions.StandardActions;
import org.jabref.gui.help.HelpAction;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.gui.util.ViewModelListCellFactory;
Expand Down Expand Up @@ -55,6 +57,9 @@ class GeneralTab extends Pane implements PrefsTab {
public GeneralTab(DialogService dialogService, JabRefPreferences prefs) {
this.prefs = prefs;
this.dialogService = dialogService;

ActionFactory factory = new ActionFactory(prefs.getKeyBindingRepository());

biblatexMode = new ComboBox<>(FXCollections.observableArrayList(BibDatabaseMode.values()));
memoryStick = new CheckBox(Localization.lang("Load and Save preferences from/to jabref.xml on start-up (memory stick mode)"));
useOwner = new CheckBox(Localization.lang("Mark new entries with owner name") + ':');
Expand Down Expand Up @@ -90,10 +95,8 @@ public GeneralTab(DialogService dialogService, JabRefPreferences prefs) {
builder.add(defOwnerField, 2, 10);
builder.add(overwriteOwner, 3, 10);

Button help = new Button("?");
help.setPrefSize(10, 10);
help.setOnAction(event -> new HelpAction(HelpFile.OWNER).getHelpButton().doClick());
builder.add(help, 4, 10);
Button helpOwner = factory.createIconButton(StandardActions.HELP, new HelpAction(HelpFile.OWNER).getCommand());
builder.add(helpOwner, 4, 10);

builder.add(useTimeStamp, 1, 13);
builder.add(timeStampFormat, 2, 13);
Expand All @@ -102,9 +105,8 @@ public GeneralTab(DialogService dialogService, JabRefPreferences prefs) {
builder.add(fieldName, 3, 13);
builder.add(timeStampField, 4, 13);

Button help1 = new Button("?");
help1.setOnAction(event -> new HelpAction(HelpFile.TIMESTAMP).getHelpButton().doClick());
builder.add(help1, 6, 13);
Button helpTimestamp = factory.createIconButton(StandardActions.HELP, new HelpAction(HelpFile.TIMESTAMP).getCommand());
builder.add(helpTimestamp, 6, 13);

builder.add(updateTimeStamp, 1, 14);
builder.add(new Line(), 1, 15);
Expand Down
78 changes: 44 additions & 34 deletions src/main/java/org/jabref/gui/preferences/NameFormatterTab.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jabref.gui.preferences;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

Expand All @@ -21,6 +22,8 @@
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;

import org.jabref.gui.actions.ActionFactory;
import org.jabref.gui.actions.StandardActions;
import org.jabref.gui.help.HelpAction;
import org.jabref.logic.help.HelpFile;
import org.jabref.logic.l10n.Localization;
Expand All @@ -31,24 +34,25 @@ public class NameFormatterTab extends Pane implements PrefsTab {

private final JabRefPreferences prefs;
private boolean tableChanged;
private final TableView table;
private final TableView<NameFormatterViewModel> table;
private final GridPane builder = new GridPane();
private final List<TableRow> tableRows = new ArrayList<>(10);
private final ObservableList<TableRow> data = FXCollections.observableArrayList();
private final List<NameFormatterViewModel> tableRows = new ArrayList<>(10);
private final ObservableList<NameFormatterViewModel> data = FXCollections.observableArrayList();

public static class TableRow {
private SimpleStringProperty name;
private SimpleStringProperty format;
public static class NameFormatterViewModel {

TableRow() {
private final SimpleStringProperty name;
private final SimpleStringProperty format;

NameFormatterViewModel() {
this("");
}

TableRow(String name) {
NameFormatterViewModel(String name) {
this(name, NameFormatter.DEFAULT_FORMAT);
}

TableRow(String name, String format) {
NameFormatterViewModel(String name, String format) {
this.name = new SimpleStringProperty(name);
this.format = new SimpleStringProperty(format);
}
Expand Down Expand Up @@ -77,28 +81,32 @@ public void setFormat(String format) {
public NameFormatterTab(JabRefPreferences prefs) {
this.prefs = Objects.requireNonNull(prefs);

TableColumn<TableRow,String> firstCol = new TableColumn<>(Localization.lang("Formatter name"));
TableColumn<TableRow,String> lastCol = new TableColumn<>(Localization.lang("Format string"));
table = new TableView();
ActionFactory factory = new ActionFactory(prefs.getKeyBindingRepository());

TableColumn<NameFormatterViewModel, String> firstCol = new TableColumn<>(Localization.lang("Formatter name"));
TableColumn<NameFormatterViewModel, String> lastCol = new TableColumn<>(Localization.lang("Format string"));
table = new TableView<>();
table.setEditable(true);
firstCol.setCellValueFactory(new PropertyValueFactory<>("name"));
firstCol.setCellFactory(TextFieldTableCell.forTableColumn());
firstCol.setOnEditCommit(
(TableColumn.CellEditEvent<TableRow, String> t) -> {
t.getTableView().getItems().get(
t.getTablePosition().getRow()).setName(t.getNewValue());
});
(TableColumn.CellEditEvent<NameFormatterViewModel, String> t) -> {
t.getTableView().getItems().get(
t.getTablePosition().getRow())
.setName(t.getNewValue());
});
lastCol.setCellValueFactory(new PropertyValueFactory<>("format"));
lastCol.setCellFactory(TextFieldTableCell.forTableColumn());
lastCol.setOnEditCommit(
(TableColumn.CellEditEvent<TableRow, String> t) -> {
t.getTableView().getItems().get(
t.getTablePosition().getRow()).setFormat(t.getNewValue());
});
(TableColumn.CellEditEvent<NameFormatterViewModel, String> t) -> {
t.getTableView().getItems().get(
t.getTablePosition().getRow())
.setFormat(t.getNewValue());
});
firstCol.setPrefWidth(140);
lastCol.setPrefWidth(200);
table.setItems(data);
table.getColumns().addAll(firstCol, lastCol);
table.getColumns().addAll(Arrays.asList(firstCol, lastCol));
final TextField addName = new TextField();
addName.setPromptText("name");
addName.setMaxWidth(100);
Expand All @@ -116,9 +124,9 @@ public NameFormatterTab(JabRefPreferences prefs) {
Label insertRows = new Label(Localization.lang("Insert rows"));
insertRows.setVisible(false);
Button add = new Button("Insert");
add.setOnAction(e-> {
add.setOnAction(e -> {
if (!addName.getText().isEmpty() && !addLast.getText().isEmpty()) {
TableRow tableRow = new TableRow(addName.getText(), addLast.getText());
NameFormatterViewModel tableRow = new NameFormatterViewModel(addName.getText(), addLast.getText());
addName.clear();
addLast.clear();
data.add(tableRow);
Expand All @@ -131,21 +139,22 @@ public NameFormatterTab(JabRefPreferences prefs) {
Label deleteRows = new Label(Localization.lang("Delete rows"));
deleteRows.setVisible(false);
Button delete = new Button("Delete");
delete.setOnAction(e-> {
if (table.getFocusModel() != null && table.getFocusModel().getFocusedIndex() != -1) {
delete.setOnAction(e -> {
if ((table.getFocusModel() != null) && (table.getFocusModel().getFocusedIndex() != -1)) {
tableChanged = true;
int row = table.getFocusModel().getFocusedIndex();
TableRow tableRow = tableRows.get(row);
NameFormatterViewModel tableRow = tableRows.get(row);
tableRows.remove(tableRow);
data.remove(tableRow);
table.setItems(data);
table.refresh();
}});
Button help = new Button("?");
help.setOnAction(e-> new HelpAction(Localization.lang("Help on Name Formatting"),
HelpFile.CUSTOM_EXPORTS_NAME_FORMATTER).getHelpButton().doClick());
}
});

Button help = factory.createIconButton(StandardActions.HELP, new HelpAction(Localization.lang("Help on Name Formatting"),
HelpFile.CUSTOM_EXPORTS_NAME_FORMATTER).getCommand());
HBox toolbar = new HBox();
toolbar.getChildren().addAll(addName, addLast,add,delete,help);
toolbar.getChildren().addAll(addName, addLast, add, delete, help);
tabPanel.setBottom(toolbar);

Label specialNameFormatters = new Label(Localization.lang("Special name formatters"));
Expand All @@ -154,6 +163,7 @@ public NameFormatterTab(JabRefPreferences prefs) {
builder.add(tabPanel, 1, 2);
}

@Override
public Node getBuilder() {
return builder;
}
Expand All @@ -166,9 +176,9 @@ public void setValues() {

for (int i = 0; i < names.size(); i++) {
if (i < formats.size()) {
tableRows.add(new TableRow(names.get(i), formats.get(i)));
tableRows.add(new NameFormatterViewModel(names.get(i), formats.get(i)));
} else {
tableRows.add(new TableRow(names.get(i)));
tableRows.add(new NameFormatterViewModel(names.get(i)));
}
}
}
Expand Down Expand Up @@ -198,7 +208,7 @@ public void storeSettings() {
List<String> names = new ArrayList<>(tableRows.size());
List<String> formats = new ArrayList<>(tableRows.size());

for (TableRow tr : tableRows) {
for (NameFormatterViewModel tr : tableRows) {
names.add(tr.getName());
formats.add(tr.getFormat());
}
Expand Down
Loading