Revision: 4070 http://vexi.svn.sourceforge.net/vexi/?rev=4070&view=rev Author: clrg Date: 2011-03-24 04:10:08 +0000 (Thu, 24 Mar 2011)
Log Message: ----------- The real fix for #45 - Maximized, and Minimized, handling - don't manage it in the EDT, it is not necessary - use WindowStateListener.windowOpened to set initial Maximized state - fix deiconify to Maximized i.e. maintain Maximized when setting Minimized - fix Maximizing to current screen in multi-screen environment 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-24 04:05:56 UTC (rev 4069) +++ trunk/org.vexi-core.main/src/main/java/org/vexi/plat/Swing.java 2011-03-24 04:10:08 UTC (rev 4070) @@ -14,8 +14,6 @@ import java.awt.Graphics2D; import java.awt.Image; import java.awt.Insets; -import java.awt.Point; -import java.awt.Toolkit; import java.awt.Window; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; @@ -186,21 +184,23 @@ } public void _setMinimized(boolean b) { if (frame!=null) { - // Swing is not thread safe; changes must be made in the EDT - // @see InnerFrame.paint() - //frame.setExtendedState(b ? Frame.ICONIFIED : Frame.NORMAL); + // take care to maintain the maximized state + // when uniconifying/unminimizing a frame + frame.setExtendedState(b + ? (Frame.ICONIFIED | (maximized ? JFrame.MAXIMIZED_BOTH : 0)) + : (maximized ? JFrame.MAXIMIZED_BOTH : JFrame.NORMAL)); } else { Log.warn(this, "JDK 1.1 platforms cannot minimize or unminimize windows"); } } + public void _setMaximized(boolean b) { if (frame!=null) { - // Swing is not thread safe; changes must be made in the EDT - // @see InnerFrame.paint() - //frame.setExtendedState(b ? Frame.MAXIMIZED_BOTH : Frame.NORMAL); + frame.setExtendedState(b ? Frame.MAXIMIZED_BOTH : Frame.NORMAL); } else { - window.setLocation(new Point(0, 0)); - window.setSize(Toolkit.getDefaultToolkit().getScreenSize()); + // windows can not be explicitly maximized, thus + // instead resize them to the size of the screen + window.setBounds(window.getGraphicsConfiguration().getBounds()); } } @@ -305,23 +305,6 @@ // NB Swing is double buffered by default but not sufficiently createBufferStrategy(2); } - public void paint(Graphics g) { - super.paint(g); - final int state = getExtendedState(); - if (maximized) { - if ((state & JFrame.MAXIMIZED_BOTH)==0) { - setExtendedState(JFrame.MAXIMIZED_BOTH | (state & JFrame.ICONIFIED)); - } - } - if (minimized) { - if ((state & JFrame.ICONIFIED)==0) { - frame.setExtendedState(JFrame.ICONIFIED | (state & JFrame.MAXIMIZED_BOTH)); - } - } - if ((state & JFrame.NORMAL)==0) { - frame.setExtendedState(JFrame.NORMAL); - } - } // public ComponentAdapter enforceMinSize = new ComponentAdapter() { // public void componentResized(ComponentEvent event) { @@ -350,6 +333,21 @@ super(new Frame()); } public boolean isDoubleBuffered() { return true; } + + private int oldwidth, oldheight; + public void setMaximized(boolean b) { + if (b) { + // remember the pre-Maximized size for later un-maximizing + oldwidth = window.getWidth(); + oldheight = window.getHeight(); + // windows can not be explicitly maximized, thus + // instead resize them to the size of the screen + window.setBounds(window.getGraphicsConfiguration().getBounds()); + } else { + // fake un-Maximized by reverting to the previous size + window.setSize(oldwidth, oldheight); + } + } /** overrides the native Window method to enforce a minimum size */ private Dimension minimumSize = new Dimension(0, 0); public void setMinimumDimensions(int w, int h) { minimumSize = new Dimension(w, h); } @@ -612,7 +610,7 @@ public void componentHidden(ComponentEvent e) { } public void componentShown(ComponentEvent e) { } - public void windowOpened(WindowEvent e) { } + public void windowOpened(WindowEvent e) { if (maximized) _setMaximized(true); } public void windowClosed(WindowEvent e) { } public void windowClosing(WindowEvent e) { Close(); } public void windowIconified(WindowEvent e) { Minimized(true); } @@ -676,7 +674,7 @@ public void mouseExited(MouseEvent m) { mouseMoved(m); } public void mouseEntered(MouseEvent m) { mouseMoved(m); } public void mouseDragged(MouseEvent m) { mouseMoved(m); } - public void mouseMoved(MouseEvent m) { checkEvent(m); Move(m.getX(), m.getY()); } //window.repaint(); } + public void mouseMoved(MouseEvent m) { checkEvent(m); Move(m.getX(), m.getY()); } public void mousePressed(MouseEvent m) { checkEvent(m); Press(modifiersToButtonNumber(m.getModifiers())); } public void mouseReleased(MouseEvent m) { checkEvent(m); Release(modifiersToButtonNumber(m.getModifiers())); } public void mouseClicked(MouseEvent m) { 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