You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2020/06/26 07:10:58 UTC

[isis] branch master updated: ISIS-2340: fx: adds application icon

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new 5a60445  ISIS-2340: fx: adds application icon
5a60445 is described below

commit 5a60445d8424acf2cb334faad970d8a7105f60ce
Author: Andi Huber <ah...@apache.org>
AuthorDate: Fri Jun 26 09:10:42 2020 +0200

    ISIS-2340: fx: adds application icon
---
 .../main/java/demoapp/javafx/DemoAppJavaFx.java    |   2 ++
 .../javafx/src/main/java/demoapp/javafx/icon.png   | Bin 0 -> 1597 bytes
 .../javafx/model/events/JavaFxViewerConfig.java    |   4 +++
 .../viewer/javafx/ui/main/UiActionHandler.java     |  19 +++++++++++++
 .../incubator/viewer/javafx/ui/main/UiBuilder.java |  31 +++++++++++++++------
 5 files changed, 48 insertions(+), 8 deletions(-)

diff --git a/examples/demo/javafx/src/main/java/demoapp/javafx/DemoAppJavaFx.java b/examples/demo/javafx/src/main/java/demoapp/javafx/DemoAppJavaFx.java
index e18cdbd..524d977 100644
--- a/examples/demo/javafx/src/main/java/demoapp/javafx/DemoAppJavaFx.java
+++ b/examples/demo/javafx/src/main/java/demoapp/javafx/DemoAppJavaFx.java
@@ -31,6 +31,7 @@ import org.apache.isis.incubator.viewer.javafx.viewer.JavafxViewer;
 import org.apache.isis.security.bypass.IsisModuleSecurityBypass;
 
 import demoapp.dom.DemoModule;
+import javafx.scene.image.Image;
 
 /**
  * Bootstrap the application.
@@ -50,6 +51,7 @@ public class DemoAppJavaFx {
     public JavaFxViewerConfig viewerConfig() {
         return JavaFxViewerConfig.builder()
                 .applicationTitle("Apache Isis Demo")
+                .applicationIcon(new Image(DemoAppJavaFx.class.getResourceAsStream("icon.png")))
                 .build();
     }
 
diff --git a/examples/demo/javafx/src/main/java/demoapp/javafx/icon.png b/examples/demo/javafx/src/main/java/demoapp/javafx/icon.png
new file mode 100644
index 0000000..d1b0ea1
Binary files /dev/null and b/examples/demo/javafx/src/main/java/demoapp/javafx/icon.png differ
diff --git a/incubator/viewers/javafx/model/src/main/java/org/apache/isis/incubator/viewer/javafx/model/events/JavaFxViewerConfig.java b/incubator/viewers/javafx/model/src/main/java/org/apache/isis/incubator/viewer/javafx/model/events/JavaFxViewerConfig.java
index 285caa7..c95e9be 100644
--- a/incubator/viewers/javafx/model/src/main/java/org/apache/isis/incubator/viewer/javafx/model/events/JavaFxViewerConfig.java
+++ b/incubator/viewers/javafx/model/src/main/java/org/apache/isis/incubator/viewer/javafx/model/events/JavaFxViewerConfig.java
@@ -24,12 +24,16 @@ import org.springframework.core.io.Resource;
 import lombok.Builder;
 import lombok.Getter;
 
+import javafx.scene.image.Image;
+
 @Getter @Builder
 public class JavaFxViewerConfig {
 
     private String applicationTitle;
+    private Image applicationIcon;
     
     @Builder.Default
     private Resource uiLayout = new ClassPathResource("/ui.fxml");
     
+    
 }
diff --git a/incubator/viewers/javafx/ui/src/main/java/org/apache/isis/incubator/viewer/javafx/ui/main/UiActionHandler.java b/incubator/viewers/javafx/ui/src/main/java/org/apache/isis/incubator/viewer/javafx/ui/main/UiActionHandler.java
index a3a8df3..aca2143 100644
--- a/incubator/viewers/javafx/ui/src/main/java/org/apache/isis/incubator/viewer/javafx/ui/main/UiActionHandler.java
+++ b/incubator/viewers/javafx/ui/src/main/java/org/apache/isis/incubator/viewer/javafx/ui/main/UiActionHandler.java
@@ -1,3 +1,21 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
 package org.apache.isis.incubator.viewer.javafx.ui.main;
 
 import java.util.function.Consumer;
@@ -33,6 +51,7 @@ public class UiActionHandler {
         log.info("about to build an action prompt for {}", managedAction.getIdentifier());
         
         // TODO get an ActionPrompt, then on invocation show the result in the content view
+        
 
         isisInteractionFactory.runAnonymous(()->{
 
diff --git a/incubator/viewers/javafx/ui/src/main/java/org/apache/isis/incubator/viewer/javafx/ui/main/UiBuilder.java b/incubator/viewers/javafx/ui/src/main/java/org/apache/isis/incubator/viewer/javafx/ui/main/UiBuilder.java
index b6e3e9e..9913e22 100644
--- a/incubator/viewers/javafx/ui/src/main/java/org/apache/isis/incubator/viewer/javafx/ui/main/UiBuilder.java
+++ b/incubator/viewers/javafx/ui/src/main/java/org/apache/isis/incubator/viewer/javafx/ui/main/UiBuilder.java
@@ -18,6 +18,8 @@
  */
 package org.apache.isis.incubator.viewer.javafx.ui.main;
 
+import java.util.Optional;
+
 import javax.inject.Inject;
 
 import org.springframework.context.ApplicationContext;
@@ -37,6 +39,7 @@ import lombok.extern.log4j.Log4j2;
 import javafx.fxml.FXMLLoader;
 import javafx.scene.Parent;
 import javafx.scene.Scene;
+import javafx.stage.Stage;
 
 @Component
 @RequiredArgsConstructor(onConstructor_ = {@Inject})
@@ -45,7 +48,6 @@ public class UiBuilder {
     
     private final ApplicationContext springContext;
     private final JavaFxViewerConfig viewerConfig;
-    private Scene scene;
 
     @EventListener(PrimaryStageReadyEvent.class)
     @SneakyThrows
@@ -58,17 +60,14 @@ public class UiBuilder {
         val scene = new Scene(uiRoot);
         val stage = event.getStage();
         stage.setScene(scene);
-        stage.setTitle(viewerConfig.getApplicationTitle());
-        stage.show();
+        setupTitle(stage);
+        setupIcon(stage);
         
-        this.scene = scene;
+        stage.show();
     }
-    
+
     @EventListener(IsisInteractionLifecycleEvent.class)
     public void onIsisInteractionLifecycleEvent(IsisInteractionLifecycleEvent event) {
-        if(scene==null) {
-            return;
-        }
         switch(event.getEventType()) {
         case HAS_STARTED:
             //TODO this would be the place to indicate to the user, that a long running task has started  
@@ -86,6 +85,22 @@ public class UiBuilder {
         
     }
     
+    // -- HELPER
+        
+    private void setupTitle(Stage stage) {
+        val title = Optional.ofNullable(viewerConfig.getApplicationTitle())
+                .orElse("Unknonw Title");
+        stage.setTitle(title);
+    }
+    
+    private void setupIcon(Stage stage) {
+        val icon = viewerConfig.getApplicationIcon();
+        if(icon==null) {
+            return; 
+        }
+        stage.getIcons().add(icon);
+    }
+    
     
 
 }