Skip to content

Commit

Permalink
Merge pull request #2 from carldea/feature/create-macos-sample-app-fo…
Browse files Browse the repository at this point in the history
…r-blur

Created a profile to run mac sample
  • Loading branch information
dukke committed Feb 26, 2024
2 parents f821755 + b12fddc commit 0878a7f
Show file tree
Hide file tree
Showing 16 changed files with 773 additions and 21 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ target/
.settings/

# Mac
.DS_Store
.DS_Store
xcuserdata/
**/xcuserdata/*
FXThemes/src/main/java/impl/com/pixelduke/window/macos/macos10_10/FXThemes.xcodeproj/project.xcworkspace/xcuserdata/
34 changes: 25 additions & 9 deletions FXThemes-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,48 +17,47 @@
<artifactId>fxthemes-samples</artifactId>
<version>1.2.0</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<os-classifier>win</os-classifier>
<forceUploadingPainter>true</forceUploadingPainter>
</properties>

<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
<version>20.0.2</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>20.0.2</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>20.0.2</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>20.0.2</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<version>20.0.2</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>20.0.2</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>20.0.2</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>com.pixelduke</groupId>
Expand All @@ -72,6 +71,23 @@
</dependency>
</dependencies>

<profiles>
<!-- MacOS X compiling step -->
<profile>
<id>mac</id>
<activation>
<os>
<family>mac</family>
</os>
</activation>
<properties>
<xcodeScheme>Debug</xcodeScheme>
<my.property>running.on.mac</my.property>
<forceUploadingPainter>false</forceUploadingPainter>
</properties>
</profile>
</profiles>

<build>
<plugins>
<plugin>
Expand All @@ -92,7 +108,7 @@
<!-- Default configuration for running with: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>com.pixelduke.samples.window.Windows11BackdropSample</mainClass>
<mainClass>com.pixelduke.samples.fxthemes/com.pixelduke.samples.window.DarkThemeSample</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>
Expand All @@ -101,7 +117,7 @@
<noHeaderFiles>true</noHeaderFiles>
<options>
<!-- So that changing the background of a native Window works well (at least on some machines using win11) -->
<option>-Dprism.forceUploadingPainter=true</option>
<option>-Dprism.forceUploadingPainter=${forceUploadingPainter}</option>
<!-- For getting the native window handle (WindowUtils.getNativeHandleForStage method) -->
<option>--add-opens</option>
<option>javafx.graphics/javafx.stage=com.pixelduke.fxthemes</option>
Expand Down
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();
}
}
74 changes: 72 additions & 2 deletions FXThemes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,60 @@
<system>GitHub</system>
<url>https://github.com/dukke/FXThemes/issues</url>
</issueManagement>

<profiles>
<!-- MacOS X compiling step -->
<profile>
<id>mac</id>
<activation>
<os>
<family>mac</family>
</os>
</activation>
<properties>
<xcodeScheme>Debug</xcodeScheme>
<my.property>running.on.mac</my.property>
</properties>
<build>
<plugins>
<!-- native MacOS Objective-C build -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>xcodebuild</id>
<phase>generate-resources</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>xcodebuild</executable>
<arguments>
<argument>-project</argument>
<argument>src/main/java/impl/com/pixelduke/window/macos/macos10_10/FXThemes.xcodeproj</argument>
<argument>-scheme</argument>
<argument>FXThemes</argument>
<argument>-configuration</argument>
<argument>${xcodeScheme}</argument>
<argument>CONFIGURATION_BUILD_DIR=${project.build.outputDirectory}</argument>
<argument>build</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<xcodeScheme>Debug</xcodeScheme>
</properties>

<licenses>
<license>
<name>GNU General Public License, version 2, with the Classpath Exception</name>
Expand All @@ -39,6 +93,9 @@
<developer>
<name>Pedro Duque Vieira</name>
</developer>
<developer>
<name>Carl Dea</name>
</developer>
</developers>

<build>
Expand All @@ -56,6 +113,21 @@
<artifactId>maven-jar-plugin</artifactId>
<version>3.3.0</version>
</plugin>
<!-- display active profile in compile phase -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-help-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>show-profiles</id>
<phase>compile</phase>
<goals>
<goal>active-profiles</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down Expand Up @@ -93,13 +165,11 @@
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>21</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>21</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
Expand Down

0 comments on commit 0878a7f

Please sign in to comment.