JPro-one / JPro

The right place to report about bugs or suggest improvements for JPro.
https://www.jpro.one
9 stars 4 forks source link

Popup Resize #178

Open nyzzik opened 5 months ago

nyzzik commented 5 months ago

I am trying to resize a stage popup after calling WebAPI.openStageAsPopup(). I found a way to do it using javascript using window.resizeTo() however this is only working when i set it trigger on button press. If i call it after I popup the window i get this error. I have tried doing it in the JavaFX initialize method as well as setting up a window on load event listener using javascript and receive the same error. Is a way to resize the popup window?

Exception in thread "JavaFX Application Thread" java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:115)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at simplefx.util.ReflectionUtil$UseReflection.applyDynamic(ReflectionUtil.scala:21)
        at com.sun.glass.ui.monocle.input.fork.NativeMouseInput.notifyMouse(NativeMouseInput.scala:335)
        at com.sun.glass.ui.monocle.input.fork.NativeMouseInput.postMouseEvent(NativeMouseInput.scala:227)
        at com.sun.glass.ui.monocle.input.fork.NativeMouseInput.setState(NativeMouseInput.scala:186)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        at java.base/java.lang.reflect.Method.invoke(Method.java:580)
        at simplefx.util.ReflectionUtil$UseReflection.applyDynamic(ReflectionUtil.scala:21)
        at com.jpro.meta.tk.SceneInputListener.processInputInScene(SceneInputListener.scala:305)
        at com.jpro.meta.tk.SceneInputListener.processInput(SceneInputListener.scala:205)
        at com.jpro.meta.tk.SceneInputListener.processInputs(SceneInputListener.scala:132)
        at com.jpro.meta.tk.SceneInputListener.processOrRequest(SceneInputListener.scala:40)
        at com.jpro.meta.tk.SceneInputListener.$anonfun$new$4(SceneInputListener.scala:58)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
        at simplefx.cores.standard.parts.CoreTimeEvent$$anon$3.run(CoreTimeEvent.scala:62)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
        at com.sun.glass.ui.monocle.RunnableProcessor.runLoop(RunnableProcessor.java:92)
        at com.sun.glass.ui.monocle.RunnableProcessor.run(RunnableProcessor.java:51)
        at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.lang.NullPointerException: Cannot invoke "com.jpro.internal.communicator.InstanceImpl.views()" because the return value of "com.jpro.WebAPIImpl$ExtendStage.instance()" is null
        at com.jpro.WebAPIImpl$WebAPIImpl.addCommand(WebAPIImpl.scala:159)
        at com.jpro.WebAPIImpl$WebAPIImpl$JS$.$anonfun$evalFuture$1(WebAPIImpl.scala:135)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
        at simplefx.cores.interfaces.parts.testing.CoreTesting.inFX(CoreTesting.scala:21)
        at simplefx.cores.interfaces.parts.testing.CoreTesting.inFX$(CoreTesting.scala:18)
        at simplefx.cores.standard.Core.inFX(Core.scala:9)
        at com.jpro.WebAPIImpl$WebAPIImpl$JS$.evalFuture(WebAPIImpl.scala:135)
        at com.jpro.WebAPIImpl$WebAPIImpl.executeJSAsync(WebAPIImpl.scala:504)
        at ddg51.datavac.gui.AppMenuBar$6.handle(AppMenuBar.java:219)
        at ddg51.datavac.gui.AppMenuBar$6.handle(AppMenuBar.java:1)
        at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
        at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:232)
        at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:189)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
        at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
        at javafx.event.Event.fireEvent(Event.java:198)
        at javafx.scene.control.MenuItem.fire(MenuItem.java:459)
        at com.sun.javafx.scene.control.ContextMenuContent$MenuItemContainer.lambda$createNodeMenuItemChildren$14(ContextMenuContent.java:1437)
        at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:247)
        at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
        at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:232)
        at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:189)
        at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
        at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
        at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
        at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
        at javafx.event.Event.fireEvent(Event.java:198)
        at javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3737)
        at javafx.scene.Scene$MouseHandler.process(Scene.java:4042)
        at javafx.scene.Scene.processMouseEvent(Scene.java:1933)
        at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2757)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:411)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:301)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:450)
        at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:436)
        at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:449)
        at com.sun.glass.ui.View.handleMouseEvent(View.java:551)
        at com.sun.glass.ui.View.notifyMouse(View.java:937)
        at com.sun.glass.ui.monocle.MonocleView.notifyMouse(MonocleView.java:116)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
        ... 21 more
FlorianKirmaier commented 4 months ago

@nyzzik Can you test the latest 2024.2.2-SNAPSHOT build? Executing JS commands directly after calling WebAPI.openStageAsPopup() should work now.

We should probably also redesign the openStageAsPopup() API. Be aware, that when you set the owner of s Stage, it's always shown in the main application. Which could also be a solution to what you are trying to achieve.

nyzzik commented 4 months ago

On 2024.2.2-SNAPSHOT I am running into the same error

app.getWebAPI().openStageAsPopup(as);
WebAPI.getWebAPI(as.getScene()).executeJSAsync("window.resizeTo(700,300);");

This is the code I am trying to execute, app being my main JProApplication and as being the stage I am opening up.

FlorianKirmaier commented 4 months ago

Can you add the initial output of your server - with the JPro build-timestamp? This is to double-check that you are running the correct version. (You might have cached the previous build)

nyzzik commented 4 months ago
[INFO ] c.jpro.activity - Starting the server
[INFO ] c.j.i.s.JProInitializer$ -  *** Starting JPro: https://www.jpro.one/ ***
[INFO ] c.j.i.s.JProInitializer$ - OS: Windows 11
[INFO ] c.j.i.s.JProInitializer$ - JPro: 2024.2.2-SNAPSHOT
[INFO ] c.j.i.s.JProInitializer$ - JPro buildtime: Thu, 27 Jun 2024 11:57:03 -0400
[INFO ] c.j.i.s.JProInitializer$ - Java version: 21.0.2
[INFO ] c.j.i.s.JProInitializer$ - JVM: 21.0.2 Oracle Corporation
[INFO ] c.j.i.s.JProInitializer$ - JavaFX jar: file:/C:/Users/{my user}/.m2/repository/org/openjfx/javafx-graphics/22.0.2-jpro/javafx-graphics-22.0.2-jpro-win.jar
[INFO ] c.j.i.s.JProInitializer$ - Configuring logging from url: 'jar:file:/C:/Users/{my user}/.m2/repository/com/sandec/jpro/jpro-server_2.12/2024.2.2-SNAPSHOT/jpro-server_2.12-2024.2.2-SNAPSHOT.jar!/logback-jpro-default.xml'
[INFO ] c.j.i.s.JProInitializer$ - JavaFX version: 22.0.2-jpro+0
G1 Young Generation
G1 Concurrent GC
G1 Old Generation
[INFO ] c.j.i.s.JProInitializer$ - finished init!
[INFO ] c.j.i.s.JProInitializer$ - [JPro] -> Server started: {start_time: 1719936727164, os_name: Windows 11, jpro_version: 2024.2.2-SNAPSHOT}
[INFO ] a.e.s.Slf4jLogger - Slf4jLogger started
[INFO ] play.api.Play - Application started (Prod) (no global state)
[INFO ] p.c.s.AkkaHttpServer - Enabling HTTP/2 on Akka HTTP server...
[INFO ] p.c.s.AkkaHttpServer - Listening for HTTP on /0.0.0.0:8080
[INFO ] c.jpro - application requested: MyApp params: Map(instanceID -> List(573772191))
[INFO ] c.jpro - Creating Application: MyApp
[INFO ] c.jpro - remoteAddress 127.0.0.1
[INFO ] c.jpro - host          localhost:8080
[INFO ] c.jpro - uri           /app/ws/MyApp?instanceID=573772191
[INFO] [start] - 2024-07-02T12:12:11.300826 - JPro server is alive!
[INFO ] c.j.i.s.ViewInfo$ - [JPro] -> View created: {app_name: myapp, host_name: localhost:8080, instance_id: 782208353, browser: Unknown, browser_url: http://localhost:8080/, client_ip: 127.0.0.1}

It looks like i am running the correct version

nyzzik commented 4 months ago

After deleting the version that was in my .m2 repository and redownloading it, it looks like it is working now. It doesnt seem to be working in firefox but that seems to be a firefox thing not a jpro thing. Are there any other ways of resizing the popup or would this be it?

Thanks for the help.

FlorianKirmaier commented 4 months ago

I'm thinking about redesigning how the popup API works. Technically, we can set both the x/y position and the width and height. I guess it's still a surprise what the browser is doing with it. But that's a non-trivial improvement to JPro.

This is basically what the showStageAsPopup API is doing:

val quoted = JSONObject.quote(url)    executeScript(s"""window.open($quoted,'_blank','height=500,width=400,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes');""")

So you can copy it and adapt it to your needs.

However, I recommend against using "browser" popups; instead, show either the stage with the owner property or somehow show it inside the application.