Drag frames beyond app window?

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Drag frames beyond app window?

Josh Highley
Is it possible to create a non-modal frame (or similar) that can be dragged outside the main application window? 

For example, I have a log console Frame and some other non-modal info Frames that a user can show/hide.  I want them to be able to drag it out from in front of the main application window, like to another monitor.  At the moment, the Frames will get cutoff when they pass the edge of the underlying app window.

Thanks,

Josh
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Drag frames beyond app window?

Roger and Beth Whitcomb
Hi Josh,

     Yes it is, but it is complicated.  You basically have to create a
new top-level JFrame, and host the Pivot window inside that, and do the
message passing by hooking up listeners, etc.  We have done it in our
application, and I hope to be able to submit the code at some point, but
it is not ready yet (still some proprietary bits in there still).  I'm
not even sure I could send our code to you in a way that would be
helpful (i.e., that you could build).  But what we did was based on some
of the example code that is already there, so you could potentially
reinvent it ....

     Let me see if I can at least point you to the example code, but it
will have to wait until next week for me ...

HTH,

~Roger

On 6/8/16 11:27 AM, Josh Highley wrote:

> Is it possible to create a non-modal frame (or similar) that can be
> dragged outside the main application window?
>
> For example, I have a log console Frame and some other non-modal info
> Frames that a user can show/hide.  I want them to be able to drag it
> out from in front of the main application window, like to another
> monitor.  At the moment, the Frames will get cutoff when they pass the
> edge of the underlying app window.
>
> Thanks,
>
> Josh

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Drag frames beyond app window?

Josh Highley
Is the JFrame at the application level or at each individual, drag-able, frame level?  I don't necessarily need example code if you can do a bit of a "brain dump" with some of the trickier details.  You said " new top-level JFrame, and host the Pivot window inside that" -- how is that relationship made?  I see JFrame will give a Graphics object, and I know Pivot components draw themselves with Graphics....

On Wed, Jun 8, 2016 at 10:11 PM, Roger and Beth Whitcomb <[hidden email]> wrote:
Hi Josh,

    Yes it is, but it is complicated.  You basically have to create a new top-level JFrame, and host the Pivot window inside that, and do the message passing by hooking up listeners, etc.  We have done it in our application, and I hope to be able to submit the code at some point, but it is not ready yet (still some proprietary bits in there still).  I'm not even sure I could send our code to you in a way that would be helpful (i.e., that you could build).  But what we did was based on some of the example code that is already there, so you could potentially reinvent it ....

    Let me see if I can at least point you to the example code, but it will have to wait until next week for me ...

HTH,

~Roger


On 6/8/16 11:27 AM, Josh Highley wrote:
Is it possible to create a non-modal frame (or similar) that can be dragged outside the main application window?

For example, I have a log console Frame and some other non-modal info Frames that a user can show/hide.  I want them to be able to drag it out from in front of the main application window, like to another monitor.  At the moment, the Frames will get cutoff when they pass the edge of the underlying app window.

Thanks,

Josh


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Drag frames beyond app window?

Josh Highley
Documenting my progress in case others need this in the future.  I found the SwingDemo code in the Pivot SVN, which got me started.  I ended up using a JDialog instead of JFrame because I didn't want the minimize or maximize buttons, or a separate task bar item.

I'm still trying to figure some things out, mainly the simplest way to tie the JDialog's AWT events (WindowListener) to Pivots window events.  I need to fire Pivot window state events so that other Pivot components are kept in sync with this dialog's window state.  Also, minimizing my main application's window does not also hide this dialog. Again, need to tie events between Pivot and Swing/AWT.


This code is still a work in progress.  I _think_ I've removed my app-specific code, but no guarantee it will compile.

import java.awt.Dimension;

import java.awt.Image;

import java.awt.Point;

import java.awt.event.WindowEvent;

import java.awt.event.WindowListener;

import java.awt.image.BufferedImage;


import javax.swing.JDesktopPane;

import javax.swing.JDialog;

import javax.swing.JInternalFrame;

import javax.swing.plaf.basic.BasicInternalFrameUI;


import org.apache.pivot.beans.BXML;

import org.apache.pivot.beans.BXMLSerializer;

import org.apache.pivot.wtk.ApplicationContext;

import org.apache.pivot.wtk.Container;

import org.apache.pivot.wtk.Form;

import org.apache.pivot.wtk.Window;

 

public class MyDialog  extends Window implements WindowListener

{

       // replace the default coffee cup icon

       private static final Image ICON = new BufferedImage(1,1,BufferedImage.TYPE_INT_ARGB_PRE);

       private JDialog jDialog;

      

       public MyDialog() {

              super();

             

              try {


              JDesktopPane desktop = new JDesktopPane();

              ApplicationContext.DisplayHost displayHost = new ApplicationContext.DisplayHost();

              ApplicationContext.getDisplays().add(displayHost.getDisplay());

             

              jDialog = new JDialog();

              jDialog.setTitle("My Dialog");

              jDialog.setIconImage(ICON);

              jDialog.setAlwaysOnTop(true);

              jDialog.addWindowListener(this);

               jDialog.setContentPane(desktop);

               jDialog.setSize(1024, 768);  

               jDialog.setVisible(true);

               jDialog.setResizable(true);

 

               JInternalFrame internalFrame = new JInternalFrame(""falsefalsefalse);

               internalFrame.add(displayHost);

               // remove the JInternalFrame border and title bar since JDialog provides this

               internalFrame.setBorder(null);

               ((BasicInternalFrameUI)internalFrame.getUI()).setNorthPane(null);

              

               desktop.add(internalFrame);

              

               // maximize our Pivot content to size it with the Swing container

                setMaximized(true);

                BXMLSerializer bxmlSerializer = new BXMLSerializer();

                setContent((Container) bxmlSerializer.readObject(Container.class"my_dialog.bxml"));

                bxmlSerializer.bind(this, MyDialog.class);

                 

                open(displayHost.getDisplay());

             

               internalFrame.setMaximum(true);

               internalFrame.setLocation(0, 0);

               internalFrame.setSize(desktop.getSize());

               internalFrame.setVisible(true);

 

              } catch (Throwable t) {

                     t.printStackTrace();

              }            

       }

      

       @Override

       public void setVisible(boolean visible) {

              jDialog.setVisible(visible);

       }

 

       private void saveSizeAndLocation() {

              // removed code to save preferences  jDialog.getLocation());    jDialog.getSize());

       }

      

       private void setSizeAndLocation() {

           // removed code to load preferences        jFrjDialogme.setSize((Dimension)obj);     jDialog.setLocation((Point)obj);

       }

      

       ////////////////// AWT WindowListener ////////////////////

       // I left println here temporarily to see what/when events are fired

       public void windowOpened(WindowEvent e) {

              System.out.println("MyDialog windowOpened");

              setSizeAndLocation();

       }


       public void windowClosing(WindowEvent e) {

              System.out.println("MyDialog windowClosing");

              saveSizeAndLocation();

       }

      

       public void windowClosed(WindowEvent e) { System.out.println("MyDialog windowClosed"); }

       public void windowIconified(WindowEvent e) { System.out.println("MyDialog windowIconified"); }

       public void windowDeiconified(WindowEvent e) { System.out.println("MyDialog windowDeiconified"); }

       public void windowActivated(WindowEvent e) { System.out.println("MyDialog windowActivated"); }

       public void windowDeactivated(WindowEvent e) { System.out.println("MyDialog windowDeactivated");  }

}





On Fri, Jun 10, 2016 at 11:47 AM, Josh Highley <[hidden email]> wrote:
Is the JFrame at the application level or at each individual, drag-able, frame level?  I don't necessarily need example code if you can do a bit of a "brain dump" with some of the trickier details.  You said " new top-level JFrame, and host the Pivot window inside that" -- how is that relationship made?  I see JFrame will give a Graphics object, and I know Pivot components draw themselves with Graphics....

On Wed, Jun 8, 2016 at 10:11 PM, Roger and Beth Whitcomb <[hidden email]> wrote:
Hi Josh,

    Yes it is, but it is complicated.  You basically have to create a new top-level JFrame, and host the Pivot window inside that, and do the message passing by hooking up listeners, etc.  We have done it in our application, and I hope to be able to submit the code at some point, but it is not ready yet (still some proprietary bits in there still).  I'm not even sure I could send our code to you in a way that would be helpful (i.e., that you could build).  But what we did was based on some of the example code that is already there, so you could potentially reinvent it ....

    Let me see if I can at least point you to the example code, but it will have to wait until next week for me ...

HTH,

~Roger


On 6/8/16 11:27 AM, Josh Highley wrote:
Is it possible to create a non-modal frame (or similar) that can be dragged outside the main application window?

For example, I have a log console Frame and some other non-modal info Frames that a user can show/hide.  I want them to be able to drag it out from in front of the main application window, like to another monitor.  At the moment, the Frames will get cutoff when they pass the edge of the underlying app window.

Thanks,

Josh



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Drag frames beyond app window?

Sandro Martini

Hi Josh,
thanks for sharing with us your work-in-progress ...

Could you attach it in a jira issue ?
So in this way we could integrate in Pivot sources in next release as a sample ...

Bye,
Sandro

Il 16/Giu/2016 22:05, "Josh Highley" <[hidden email]> ha scritto:
Documenting my progress in case others need this in the future.  I found the SwingDemo code in the Pivot SVN, which got me started.  I ended up using a JDialog instead of JFrame because I didn't want the minimize or maximize buttons, or a separate task bar item.

I'm still trying to figure some things out, mainly the simplest way to tie the JDialog's AWT events (WindowListener) to Pivots window events.  I need to fire Pivot window state events so that other Pivot components are kept in sync with this dialog's window state.  Also, minimizing my main application's window does not also hide this dialog. Again, need to tie events between Pivot and Swing/AWT.


This code is still a work in progress.  I _think_ I've removed my app-specific code, but no guarantee it will compile.

import java.awt.Dimension;

import java.awt.Image;

import java.awt.Point;

import java.awt.event.WindowEvent;

import java.awt.event.WindowListener;

import java.awt.image.BufferedImage;


import javax.swing.JDesktopPane;

import javax.swing.JDialog;

import javax.swing.JInternalFrame;

import javax.swing.plaf.basic.BasicInternalFrameUI;


import org.apache.pivot.beans.BXML;

import org.apache.pivot.beans.BXMLSerializer;

import org.apache.pivot.wtk.ApplicationContext;

import org.apache.pivot.wtk.Container;

import org.apache.pivot.wtk.Form;

import org.apache.pivot.wtk.Window;

 

public class MyDialog  extends Window implements WindowListener

{

       // replace the default coffee cup icon

       private static final Image ICON = new BufferedImage(1,1,BufferedImage.TYPE_INT_ARGB_PRE);

       private JDialog jDialog;

      

       public MyDialog() {

              super();

             

              try {


              JDesktopPane desktop = new JDesktopPane();

              ApplicationContext.DisplayHost displayHost = new ApplicationContext.DisplayHost();

              ApplicationContext.getDisplays().add(displayHost.getDisplay());

             

              jDialog = new JDialog();

              jDialog.setTitle("My Dialog");

              jDialog.setIconImage(ICON);

              jDialog.setAlwaysOnTop(true);

              jDialog.addWindowListener(this);

               jDialog.setContentPane(desktop);

               jDialog.setSize(1024, 768);  

               jDialog.setVisible(true);

               jDialog.setResizable(true);

 

               JInternalFrame internalFrame = new JInternalFrame(""falsefalsefalse);

               internalFrame.add(displayHost);

               // remove the JInternalFrame border and title bar since JDialog provides this

               internalFrame.setBorder(null);

               ((BasicInternalFrameUI)internalFrame.getUI()).setNorthPane(null);

              

               desktop.add(internalFrame);

              

               // maximize our Pivot content to size it with the Swing container

                setMaximized(true);

                BXMLSerializer bxmlSerializer = new BXMLSerializer();

                setContent((Container) bxmlSerializer.readObject(Container.class"my_dialog.bxml"));

                bxmlSerializer.bind(this, MyDialog.class);

                 

                open(displayHost.getDisplay());

             

               internalFrame.setMaximum(true);

               internalFrame.setLocation(0, 0);

               internalFrame.setSize(desktop.getSize());

               internalFrame.setVisible(true);

 

              } catch (Throwable t) {

                     t.printStackTrace();

              }            

       }

      

       @Override

       public void setVisible(boolean visible) {

              jDialog.setVisible(visible);

       }

 

       private void saveSizeAndLocation() {

              // removed code to save preferences  jDialog.getLocation());    jDialog.getSize());

       }

      

       private void setSizeAndLocation() {

           // removed code to load preferences        jFrjDialogme.setSize((Dimension)obj);     jDialog.setLocation((Point)obj);

       }

      

       ////////////////// AWT WindowListener ////////////////////

       // I left println here temporarily to see what/when events are fired

       public void windowOpened(WindowEvent e) {

              System.out.println("MyDialog windowOpened");

              setSizeAndLocation();

       }


       public void windowClosing(WindowEvent e) {

              System.out.println("MyDialog windowClosing");

              saveSizeAndLocation();

       }

      

       public void windowClosed(WindowEvent e) { System.out.println("MyDialog windowClosed"); }

       public void windowIconified(WindowEvent e) { System.out.println("MyDialog windowIconified"); }

       public void windowDeiconified(WindowEvent e) { System.out.println("MyDialog windowDeiconified"); }

       public void windowActivated(WindowEvent e) { System.out.println("MyDialog windowActivated"); }

       public void windowDeactivated(WindowEvent e) { System.out.println("MyDialog windowDeactivated");  }

}





On Fri, Jun 10, 2016 at 11:47 AM, Josh Highley <[hidden email]> wrote:
Is the JFrame at the application level or at each individual, drag-able, frame level?  I don't necessarily need example code if you can do a bit of a "brain dump" with some of the trickier details.  You said " new top-level JFrame, and host the Pivot window inside that" -- how is that relationship made?  I see JFrame will give a Graphics object, and I know Pivot components draw themselves with Graphics....

On Wed, Jun 8, 2016 at 10:11 PM, Roger and Beth Whitcomb <[hidden email]> wrote:
Hi Josh,

    Yes it is, but it is complicated.  You basically have to create a new top-level JFrame, and host the Pivot window inside that, and do the message passing by hooking up listeners, etc.  We have done it in our application, and I hope to be able to submit the code at some point, but it is not ready yet (still some proprietary bits in there still).  I'm not even sure I could send our code to you in a way that would be helpful (i.e., that you could build).  But what we did was based on some of the example code that is already there, so you could potentially reinvent it ....

    Let me see if I can at least point you to the example code, but it will have to wait until next week for me ...

HTH,

~Roger


On 6/8/16 11:27 AM, Josh Highley wrote:
Is it possible to create a non-modal frame (or similar) that can be dragged outside the main application window?

For example, I have a log console Frame and some other non-modal info Frames that a user can show/hide.  I want them to be able to drag it out from in front of the main application window, like to another monitor.  At the moment, the Frames will get cutoff when they pass the edge of the underlying app window.

Thanks,

Josh



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Drag frames beyond app window?

Josh Highley
I will, but I'd like to figure out the event chaining first.  I'm having issues getting the JDialog to behave in sync with my main application window (Pivot).  Also, the app window isn't firing events like I'd expect -- nothing when it loses focus or is minimized.  It does fire a activeChanged event when it gains focus, though.  This makes it impossible to know when to also minimize the JDialog.

I set the JDialog alwaysOnTop to true so that it doesn't get lost behind the app window. However, that makes the JDialog also stay on top of all other windows  (web browser, IDE, etc) and the JDialog stays visible even when the main app window is minimized.

Roger implied they'd figured out the events, so I'm hoping he'll chime in with some pointers.

Thanks,

Josh


On Thu, Jun 16, 2016 at 3:38 PM, Sandro Martini <[hidden email]> wrote:

Hi Josh,
thanks for sharing with us your work-in-progress ...

Could you attach it in a jira issue ?
So in this way we could integrate in Pivot sources in next release as a sample ...

Bye,
Sandro

Il 16/Giu/2016 22:05, "Josh Highley" <[hidden email]> ha scritto:
Documenting my progress in case others need this in the future.  I found the SwingDemo code in the Pivot SVN, which got me started.  I ended up using a JDialog instead of JFrame because I didn't want the minimize or maximize buttons, or a separate task bar item.

I'm still trying to figure some things out, mainly the simplest way to tie the JDialog's AWT events (WindowListener) to Pivots window events.  I need to fire Pivot window state events so that other Pivot components are kept in sync with this dialog's window state.  Also, minimizing my main application's window does not also hide this dialog. Again, need to tie events between Pivot and Swing/AWT.


This code is still a work in progress.  I _think_ I've removed my app-specific code, but no guarantee it will compile.

import java.awt.Dimension;

import java.awt.Image;

import java.awt.Point;

import java.awt.event.WindowEvent;

import java.awt.event.WindowListener;

import java.awt.image.BufferedImage;


import javax.swing.JDesktopPane;

import javax.swing.JDialog;

import javax.swing.JInternalFrame;

import javax.swing.plaf.basic.BasicInternalFrameUI;


import org.apache.pivot.beans.BXML;

import org.apache.pivot.beans.BXMLSerializer;

import org.apache.pivot.wtk.ApplicationContext;

import org.apache.pivot.wtk.Container;

import org.apache.pivot.wtk.Form;

import org.apache.pivot.wtk.Window;

 

public class MyDialog  extends Window implements WindowListener

{

       // replace the default coffee cup icon

       private static final Image ICON = new BufferedImage(1,1,BufferedImage.TYPE_INT_ARGB_PRE);

       private JDialog jDialog;

      

       public MyDialog() {

              super();

             

              try {


              JDesktopPane desktop = new JDesktopPane();

              ApplicationContext.DisplayHost displayHost = new ApplicationContext.DisplayHost();

              ApplicationContext.getDisplays().add(displayHost.getDisplay());

             

              jDialog = new JDialog();

              jDialog.setTitle("My Dialog");

              jDialog.setIconImage(ICON);

              jDialog.setAlwaysOnTop(true);

              jDialog.addWindowListener(this);

               jDialog.setContentPane(desktop);

               jDialog.setSize(1024, 768);  

               jDialog.setVisible(true);

               jDialog.setResizable(true);

 

               JInternalFrame internalFrame = new JInternalFrame(""falsefalsefalse);

               internalFrame.add(displayHost);

               // remove the JInternalFrame border and title bar since JDialog provides this

               internalFrame.setBorder(null);

               ((BasicInternalFrameUI)internalFrame.getUI()).setNorthPane(null);

              

               desktop.add(internalFrame);

              

               // maximize our Pivot content to size it with the Swing container

                setMaximized(true);

                BXMLSerializer bxmlSerializer = new BXMLSerializer();

                setContent((Container) bxmlSerializer.readObject(Container.class"my_dialog.bxml"));

                bxmlSerializer.bind(this, MyDialog.class);

                 

                open(displayHost.getDisplay());

             

               internalFrame.setMaximum(true);

               internalFrame.setLocation(0, 0);

               internalFrame.setSize(desktop.getSize());

               internalFrame.setVisible(true);

 

              } catch (Throwable t) {

                     t.printStackTrace();

              }            

       }

      

       @Override

       public void setVisible(boolean visible) {

              jDialog.setVisible(visible);

       }

 

       private void saveSizeAndLocation() {

              // removed code to save preferences  jDialog.getLocation());    jDialog.getSize());

       }

      

       private void setSizeAndLocation() {

           // removed code to load preferences        jFrjDialogme.setSize((Dimension)obj);     jDialog.setLocation((Point)obj);

       }

      

       ////////////////// AWT WindowListener ////////////////////

       // I left println here temporarily to see what/when events are fired

       public void windowOpened(WindowEvent e) {

              System.out.println("MyDialog windowOpened");

              setSizeAndLocation();

       }


       public void windowClosing(WindowEvent e) {

              System.out.println("MyDialog windowClosing");

              saveSizeAndLocation();

       }

      

       public void windowClosed(WindowEvent e) { System.out.println("MyDialog windowClosed"); }

       public void windowIconified(WindowEvent e) { System.out.println("MyDialog windowIconified"); }

       public void windowDeiconified(WindowEvent e) { System.out.println("MyDialog windowDeiconified"); }

       public void windowActivated(WindowEvent e) { System.out.println("MyDialog windowActivated"); }

       public void windowDeactivated(WindowEvent e) { System.out.println("MyDialog windowDeactivated");  }

}





On Fri, Jun 10, 2016 at 11:47 AM, Josh Highley <[hidden email]> wrote:
Is the JFrame at the application level or at each individual, drag-able, frame level?  I don't necessarily need example code if you can do a bit of a "brain dump" with some of the trickier details.  You said " new top-level JFrame, and host the Pivot window inside that" -- how is that relationship made?  I see JFrame will give a Graphics object, and I know Pivot components draw themselves with Graphics....

On Wed, Jun 8, 2016 at 10:11 PM, Roger and Beth Whitcomb <[hidden email]> wrote:
Hi Josh,

    Yes it is, but it is complicated.  You basically have to create a new top-level JFrame, and host the Pivot window inside that, and do the message passing by hooking up listeners, etc.  We have done it in our application, and I hope to be able to submit the code at some point, but it is not ready yet (still some proprietary bits in there still).  I'm not even sure I could send our code to you in a way that would be helpful (i.e., that you could build).  But what we did was based on some of the example code that is already there, so you could potentially reinvent it ....

    Let me see if I can at least point you to the example code, but it will have to wait until next week for me ...

HTH,

~Roger


On 6/8/16 11:27 AM, Josh Highley wrote:
Is it possible to create a non-modal frame (or similar) that can be dragged outside the main application window?

For example, I have a log console Frame and some other non-modal info Frames that a user can show/hide.  I want them to be able to drag it out from in front of the main application window, like to another monitor.  At the moment, the Frames will get cutoff when they pass the edge of the underlying app window.

Thanks,

Josh




Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Drag frames beyond app window?

Sandro Martini

Ok.

I'm sorry because I can't help you so much in this feature, but maybe Roger can.

Keep us updated.

Thanks again.
Bye

Il 17/Giu/2016 19:18, "Josh Highley" <[hidden email]> ha scritto:
I will, but I'd like to figure out the event chaining first.  I'm having issues getting the JDialog to behave in sync with my main application window (Pivot).  Also, the app window isn't firing events like I'd expect -- nothing when it loses focus or is minimized.  It does fire a activeChanged event when it gains focus, though.  This makes it impossible to know when to also minimize the JDialog.

I set the JDialog alwaysOnTop to true so that it doesn't get lost behind the app window. However, that makes the JDialog also stay on top of all other windows  (web browser, IDE, etc) and the JDialog stays visible even when the main app window is minimized.

Roger implied they'd figured out the events, so I'm hoping he'll chime in with some pointers.

Thanks,

Josh


On Thu, Jun 16, 2016 at 3:38 PM, Sandro Martini <[hidden email]> wrote:

Hi Josh,
thanks for sharing with us your work-in-progress ...

Could you attach it in a jira issue ?
So in this way we could integrate in Pivot sources in next release as a sample ...

Bye,
Sandro

Il 16/Giu/2016 22:05, "Josh Highley" <[hidden email]> ha scritto:
Documenting my progress in case others need this in the future.  I found the SwingDemo code in the Pivot SVN, which got me started.  I ended up using a JDialog instead of JFrame because I didn't want the minimize or maximize buttons, or a separate task bar item.

I'm still trying to figure some things out, mainly the simplest way to tie the JDialog's AWT events (WindowListener) to Pivots window events.  I need to fire Pivot window state events so that other Pivot components are kept in sync with this dialog's window state.  Also, minimizing my main application's window does not also hide this dialog. Again, need to tie events between Pivot and Swing/AWT.


This code is still a work in progress.  I _think_ I've removed my app-specific code, but no guarantee it will compile.

import java.awt.Dimension;

import java.awt.Image;

import java.awt.Point;

import java.awt.event.WindowEvent;

import java.awt.event.WindowListener;

import java.awt.image.BufferedImage;


import javax.swing.JDesktopPane;

import javax.swing.JDialog;

import javax.swing.JInternalFrame;

import javax.swing.plaf.basic.BasicInternalFrameUI;


import org.apache.pivot.beans.BXML;

import org.apache.pivot.beans.BXMLSerializer;

import org.apache.pivot.wtk.ApplicationContext;

import org.apache.pivot.wtk.Container;

import org.apache.pivot.wtk.Form;

import org.apache.pivot.wtk.Window;

 

public class MyDialog  extends Window implements WindowListener

{

       // replace the default coffee cup icon

       private static final Image ICON = new BufferedImage(1,1,BufferedImage.TYPE_INT_ARGB_PRE);

       private JDialog jDialog;

      

       public MyDialog() {

              super();

             

              try {


              JDesktopPane desktop = new JDesktopPane();

              ApplicationContext.DisplayHost displayHost = new ApplicationContext.DisplayHost();

              ApplicationContext.getDisplays().add(displayHost.getDisplay());

             

              jDialog = new JDialog();

              jDialog.setTitle("My Dialog");

              jDialog.setIconImage(ICON);

              jDialog.setAlwaysOnTop(true);

              jDialog.addWindowListener(this);

               jDialog.setContentPane(desktop);

               jDialog.setSize(1024, 768);  

               jDialog.setVisible(true);

               jDialog.setResizable(true);

 

               JInternalFrame internalFrame = new JInternalFrame(""falsefalsefalse);

               internalFrame.add(displayHost);

               // remove the JInternalFrame border and title bar since JDialog provides this

               internalFrame.setBorder(null);

               ((BasicInternalFrameUI)internalFrame.getUI()).setNorthPane(null);

              

               desktop.add(internalFrame);

              

               // maximize our Pivot content to size it with the Swing container

                setMaximized(true);

                BXMLSerializer bxmlSerializer = new BXMLSerializer();

                setContent((Container) bxmlSerializer.readObject(Container.class"my_dialog.bxml"));

                bxmlSerializer.bind(this, MyDialog.class);

                 

                open(displayHost.getDisplay());

             

               internalFrame.setMaximum(true);

               internalFrame.setLocation(0, 0);

               internalFrame.setSize(desktop.getSize());

               internalFrame.setVisible(true);

 

              } catch (Throwable t) {

                     t.printStackTrace();

              }            

       }

      

       @Override

       public void setVisible(boolean visible) {

              jDialog.setVisible(visible);

       }

 

       private void saveSizeAndLocation() {

              // removed code to save preferences  jDialog.getLocation());    jDialog.getSize());

       }

      

       private void setSizeAndLocation() {

           // removed code to load preferences        jFrjDialogme.setSize((Dimension)obj);     jDialog.setLocation((Point)obj);

       }

      

       ////////////////// AWT WindowListener ////////////////////

       // I left println here temporarily to see what/when events are fired

       public void windowOpened(WindowEvent e) {

              System.out.println("MyDialog windowOpened");

              setSizeAndLocation();

       }


       public void windowClosing(WindowEvent e) {

              System.out.println("MyDialog windowClosing");

              saveSizeAndLocation();

       }

      

       public void windowClosed(WindowEvent e) { System.out.println("MyDialog windowClosed"); }

       public void windowIconified(WindowEvent e) { System.out.println("MyDialog windowIconified"); }

       public void windowDeiconified(WindowEvent e) { System.out.println("MyDialog windowDeiconified"); }

       public void windowActivated(WindowEvent e) { System.out.println("MyDialog windowActivated"); }

       public void windowDeactivated(WindowEvent e) { System.out.println("MyDialog windowDeactivated");  }

}





On Fri, Jun 10, 2016 at 11:47 AM, Josh Highley <[hidden email]> wrote:
Is the JFrame at the application level or at each individual, drag-able, frame level?  I don't necessarily need example code if you can do a bit of a "brain dump" with some of the trickier details.  You said " new top-level JFrame, and host the Pivot window inside that" -- how is that relationship made?  I see JFrame will give a Graphics object, and I know Pivot components draw themselves with Graphics....

On Wed, Jun 8, 2016 at 10:11 PM, Roger and Beth Whitcomb <[hidden email]> wrote:
Hi Josh,

    Yes it is, but it is complicated.  You basically have to create a new top-level JFrame, and host the Pivot window inside that, and do the message passing by hooking up listeners, etc.  We have done it in our application, and I hope to be able to submit the code at some point, but it is not ready yet (still some proprietary bits in there still).  I'm not even sure I could send our code to you in a way that would be helpful (i.e., that you could build).  But what we did was based on some of the example code that is already there, so you could potentially reinvent it ....

    Let me see if I can at least point you to the example code, but it will have to wait until next week for me ...

HTH,

~Roger


On 6/8/16 11:27 AM, Josh Highley wrote:
Is it possible to create a non-modal frame (or similar) that can be dragged outside the main application window?

For example, I have a log console Frame and some other non-modal info Frames that a user can show/hide.  I want them to be able to drag it out from in front of the main application window, like to another monitor.  At the moment, the Frames will get cutoff when they pass the edge of the underlying app window.

Thanks,

Josh




Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Drag frames beyond app window?

Roger and Beth Whitcomb

Yeah, been pretty busy this week, but I should have a chance to look at our code some more in the next couple of days, but so far, it seems you are going in the correct direction.

~Roger


On 6/17/16 11:11 AM, Sandro Martini wrote:

Ok.

I'm sorry because I can't help you so much in this feature, but maybe Roger can.

Keep us updated.

Thanks again.
Bye

Il 17/Giu/2016 19:18, "Josh Highley" <[hidden email]> ha scritto:
I will, but I'd like to figure out the event chaining first.  I'm having issues getting the JDialog to behave in sync with my main application window (Pivot).  Also, the app window isn't firing events like I'd expect -- nothing when it loses focus or is minimized.  It does fire a activeChanged event when it gains focus, though.  This makes it impossible to know when to also minimize the JDialog.

I set the JDialog alwaysOnTop to true so that it doesn't get lost behind the app window. However, that makes the JDialog also stay on top of all other windows  (web browser, IDE, etc) and the JDialog stays visible even when the main app window is minimized.

Roger implied they'd figured out the events, so I'm hoping he'll chime in with some pointers.

Thanks,

Josh


On Thu, Jun 16, 2016 at 3:38 PM, Sandro Martini <[hidden email]> wrote:

Hi Josh,
thanks for sharing with us your work-in-progress ...

Could you attach it in a jira issue ?
So in this way we could integrate in Pivot sources in next release as a sample ...

Bye,
Sandro

Il 16/Giu/2016 22:05, "Josh Highley" <[hidden email]> ha scritto:
Documenting my progress in case others need this in the future.  I found the SwingDemo code in the Pivot SVN, which got me started.  I ended up using a JDialog instead of JFrame because I didn't want the minimize or maximize buttons, or a separate task bar item.

I'm still trying to figure some things out, mainly the simplest way to tie the JDialog's AWT events (WindowListener) to Pivots window events.  I need to fire Pivot window state events so that other Pivot components are kept in sync with this dialog's window state.  Also, minimizing my main application's window does not also hide this dialog. Again, need to tie events between Pivot and Swing/AWT.


This code is still a work in progress.  I _think_ I've removed my app-specific code, but no guarantee it will compile.

import java.awt.Dimension;

import java.awt.Image;

import java.awt.Point;

import java.awt.event.WindowEvent;

import java.awt.event.WindowListener;

import java.awt.image.BufferedImage;


import javax.swing.JDesktopPane;

import javax.swing.JDialog;

import javax.swing.JInternalFrame;

import javax.swing.plaf.basic.BasicInternalFrameUI;


import org.apache.pivot.beans.BXML;

import org.apache.pivot.beans.BXMLSerializer;

import org.apache.pivot.wtk.ApplicationContext;

import org.apache.pivot.wtk.Container;

import org.apache.pivot.wtk.Form;

import org.apache.pivot.wtk.Window;

 

public class MyDialog  extends Window implements WindowListener

{

       // replace the default coffee cup icon

       private static final Image ICON = new BufferedImage(1,1,BufferedImage.TYPE_INT_ARGB_PRE);

       private JDialog jDialog;

      

       public MyDialog() {

              super();

             

              try {


              JDesktopPane desktop = new JDesktopPane();

              ApplicationContext.DisplayHost displayHost = new ApplicationContext.DisplayHost();

              ApplicationContext.getDisplays().add(displayHost.getDisplay());

             

              jDialog = new JDialog();

              jDialog.setTitle("My Dialog");

              jDialog.setIconImage(ICON);

              jDialog.setAlwaysOnTop(true);

              jDialog.addWindowListener(this);

               jDialog.setContentPane(desktop);

               jDialog.setSize(1024, 768);  

               jDialog.setVisible(true);

               jDialog.setResizable(true);

 

               JInternalFrame internalFrame = new JInternalFrame(""falsefalsefalse);

               internalFrame.add(displayHost);

               // remove the JInternalFrame border and title bar since JDialog provides this

               internalFrame.setBorder(null);

               ((BasicInternalFrameUI)internalFrame.getUI()).setNorthPane(null);

              

               desktop.add(internalFrame);

              

               // maximize our Pivot content to size it with the Swing container

                setMaximized(true);

                BXMLSerializer bxmlSerializer = new BXMLSerializer();

                setContent((Container) bxmlSerializer.readObject(Container.class"my_dialog.bxml"));

                bxmlSerializer.bind(this, MyDialog.class);

                 

                open(displayHost.getDisplay());

             

               internalFrame.setMaximum(true);

               internalFrame.setLocation(0, 0);

               internalFrame.setSize(desktop.getSize());

               internalFrame.setVisible(true);

 

              } catch (Throwable t) {

                     t.printStackTrace();

              }            

       }

      

       @Override

       public void setVisible(boolean visible) {

              jDialog.setVisible(visible);

       }

 

       private void saveSizeAndLocation() {

              // removed code to save preferences  jDialog.getLocation());    jDialog.getSize());

       }

      

       private void setSizeAndLocation() {

           // removed code to load preferences        jFrjDialogme.setSize((Dimension)obj);     jDialog.setLocation((Point)obj);

       }

      

       ////////////////// AWT WindowListener ////////////////////

       // I left println here temporarily to see what/when events are fired

       public void windowOpened(WindowEvent e) {

              System.out.println("MyDialog windowOpened");

              setSizeAndLocation();

       }


       public void windowClosing(WindowEvent e) {

              System.out.println("MyDialog windowClosing");

              saveSizeAndLocation();

       }

      

       public void windowClosed(WindowEvent e) { System.out.println("MyDialog windowClosed"); }

       public void windowIconified(WindowEvent e) { System.out.println("MyDialog windowIconified"); }

       public void windowDeiconified(WindowEvent e) { System.out.println("MyDialog windowDeiconified"); }

       public void windowActivated(WindowEvent e) { System.out.println("MyDialog windowActivated"); }

       public void windowDeactivated(WindowEvent e) { System.out.println("MyDialog windowDeactivated");  }

}





On Fri, Jun 10, 2016 at 11:47 AM, Josh Highley <[hidden email]> wrote:
Is the JFrame at the application level or at each individual, drag-able, frame level?  I don't necessarily need example code if you can do a bit of a "brain dump" with some of the trickier details.  You said " new top-level JFrame, and host the Pivot window inside that" -- how is that relationship made?  I see JFrame will give a Graphics object, and I know Pivot components draw themselves with Graphics....

On Wed, Jun 8, 2016 at 10:11 PM, Roger and Beth Whitcomb <[hidden email]> wrote:
Hi Josh,

    Yes it is, but it is complicated.  You basically have to create a new top-level JFrame, and host the Pivot window inside that, and do the message passing by hooking up listeners, etc.  We have done it in our application, and I hope to be able to submit the code at some point, but it is not ready yet (still some proprietary bits in there still).  I'm not even sure I could send our code to you in a way that would be helpful (i.e., that you could build).  But what we did was based on some of the example code that is already there, so you could potentially reinvent it ....

    Let me see if I can at least point you to the example code, but it will have to wait until next week for me ...

HTH,

~Roger


On 6/8/16 11:27 AM, Josh Highley wrote:
Is it possible to create a non-modal frame (or similar) that can be dragged outside the main application window?

For example, I have a log console Frame and some other non-modal info Frames that a user can show/hide.  I want them to be able to drag it out from in front of the main application window, like to another monitor.  At the moment, the Frames will get cutoff when they pass the edge of the underlying app window.

Thanks,

Josh





Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Drag frames beyond app window?

Josh Highley
Is there an event that should fire when an application is minimized?  I can't find anything in Pivot that I can use to sync the state of the Swing frame.

On Fri, Jun 17, 2016 at 1:23 PM, Roger and Beth Whitcomb <[hidden email]> wrote:

Yeah, been pretty busy this week, but I should have a chance to look at our code some more in the next couple of days, but so far, it seems you are going in the correct direction.

~Roger


On 6/17/16 11:11 AM, Sandro Martini wrote:

Ok.

I'm sorry because I can't help you so much in this feature, but maybe Roger can.

Keep us updated.

Thanks again.
Bye

Il 17/Giu/2016 19:18, "Josh Highley" <[hidden email][hidden email]> ha scritto:
I will, but I'd like to figure out the event chaining first.  I'm having issues getting the JDialog to behave in sync with my main application window (Pivot).  Also, the app window isn't firing events like I'd expect -- nothing when it loses focus or is minimized.  It does fire a activeChanged event when it gains focus, though.  This makes it impossible to know when to also minimize the JDialog.

I set the JDialog alwaysOnTop to true so that it doesn't get lost behind the app window. However, that makes the JDialog also stay on top of all other windows  (web browser, IDE, etc) and the JDialog stays visible even when the main app window is minimized.

Roger implied they'd figured out the events, so I'm hoping he'll chime in with some pointers.

Thanks,

Josh


On Thu, Jun 16, 2016 at 3:38 PM, Sandro Martini <[hidden email][hidden email]> wrote:

Hi Josh,
thanks for sharing with us your work-in-progress ...

Could you attach it in a jira issue ?
So in this way we could integrate in Pivot sources in next release as a sample ...

Bye,
Sandro

Il 16/Giu/2016 22:05, "Josh Highley" <[hidden email]> ha scritto:
Documenting my progress in case others need this in the future.  I found the SwingDemo code in the Pivot SVN, which got me started.  I ended up using a JDialog instead of JFrame because I didn't want the minimize or maximize buttons, or a separate task bar item.

I'm still trying to figure some things out, mainly the simplest way to tie the JDialog's AWT events (WindowListener) to Pivots window events.  I need to fire Pivot window state events so that other Pivot components are kept in sync with this dialog's window state.  Also, minimizing my main application's window does not also hide this dialog. Again, need to tie events between Pivot and Swing/AWT.


This code is still a work in progress.  I _think_ I've removed my app-specific code, but no guarantee it will compile.

import java.awt.Dimension;

import java.awt.Image;

import java.awt.Point;

import java.awt.event.WindowEvent;

import java.awt.event.WindowListener;

import java.awt.image.BufferedImage;


import javax.swing.JDesktopPane;

import javax.swing.JDialog;

import javax.swing.JInternalFrame;

import javax.swing.plaf.basic.BasicInternalFrameUI;


import org.apache.pivot.beans.BXML;

import org.apache.pivot.beans.BXMLSerializer;

import org.apache.pivot.wtk.ApplicationContext;

import org.apache.pivot.wtk.Container;

import org.apache.pivot.wtk.Form;

import org.apache.pivot.wtk.Window;

 

public class MyDialog  extends Window implements WindowListener

{

       // replace the default coffee cup icon

       private static final Image ICON = new BufferedImage(1,1,BufferedImage.TYPE_INT_ARGB_PRE);

       private JDialog jDialog;

      

       public MyDialog() {

              super();

             

              try {


              JDesktopPane desktop = new JDesktopPane();

              ApplicationContext.DisplayHost displayHost = new ApplicationContext.DisplayHost();

              ApplicationContext.getDisplays().add(displayHost.getDisplay());

             

              jDialog = new JDialog();

              jDialog.setTitle("My Dialog");

              jDialog.setIconImage(ICON);

              jDialog.setAlwaysOnTop(true);

              jDialog.addWindowListener(this);

               jDialog.setContentPane(desktop);

               jDialog.setSize(1024, 768);  

               jDialog.setVisible(true);

               jDialog.setResizable(true);

 

               JInternalFrame internalFrame = new JInternalFrame(""falsefalsefalse);

               internalFrame.add(displayHost);

               // remove the JInternalFrame border and title bar since JDialog provides this

               internalFrame.setBorder(null);

               ((BasicInternalFrameUI)internalFrame.getUI()).setNorthPane(null);

              

               desktop.add(internalFrame);

              

               // maximize our Pivot content to size it with the Swing container

                setMaximized(true);

                BXMLSerializer bxmlSerializer = new BXMLSerializer();

                setContent((Container) bxmlSerializer.readObject(Container.class"my_dialog.bxml"));

                bxmlSerializer.bind(this, MyDialog.class);

                 

                open(displayHost.getDisplay());

             

               internalFrame.setMaximum(true);

               internalFrame.setLocation(0, 0);

               internalFrame.setSize(desktop.getSize());

               internalFrame.setVisible(true);

 

              } catch (Throwable t) {

                     t.printStackTrace();

              }            

       }

      

       @Override

       public void setVisible(boolean visible) {

              jDialog.setVisible(visible);

       }

 

       private void saveSizeAndLocation() {

              // removed code to save preferences  jDialog.getLocation());    jDialog.getSize());

       }

      

       private void setSizeAndLocation() {

           // removed code to load preferences        jFrjDialogme.setSize((Dimension)obj);     jDialog.setLocation((Point)obj);

       }

      

       ////////////////// AWT WindowListener ////////////////////

       // I left println here temporarily to see what/when events are fired

       public void windowOpened(WindowEvent e) {

              System.out.println("MyDialog windowOpened");

              setSizeAndLocation();

       }


       public void windowClosing(WindowEvent e) {

              System.out.println("MyDialog windowClosing");

              saveSizeAndLocation();

       }

      

       public void windowClosed(WindowEvent e) { System.out.println("MyDialog windowClosed"); }

       public void windowIconified(WindowEvent e) { System.out.println("MyDialog windowIconified"); }

       public void windowDeiconified(WindowEvent e) { System.out.println("MyDialog windowDeiconified"); }

       public void windowActivated(WindowEvent e) { System.out.println("MyDialog windowActivated"); }

       public void windowDeactivated(WindowEvent e) { System.out.println("MyDialog windowDeactivated");  }

}





On Fri, Jun 10, 2016 at 11:47 AM, Josh Highley <[hidden email]> wrote:
Is the JFrame at the application level or at each individual, drag-able, frame level?  I don't necessarily need example code if you can do a bit of a "brain dump" with some of the trickier details.  You said " new top-level JFrame, and host the Pivot window inside that" -- how is that relationship made?  I see JFrame will give a Graphics object, and I know Pivot components draw themselves with Graphics....

On Wed, Jun 8, 2016 at 10:11 PM, Roger and Beth Whitcomb <[hidden email][hidden email]> wrote:
Hi Josh,

    Yes it is, but it is complicated.  You basically have to create a new top-level JFrame, and host the Pivot window inside that, and do the message passing by hooking up listeners, etc.  We have done it in our application, and I hope to be able to submit the code at some point, but it is not ready yet (still some proprietary bits in there still).  I'm not even sure I could send our code to you in a way that would be helpful (i.e., that you could build).  But what we did was based on some of the example code that is already there, so you could potentially reinvent it ....

    Let me see if I can at least point you to the example code, but it will have to wait until next week for me ...

HTH,

~Roger


On 6/8/16 11:27 AM, Josh Highley wrote:
Is it possible to create a non-modal frame (or similar) that can be dragged outside the main application window?

For example, I have a log console Frame and some other non-modal info Frames that a user can show/hide.  I want them to be able to drag it out from in front of the main application window, like to another monitor.  At the moment, the Frames will get cutoff when they pass the edge of the underlying app window.

Thanks,

Josh






Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Drag frames beyond app window?

Roger Whitcomb-2

Here is our PivotDialogHost adapter class that does the marshaling between AWT windows and Pivot windows.  Hope you can get some clues from here.

 

~Roger

 

import org.apache.pivot.wtk.ApplicationContext;

import org.apache.pivot.wtk.Component;

import org.apache.pivot.wtk.DesktopApplicationContext;

import org.apache.pivot.wtk.DesktopApplicationContext.DisplayListener;

import org.apache.pivot.wtk.Dialog;

import org.apache.pivot.wtk.DialogCloseListener;

import org.apache.pivot.wtk.Dimensions;

import org.apache.pivot.wtk.Display;

import org.apache.pivot.wtk.Window;

 

import java.awt.Dimension;

import java.awt.event.ComponentEvent;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import java.awt.event.WindowFocusListener;

 

/**

* A modal dialog that can hostDialog a pivot dialog outside of the normal ApplicationContext.

*/

public class PivotDialogHost

{

    /**

     * The height of the pivot dialogs title bar.

     */

    private static final int PIVOT_DIALOG_TITLE_BAR_HEIGHT = 23;

 

    /**

     * The delay used when requesting the focus of the initial component.

     */

    public static final int FOCUS_INITIAL_COMPONENT_DELAY = 50;

 

    // HACK: Needs fixing!

    int reduction = 4;

 

    /**

     * The host type that should be used.

     */

    private DialogHostingMode dialogHostingMode;

 

    /**

     * The dialog that is being shown.

     */

    private Dialog dialog;

 

    /**

     * The window that the dialog will be shown inside.

     */

    private Window window = new Window();

 

    /**

     * The hostDialog that is being used.

     */

    public HostDialog hostDialog;

 

    /**

     * The hostFrame that is being used.

     */

    public HostFrame hostFrame;

 

    /**

     * Whether the host will be modal.

     */

    private boolean modal = true;

 

    /**

     * The insets for the host.

     */

    java.awt.Insets insets;

 

    /**

     * Whether the host will be resizable.

     */

    private boolean resizable = true;

 

    /**

     * The dialog close listener.

     */

    private DialogCloseListener dialogCloseListener = null;

 

    /**

     * The initially focused component.

     */

    private Component focusComponent = null;

 

    /**

     * close hostDialog, when the content dialog is closed

     */

    private final DialogCloseListener closeListener = new DialogCloseListener() {

        @Override

        public void dialogClosed(Dialog dialog, boolean modal) {

 

            switch (dialogHostingMode) {

                case DIALOG:

                    hostDialog.setVisible(false);

                    hostDialog.removeWindowFocusListener(focusListener);

                    break;

                case FRAME:

                    hostFrame.setVisible(false);

                    hostFrame.removeWindowFocusListener(focusListener);

                    break;

            }

 

            if (dialogCloseListener != null){

                dialogCloseListener.dialogClosed(dialog, modal);

            }

        }

    };

 

    /**

     * Display listener for the host.

     */

    DisplayListener hostDisplayListener = new DisplayListener(){

        @Override

        public void hostWindowOpened(Display components) {

        }

 

        @Override

        public void hostWindowClosed(Display components) {

            // Invoke the dialog close event directly, if the host dialog is closed.

            dialog.close();

        }

    };

 

    /**

     * Move the host to the same position as the content.

     */

    private final java.awt.event.ComponentListener moveListener = new java.awt.event.ComponentListener() {

 

        @Override

        public void componentResized(ComponentEvent e) {

 

            if (insets == null){

                return;

            }

 

            // Get the window

            java.awt.Window window = (java.awt.Window)e.getSource();

 

            // Determine its dimension.

            Dimension dimension =  window.getSize();

 

            // Build a pivot dimensions, accounting for inset and width of pivot dialog title bar.

            Dimensions dimensions = new Dimensions(dimension.width - insets.left - insets.right + reduction,

                    dimension.height - insets.top - insets.bottom + PIVOT_DIALOG_TITLE_BAR_HEIGHT + reduction);

 

            // Set the preferred size of the pivot dialog.

            dialog.setPreferredSize(dimensions);

 

            // Request focus on the host.

            e.getComponent().requestFocus();

        }

 

        @Override

        public void componentMoved(ComponentEvent e) {}

 

        @Override

        public void componentShown(ComponentEvent e) {}

 

        @Override

        public void componentHidden(ComponentEvent e) {}

    };

 

    boolean firstFocus = true;

 

    /**

     * Transfers Focus to the dialog, when the hostDialog has been opened

     */

    private WindowFocusListener focusListener = new WindowFocusListener() {

        @Override

        public void windowLostFocus(WindowEvent e) {

        }

 

        @Override

        public void windowGainedFocus(WindowEvent e) {

            dialog.requestActive();

 

            // If the dialog is being focused for the first time and we have a focusComponent

            if (firstFocus && focusComponent != null){

                // Request focus on the component.

                ApplicationContext.scheduleCallback(new Runnable() {

                    @Override

                    public void run() {

                        focusComponent.requestFocus();

                    }

                }, FOCUS_INITIAL_COMPONENT_DELAY);

 

                firstFocus = false;

            }

            else {

                // Otherwise just request focus on the dialog itself.

                dialog.requestFocus();

            }

        }

    };

 

    /**

     * Initializes a new instance of the PivotDialogHost dialog.

     *

     * @param dialog The Apache Pivot dialog that is to be hosted.

     * @param dialogHostingMode The hosting mode: dialog or frame.

     * @param focusComponent The initially focused component.

     * @param dialogCloseListener The close listener.

     * @param resizable Whether the host is to be resizable.

     */

    public PivotDialogHost(Dialog dialog, DialogHostingMode dialogHostingMode, Component focusComponent, DialogCloseListener dialogCloseListener, boolean resizable) {

        this.dialogHostingMode = dialogHostingMode;

        this.focusComponent = focusComponent;

        this.dialog = dialog;

 

        // Need a pivot change to allow: contentBorderColor:10

        AppUtil.setStyles(this.dialog, "{resizable:'false'}");

 

        // Remove any decorators (such as drop shadows)

        this.dialog.getDecorators().removeAll();

 

        this.dialogCloseListener = dialogCloseListener;

        this.resizable = resizable;

    }

 

    /**

     * Opens the hosted dialog.

     *

     * @param display The display in which the hosted dialog should be opened.

     *

     * @return The hosted dialog.

     */

    public Dialog open(Display display) {

 

        // Determine dimensions

        Dimensions dimensions = dialog.getPreferredSize();

        int width =  dimensions.width;

        int height = dimensions.height;

 

        Display newDisplay = null;

 

        int x = 0;

        int y = 0;

 

        if (display == null) {

            Window mainWindow = AppUtil.getMainWindow();

            display = mainWindow != null ? mainWindow.getDisplay() : null;

        }

        if (display != null) {

            java.awt.Window hostWindow = display.getHostWindow();

            x = hostWindow.getX() + (display.getWidth() - width) / 2;

            y = hostWindow.getY() + (display.getHeight() - height) / 2;

        }

 

        // Instantiate the host.

        switch (dialogHostingMode) {

            case DIALOG:

                hostDialog = createDialogDisplay(width,

                        height,

                        x,

                        y,

                        modal,

                        resizable,

                        false,

                        display.getHostWindow(),

                        hostDisplayListener,

                        moveListener);

 

                newDisplay = hostDialog.getDisplay();

                break;

            case FRAME:

                hostFrame = createFrameDisplay(width,

                        height,

                        x,

                        y,

                        resizable,

                        false,

                        hostDisplayListener,

                        moveListener);

 

                newDisplay = hostFrame.getDisplay();

 

                break;

        }

 

        window.open(newDisplay);

 

        dialog.open(window, closeListener);

 

        // Set the location of the dialog within the host.

        dialog.setLocation(-2, -PIVOT_DIALOG_TITLE_BAR_HEIGHT);

 

        switch (dialogHostingMode) {

            case DIALOG:

                hostDialog.setTitle(dialog.getTitle());

                hostDialog.requestFocus();

                hostDialog.setVisible(true);

                break;

            case FRAME:

                hostFrame.setTitle(dialog.getTitle());

                hostFrame.requestFocus();

                hostFrame.setVisible(true);

                break;

        }

 

        return dialog;

    }

 

    /**

     * Creates a new secondary display hosted in a dialog.

     *

     * @param width The width of the content.

     * @param height The height of the content.

     * @param x The x coordinate for the display.

     * @param y The y coordinate for the display.

     * @param modal Whether or not the display is modal.

     * @param resizable Whether the frame is resizable.

     * @param undecorated Whether the frame is undecorated.

     * @param owner The owner.

     * @param displayCloseListener The display close listener.

     * @param componentListener The component listener.

     *

     * @return The host dialog.

     */

    private HostDialog createDialogDisplay(int width, int height, int x, int y, boolean modal, boolean resizable,

                                           boolean undecorated, java.awt.Window owner, DisplayListener displayCloseListener, java.awt.event.ComponentListener componentListener) {

        if (DesktopApplicationContext.isFullScreen()) {

            throw new IllegalStateException();

        }

 

        final HostDialog host = new HostDialog(owner, modal, displayCloseListener);

 

        // Add a window listener.

        host.addWindowListener(new PivotHostWindowAdapter(host));

 

        // Add the component listener.

        host.addComponentListener(componentListener);

 

        host.setResizable(resizable);

        host.setUndecorated(undecorated);

 

        performHostInitialization(host, width, height, x, y);

 

        return host;

    }

 

    /**

     * Creates a new secondary display hosted in a frame..

     *

     * @param width The width of the content.

     * @param height The height of the content.

     * @param x The x coordinate for the display.

     * @param y The y coordinate for the display.

     * @param resizable Whether the frame is resizable.

     * @param undecorated Whether the frame is undecorated.

     * @param displayCloseListener The display close listener.

     * @param componentListener The component listener.

     *

     * @return The host frame.

     */

    private HostFrame createFrameDisplay(int width, int height, int x, int y, boolean resizable,

                                         boolean undecorated, DisplayListener displayCloseListener, java.awt.event.ComponentListener componentListener) {

        if (DesktopApplicationContext.isFullScreen()) {

            throw new IllegalStateException();

        }

 

        final HostFrame host = new HostFrame(displayCloseListener);

 

        // Add a window listener.

        host.addWindowListener(new PivotHostWindowAdapter(host));

 

        // Add the component listener.

        host.addComponentListener(componentListener);

 

        host.setResizable(resizable);

        host.setUndecorated(undecorated);

 

        performHostInitialization(host, width, height, x, y);

 

        return host;

    }

 

    /**

     * Performs common host initialization tasks.

     *

     * @param host The host.

     * @param width The width of the content.

     * @param height The height of the content.

     * @param x The x coordinate for the display.

     * @param y The y coordinate for the display.

     */

    private void performHostInitialization(java.awt.Window host, int width, int height, int x, int y) {

 

        host.addWindowFocusListener(focusListener);

 

        host.setLocation(x, y);

 

        host.pack();

 

        insets = host.getInsets();

 

        Dimension dimension = new Dimension(width + insets.left + insets.right - reduction,

                height + insets.top + insets.bottom - PIVOT_DIALOG_TITLE_BAR_HEIGHT - reduction);

 

        host.setSize(dimension);

 

        host.setMinimumSize(dimension);

    }

 

    /**

     * Window adapter for pivot hosts.

     */

    private class PivotHostWindowAdapter extends WindowAdapter

    {

        /**

         * The host window.

         */

        private java.awt.Window host;

 

        /**

         * Initializes a new instance of the pivot host window adapter.

         *

         * @param host The host.

         */

        public PivotHostWindowAdapter(java.awt.Window host) {

            this.host = host;

        }

 

        /**

         * Handles the window closing event for the host.

         *

         * @param ev The window event.

         */

        public void windowClosing(WindowEvent ev) {

            dialog.close(false);

        }

 

        /**

         * Handles the window closed event for the host.

         *

         * @param ev The window event.

         */

        public void windowClosed(WindowEvent ev) {

            if (host != null) {

                host.dispose();

            }

        }

    }

 

    /**

     * Set focus to this window/dialog.

     */

    public void setFocus() {

        switch (dialogHostingMode) {

            case DIALOG:

                hostDialog.requestFocus();

                hostDialog.setVisible(true);

                break;

            case FRAME:

                hostFrame.requestFocus();

                hostFrame.setVisible(true);

                break;

        }

    }

 

}

 

From: Josh Highley [mailto:[hidden email]]
Sent: Monday, June 27, 2016 7:12 AM
To: [hidden email]
Subject: Re: Drag frames beyond app window?

 

Is there an event that should fire when an application is minimized?  I can't find anything in Pivot that I can use to sync the state of the Swing frame.

 

On Fri, Jun 17, 2016 at 1:23 PM, Roger and Beth Whitcomb <[hidden email]> wrote:

Yeah, been pretty busy this week, but I should have a chance to look at our code some more in the next couple of days, but so far, it seems you are going in the correct direction.

~Roger

 

On 6/17/16 11:11 AM, Sandro Martini wrote:

Ok.

I'm sorry because I can't help you so much in this feature, but maybe Roger can.

Keep us updated.

Thanks again.
Bye

Il 17/Giu/2016 19:18, "Josh Highley" <[hidden email]> ha scritto:

I will, but I'd like to figure out the event chaining first.  I'm having issues getting the JDialog to behave in sync with my main application window (Pivot).  Also, the app window isn't firing events like I'd expect -- nothing when it loses focus or is minimized.  It does fire a activeChanged event when it gains focus, though.  This makes it impossible to know when to also minimize the JDialog.

 

I set the JDialog alwaysOnTop to true so that it doesn't get lost behind the app window. However, that makes the JDialog also stay on top of all other windows  (web browser, IDE, etc) and the JDialog stays visible even when the main app window is minimized.

 

Roger implied they'd figured out the events, so I'm hoping he'll chime in with some pointers.

 

Thanks,

 

Josh

 

 

On Thu, Jun 16, 2016 at 3:38 PM, Sandro Martini <[hidden email]> wrote:

Hi Josh,
thanks for sharing with us your work-in-progress ...

Could you attach it in a jira issue ?
So in this way we could integrate in Pivot sources in next release as a sample ...

Bye,
Sandro

Il 16/Giu/2016 22:05, "Josh Highley" <[hidden email]> ha scritto:

Documenting my progress in case others need this in the future.  I found the SwingDemo code in the Pivot SVN, which got me started.  I ended up using a JDialog instead of JFrame because I didn't want the minimize or maximize buttons, or a separate task bar item.

 

I'm still trying to figure some things out, mainly the simplest way to tie the JDialog's AWT events (WindowListener) to Pivots window events.  I need to fire Pivot window state events so that other Pivot components are kept in sync with this dialog's window state.  Also, minimizing my main application's window does not also hide this dialog. Again, need to tie events between Pivot and Swing/AWT.

 

 

This code is still a work in progress.  I _think_ I've removed my app-specific code, but no guarantee it will compile.

 

import java.awt.Dimension;

import java.awt.Image;

import java.awt.Point;

import java.awt.event.WindowEvent;

import java.awt.event.WindowListener;

import java.awt.image.BufferedImage;

 

import javax.swing.JDesktopPane;

import javax.swing.JDialog;

import javax.swing.JInternalFrame;

import javax.swing.plaf.basic.BasicInternalFrameUI;

 

import org.apache.pivot.beans.BXML;

import org.apache.pivot.beans.BXMLSerializer;

import org.apache.pivot.wtk.ApplicationContext;

import org.apache.pivot.wtk.Container;

import org.apache.pivot.wtk.Form;

import org.apache.pivot.wtk.Window;

 

public class MyDialog  extends Window implements WindowListener

{

       // replace the default coffee cup icon

       private static final Image ICON = new BufferedImage(1,1,BufferedImage.TYPE_INT_ARGB_PRE);

       private JDialog jDialog;

      

       public MyDialog() {

              super();

             

              try {

 

              JDesktopPane desktop = new JDesktopPane();

              ApplicationContext.DisplayHost displayHost = new ApplicationContext.DisplayHost();

              ApplicationContext.getDisplays().add(displayHost.getDisplay());

             

              jDialog = new JDialog();

              jDialog.setTitle("My Dialog");

              jDialog.setIconImage(ICON);

              jDialog.setAlwaysOnTop(true);

              jDialog.addWindowListener(this);

               jDialog.setContentPane(desktop);

               jDialog.setSize(1024, 768);  

               jDialog.setVisible(true);

               jDialog.setResizable(true);

 

               JInternalFrame internalFrame = new JInternalFrame("", false, false, false);

               internalFrame.add(displayHost);

               // remove the JInternalFrame border and title bar since JDialog provides this

               internalFrame.setBorder(null);

               ((BasicInternalFrameUI)internalFrame.getUI()).setNorthPane(null);

              

               desktop.add(internalFrame);

              

               // maximize our Pivot content to size it with the Swing container

                setMaximized(true);

                BXMLSerializer bxmlSerializer = new BXMLSerializer();

                setContent((Container) bxmlSerializer.readObject(Container.class, "my_dialog.bxml"));

                bxmlSerializer.bind(this, MyDialog.class);

                 

                open(displayHost.getDisplay());

             

               internalFrame.setMaximum(true);

               internalFrame.setLocation(0, 0);

               internalFrame.setSize(desktop.getSize());

               internalFrame.setVisible(true);

 

              } catch (Throwable t) {

                     t.printStackTrace();

              }            

       }

      

       @Override

       public void setVisible(boolean visible) {

              jDialog.setVisible(visible);

       }

 

       private void saveSizeAndLocation() {

              // removed code to save preferences  jDialog.getLocation());    jDialog.getSize());

       }

      

       private void setSizeAndLocation() {

           // removed code to load preferences        jFrjDialogme.setSize((Dimension)obj);     jDialog.setLocation((Point)obj);

       }

      

       ////////////////// AWT WindowListener ////////////////////

       // I left println here temporarily to see what/when events are fired

       public void windowOpened(WindowEvent e) {

              System.out.println("MyDialog windowOpened");

              setSizeAndLocation();

       }

 

       public void windowClosing(WindowEvent e) {

              System.out.println("MyDialog windowClosing");

              saveSizeAndLocation();

       }

      

       public void windowClosed(WindowEvent e) { System.out.println("MyDialog windowClosed"); }

       public void windowIconified(WindowEvent e) { System.out.println("MyDialog windowIconified"); }

       public void windowDeiconified(WindowEvent e) { System.out.println("MyDialog windowDeiconified"); }

       public void windowActivated(WindowEvent e) { System.out.println("MyDialog windowActivated"); }

       public void windowDeactivated(WindowEvent e) { System.out.println("MyDialog windowDeactivated");  }

}

 

 

 

 

 

On Fri, Jun 10, 2016 at 11:47 AM, Josh Highley <[hidden email]> wrote:

Is the JFrame at the application level or at each individual, drag-able, frame level?  I don't necessarily need example code if you can do a bit of a "brain dump" with some of the trickier details.  You said " new top-level JFrame, and host the Pivot window inside that" -- how is that relationship made?  I see JFrame will give a Graphics object, and I know Pivot components draw themselves with Graphics....

 

On Wed, Jun 8, 2016 at 10:11 PM, Roger and Beth Whitcomb <[hidden email]> wrote:

Hi Josh,

    Yes it is, but it is complicated.  You basically have to create a new top-level JFrame, and host the Pivot window inside that, and do the message passing by hooking up listeners, etc.  We have done it in our application, and I hope to be able to submit the code at some point, but it is not ready yet (still some proprietary bits in there still).  I'm not even sure I could send our code to you in a way that would be helpful (i.e., that you could build).  But what we did was based on some of the example code that is already there, so you could potentially reinvent it ....

    Let me see if I can at least point you to the example code, but it will have to wait until next week for me ...

HTH,

~Roger



On 6/8/16 11:27 AM, Josh Highley wrote:

Is it possible to create a non-modal frame (or similar) that can be dragged outside the main application window?

For example, I have a log console Frame and some other non-modal info Frames that a user can show/hide.  I want them to be able to drag it out from in front of the main application window, like to another monitor.  At the moment, the Frames will get cutoff when they pass the edge of the underlying app window.

Thanks,

Josh

 

 

 

 

 

 

Loading...