Revision: 4061
          http://vexi.svn.sourceforge.net/vexi/?rev=4061&view=rev
Author:   clrg
Date:     2011-03-22 03:44:17 +0000 (Tue, 22 Mar 2011)

Log Message:
-----------
Fix #35 - move Maximized extended state setting in to EDT

Modified Paths:
--------------
    trunk/org.vexi-core.main/src/main/java/org/vexi/plat/Swing.java

Modified: trunk/org.vexi-core.main/src/main/java/org/vexi/plat/Swing.java
===================================================================
--- trunk/org.vexi-core.main/src/main/java/org/vexi/plat/Swing.java     
2011-03-21 02:02:47 UTC (rev 4060)
+++ trunk/org.vexi-core.main/src/main/java/org/vexi/plat/Swing.java     
2011-03-22 03:44:17 UTC (rev 4061)
@@ -46,6 +46,7 @@
 import java.awt.event.MouseWheelListener;
 import java.awt.event.WindowEvent;
 import java.awt.event.WindowListener;
+import java.awt.event.WindowStateListener;
 import java.awt.im.InputMethodRequests;
 import java.awt.image.BufferedImage;
 import java.awt.image.ColorModel;
@@ -444,7 +445,7 @@
     
     
     protected static class AWTSurface extends 
Surface.DoubleBufferedSurfaceNoBlit
-        implements MouseListener, MouseMotionListener, MouseWheelListener, 
KeyListener, ComponentListener, WindowListener {
+        implements MouseListener, MouseMotionListener, MouseWheelListener, 
KeyListener, ComponentListener, WindowListener, WindowStateListener {
         
         public Picture toPicture() { return new 
AWTPicture(((AWTPixelBuffer)backbuffer).i); }
         private Object buffersync = new Object();
@@ -508,22 +509,24 @@
         }
         protected void _setMinimized(boolean b) {
             if (frame!=null) {
-                frame.setExtendedState(b ? Frame.ICONIFIED : Frame.NORMAL);
+                // Swing is not thread safe; changes must be made in the EDT
+                // @see InnerFrame.paint()
+                //frame.setExtendedState(b ? Frame.ICONIFIED : Frame.NORMAL);
             } else {
                 Log.warn(this, "JDK 1.1 platforms cannot minimize or 
unminimize windows");
             }
         }
         protected void _setMaximized(boolean b) {
             if (frame!=null) {
-                frame.setExtendedState(b ? Frame.MAXIMIZED_BOTH : 
Frame.NORMAL);
+                // Swing is not thread safe; changes must be made in the EDT
+                // @see InnerFrame.paint()
+                //frame.setExtendedState(b ? Frame.MAXIMIZED_BOTH : 
Frame.NORMAL);
             } else {
                 window.setLocation(new Point(0, 0));
                 window.setSize(Toolkit.getDefaultToolkit().getScreenSize());
             }
         }
         
-//        private boolean invalidated = false;
-        
         class InnerIcon extends ImageIcon {
             public InnerIcon(Image buffer) { super(buffer); }
             public void paintIcon(Component c, Graphics g, int x, int y) {
@@ -625,6 +628,15 @@
                 // NB Swing is double buffered by default but not sufficiently
                 createBufferStrategy(2);
             }
+            public void paint(Graphics g) {
+                super.paint(g);
+                if (maximized!=((getExtendedState() & 
JFrame.MAXIMIZED_BOTH)!=0)) {
+                    setExtendedState(maximized ? JFrame.MAXIMIZED_BOTH : 
JFrame.NORMAL);
+                }
+                if (minimized!=((getExtendedState() & JFrame.ICONIFIED)!=0)) {
+                    frame.setExtendedState(minimized ? JFrame.ICONIFIED : 
JFrame.NORMAL);
+                }
+            }
 
 //            public ComponentAdapter enforceMinSize = new ComponentAdapter() {
 //                public void componentResized(ComponentEvent event) {
@@ -843,6 +855,7 @@
             panel.addMouseWheelListener(this);
             window.addKeyListener(this);
             window.addWindowListener(this);
+            window.addWindowStateListener(this);
             // workaround for an OS X limitation
             try {
                 window.getInputContext().setCompositionEnabled(false);
@@ -856,10 +869,6 @@
         // to ensure that our peer has been created
         public void makeVisible(boolean b) {
             window.setVisible(b);
-            // respect a frame's requested maximized state
-            if (b && frame!=null) {
-                frame.setExtendedState(maximized ? Frame.MAXIMIZED_BOTH : 
Frame.NORMAL);
-            }
         }
         
         public void _dispose() {
@@ -904,9 +913,15 @@
         public void windowClosed(WindowEvent e) { }
         public void windowClosing(WindowEvent e) { Close(); }
         public void windowIconified(WindowEvent e) { Minimized(true); }
-        public void windowDeiconified(WindowEvent e) { window.repaint(0, 0, 
root.width, root.height); Minimized(false); }
+        public void windowDeiconified(WindowEvent e) { Minimized(false); }
         public void windowActivated(WindowEvent e) { Focused(true); }
         public void windowDeactivated(WindowEvent e) { Focused(false); }
+        public void windowStateChanged(WindowEvent e) {
+            boolean maximized = (e.getNewState() & JFrame.MAXIMIZED_BOTH) != 0;
+            if (maximized != this.maximized) {
+                Maximized(maximized);
+            }
+        }
         public void componentMoved(ComponentEvent e) { 
PosChange(window.getLocation().x, window.getLocation().y); }
 
         public void componentResized(ComponentEvent e) {


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software 
be a part of the solution? Download the Intel(R) Manageability Checker 
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to