-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added first version of visibility property
- Loading branch information
1 parent
f4eefac
commit 5642b63
Showing
6 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...x-demo/src/main/java/com/dlsc/preferencesfx/demo/visibility/VisibilityDemoAppStarter.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,35 @@ | ||
package com.dlsc.preferencesfx.demo.visibility; | ||
|
||
import javafx.application.Application; | ||
import javafx.scene.Scene; | ||
import javafx.scene.control.Tab; | ||
import javafx.scene.control.TabPane; | ||
import javafx.scene.layout.Pane; | ||
import javafx.stage.Stage; | ||
|
||
public class VisibilityDemoAppStarter extends Application { | ||
|
||
public static void main(String[] args) { | ||
launch(args); | ||
} | ||
|
||
@Override | ||
public void start(Stage primaryStage) { | ||
TabPane tabPane = new TabPane(); | ||
Pane[] panels = new Pane[] {new VisibilityNodeExample()}; | ||
|
||
for (Pane pane : panels) { | ||
tabPane.getTabs().add(new Tab(pane.getClass().getSimpleName().replace("Example", ""), pane)); | ||
} | ||
|
||
Scene mainScene = new Scene(tabPane); | ||
|
||
primaryStage.setTitle("Visibility PreferencesFX Demo"); | ||
primaryStage.setScene(mainScene); | ||
primaryStage.setWidth(1000); | ||
primaryStage.setHeight(700); | ||
primaryStage.show(); | ||
primaryStage.centerOnScreen(); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...esfx-demo/src/main/java/com/dlsc/preferencesfx/demo/visibility/VisibilityNodeExample.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,39 @@ | ||
package com.dlsc.preferencesfx.demo.visibility; | ||
|
||
import com.dlsc.preferencesfx.PreferencesFx; | ||
import com.dlsc.preferencesfx.model.Category; | ||
import com.dlsc.preferencesfx.model.Group; | ||
import com.dlsc.preferencesfx.model.Setting; | ||
import javafx.beans.property.BooleanProperty; | ||
import javafx.beans.property.IntegerProperty; | ||
import javafx.beans.property.SimpleBooleanProperty; | ||
import javafx.beans.property.SimpleIntegerProperty; | ||
import javafx.scene.layout.StackPane; | ||
|
||
public class VisibilityNodeExample extends StackPane { | ||
|
||
public PreferencesFx preferencesFx; | ||
|
||
IntegerProperty brightness = new SimpleIntegerProperty(50); | ||
|
||
BooleanProperty nightMode = new SimpleBooleanProperty(true); | ||
|
||
public VisibilityNodeExample() { | ||
preferencesFx = createPreferences(); | ||
getChildren().add(new VisibilityNodeView(preferencesFx, this)); | ||
} | ||
|
||
private PreferencesFx createPreferences() { | ||
SimpleBooleanProperty visibilityProperty = new SimpleBooleanProperty(true); | ||
brightness.addListener((observable, oldValue, newValue) -> { visibilityProperty.set(newValue.intValue() > 50); }); | ||
|
||
return PreferencesFx.of(VisibilityNodeExample.class, | ||
Category.of("General", | ||
Group.of("Display", | ||
Setting.of("Brightness", brightness), | ||
Setting.of("Night mode", nightMode, visibilityProperty) | ||
) | ||
) | ||
).persistWindowState(false).saveSettings(true).debugHistoryMode(false).buttonsVisibility(true); | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
...encesfx-demo/src/main/java/com/dlsc/preferencesfx/demo/visibility/VisibilityNodeView.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,92 @@ | ||
package com.dlsc.preferencesfx.demo.visibility; | ||
|
||
import com.dlsc.preferencesfx.PreferencesFx; | ||
import com.dlsc.preferencesfx.demo.AppStarter; | ||
import com.dlsc.preferencesfx.view.PreferencesFxView; | ||
import javafx.geometry.Insets; | ||
import javafx.scene.control.Button; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.layout.BorderPane; | ||
import javafx.scene.layout.HBox; | ||
import javafx.scene.layout.Priority; | ||
import javafx.scene.layout.VBox; | ||
|
||
public class VisibilityNodeView extends VBox { | ||
private PreferencesFx preferencesFx; | ||
private VisibilityNodeExample rootPane; | ||
|
||
private Label brightnessLabel; | ||
private Label nightModeLabel; | ||
|
||
public VisibilityNodeView(PreferencesFx preferencesFx, VisibilityNodeExample rootPane) { | ||
this.preferencesFx = preferencesFx; | ||
this.rootPane = rootPane; | ||
|
||
initializeParts(); | ||
layoutParts(); | ||
setupBindings(); | ||
setupListeners(); | ||
} | ||
|
||
private void initializeParts() { | ||
brightnessLabel = new Label(); | ||
nightModeLabel = new Label(); | ||
} | ||
|
||
private void layoutParts() { | ||
// VBox with values | ||
VBox valueBox = new VBox( | ||
brightnessLabel, | ||
nightModeLabel | ||
); | ||
|
||
valueBox.setSpacing(20); | ||
valueBox.setPadding(new Insets(20, 0, 0, 20)); | ||
Button saveSettingsButton = new Button("Save Settings"); | ||
saveSettingsButton.setOnAction(event -> preferencesFx.saveSettings()); | ||
Button discardChangesButton = new Button("Discard Changes"); | ||
discardChangesButton.setOnAction(event -> preferencesFx.discardChanges()); | ||
// VBox with descriptions | ||
VBox descriptionBox = new VBox( | ||
new Label("Brightness:"), | ||
new Label("Night mode:"), | ||
saveSettingsButton, | ||
discardChangesButton | ||
); | ||
descriptionBox.setSpacing(20); | ||
descriptionBox.setPadding(new Insets(20, 0, 0, 20)); | ||
|
||
PreferencesFxView preferencesFxView = preferencesFx.getView(); | ||
// Put everything together | ||
BorderPane pane = new BorderPane(); | ||
HBox hBox = new HBox(descriptionBox, valueBox); | ||
pane.setLeft(hBox); | ||
hBox.setPadding(new Insets(0, 20, 0, 0)); | ||
pane.setCenter(preferencesFxView); | ||
VBox.setVgrow(pane, Priority.ALWAYS); | ||
getChildren().addAll( | ||
pane | ||
); | ||
|
||
// Styling | ||
getStyleClass().add("demo-view"); | ||
if (rootPane.nightMode.get()) { | ||
getStylesheets().add(AppStarter.class.getResource("darkTheme.css").toExternalForm()); | ||
} | ||
} | ||
|
||
private void setupBindings() { | ||
brightnessLabel.textProperty().bind(rootPane.brightness.asString().concat("%")); | ||
nightModeLabel.textProperty().bind(rootPane.nightMode.asString()); | ||
} | ||
|
||
private void setupListeners() { | ||
rootPane.nightMode.addListener((observable, oldValue, newValue) -> { | ||
if (newValue) { | ||
getStylesheets().add(AppStarter.class.getResource("darkTheme.css").toExternalForm()); | ||
} else { | ||
getStylesheets().remove(AppStarter.class.getResource("darkTheme.css").toExternalForm()); | ||
} | ||
}); | ||
} | ||
} |
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