From: <jde...@us...> - 2012-06-09 05:57:59
|
Revision: 16843 http://pcgen.svn.sourceforge.net/pcgen/?rev=16843&view=rev Author: jdempsey Date: 2012-06-09 05:57:53 +0000 (Sat, 09 Jun 2012) Log Message: ----------- Fix bug: Create Monster / Kit Box is too large for my screen (Close Button can't be reached) Issue#: CODE-1490 Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/gui2/dialog/KitSelectionDialog.java Trunk/pcgen/code/src/java/pcgen/gui2/tools/Utility.java Modified: Trunk/pcgen/code/src/java/pcgen/gui2/dialog/KitSelectionDialog.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui2/dialog/KitSelectionDialog.java 2012-06-09 04:14:08 UTC (rev 16842) +++ Trunk/pcgen/code/src/java/pcgen/gui2/dialog/KitSelectionDialog.java 2012-06-09 05:57:53 UTC (rev 16843) @@ -74,6 +74,7 @@ setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); initComponents(); pack(); + Utility.resizeDialogToScreen(this); } private void initComponents() Modified: Trunk/pcgen/code/src/java/pcgen/gui2/tools/Utility.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui2/tools/Utility.java 2012-06-09 04:14:08 UTC (rev 16842) +++ Trunk/pcgen/code/src/java/pcgen/gui2/tools/Utility.java 2012-06-09 05:57:53 UTC (rev 16843) @@ -152,7 +152,10 @@ // encapsulated to accomodate this with a hack. // TODO: remove the hack, once Java fixed this. // final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - final Rectangle screenSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getBounds(); + final Rectangle screenSize = + GraphicsEnvironment.getLocalGraphicsEnvironment() + .getDefaultScreenDevice().getDefaultConfiguration() + .getBounds(); final Dimension dialogSize = dialog.getSize(); @@ -165,12 +168,35 @@ { dialogSize.width = screenSize.width; } - + dialog.setSize(dialogSize); + dialog.setLocation(screenSize.x + (screenSize.width - dialogSize.width) / 2, screenSize.y + (screenSize.height - dialogSize.height) / 2); } /** + * Update the size of the dialog to ensure it will fit on the screen. + * @param dialog The dialog to be resized. + */ + public static void resizeDialogToScreen(JDialog dialog) + { + Rectangle screenBounds = dialog.getGraphicsConfiguration().getBounds(); + + final Dimension dialogSize = dialog.getSize(); + + if (dialogSize.height > screenBounds.height) + { + dialogSize.height = screenBounds.height; + } + + if (dialogSize.width > screenBounds.width) + { + dialogSize.width = screenBounds.width; + } + dialog.setSize(dialogSize); + } + + /** * Centers a <code>JFrame</code> to the screen. * * @param frame JFrame frame to center This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |