Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created a profile to run mac sample #2

Merged
merged 8 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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/
69 changes: 60 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,56 @@
</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>
<build>
<plugins>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<executions>
<execution>
<!-- Default configuration for running with: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>com.pixelduke.samples.window.DarkThemeSampleMac</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>
<noManPages>true</noManPages>
<stripDebug>true</stripDebug>
<noHeaderFiles>true</noHeaderFiles>
<options>
<!-- For getting the native window handle (WindowUtils.getNativeHandleForStage method) -->
<option>--add-opens</option>
<option>javafx.graphics/javafx.stage=com.pixelduke.fxthemes</option>
<option>--add-exports</option>
<option>javafx.graphics/com.sun.javafx.tk.quantum=com.pixelduke.fxthemes</option>
<option>--add-exports</option>
<option>javafx.graphics/com.sun.glass.ui=com.pixelduke.fxthemes</option>
</options>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<build>
<plugins>
<plugin>
Expand All @@ -92,7 +141,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.window.DarkThemeSample</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>
Expand All @@ -101,12 +150,14 @@
<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>
<option>--add-exports</option>
<option>javafx.graphics/com.sun.javafx.tk.quantum=com.pixelduke.fxthemes</option>
<option>--add-exports</option>
<option>javafx.graphics/com.sun.glass.ui=com.pixelduke.fxthemes</option>
dukke marked this conversation as resolved.
Show resolved Hide resolved
</options>
</configuration>
</execution>
Expand Down
dukke marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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;

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();
}
}
72 changes: 72 additions & 0 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