-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert "Show preferences" dialog to JavaFX (#4605)
- Loading branch information
1 parent
c6a1fcb
commit 5d2b765
Showing
3 changed files
with
80 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/org/jabref/gui/preferences/PreferencesFilterDialog.fxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.geometry.Insets?> | ||
<?import javafx.scene.control.ButtonType?> | ||
<?import javafx.scene.control.CheckBox?> | ||
<?import javafx.scene.control.DialogPane?> | ||
<?import javafx.scene.control.Label?> | ||
<?import javafx.scene.control.TableColumn?> | ||
<?import javafx.scene.control.TableView?> | ||
<?import javafx.scene.layout.BorderPane?> | ||
<?import javafx.scene.layout.HBox?> | ||
<DialogPane xmlns:fx="http://javafx.com/fxml/1" prefHeight="600.0" prefWidth="950.0" | ||
xmlns="http://javafx.com/javafx/8.0.121" fx:controller="org.jabref.gui.preferences.PreferencesFilterDialog"> | ||
|
||
<content> | ||
<BorderPane> | ||
<bottom> | ||
<HBox> | ||
<CheckBox fx:id="showOnlyDeviatingPreferenceOptions" | ||
text="%Show only preferences deviating from their default value"/> | ||
<HBox HBox.hgrow="ALWAYS"/> | ||
<Label fx:id="count"/> | ||
</HBox> | ||
</bottom> | ||
<center> | ||
<TableView fx:id="table"> | ||
<columns> | ||
<TableColumn fx:id="columnType" text="%type"/> | ||
<TableColumn fx:id="columnKey" text="%key"/> | ||
<TableColumn fx:id="columnValue" text="%value"/> | ||
<TableColumn fx:id="columnDefaultValue" text="%default"/> | ||
</columns> | ||
<padding> | ||
<Insets bottom="30.0"/> | ||
</padding> | ||
</TableView> | ||
</center> | ||
</BorderPane> | ||
</content> | ||
<ButtonType fx:constant="CLOSE"/> | ||
</DialogPane> |
137 changes: 38 additions & 99 deletions
137
src/main/java/org/jabref/gui/preferences/PreferencesFilterDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,125 +1,64 @@ | ||
package org.jabref.gui.preferences; | ||
|
||
import java.awt.BorderLayout; | ||
import java.awt.Dimension; | ||
import java.awt.FlowLayout; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import javax.swing.JCheckBox; | ||
import javax.swing.JLabel; | ||
import javax.swing.JPanel; | ||
import javax.swing.JScrollPane; | ||
import javax.swing.JTable; | ||
import javax.swing.table.AbstractTableModel; | ||
|
||
import org.jabref.gui.JabRefDialog; | ||
import org.jabref.gui.WrapLayout; | ||
import javafx.beans.property.ReadOnlyObjectWrapper; | ||
import javafx.beans.property.ReadOnlyStringWrapper; | ||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
import javafx.fxml.FXML; | ||
import javafx.scene.control.CheckBox; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.control.TableColumn; | ||
import javafx.scene.control.TableView; | ||
|
||
import org.jabref.gui.util.BaseDialog; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.preferences.JabRefPreferencesFilter; | ||
|
||
class PreferencesFilterDialog extends JabRefDialog { | ||
import com.airhacks.afterburner.views.ViewLoader; | ||
|
||
public class PreferencesFilterDialog extends BaseDialog<Void> { | ||
|
||
private final JabRefPreferencesFilter preferencesFilter; | ||
private final ObservableList<JabRefPreferencesFilter.PreferenceOption> preferenceOptions; | ||
|
||
private final JTable table; | ||
private final JCheckBox showOnlyDeviatingPreferenceOptions; | ||
private final JLabel count; | ||
@FXML private TableView<JabRefPreferencesFilter.PreferenceOption> table; | ||
@FXML private TableColumn<JabRefPreferencesFilter.PreferenceOption, JabRefPreferencesFilter.PreferenceType> columnType; | ||
@FXML private TableColumn<JabRefPreferencesFilter.PreferenceOption, String> columnKey; | ||
@FXML private TableColumn<JabRefPreferencesFilter.PreferenceOption, Object> columnValue; | ||
@FXML private TableColumn<JabRefPreferencesFilter.PreferenceOption, Object> columnDefaultValue; | ||
@FXML private CheckBox showOnlyDeviatingPreferenceOptions; | ||
@FXML private Label count; | ||
|
||
public PreferencesFilterDialog(JabRefPreferencesFilter preferencesFilter) { | ||
super(true, PreferencesFilterDialog.class); | ||
|
||
this.preferencesFilter = Objects.requireNonNull(preferencesFilter); | ||
this.preferenceOptions = FXCollections.observableArrayList(); | ||
|
||
this.setTitle(Localization.lang("Preferences")); | ||
this.setSize(new Dimension(800, 600)); | ||
ViewLoader.view(this) | ||
.load() | ||
.setAsDialogPane(this); | ||
|
||
JPanel panel = new JPanel(); | ||
panel.setLayout(new BorderLayout()); | ||
|
||
JPanel northPanel = new JPanel(); | ||
northPanel.setLayout(new WrapLayout(FlowLayout.LEFT)); | ||
showOnlyDeviatingPreferenceOptions = new JCheckBox(Localization.lang("Show only preferences deviating from their default value"), false); | ||
showOnlyDeviatingPreferenceOptions.addChangeListener(x -> updateModel()); | ||
northPanel.add(showOnlyDeviatingPreferenceOptions); | ||
count = new JLabel(); | ||
northPanel.add(count); | ||
panel.add(northPanel, BorderLayout.NORTH); | ||
|
||
table = new JTable(); | ||
table.setAutoCreateRowSorter(true); | ||
this.setTitle(Localization.lang("Preferences")); | ||
} | ||
|
||
@FXML | ||
private void initialize() { | ||
showOnlyDeviatingPreferenceOptions.setOnAction(event -> updateModel()); | ||
columnType.setCellValueFactory(data -> new ReadOnlyObjectWrapper<>(data.getValue().getType())); | ||
columnKey.setCellValueFactory(data -> new ReadOnlyStringWrapper(data.getValue().getKey())); | ||
columnValue.setCellValueFactory(data -> new ReadOnlyObjectWrapper<>(data.getValue().getValue())); | ||
columnDefaultValue.setCellValueFactory(data -> new ReadOnlyObjectWrapper<>(data.getValue().getDefaultValue().orElse(""))); | ||
table.setItems(preferenceOptions); | ||
updateModel(); | ||
panel.add(new JScrollPane(table), BorderLayout.CENTER); | ||
|
||
this.getContentPane().add(panel); | ||
} | ||
|
||
private void updateModel() { | ||
List<JabRefPreferencesFilter.PreferenceOption> preferenceOptions; | ||
|
||
if (showOnlyDeviatingPreferenceOptions.isSelected()) { | ||
preferenceOptions = preferencesFilter.getDeviatingPreferences(); | ||
preferenceOptions.setAll(preferencesFilter.getDeviatingPreferences()); | ||
} else { | ||
preferenceOptions = preferencesFilter.getPreferenceOptions(); | ||
preferenceOptions.setAll(preferencesFilter.getPreferenceOptions()); | ||
} | ||
|
||
table.setModel(new PreferencesTableModel(preferenceOptions)); | ||
count.setText(String.format("(%d)", preferenceOptions.size())); | ||
} | ||
|
||
private static class PreferencesTableModel extends AbstractTableModel { | ||
|
||
private final List<JabRefPreferencesFilter.PreferenceOption> preferences; | ||
|
||
public PreferencesTableModel(List<JabRefPreferencesFilter.PreferenceOption> preferences) { | ||
this.preferences = Objects.requireNonNull(preferences); | ||
} | ||
|
||
@Override | ||
public String getColumnName(int column) { | ||
if (column == 0) { | ||
return Localization.lang("type"); | ||
} else if (column == 1) { | ||
return Localization.lang("key"); | ||
} else if (column == 2) { | ||
return Localization.lang("value"); | ||
} else if (column == 3) { | ||
return Localization.lang("default"); | ||
} else { | ||
return "n/a"; | ||
} | ||
} | ||
|
||
@Override | ||
public int getRowCount() { | ||
return preferences.size(); | ||
} | ||
|
||
@Override | ||
public int getColumnCount() { | ||
return 4; | ||
} | ||
|
||
@Override | ||
public Object getValueAt(int rowIndex, int columnIndex) { | ||
if ((rowIndex < 0) || ((rowIndex - 1) > preferences.size())) { | ||
return "n/a"; | ||
} | ||
|
||
JabRefPreferencesFilter.PreferenceOption preferenceOption = preferences.get(rowIndex); | ||
if (columnIndex == 0) { | ||
return preferenceOption.getType(); | ||
} else if (columnIndex == 1) { | ||
return preferenceOption.getKey(); | ||
} else if (columnIndex == 2) { | ||
return preferenceOption.getValue(); | ||
} else if (columnIndex == 3) { | ||
return preferenceOption.getDefaultValue().orElse("NULL"); | ||
} else { | ||
return "n/a"; | ||
} | ||
} | ||
} | ||
|
||
} |