/hg/icedtea-web: All IcedTea-Web dialogues are centered to middl...

jvanek at icedtea.classpath.org jvanek at icedtea.classpath.org
Thu Jan 10 08:56:59 PST 2013


changeset 3e4b40d47487 in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=3e4b40d47487
author: Jiri Vanek <jvanek at redhat.com>
date: Thu Jan 10 17:57:19 2013 +0100

	All IcedTea-Web dialogues are centered to middle of active screen

	Active screen in this context is the one, where the mouse is presented
	or default when no mouse presention detected.
	Patch is affecteing only IcedTea-Web custom dialogues.


diffstat:

 ChangeLog                                                                             |   14 +
 NEWS                                                                                  |    1 +
 netx/net/sourceforge/jnlp/JNLPSplashScreen.java                                       |    8 +-
 netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsDialog.java               |    6 +-
 netx/net/sourceforge/jnlp/controlpanel/CacheViewer.java                               |    6 +-
 netx/net/sourceforge/jnlp/security/SecurityDialog.java                                |    7 +-
 netx/net/sourceforge/jnlp/security/viewer/CertificateViewer.java                      |    7 +-
 netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/BasePainter.java |    3 +-
 netx/net/sourceforge/jnlp/util/ScreenFinder.java                                      |  100 ++++++++++
 9 files changed, 128 insertions(+), 24 deletions(-)

diffs (281 lines):

diff -r 1b86028e546b -r 3e4b40d47487 ChangeLog
--- a/ChangeLog	Thu Jan 10 13:18:45 2013 +0100
+++ b/ChangeLog	Thu Jan 10 17:57:19 2013 +0100
@@ -1,3 +1,17 @@
+2013-01-10  Jiri Vanek  <jvanek at redhat.com>
+
+	All IcedTea-Web dialogues are centered to middle of active screen
+	* NEWS: mentioned this feature
+	* netx/net/sourceforge/jnlp/JNLPSplashScreen.java:
+	* netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsDialog.java:
+	* netx/net/sourceforge/jnlp/controlpanel/CacheViewer.java:
+	* netx/net/sourceforge/jnlp/security/SecurityDialog.java:
+	* netx/net/sourceforge/jnlp/security/viewer/CertificateViewer.java:
+	* netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/BasePainter.java:
+	Dialogues in above classes made centering to active screen
+	* netx/net/sourceforge/jnlp/util/ScreenFinder.java: New file, utility
+	class which can find active monitor and center dialogue into it.
+
 2013-01-09  Jiri Vanek  <jvanek at redhat.com>
 
 	First part of fix of recreating desktop icon
diff -r 1b86028e546b -r 3e4b40d47487 NEWS
--- a/NEWS	Thu Jan 10 13:18:45 2013 +0100
+++ b/NEWS	Thu Jan 10 17:57:19 2013 +0100
@@ -11,6 +11,7 @@
 New in release 1.4 (2012-XX-XX):
 * Added cs_CZ localisation
 * Splash screen for javaws and plugin
+* All IcedTea-Web dialogues are centered to middle of active screen
 * Security updates
   - CVE-2012-3422, RH840592: Potential read from an uninitialized memory location
   - CVE-2012-3423, RH841345: Incorrect handling of not 0-terminated strings
diff -r 1b86028e546b -r 3e4b40d47487 netx/net/sourceforge/jnlp/JNLPSplashScreen.java
--- a/netx/net/sourceforge/jnlp/JNLPSplashScreen.java	Thu Jan 10 13:18:45 2013 +0100
+++ b/netx/net/sourceforge/jnlp/JNLPSplashScreen.java	Thu Jan 10 17:57:19 2013 +0100
@@ -43,6 +43,7 @@
 import java.awt.Graphics2D;
 import java.awt.Image;
 import java.awt.Insets;
+import java.awt.Rectangle;
 import java.io.IOException;
 import java.net.URL;
 import javax.imageio.ImageIO;
@@ -53,6 +54,7 @@
 import net.sourceforge.jnlp.splashscreen.SplashUtils;
 import net.sourceforge.jnlp.splashscreen.parts.InformationElement;
 import net.sourceforge.jnlp.util.ImageResources;
+import net.sourceforge.jnlp.util.ScreenFinder;
 
 public class JNLPSplashScreen extends JDialog {
 
@@ -145,11 +147,7 @@
         setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
         setSize(new Dimension(minimumWidth, minimumHeight));
         setPreferredSize(new Dimension(minimumWidth, minimumHeight));
-        // Centering to middle of Toolkit.getDefaultToolkit().getScreenSize()
-        // centers to the middle of all monitors. Let's center to the middle
-        // of the primary monitor instead.
-        // TODO center on the 'current' monitor to meet user expectation
-        setLocationRelativeTo(null);
+        ScreenFinder.centerWindowsToCurrentScreen(this);
     }
 
     @Override
diff -r 1b86028e546b -r 3e4b40d47487 netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsDialog.java
--- a/netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsDialog.java	Thu Jan 10 13:18:45 2013 +0100
+++ b/netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsDialog.java	Thu Jan 10 17:57:19 2013 +0100
@@ -32,6 +32,7 @@
 import net.sourceforge.jnlp.config.DeploymentConfiguration;
 import net.sourceforge.jnlp.runtime.Translator;
 import net.sourceforge.jnlp.util.ImageResources;
+import net.sourceforge.jnlp.util.ScreenFinder;
 
 /**
  * This dialog provides a means for user to edit more of the proxy settings.
@@ -106,10 +107,7 @@
      * Center the dialog box.
      */
     private void centerDialog() {
-        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
-        Dimension dialogSize = getSize();
-
-        setLocation((screen.width - dialogSize.width) / 2, (screen.height - dialogSize.height) / 2);
+        ScreenFinder.centerWindowsToCurrentScreen(this);
     }
 
     /**
diff -r 1b86028e546b -r 3e4b40d47487 netx/net/sourceforge/jnlp/controlpanel/CacheViewer.java
--- a/netx/net/sourceforge/jnlp/controlpanel/CacheViewer.java	Thu Jan 10 13:18:45 2013 +0100
+++ b/netx/net/sourceforge/jnlp/controlpanel/CacheViewer.java	Thu Jan 10 17:57:19 2013 +0100
@@ -31,6 +31,7 @@
 import net.sourceforge.jnlp.config.DeploymentConfiguration;
 import net.sourceforge.jnlp.runtime.Translator;
 import net.sourceforge.jnlp.util.ImageResources;
+import net.sourceforge.jnlp.util.ScreenFinder;
 
 /**
  * This class will provide a visual way of viewing cache.
@@ -113,9 +114,6 @@
      * Center the dialog box.
      */
     private void centerDialog() {
-        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
-        Dimension dialogSize = getSize();
-
-        setLocation((screen.width - dialogSize.width) / 2, (screen.height - dialogSize.height) / 2);
+        ScreenFinder.centerWindowsToCurrentScreen(this);
     }
 }
diff -r 1b86028e546b -r 3e4b40d47487 netx/net/sourceforge/jnlp/security/SecurityDialog.java
--- a/netx/net/sourceforge/jnlp/security/SecurityDialog.java	Thu Jan 10 13:18:45 2013 +0100
+++ b/netx/net/sourceforge/jnlp/security/SecurityDialog.java	Thu Jan 10 17:57:19 2013 +0100
@@ -52,6 +52,7 @@
 import java.util.concurrent.CopyOnWriteArrayList;
 
 import java.util.List;
+import net.sourceforge.jnlp.util.ScreenFinder;
 
 /**
  * Provides methods for showing security warning dialogs for a wide range of
@@ -312,11 +313,7 @@
     }
 
     private static void centerDialog(JDialog dialog) {
-        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
-        Dimension dialogSize = dialog.getSize();
-
-        dialog.setLocation((screen.width - dialogSize.width) / 2,
-                        (screen.height - dialogSize.height) / 2);
+        ScreenFinder.centerWindowsToCurrentScreen(dialog);
     }
 
     private void selectDefaultButton() {
diff -r 1b86028e546b -r 3e4b40d47487 netx/net/sourceforge/jnlp/security/viewer/CertificateViewer.java
--- a/netx/net/sourceforge/jnlp/security/viewer/CertificateViewer.java	Thu Jan 10 13:18:45 2013 +0100
+++ b/netx/net/sourceforge/jnlp/security/viewer/CertificateViewer.java	Thu Jan 10 17:57:19 2013 +0100
@@ -52,6 +52,7 @@
 
 import net.sourceforge.jnlp.runtime.JNLPRuntime;
 import net.sourceforge.jnlp.util.ImageResources;
+import net.sourceforge.jnlp.util.ScreenFinder;
 
 public class CertificateViewer extends JDialog {
 
@@ -94,11 +95,7 @@
     }
 
     private void centerDialog() {
-        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
-        Dimension dialogSize = getSize();
-
-        setLocation((screen.width - dialogSize.width) / 2,
-                        (screen.height - dialogSize.height) / 2);
+        ScreenFinder.centerWindowsToCurrentScreen(this);
     }
 
     public static void showCertificateViewer() throws Exception {
diff -r 1b86028e546b -r 3e4b40d47487 netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/BasePainter.java
--- a/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/BasePainter.java	Thu Jan 10 13:18:45 2013 +0100
+++ b/netx/net/sourceforge/jnlp/splashscreen/impls/defaultsplashscreen2012/BasePainter.java	Thu Jan 10 17:57:19 2013 +0100
@@ -58,6 +58,7 @@
 import net.sourceforge.jnlp.splashscreen.parts.BasicComponentSplashScreen;
 import net.sourceforge.jnlp.splashscreen.parts.InfoItem;
 import net.sourceforge.jnlp.splashscreen.parts.InformationElement;
+import net.sourceforge.jnlp.util.ScreenFinder;
 
 public class BasePainter implements Observer {
 
@@ -281,7 +282,7 @@
                 showInfo = false;
             }
         }
-        if (Math.min(h, w) < Toolkit.getDefaultToolkit().getScreenSize().getHeight() / 10) {
+        if (Math.min(h, w) < ScreenFinder.getCurrentScreenSizeWithoutBounds().getHeight() / 10) {
             showNiceTexts = false;
         } else {
             showNiceTexts = true;
diff -r 1b86028e546b -r 3e4b40d47487 netx/net/sourceforge/jnlp/util/ScreenFinder.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/netx/net/sourceforge/jnlp/util/ScreenFinder.java	Thu Jan 10 17:57:19 2013 +0100
@@ -0,0 +1,100 @@
+/* ScreenFinder.java
+Copyright (C) 2012 Red Hat, Inc.
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+IcedTea is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+package net.sourceforge.jnlp.util;
+
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import java.awt.Insets;
+import java.awt.MouseInfo;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.Toolkit;
+import java.awt.Window;
+
+public class ScreenFinder {
+
+    public static GraphicsDevice getCurrentScreen() {
+        Point p = MouseInfo.getPointerInfo().getLocation();
+        return getScreenOnCoords(p);
+
+    }
+    public static Rectangle  getCurrentScreenSizeWithoutBounds() {
+        Point p = MouseInfo.getPointerInfo().getLocation();
+        return getScreenOnCoordsWithutBounds(p);
+
+    }
+
+     public static void  centerWindowsToCurrentScreen(Window w) {
+        Rectangle bounds = getCurrentScreenSizeWithoutBounds();
+        w.setLocation(bounds.x + (bounds.width - w.getWidth())/2,
+                bounds.y + (bounds.height - w.getHeight())/2);
+
+    }
+
+    public static GraphicsDevice getScreenOnCoords(Point point) {
+        GraphicsEnvironment e = GraphicsEnvironment.getLocalGraphicsEnvironment();
+        GraphicsDevice[] devices = e.getScreenDevices();
+        GraphicsDevice result = null;
+        //now get the configuration(s) for each device
+        for (GraphicsDevice device : devices) {
+            //GraphicsConfiguration[] configurations = device.getConfigurations();
+            //or?
+            GraphicsConfiguration[] configurations = new GraphicsConfiguration[]{device.getDefaultConfiguration()};
+            for (GraphicsConfiguration config : configurations) {
+                Rectangle gcBounds = config.getBounds();
+                if (gcBounds.contains(point)) {
+                    result = device;
+                }
+            }
+        }
+        if (result == null) {
+            //not found, get the default display
+            result = e.getDefaultScreenDevice();
+        }
+        return result;
+    }
+
+    public static Rectangle getScreenOnCoordsWithutBounds(Point p) {
+        GraphicsDevice device = getScreenOnCoords(p);
+        Rectangle screenSize = device.getDefaultConfiguration().getBounds();
+        Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(device.getDefaultConfiguration());
+        return new Rectangle((int)screenSize.getX()+insets.left, (int)screenSize.getY()+insets.top, (int)screenSize.getWidth()-insets.left, (int)screenSize.getHeight()-insets.bottom);
+    }
+
+
+}



More information about the distro-pkg-dev mailing list