-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2759 from JabRef/moreEditors
More JavaFX editors
- Loading branch information
Showing
34 changed files
with
407 additions
and
306 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
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
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
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
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
19 changes: 19 additions & 0 deletions
19
src/main/java/org/jabref/gui/fieldeditors/JournalEditor.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,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.scene.control.Button?> | ||
<?import javafx.scene.control.Tooltip?> | ||
<?import javafx.scene.layout.HBox?> | ||
<?import org.jabref.gui.fieldeditors.EditorTextArea?> | ||
<?import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIconView?> | ||
<fx:root xmlns:fx="http://javafx.com/fxml/1" type="HBox" xmlns="http://javafx.com/javafx/8.0.112"> | ||
<EditorTextArea fx:id="textArea" prefHeight="0.0" HBox.hgrow="ALWAYS"/> | ||
<Button onAction="#toggleAbbreviation" | ||
styleClass="flatButton"> | ||
<graphic> | ||
<MaterialDesignIconView glyphName="TEXT_SHADOW"/> | ||
</graphic> | ||
<tooltip> | ||
<Tooltip text="%Switches between full and abbreviated journal name if the journal name is known."/> | ||
</tooltip> | ||
</Button> | ||
</fx:root> |
51 changes: 51 additions & 0 deletions
51
src/main/java/org/jabref/gui/fieldeditors/JournalEditor.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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.jabref.gui.fieldeditors; | ||
|
||
import java.util.Optional; | ||
|
||
import javafx.event.ActionEvent; | ||
import javafx.fxml.FXML; | ||
import javafx.scene.Parent; | ||
import javafx.scene.layout.HBox; | ||
|
||
import org.jabref.gui.util.ControlHelper; | ||
import org.jabref.logic.journals.JournalAbbreviationLoader; | ||
import org.jabref.logic.journals.JournalAbbreviationPreferences; | ||
import org.jabref.model.entry.BibEntry; | ||
|
||
|
||
public class JournalEditor extends HBox implements FieldEditorFX { | ||
|
||
private final String fieldName; | ||
@FXML private JournalEditorViewModel viewModel; | ||
@FXML private EditorTextArea textArea; | ||
private Optional<BibEntry> entry; | ||
|
||
public JournalEditor(String fieldName, JournalAbbreviationLoader journalAbbreviationLoader, JournalAbbreviationPreferences journalAbbreviationPreferences) { | ||
this.fieldName = fieldName; | ||
this.viewModel = new JournalEditorViewModel(journalAbbreviationLoader, journalAbbreviationPreferences); | ||
|
||
ControlHelper.loadFXMLForControl(this); | ||
|
||
viewModel.textProperty().bindBidirectional(textArea.textProperty()); | ||
} | ||
|
||
public JournalEditorViewModel getViewModel() { | ||
return viewModel; | ||
} | ||
|
||
@Override | ||
public void bindToEntry(BibEntry entry) { | ||
this.entry = Optional.of(entry); | ||
textArea.bindToEntry(fieldName, entry); | ||
} | ||
|
||
@Override | ||
public Parent getNode() { | ||
return this; | ||
} | ||
|
||
@FXML | ||
private void toggleAbbreviation(ActionEvent event) { | ||
viewModel.toggleAbbreviation(); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/org/jabref/gui/fieldeditors/JournalEditorViewModel.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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.jabref.gui.fieldeditors; | ||
|
||
import java.util.Optional; | ||
|
||
import javafx.beans.property.SimpleStringProperty; | ||
import javafx.beans.property.StringProperty; | ||
|
||
import org.jabref.gui.AbstractViewModel; | ||
import org.jabref.logic.journals.JournalAbbreviationLoader; | ||
import org.jabref.logic.journals.JournalAbbreviationPreferences; | ||
import org.jabref.logic.journals.JournalAbbreviationRepository; | ||
import org.jabref.model.strings.StringUtil; | ||
|
||
public class JournalEditorViewModel extends AbstractViewModel { | ||
private final JournalAbbreviationLoader journalAbbreviationLoader; | ||
private final JournalAbbreviationPreferences journalAbbreviationPreferences; | ||
private StringProperty text = new SimpleStringProperty(); | ||
|
||
public JournalEditorViewModel(JournalAbbreviationLoader journalAbbreviationLoader, JournalAbbreviationPreferences journalAbbreviationPreferences) { | ||
this.journalAbbreviationLoader = journalAbbreviationLoader; | ||
this.journalAbbreviationPreferences = journalAbbreviationPreferences; | ||
} | ||
|
||
public StringProperty textProperty() { | ||
return text; | ||
} | ||
|
||
public void toggleAbbreviation() { | ||
if (StringUtil.isBlank(text.get())) { | ||
return; | ||
} | ||
|
||
JournalAbbreviationRepository abbreviationRepository = journalAbbreviationLoader.getRepository(journalAbbreviationPreferences); | ||
if (abbreviationRepository.isKnownName(text.get())) { | ||
Optional<String> nextAbbreviation = abbreviationRepository.getNextAbbreviation(text.get()); | ||
|
||
if (nextAbbreviation.isPresent()) { | ||
text.set(nextAbbreviation.get()); | ||
// TODO: Add undo | ||
//panel.getUndoManager().addEdit(new UndoableFieldChange(entry, editor.getFieldName(), text, nextAbbreviation)); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.