-
Notifications
You must be signed in to change notification settings - Fork 3
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 #2 from carldea/feature/create-macos-sample-app-fo…
…r-blur Created a profile to run mac sample
- Loading branch information
Showing
16 changed files
with
773 additions
and
21 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
74 changes: 74 additions & 0 deletions
74
FXThemes-samples/src/main/java/com/pixelduke/samples/window/DarkThemeSampleMac.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,74 @@ | ||
package com.pixelduke.samples.window; | ||
|
||
import com.pixelduke.transit.Style; | ||
import com.pixelduke.transit.TransitStyleClass; | ||
import com.pixelduke.transit.TransitTheme; | ||
import com.pixelduke.window.ThemeWindowManager; | ||
import com.pixelduke.window.ThemeWindowManagerFactory; | ||
import javafx.application.Application; | ||
import javafx.collections.FXCollections; | ||
import javafx.scene.Scene; | ||
import javafx.scene.control.Button; | ||
import javafx.scene.control.ComboBox; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.layout.HBox; | ||
import javafx.scene.layout.StackPane; | ||
import javafx.scene.layout.VBox; | ||
import javafx.stage.Stage; | ||
import javafx.stage.StageStyle; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
/** | ||
* This version will showcase Mac Specific background blur behavior. | ||
* Two of the following to ensure the blur will take effect in JavaFX stage window. | ||
* <pre> | ||
* Note 1: Must use UNIFIED style for effect to work. | ||
* stage.initStyle(StageStyle.UNIFIED); | ||
* Note 2: Must use a transparent fill of the scene & root pane's background's alpha channel to work. | ||
* scene.setFill(javafx.scene.paint.Color.TRANSPARENT); | ||
* scene.getRoot().setStyle("-fx-background-color: rgba(255, 255, 255, 0.2);"); | ||
* </pre> | ||
*/ | ||
public class DarkThemeSampleMac extends Application { | ||
|
||
private final String darkModeOnLabel = "Switch to Dark mode"; | ||
private final String lightModeOnLabel = "Switch to Light mode"; | ||
|
||
public static void main(String[] args) { | ||
launch(args); | ||
} | ||
|
||
private static ThemeWindowManager themeWindowManager; | ||
|
||
@Override | ||
public void start(Stage stage) { | ||
themeWindowManager = ThemeWindowManagerFactory.create(); | ||
stage.setOnShown((windowEvent -> { | ||
System.out.println("ThemeWindowManager: " + themeWindowManager.getClass().getName()); | ||
themeWindowManager.setDarkModeForWindowFrame(stage, false); | ||
})); | ||
|
||
// Note 1: must use UNIFIED style for effect to work. | ||
stage.initStyle(StageStyle.UNIFIED); | ||
|
||
Button button = new Button(darkModeOnLabel); | ||
button.setOnAction((actionEvent -> { | ||
boolean isDark = darkModeOnLabel.equals(button.getText()); | ||
button.setText(isDark ? lightModeOnLabel : darkModeOnLabel); | ||
themeWindowManager.setDarkModeForWindowFrame(stage, isDark); | ||
})); | ||
stage.setTitle("DarkThemeSampleMac"); | ||
var root = new StackPane(button); | ||
var scene = new Scene(root, 640, 480); | ||
|
||
// Note 2: Must use a transparent fill of the scene & root pane's background's alpha channel to work. | ||
scene.setFill(javafx.scene.paint.Color.TRANSPARENT); | ||
scene.getRoot().setStyle("-fx-background-color: rgba(255, 255, 255, 0.2);"); | ||
stage.setScene(scene); | ||
stage.show(); | ||
stage.toFront(); | ||
} | ||
} |
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.