You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by Michel Eisenmann <mi...@fr.ibm.com> on 2014/05/27 19:42:27 UTC

Swing and Pivot Integration using JPanel

Hi,

I'm integrating Pivot in my Swing application successfully except for the
transition/animation part. 

The way I've been doing things is the following:

- I've created my own ApplicationContext to ensure that the Pivot Timer was
properly created.

public class LocalApplicationContext extends ApplicationContext {
  static public LocalApplicationContext singleton = null;

  public LocalApplicationContext() {
    createTimer();
  }

  static public LocalApplicationContext GetOrCreate() {
    if (singleton != null) return singleton;
    singleton = new LocalApplicationContext();
    return singleton;
  }


- Then I use this singleton everytime I need to create a JPanel that
contains some Pivot widgets:

  public static NewPlanAreaBXML InitializePanel(JPanel panel,
SchemaCollector coll) {
    LocalApplicationContext.GetOrCreate();
    BXMLSerializer bxmlSerializer = new BXMLSerializer();
    ApplicationContext.DisplayHost displayHost = new
ApplicationContext.DisplayHost();
    try {
      panel.setLayout(new BorderLayout());
      // the BXML that will be inserted in the JPanel
      NewPlanAreaBXML window = (NewPlanAreaBXML)
bxmlSerializer.readObject(NewPlanAreaBXML.class
          .getResource(getXmlFile()));
      // 
      window.open(displayHost.getDisplay());
      window.setCollector(coll);
      panel.add(displayHost);
      panel.setPreferredSize(new Dimension(getDefaultWidth(),
getDefaultHeight()));
      return window;
    } catch (IOException e) {
      e.printStackTrace();
    } catch (SerializationException e) {
      e.printStackTrace();
    }
    return null;
  }

This is working pretty well for most of what I need. Except for
animations/transitions that seem to be triggered *ONLY* if I move the mouse. 

For example, I've built an accordion based on the tutorial example and when
I click on the next button, the actual change happens only when I move my
mouse. If I don't move my mouse, nothing happens. 

It looks like some event loop related issue but... well. Ideas are welcome.

Thanks in advance
Michel





--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Swing-and-Pivot-Integration-using-JPanel-tp4022931.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

RE: Swing and Pivot Integration using JPanel

Posted by Michel Eisenmann <mi...@fr.ibm.com>.
Hi Rodger

Thanks for your answer. I've been very busy till now and had no time to take
a look at your solution.
I'll do that as soon as I can. 

Will keep you updated with my success/failure... :-)

Regards
Michel




--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Swing-and-Pivot-Integration-using-JPanel-tp4022931p4022962.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

RE: Swing and Pivot Integration using JPanel

Posted by Roger Whitcomb <Ro...@actian.com>.
So, here's the way to hook into the display/event dispatch logic:

First, you need to be catching AWT window events, then on WINDOW_OPENED and WINDOW_CLOSED you need to hook your Display object into the Pivot ApplicationContext "displays" list:
    @Override
    public void processWindowEvent(WindowEvent event) {

        // Call the superclass implementation.
        super.processWindowEvent(event);

        switch (event.getID()) {
            case WindowEvent.WINDOW_OPENED:
                ApplicationContext.getDisplays().add(displayObject);
...
                break;
            // The WINDOW_CLOSED event.
            case WindowEvent.WINDOW_CLOSED:

                ApplicationContext.getDisplays().remove(displayObject);
                break;
        }
    }

I realize it may be more complicated than this, and I'm sure I don't understand completely what you're doing.  But, this is the crucial piece that we added to Pivot (access to the "Display" list) that is needed to make events / repaint work correctly.

HTH,
~Roger Whitcomb

-----Original Message-----
From: Roger and Beth Whitcomb [mailto:RogerandBeth@rbwhitcomb.com] 
Sent: Thursday, May 29, 2014 9:31 AM
To: user@pivot.apache.org
Subject: Re: Swing and Pivot Integration using JPanel

Hi Michel,
     There is one more thing needed -- there is a list of DisplayHost objects that is maintained for purposes of dispatching events.  We added a method/hook to be able to add your new object to this list. I don't have the code right in front of me -- but I will dig it out and let you know.

~Roger Whitcomb

On 5/27/14 10:42 AM, Michel Eisenmann wrote:
> Hi,
>
> I'm integrating Pivot in my Swing application successfully except for 
> the transition/animation part.
>
> The way I've been doing things is the following:
>
> - I've created my own ApplicationContext to ensure that the Pivot 
> Timer was properly created.
>
> public class LocalApplicationContext extends ApplicationContext {
>    static public LocalApplicationContext singleton = null;
>
>    public LocalApplicationContext() {
>      createTimer();
>    }
>
>    static public LocalApplicationContext GetOrCreate() {
>      if (singleton != null) return singleton;
>      singleton = new LocalApplicationContext();
>      return singleton;
>    }
>
>
> - Then I use this singleton everytime I need to create a JPanel that 
> contains some Pivot widgets:
>
>    public static NewPlanAreaBXML InitializePanel(JPanel panel, 
> SchemaCollector coll) {
>      LocalApplicationContext.GetOrCreate();
>      BXMLSerializer bxmlSerializer = new BXMLSerializer();
>      ApplicationContext.DisplayHost displayHost = new 
> ApplicationContext.DisplayHost();
>      try {
>        panel.setLayout(new BorderLayout());
>        // the BXML that will be inserted in the JPanel
>        NewPlanAreaBXML window = (NewPlanAreaBXML) 
> bxmlSerializer.readObject(NewPlanAreaBXML.class
>            .getResource(getXmlFile()));
>        //
>        window.open(displayHost.getDisplay());
>        window.setCollector(coll);
>        panel.add(displayHost);
>        panel.setPreferredSize(new Dimension(getDefaultWidth(), 
> getDefaultHeight()));
>        return window;
>      } catch (IOException e) {
>        e.printStackTrace();
>      } catch (SerializationException e) {
>        e.printStackTrace();
>      }
>      return null;
>    }
>
> This is working pretty well for most of what I need. Except for 
> animations/transitions that seem to be triggered *ONLY* if I move the mouse.
>
> For example, I've built an accordion based on the tutorial example and 
> when I click on the next button, the actual change happens only when I 
> move my mouse. If I don't move my mouse, nothing happens.
>
> It looks like some event loop related issue but... well. Ideas are welcome.
>
> Thanks in advance
> Michel
>
>
>
>
>
> --
> View this message in context: 
> http://apache-pivot-users.399431.n3.nabble.com/Swing-and-Pivot-Integra
> tion-using-JPanel-tp4022931.html Sent from the Apache Pivot - Users 
> mailing list archive at Nabble.com.
>
>


Re: Swing and Pivot Integration using JPanel

Posted by Roger and Beth Whitcomb <Ro...@rbwhitcomb.com>.
Hi Michel,
     There is one more thing needed -- there is a list of DisplayHost 
objects that is maintained for purposes of dispatching events.  We added 
a method/hook to be able to add your new object to this list. I don't 
have the code right in front of me -- but I will dig it out and let you 
know.

~Roger Whitcomb

On 5/27/14 10:42 AM, Michel Eisenmann wrote:
> Hi,
>
> I'm integrating Pivot in my Swing application successfully except for the
> transition/animation part.
>
> The way I've been doing things is the following:
>
> - I've created my own ApplicationContext to ensure that the Pivot Timer was
> properly created.
>
> public class LocalApplicationContext extends ApplicationContext {
>    static public LocalApplicationContext singleton = null;
>
>    public LocalApplicationContext() {
>      createTimer();
>    }
>
>    static public LocalApplicationContext GetOrCreate() {
>      if (singleton != null) return singleton;
>      singleton = new LocalApplicationContext();
>      return singleton;
>    }
>
>
> - Then I use this singleton everytime I need to create a JPanel that
> contains some Pivot widgets:
>
>    public static NewPlanAreaBXML InitializePanel(JPanel panel,
> SchemaCollector coll) {
>      LocalApplicationContext.GetOrCreate();
>      BXMLSerializer bxmlSerializer = new BXMLSerializer();
>      ApplicationContext.DisplayHost displayHost = new
> ApplicationContext.DisplayHost();
>      try {
>        panel.setLayout(new BorderLayout());
>        // the BXML that will be inserted in the JPanel
>        NewPlanAreaBXML window = (NewPlanAreaBXML)
> bxmlSerializer.readObject(NewPlanAreaBXML.class
>            .getResource(getXmlFile()));
>        //
>        window.open(displayHost.getDisplay());
>        window.setCollector(coll);
>        panel.add(displayHost);
>        panel.setPreferredSize(new Dimension(getDefaultWidth(),
> getDefaultHeight()));
>        return window;
>      } catch (IOException e) {
>        e.printStackTrace();
>      } catch (SerializationException e) {
>        e.printStackTrace();
>      }
>      return null;
>    }
>
> This is working pretty well for most of what I need. Except for
> animations/transitions that seem to be triggered *ONLY* if I move the mouse.
>
> For example, I've built an accordion based on the tutorial example and when
> I click on the next button, the actual change happens only when I move my
> mouse. If I don't move my mouse, nothing happens.
>
> It looks like some event loop related issue but... well. Ideas are welcome.
>
> Thanks in advance
> Michel
>
>
>
>
>
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Swing-and-Pivot-Integration-using-JPanel-tp4022931.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
>
>


Re: Swing and Pivot Integration using JPanel

Posted by Jamal BERRICH <jb...@gmail.com>.
Hi Michel,
   Try to use my Forum application converted to use Swing and Pivot.
   https://github.com/jberrich/SwingPivotIntegration
Best,
Jamal


2014-05-30 10:10 GMT+01:00 Michel Eisenmann <mi...@fr.ibm.com>:

> Hi Sandro
>
> Thanks for your answer.
>
> I'm using the standard 2.0.3 distribution.
>
> If you agree, I'll wait for Roger's answer before creating a Jira. It looks
> like he may have a solution already.
> Of course, if you want me to create the Jira, I'll do it nevertheless..
>
> Regards
> Michel
>
>
>
> --
> View this message in context:
> http://apache-pivot-users.399431.n3.nabble.com/Swing-and-Pivot-Integration-using-JPanel-tp4022931p4022940.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
>

Re: Swing and Pivot Integration using JPanel

Posted by Michel Eisenmann <mi...@fr.ibm.com>.
Hi Sandro

Thanks for your answer.

I'm using the standard 2.0.3 distribution. 

If you agree, I'll wait for Roger's answer before creating a Jira. It looks
like he may have a solution already.
Of course, if you want me to create the Jira, I'll do it nevertheless..

Regards
Michel



--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Swing-and-Pivot-Integration-using-JPanel-tp4022931p4022940.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Swing and Pivot Integration using JPanel

Posted by Roger and Beth Whitcomb <Ro...@rbwhitcomb.com>.
Hi Jamal,
     Thank you for the offer to help.  I'm hoping that we can improve 
the interoperability between Swing and Pivot for the 2.1 release. We 
have actually done some work in that regard as well, which I hope we can 
contribute back (things like displaying dialogs inside separate host 
windows, etc.)
     I think the problem is that the new JPanel (and its associated 
Pivot Display) needs to be registered in the windows list for event 
handling.  There was an accessor method/hook added to (I think) 
ApplicationContext to make this happen, since we needed it at one point 
as well.  Let me dig that up and comment back here.

~Roger

On 5/28/14 2:47 PM, Jamal BERRICH wrote:
> Hi,
>    Integrate Pivot and Swing isn't a simple task, does't work in all time.
>    I have working with Pivot and Swing to create an entreprise 
> application.
>    But if we have the majourite of the code, purhapase we can resolve 
> your probléme.
>
> Best,
> Jamal
>
>
> 2014-05-28 10:56 GMT+01:00 Sandro Martini <sandro.martini@gmail.com 
> <ma...@gmail.com>>:
>
>     Hi Michel,
>     could you create a jira issue for this, and post there a minimal
>     sample (working), to speedup our debugging sessions ?
>     For what I read it seems something related to events, but I have no
>     idea (maybe others of us can say something) ... so we have to debug.
>
>     Last, are you trying with latest 2.0.x release or do you use updates
>     sources from trunk ?
>
>     Thanks a lot,
>     Sandro
>
>


Re: Swing and Pivot Integration using JPanel

Posted by Michel Eisenmann <mi...@fr.ibm.com>.
Hi Jamal,

Thanks for your offer of assitance. I'll definitely look at the code you
published to
see what you did.

Regards

Michel




--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Swing-and-Pivot-Integration-using-JPanel-tp4022931p4022939.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Swing and Pivot Integration using JPanel

Posted by Jamal BERRICH <jb...@gmail.com>.
Hi,
   Integrate Pivot and Swing isn't a simple task, does't work in all time.
   I have working with Pivot and Swing to create an entreprise application.
   But if we have the majourite of the code, purhapase we can resolve your
probléme.

Best,
Jamal


2014-05-28 10:56 GMT+01:00 Sandro Martini <sa...@gmail.com>:

> Hi Michel,
> could you create a jira issue for this, and post there a minimal
> sample (working), to speedup our debugging sessions ?
> For what I read it seems something related to events, but I have no
> idea (maybe others of us can say something) ... so we have to debug.
>
> Last, are you trying with latest 2.0.x release or do you use updates
> sources from trunk ?
>
> Thanks a lot,
> Sandro
>

RE: Swing and Pivot Integration using JPanel

Posted by Roger Whitcomb <Ro...@actian.com>.
Thanks, Gunnar.  I will look  at this probably tomorrow.

~Roger

From: moosbusch [mailto:gkappei@web.de]
Sent: Monday, July 21, 2014 9:44 AM
To: user@pivot.apache.org
Subject: Re: Swing and Pivot Integration using JPanel

Hi Roger,

I've been able to provide a little app that suffers from the issues I
talked about. I attached the source to Jira (Pivo-952). Seems to be an
issue related to Windows. More information is provided via Jira.

@ Michel:

Mabe the code is helpful as a starting-point for your own development.
Please feel free to use it.

Sincerely,

Gunnar Kappei
________________________________
View this message in context: Re: Swing and Pivot Integration using JPanel<http://apache-pivot-users.399431.n3.nabble.com/Swing-and-Pivot-Integration-using-JPanel-tp4022931p4022974.html>
Sent from the Apache Pivot - Users mailing list archive<http://apache-pivot-users.399431.n3.nabble.com/> at Nabble.com.



Re: Swing and Pivot Integration using JPanel

Posted by moosbusch <gk...@web.de>.
Hi Roger,

I've been able to provide a little app that suffers from the issues I 
talked about. I attached the source to Jira (Pivo-952). Seems to be an
issue related to Windows. More information is provided via Jira.

@ Michel:

Mabe the code is helpful as a starting-point for your own development.
Please feel free to use it.

Sincerely,

Gunnar Kappei




--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Swing-and-Pivot-Integration-using-JPanel-tp4022931p4022974.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Swing and Pivot Integration using JPanel

Posted by Roger Whitcomb <Ro...@rbwhitcomb.com>.
Hi Gunnar,
   That's a very interesting find. I would be very interested if you share your code, or even just a minimal app that works. 

Thank you,
~Roger Whitcomb

Sent from my iPhone

> On Jul 19, 2014, at 10:36 AM, moosbusch <gk...@web.de> wrote:
> 
> Hi,
> 
> I came across this thread while I was working on a similar subject.
> I needed to display my Pivot-application in a JFrame.
> 
> I didn't succeed at first, although i followed the steps related to
> event-handling mentioned above.
> 
> Finally, I got a working solution:
> 
> After calling setVolatileImagePaintEnabled(false) on the DisplayHost all
> rendering issues were gone
> (Win 7, JDK 8u5, Pivot 2.04). I wonder if there's a need to use
> VolatileImages at all?
> 
> I tried displaying an Accordion which worked just fine! Animations are
> working well.
> 
> I could share the code if you want.
> 
> Sincerely,
> 
> Gunnar
> 
> 
> 
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Swing-and-Pivot-Integration-using-JPanel-tp4022931p4022972.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
> 

Re: Swing and Pivot Integration using JPanel

Posted by moosbusch <gk...@web.de>.
Hi,

I came across this thread while I was working on a similar subject.
I needed to display my Pivot-application in a JFrame.

I didn't succeed at first, although i followed the steps related to
event-handling mentioned above.

Finally, I got a working solution:

After calling setVolatileImagePaintEnabled(false) on the DisplayHost all
rendering issues were gone
(Win 7, JDK 8u5, Pivot 2.04). I wonder if there's a need to use
VolatileImages at all?

I tried displaying an Accordion which worked just fine! Animations are
working well.

I could share the code if you want.

Sincerely,

Gunnar



--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Swing-and-Pivot-Integration-using-JPanel-tp4022931p4022972.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Swing and Pivot Integration using JPanel

Posted by Michel Eisenmann <mi...@fr.ibm.com>.
Hi,

Just created the Jira (PIVOT-952).

Note that I've not been able to solve the issue yet with what you proposed
to do.
I suspect I don't understand... 

Regards
Michel



--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Swing-and-Pivot-Integration-using-JPanel-tp4022931p4022967.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Swing and Pivot Integration using JPanel

Posted by Roger Whitcomb <rw...@apache.org>.
Do you have a JIRA account?  You can go to 
https://issues.apache.org/jira/secure/Dashboard.jspa to create an 
account.  Then go to here: https://issues.apache.org/jira/browse/PIVOT 
and click on the "Create Issue" button at the top.  Then just fill in 
the fields.  You will be able to attach the example file once you have 
finished the create.

HTH,
~Roger

On 6/12/14 8:56 AM, Michel Eisenmann wrote:
> Hi,
>
> Finally got the time to create a small example to reproduce my issue.
> Can you guide me on the way to share this with you?
> Not sure how to create a Jira entry...
>
> Thanks again for your help.
>
> Regards
> Michel
>
>
>
>
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Swing-and-Pivot-Integration-using-JPanel-tp4022931p4022963.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
>
>


Re: Swing and Pivot Integration using JPanel

Posted by Michel Eisenmann <mi...@fr.ibm.com>.
Hi,

Finally got the time to create a small example to reproduce my issue.
Can you guide me on the way to share this with you? 
Not sure how to create a Jira entry...

Thanks again for your help.

Regards
Michel




--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Swing-and-Pivot-Integration-using-JPanel-tp4022931p4022963.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Swing and Pivot Integration using JPanel

Posted by Sandro Martini <sa...@gmail.com>.
Hi Michel,
could you create a jira issue for this, and post there a minimal
sample (working), to speedup our debugging sessions ?
For what I read it seems something related to events, but I have no
idea (maybe others of us can say something) ... so we have to debug.

Last, are you trying with latest 2.0.x release or do you use updates
sources from trunk ?

Thanks a lot,
Sandro