Uploaded image for project: 'Pivot'
  1. Pivot
  2. PIVOT-966

UI zooming and buttons detection in Apache Pivot at program start

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Not A Problem
    • Affects Version/s: 2.0.4, 2.1
    • Fix Version/s: 2.1, 2.0.5
    • Component/s: wtk-effects
    • Labels:
      None
    • Environment:
      Ubuntu 14.04 LTS 64bit, Oracle JDK 1.7.0-65

      Description

      Zooming UI at program start wents right but all buttons responds from wrong locations (as if the zoom/scale factor would still be the default 1.0).

      This effect can be easily tested with ApachePivot org.apache.pivot.demos.text.TextPaneDemo
      by adding ScaleDecorator & setScale before window.open(display) call like this:
      ....
      final ScaleDecorator sd = new ScaleDecorator();
      window.getDecorators().add( sd );
      sd.setHorizontalAlignment( HorizontalAlignment.LEFT );
      sd.setVerticalAlignment( VerticalAlignment.TOP );
      sd.setScale( 2.0f );
      sd.update();

      window.open(display);
      textPane.requestFocus();
      }

      The program UI will scale correctly the but buttons will react from wrong locations.

      There is a issue report in the pivot-user mailing list archives: March 2015 with the same header as well with more information.

        Activity

        Hide
        VirtualMachine Vesa Muukka added a comment -

        Hi,

        Tried to make a workaround for this by creating a keyboard (Ctrl Shift +) event and sending it to DisplayHost. The event was consumed correctly at but nothing happened in the UI...

        The code:

        exitButton.getComponentKeyListeners().add(new ComponentKeyListener.Adapter() {
        @Override
        public boolean keyPressed(Component component, int keyCode,
        KeyLocation keyLocation) {
        if (keyCode == Keyboard.KeyCode.ESCAPE)

        { long ms = new GregorianCalendar().getTimeInMillis(); KeyEvent event = new KeyEvent(hostFrame,401,ms,195,521,'?',1); //AWTEvent awtevent = new AWTEvent(); ApplicationContext.DisplayHost displayHost = new ApplicationContext.DisplayHost(); displayHost.processEvent( event ); return false; }

        return super.keyPressed(component, keyCode, keyLocation);
        }
        });

        Show
        VirtualMachine Vesa Muukka added a comment - Hi, Tried to make a workaround for this by creating a keyboard (Ctrl Shift +) event and sending it to DisplayHost. The event was consumed correctly at but nothing happened in the UI... The code: exitButton.getComponentKeyListeners().add(new ComponentKeyListener.Adapter() { @Override public boolean keyPressed(Component component, int keyCode, KeyLocation keyLocation) { if (keyCode == Keyboard.KeyCode.ESCAPE) { long ms = new GregorianCalendar().getTimeInMillis(); KeyEvent event = new KeyEvent(hostFrame,401,ms,195,521,'?',1); //AWTEvent awtevent = new AWTEvent(); ApplicationContext.DisplayHost displayHost = new ApplicationContext.DisplayHost(); displayHost.processEvent( event ); return false; } return super.keyPressed(component, keyCode, keyLocation); } });
        Hide
        smartini Sandro Martini added a comment -

        Hi, sorry for the delay but these weeke I'm really busy ... note that this feature has been discussed other times during years but it shouldn't be so simple to fix because of some Pivot internals.
        Your workaround could not work because it need e refresh/repaint, I can take a look but I need some time.
        I'll keep you updated. Bye

        Show
        smartini Sandro Martini added a comment - Hi, sorry for the delay but these weeke I'm really busy ... note that this feature has been discussed other times during years but it shouldn't be so simple to fix because of some Pivot internals. Your workaround could not work because it need e refresh/repaint, I can take a look but I need some time. I'll keep you updated. Bye
        Hide
        VirtualMachine Vesa Muukka added a comment -

        Hello,

        Ok, I understand. Take your time. I'am not so hurry with this, I just decided to try someting else.

        Anyway, I have to say that Apache Pivot is great tool. I haven't seen any UI tool which really separates the UI and program business logic. It is amazing how this helps creating simple (readable and easy to manage) applications. Four weeks and I am still excited.... You guys have done someting definetly right. Thanks.

        VM

        Show
        VirtualMachine Vesa Muukka added a comment - Hello, Ok, I understand. Take your time. I'am not so hurry with this, I just decided to try someting else. Anyway, I have to say that Apache Pivot is great tool. I haven't seen any UI tool which really separates the UI and program business logic. It is amazing how this helps creating simple (readable and easy to manage) applications. Four weeks and I am still excited.... You guys have done someting definetly right. Thanks. VM
        Hide
        VirtualMachine Vesa Muukka added a comment -

        Hi. Anything new with this? I could not get the workaround (above) working. I tried to add invalidate / validate / repaint calls to both hostframe and window components but no help.

        Show
        VirtualMachine Vesa Muukka added a comment - Hi. Anything new with this? I could not get the workaround (above) working. I tried to add invalidate / validate / repaint calls to both hostframe and window components but no help.
        Hide
        rwhitcomb Roger Whitcomb added a comment -

        In the Javadoc for ScaleDecorator it says this:

        • Decorator that scales the painting of a component along the X and/or Y axes.
        • <p> Generally speaking, decorators don't force a repaint of the component(s)
        • they are attached to when their parameters are changed. So, if this decorator
        • is changed after being applied to a particular component (e.g., to do a
        • dynamic resize) then either the component.repaint() method must be called or
        • the decorator should be removed and added again to force a repaint with the
        • new scale.

        So, does it help if you attach the ScaleDecorator to the Window AFTER setting all the decorator parameters (esp. the scale factor)? Something like this:
        ....
        final ScaleDecorator sd = new ScaleDecorator();
        sd.setHorizontalAlignment( HorizontalAlignment.LEFT );
        sd.setVerticalAlignment( VerticalAlignment.TOP );
        sd.setScale( 2.0f );
        sd.update();

        window.getDecorators().add( sd );
        window.open(display);
        ....
        (You've probably tried this, but just wanted to check...)

        Thanks,
        ~Roger

        Show
        rwhitcomb Roger Whitcomb added a comment - In the Javadoc for ScaleDecorator it says this: Decorator that scales the painting of a component along the X and/or Y axes. <p> Generally speaking, decorators don't force a repaint of the component(s) they are attached to when their parameters are changed. So, if this decorator is changed after being applied to a particular component (e.g., to do a dynamic resize) then either the component.repaint() method must be called or the decorator should be removed and added again to force a repaint with the new scale. So, does it help if you attach the ScaleDecorator to the Window AFTER setting all the decorator parameters (esp. the scale factor)? Something like this: .... final ScaleDecorator sd = new ScaleDecorator(); sd.setHorizontalAlignment( HorizontalAlignment.LEFT ); sd.setVerticalAlignment( VerticalAlignment.TOP ); sd.setScale( 2.0f ); sd.update(); window.getDecorators().add( sd ); window.open(display); .... (You've probably tried this, but just wanted to check...) Thanks, ~Roger
        Hide
        rwhitcomb Roger Whitcomb added a comment -

        Aha. So, my previous suggestion does not work, but this does:

        ...
        display.getDisplayHost().setScale(2.0d);
        window.open(display);
        ...

        No need for a ScaleDecorator, but simply scale the ApplicationContext.displayHost before opening the window.

        Show
        rwhitcomb Roger Whitcomb added a comment - Aha. So, my previous suggestion does not work, but this does: ... display.getDisplayHost().setScale(2.0d); window.open(display); ... No need for a ScaleDecorator, but simply scale the ApplicationContext.displayHost before opening the window.
        Hide
        VirtualMachine Vesa Muukka added a comment -

        Million thanks! This is all I need. Very good.

        Show
        VirtualMachine Vesa Muukka added a comment - Million thanks! This is all I need. Very good.
        Hide
        smartini Sandro Martini added a comment -

        Hi all and sorry for the delay ...

        Vesa: with the suggestion by Roger all is good so we can close this (non) issue (change to non-issue then mark as resolved or closed) ?

        Roger: do you think it would be good to add some info in JavaDoc to handle this case ?

        Show
        smartini Sandro Martini added a comment - Hi all and sorry for the delay ... Vesa: with the suggestion by Roger all is good so we can close this (non) issue (change to non-issue then mark as resolved or closed) ? Roger: do you think it would be good to add some info in JavaDoc to handle this case ?
        Hide
        rwhitcomb Roger Whitcomb added a comment -

        Yes I do think some Javadoc would be good. Any suggestions as to where would be best?
        Thanks.

        Show
        rwhitcomb Roger Whitcomb added a comment - Yes I do think some Javadoc would be good. Any suggestions as to where would be best? Thanks.
        Hide
        rwhitcomb Roger Whitcomb added a comment - - edited

        Using ApplicationContext.DisplayHost.setScale() is the right way to do this. Going to add some Javadoc to help with understanding this use case.

        Show
        rwhitcomb Roger Whitcomb added a comment - - edited Using ApplicationContext.DisplayHost.setScale() is the right way to do this. Going to add some Javadoc to help with understanding this use case.
        Hide
        smartini Sandro Martini added a comment -

        Great !!
        I'll wait for the commit.
        Thanks to all.

        Show
        smartini Sandro Martini added a comment - Great !! I'll wait for the commit. Thanks to all.
        Hide
        rwhitcomb Roger Whitcomb added a comment -

        Committed Javadoc changes:
        trunk:
        Sending wtk/src/org/apache/pivot/wtk/ApplicationContext.java
        Transmitting file data .
        Committed revision 1678238.

        branches/2.0.x:
        Sending .
        Sending wtk/src/org/apache/pivot/wtk/ApplicationContext.java
        Transmitting file data .
        Committed revision 1678239.

        Show
        rwhitcomb Roger Whitcomb added a comment - Committed Javadoc changes: trunk: Sending wtk/src/org/apache/pivot/wtk/ApplicationContext.java Transmitting file data . Committed revision 1678238. branches/2.0.x: Sending . Sending wtk/src/org/apache/pivot/wtk/ApplicationContext.java Transmitting file data . Committed revision 1678239.
        Hide
        VirtualMachine Vesa Muukka added a comment -

        Zooming works perfectly when using code
        display.getDisplayHost().setScale(2.0d);
        window.open(display);
        as Roger Whitcomb suggested. Thanks for all.

        Show
        VirtualMachine Vesa Muukka added a comment - Zooming works perfectly when using code display.getDisplayHost().setScale(2.0d); window.open(display); as Roger Whitcomb suggested. Thanks for all.
        Hide
        rwhitcomb Roger Whitcomb added a comment -

        Also committed changes to TextPaneDemo.java to demonstrate the use with a "--scale=n" startup property.

        trunk:
        Sending demos\src\org\apache\pivot\demos\text\TextPaneDemo.java
        Transmitting file data .
        Committed revision 1678251.

        branches/2.0.x:
        Sending .
        Sending demos\src\org\apache\pivot\demos\text\TextPaneDemo.java
        Transmitting file data .
        Committed revision 1678253.

        Show
        rwhitcomb Roger Whitcomb added a comment - Also committed changes to TextPaneDemo.java to demonstrate the use with a "--scale=n" startup property. trunk: Sending demos\src\org\apache\pivot\demos\text\TextPaneDemo.java Transmitting file data . Committed revision 1678251. branches/2.0.x: Sending . Sending demos\src\org\apache\pivot\demos\text\TextPaneDemo.java Transmitting file data . Committed revision 1678253.
        Hide
        rwhitcomb Roger Whitcomb added a comment -

        One more thing: using Ctrl-Shift-MouseWheel will scale the display up and down as well, for the user of your application.

        Show
        rwhitcomb Roger Whitcomb added a comment - One more thing: using Ctrl-Shift-MouseWheel will scale the display up and down as well, for the user of your application.
        Hide
        smartini Sandro Martini added a comment -

        Roger, sorry one last thing: what do you think on add more evidence (so even text search in sources could find this info in a simpler way) on this feature in the test app just updated ?
        For example writing to console when the application starts something like this:

        In this test application as a sample for setting the display scale on startup, use startup argument "-scale=n" property; for instance, using "-scale=2.0" will set double scale on the whole application.
        Anyway, using Ctrl-Shift-MouseWheel will scale the display up and down as well, for the user of your application

        I can do the change, tell me.
        Bye

        Show
        smartini Sandro Martini added a comment - Roger, sorry one last thing: what do you think on add more evidence (so even text search in sources could find this info in a simpler way) on this feature in the test app just updated ? For example writing to console when the application starts something like this: In this test application as a sample for setting the display scale on startup, use startup argument "- scale=n" property; for instance, using " -scale=2.0" will set double scale on the whole application. Anyway, using Ctrl-Shift-MouseWheel will scale the display up and down as well, for the user of your application I can do the change, tell me. Bye
        Hide
        rwhitcomb Roger Whitcomb added a comment -

        Go for it! Yes, that would be good to have instructions for the test application.

        Show
        rwhitcomb Roger Whitcomb added a comment - Go for it! Yes, that would be good to have instructions for the test application.
        Hide
        smartini Sandro Martini added a comment -

        Just committed all, both in 2.0.x and in trunk.

        Show
        smartini Sandro Martini added a comment - Just committed all, both in 2.0.x and in trunk.

          People

          • Assignee:
            rwhitcomb Roger Whitcomb
            Reporter:
            VirtualMachine Vesa Muukka
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development