2626
2727public class LayoutFrame extends JFrame {
2828 private ExternalWindowObserver externalWindowObserver ;
29+ private JLabel labelName ;
2930 private JButton btnUndock ;
3031 private String windowName ;
3132 private ChannelClient channelClient ;
@@ -38,18 +39,22 @@ public LayoutFrame(DesktopConnection desktopConnection, String appUuid, String w
3839
3940 public LayoutFrame (DesktopConnection desktopConnection , String appUuid , String windowName , boolean frameless ) throws DesktopException {
4041 super ();
42+ this .setTitle (windowName );
4143 System .out .println (windowName + " being created " );
4244 this .appUuid = appUuid ;
4345 this .windowName = windowName ;
4446 this .frameless = frameless ;
4547 this .setDefaultCloseOperation (JFrame .DO_NOTHING_ON_CLOSE );
4648 this .setPreferredSize (new Dimension (640 , 480 ));
47- JPanel pnl = new JPanel (new FlowLayout (FlowLayout .CENTER ));
49+ JPanel pnl = new JPanel ();
50+ pnl .setLayout (new BoxLayout (pnl , BoxLayout .Y_AXIS ));
51+ this .labelName = new JLabel (windowName );
52+ pnl .add (labelName );
4853 this .btnUndock = new JButton ("undock" );
4954 this .btnUndock .setEnabled (false );
5055 pnl .add (btnUndock );
5156 this .getContentPane ().add (pnl );
52-
57+
5358 if (frameless ) {
5459 this .setUndecorated (true );
5560 JPanel titleBar = new JPanel (new BorderLayout ());
@@ -61,15 +66,25 @@ public void mousePressed(MouseEvent e) {
6166 pressedAtX = e .getX ();
6267 pressedAtY = e .getY ();
6368 System .out .println ("mouse pressed at x=" + pressedAtX + ", y=" + pressedAtY );
69+ LayoutFrame .this .externalWindowObserver .enterSizeMove ();
6470 }
65-
6671 @ Override
6772 public void mouseDragged (MouseEvent e ) {
6873 int distanceX = e .getX () - pressedAtX ;
6974 int distanceY = e .getY () - pressedAtY ;
7075 System .out .println ("dragged x=" + distanceX + ", y=" + distanceY );
7176 Point frameLocation = LayoutFrame .this .getLocation ();
72- LayoutFrame .this .setLocation (frameLocation .x + distanceX , frameLocation .y + distanceY );
77+ Dimension dimension = LayoutFrame .this .getSize ();
78+ WindowBounds bounds = new WindowBounds (frameLocation .x + distanceX , frameLocation .y + distanceY ,
79+ dimension .width , dimension .height );
80+ Point point = new Point (e .getX (), e .getY ());
81+ if (!LayoutFrame .this .externalWindowObserver .onMoving (bounds , point )) {
82+ LayoutFrame .this .setLocation (frameLocation .x + distanceX , frameLocation .y + distanceY );
83+ }
84+ }
85+ @ Override
86+ public void mouseReleased (MouseEvent e ) {
87+ LayoutFrame .this .externalWindowObserver .exitSizeMove ();
7388 }
7489 };
7590 titleBar .addMouseListener (myListener );
@@ -128,13 +143,13 @@ public void onError(Ack ack) {
128143 System .out .println (windowName + ": unable to register external window, " + ack .getReason ());
129144 }
130145 });
131- this .externalWindowObserver .setUserGesture (!this .frameless );
146+ // this.externalWindowObserver.setUserGesture(!this.frameless);
132147 try {
133- if (this .frameless ) {
134- WindowOptions options = new WindowOptions ();
135- options .setFrame (false );
136- this .externalWindowObserver .setWindowOptions (options );
137- }
148+ // if (this.frameless) {
149+ // WindowOptions options = new WindowOptions();
150+ // options.setFrame(false);
151+ // this.externalWindowObserver.setWindowOptions(options);
152+ // }
138153 this .externalWindowObserver .start ();
139154 } catch (Exception e ) {
140155 e .printStackTrace ();
@@ -256,7 +271,6 @@ public void mousePressed(MouseEvent e) {
256271 pressedAtY = e .getY ();
257272 System .out .println ("mouse pressed at x=" + pressedAtX + ", y=" + pressedAtY );
258273 }
259-
260274 @ Override
261275 public void mouseDragged (MouseEvent e ) {
262276 int distanceX = e .getX () - pressedAtX ;
@@ -265,6 +279,12 @@ public void mouseDragged(MouseEvent e) {
265279 Point frameLocation = frame .getLocation ();
266280 frame .setLocation (frameLocation .x + distanceX , frameLocation .y + distanceY );
267281 }
282+ @ Override
283+ public void mouseReleased (MouseEvent e ) {
284+ pressedAtX = e .getX ();
285+ pressedAtY = e .getY ();
286+ System .out .println ("mouse released at x=" + pressedAtX + ", y=" + pressedAtY );
287+ }
268288 };
269289 titleBar .addMouseListener (myListener );
270290 titleBar .addMouseMotionListener (myListener );
0 commit comments