-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Code JavaFX
Please head to https://jabref.readthedocs.io/en/latest/javafx/
The goal of the MVVM architecture is to separate the state/behavior from the appearance of the ui. This is archived by dividing JabRef into different layers, each having a clear responsibility.
- The Model contains the business logic and data structures. These aspects are again encapsulated in the logic and model package, respectively.
- The View controls the appearance and structure of the UI. It is usually defined in a FXML file.
- View model converts the data from logic and model in a form that is easily usable in the gui. Thus it controls the state of the View. Moreover, the ViewModel contains all the logic needed to change the current state of the UI or perform an action. These actions are usually passed down to the logic package, after some data validation. The important aspect is that the ViewModel contains all the ui-related logic but does not have direct access to the controls defined in the View. Hence, the ViewModel can easily be tested by unit tests.
- The Controller initializes the view model and binds it to the view. In an ideal world all the binding would already be done directly in the FXML. But JavaFX's binding expressions are not yet powerful enough to accomplish this. It is important to keep in mind that the Controller should be as minimalistic as possible. Especially one should resist the temptation to validate inputs in the controller. The ViewModel should handle data validation! It is often convenient to load the FXML file directly from the controller.
The only class which access model and logic classes is the ViewModel. Controller and View have only access the ViewModel and never the backend. The ViewModel does not know the Controller or View.
More details about the MVVM pattern can be found in an article by Microsoft and in an article focusing on the implementation with JavaFX.
- The ViewModel should derive from
AbstractViewModel
.
public class MyDialogViewModel extends AbstractViewModel {
}
- Add a (readonly) property as a private field and generate the getters according to the JavaFX bean conventions:
private final ReadOnlyStringWrapper heading = new ReadOnlyStringWrapper();
public ReadOnlyStringProperty headingProperty() {
return heading.getReadOnlyProperty();
}
public String getHeading() {
return heading.get();
}
- Create constructor which initializes the fields to their default values. Write tests to ensure that everything works as expected!
public MyDialogViewModel(Dependency dependency) {
this.dependency = Objects.requireNonNull(dependency);
heading.set("Hello " + dependency.getUserName());
}
- Add methods which allow interaction. Again, don't forget to write tests!
public void shutdown() {
heading.set("Goodbye!");
}
-
The "code-behind" part of the view, which binds the
View
to theViewModel
. -
The usual convention is that the controller ends on the suffix
*View
. Dialogs should derive fromBaseDialog
.
public class AboutDialogView extends BaseDialog<Void>
- You get access to nodes in the FXML file by declaring them with the
@FXML
annotation.
@FXML protected Button helloButton;
@FXML protected ImageView iconImage;
- Dependencies can easily be injected into the controller using the
@Inject
annotation.
@Inject private DialogService dialogService;
- It is convenient to load the FXML-view directly from the controller class.
The FXML file is loaded using
ViewLoader
based on the name of the class passed toview
. To make this convention-over-configuration approach work, both the FXML file and the View class should have the same name and should be located in the same package. Note that fields annotated with@FXML
or@Inject
only become accessible afterViewLoader.load()
is called. aView
class that loads the FXML file.
private Dependency dependency;
public AboutDialogView(Dependency dependency) {
this.dependency = dependency;
this.setTitle(Localization.lang("About JabRef"));
ViewLoader.view(this)
.load()
.setAsDialogPane(this);
}
- Dialogs should use setResultConverter to convert the data entered in the dialog to the desired result. This conversion should be done by the view model and not the controller.
setResultConverter(button -> {
if (button == ButtonType.OK) {
return viewModel.getData();
}
return null;
});
- The initialize method may use data-binding to connect the ui-controls and the
ViewModel
. However, it is recommended to do as much binding as possible directly in the FXML-file.
@FXML
private void initialize() {
viewModel = new AboutDialogViewModel(dialogService, dependency, ...);
helloLabel.textProperty().bind(viewModel.helloMessageProperty());
@FXML
private void openJabrefWebsite() {
viewModel.openJabrefWebsite();
}
The view consists a FXML file MyDialog.fxml
which defines the structure and the layout of the UI. Moreover, the FXML file may be accompanied by a style file that should have the same name as the FXML file but with a css
ending, e.g., MyDialog.css
. It is recommended to use a graphical design tools like SceneBuilder to edit the FXML file. The tool Scenic View is very helpful in debugging styling issues.
- curated list of awesome JavaFX frameworks, libraries, books and etc...
- ControlsFX amazing collection of controls
- usage of icon fonts with JavaFX or jIconFont or fontawesomefx
- Undo manager
- Docking manager or
- additional bindings or EasyBind
- Kubed: data visualization (inspired by d3)
- Validation framework
- mvvm framework
- CSS Reference
- JFoenix Material Designs look & feel
- FontAwesomeFX: supports different icon fonts
- JavaFX Documentation project: Collected information on javafx in a central place
- FXExperience JavaFX Links of the week
- bidirectional binding in FXML, see official feature request
- Home
- General Information
- Development
- Please go to our devdocs at https://devdocs.jabref.org
- "Google Summer of Code" project ideas
- Completed "Google Summer of Code" (GSoC) projects
- GSoC 2024 ‐ Improved CSL Support (and more LibreOffice‐JabRef integration enhancements)
- GSoC 2024 - Lucene Search Backend Integration
- GSoC 2024 ‐ AI‐Powered Summarization and “Interaction” with Academic Papers
- GSoC 2022 — Implement a Three Way Merge UI for merging BibTeX entries
- GSoC 2021 - Improve pdf support in JabRef
- GSoC 2021 - Microsoft Word Integration
- GSoc 2019 - Bidirectional Integration — Paper Writing — LaTeX and JabRef 5.0
- GSoC Archive
- Release
- JabCon Archive