-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the
UserInterfacePanel
with MVC in mind (#1779)
- refactor the UserInterfacePanel with MVC in mind - remove the ":" from after "Theme:"
- Loading branch information
Showing
4 changed files
with
263 additions
and
124 deletions.
There are no files selected for viewing
127 changes: 127 additions & 0 deletions
127
...afx/src/main/java/org/phoenicis/javafx/components/setting/control/UserInterfacePanel.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,127 @@ | ||
package org.phoenicis.javafx.components.setting.control; | ||
|
||
import javafx.beans.property.*; | ||
import javafx.collections.ObservableList; | ||
import org.phoenicis.javafx.components.common.control.ControlBase; | ||
import org.phoenicis.javafx.components.setting.skin.UserInterfacePanelSkin; | ||
import org.phoenicis.javafx.views.common.themes.Theme; | ||
|
||
/** | ||
* A panel containing the user interface settings | ||
*/ | ||
public class UserInterfacePanel extends ControlBase<UserInterfacePanel, UserInterfacePanelSkin> { | ||
/** | ||
* A list containing all available themes | ||
*/ | ||
private final ObservableList<Theme> themes; | ||
|
||
/** | ||
* The currently selected theme. This value should never be null | ||
*/ | ||
private final ObjectProperty<Theme> selectedTheme; | ||
|
||
/** | ||
* True if the source repository of a script should be shown | ||
*/ | ||
private final BooleanProperty showScriptSource; | ||
|
||
/** | ||
* The user interface scaling | ||
*/ | ||
private final DoubleProperty scaling; | ||
|
||
/** | ||
* Callback for the restore settings button | ||
*/ | ||
private final ObjectProperty<Runnable> onRestoreSettings; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param themes A list containing all available themes | ||
* @param selectedTheme The currently selected theme. This value should never be null | ||
* @param showScriptSource True if the source repository of a script should be shown | ||
* @param scaling The user interface scaling | ||
* @param onRestoreSettings Callback for the restore settings button | ||
*/ | ||
public UserInterfacePanel(ObservableList<Theme> themes, ObjectProperty<Theme> selectedTheme, | ||
BooleanProperty showScriptSource, DoubleProperty scaling, ObjectProperty<Runnable> onRestoreSettings) { | ||
super(); | ||
|
||
this.themes = themes; | ||
this.selectedTheme = selectedTheme; | ||
this.showScriptSource = showScriptSource; | ||
this.scaling = scaling; | ||
this.onRestoreSettings = onRestoreSettings; | ||
} | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param themes A list containing all available themes | ||
*/ | ||
public UserInterfacePanel(ObservableList<Theme> themes) { | ||
this(themes, new SimpleObjectProperty<>(), new SimpleBooleanProperty(), new SimpleDoubleProperty(), | ||
new SimpleObjectProperty<>()); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public UserInterfacePanelSkin createSkin() { | ||
return new UserInterfacePanelSkin(this); | ||
} | ||
|
||
public ObservableList<Theme> getThemes() { | ||
return this.themes; | ||
} | ||
|
||
public Theme getSelectedTheme() { | ||
return this.selectedTheme.get(); | ||
} | ||
|
||
public ObjectProperty<Theme> selectedThemeProperty() { | ||
return this.selectedTheme; | ||
} | ||
|
||
public void setSelectedTheme(Theme selectedTheme) { | ||
this.selectedTheme.set(selectedTheme); | ||
} | ||
|
||
public boolean isShowScriptSource() { | ||
return this.showScriptSource.get(); | ||
} | ||
|
||
public BooleanProperty showScriptSourceProperty() { | ||
return this.showScriptSource; | ||
} | ||
|
||
public void setShowScriptSource(boolean showScriptSource) { | ||
this.showScriptSource.set(showScriptSource); | ||
} | ||
|
||
public double getScaling() { | ||
return this.scaling.get(); | ||
} | ||
|
||
public DoubleProperty scalingProperty() { | ||
return this.scaling; | ||
} | ||
|
||
public void setScaling(double scaling) { | ||
this.scaling.set(scaling); | ||
} | ||
|
||
public Runnable getOnRestoreSettings() { | ||
return this.onRestoreSettings.get(); | ||
} | ||
|
||
public ObjectProperty<Runnable> onRestoreSettingsProperty() { | ||
return this.onRestoreSettings; | ||
} | ||
|
||
public void setOnRestoreSettings(Runnable onRestoreSettings) { | ||
this.onRestoreSettings.set(onRestoreSettings); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
...fx/src/main/java/org/phoenicis/javafx/components/setting/skin/UserInterfacePanelSkin.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,83 @@ | ||
package org.phoenicis.javafx.components.setting.skin; | ||
|
||
import javafx.beans.binding.Bindings; | ||
import javafx.scene.control.*; | ||
import javafx.scene.layout.GridPane; | ||
import javafx.scene.layout.VBox; | ||
import javafx.scene.text.Text; | ||
import org.phoenicis.javafx.components.common.skin.SkinBase; | ||
import org.phoenicis.javafx.components.setting.control.UserInterfacePanel; | ||
import org.phoenicis.javafx.views.common.themes.Theme; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.phoenicis.configuration.localisation.Localisation.tr; | ||
|
||
/** | ||
* The skin for the {@link UserInterfacePanel} component | ||
*/ | ||
public class UserInterfacePanelSkin extends SkinBase<UserInterfacePanel, UserInterfacePanelSkin> { | ||
/** | ||
* Constructor | ||
* | ||
* @param control The control belonging to the skin | ||
*/ | ||
public UserInterfacePanelSkin(UserInterfacePanel control) { | ||
super(control); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
public void initialise() { | ||
final Text title = new Text(tr("User Interface Settings")); | ||
title.getStyleClass().add("title"); | ||
|
||
final GridPane themeGrid = new GridPane(); | ||
themeGrid.getStyleClass().add("grid"); | ||
themeGrid.setHgap(20); | ||
themeGrid.setVgap(10); | ||
|
||
// change theme | ||
final Text themeLabel = new Text(tr("Theme")); | ||
themeLabel.getStyleClass().add("captionTitle"); | ||
|
||
final ComboBox<Theme> themeSelection = new ComboBox<>(); | ||
themeSelection.valueProperty().bindBidirectional(getControl().selectedThemeProperty()); | ||
|
||
Bindings.bindContent(themeSelection.getItems(), getControl().getThemes()); | ||
|
||
// view script sources | ||
final Label showScriptSourceLabel = new Label(tr("View the scripts’ source repository")); | ||
showScriptSourceLabel.getStyleClass().add("captionTitle"); | ||
|
||
final CheckBox showScriptSourceSelection = new CheckBox(); | ||
showScriptSourceSelection.selectedProperty().bindBidirectional(getControl().showScriptSourceProperty()); | ||
|
||
// scale UI | ||
final Label scalingLabel = new Label(tr("Scale the user interface")); | ||
scalingLabel.getStyleClass().add("captionTitle"); | ||
|
||
final Slider scalingSelection = new Slider(); | ||
scalingSelection.setMin(8); | ||
scalingSelection.setMax(16); | ||
scalingSelection.valueProperty().bindBidirectional(getControl().scalingProperty()); | ||
|
||
// restore default | ||
final Button restoreDefaultButton = new Button(tr("Restore defaults (requires restart)")); | ||
restoreDefaultButton.setOnAction( | ||
event -> Optional.ofNullable(getControl().getOnRestoreSettings()).ifPresent(Runnable::run)); | ||
|
||
themeGrid.addRow(0, themeLabel, themeSelection); | ||
themeGrid.addRow(1, showScriptSourceLabel, showScriptSourceSelection); | ||
themeGrid.addRow(2, scalingLabel, scalingSelection); | ||
themeGrid.add(restoreDefaultButton, 1, 3); | ||
|
||
final VBox container = new VBox(title, themeGrid); | ||
|
||
container.getStyleClass().add("containerConfigurationPane"); | ||
|
||
getChildren().setAll(container); | ||
} | ||
} |
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
Oops, something went wrong.