001    /*
002     * Dialogs
003     * 
004     * Copyright (c) 2001, 2002, 2003 Marco Schmidt.
005     * All rights reserved.
006     */
007    
008    package net.sourceforge.jiu.gui.awt.dialogs;
009    
010    import java.awt.Dimension;
011    import java.awt.Frame;
012    import java.awt.Rectangle;
013    import java.awt.Toolkit;
014    import java.awt.Window;
015    
016    /**
017     * Convenience class that provides a number of static helper methods to deal with dialogs.
018     * @author Marco Schmidt
019     */
020    public class Dialogs
021    {
022            private Dialogs()
023            {
024            }
025    
026            /**
027             * Centers the argument window on screen.
028             */
029            public static void center(Window window)
030            {
031                    if (window == null)
032                    {
033                            return;
034                    }
035                    Rectangle rect = window.getBounds();
036                    int width = rect.width;
037                    int height = rect.height;
038                    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
039                    window.setLocation((screenSize.width / 2) - (width / 2),
040                            (screenSize.height / 2) - (height / 2));
041            }
042    
043            /**
044             * Creates a new IntegerDialog, displays it and returns the Integer
045             * value specified by the user (or null if the dialog was canceled).
046             * @param owner frame from which the dialog is spawned
047             * @param title text for the title bar of the dialog
048             * @param message message displayed in the dialog
049             * @param minValue minimal allowed integer value to be entered by the user 
050             * @param initialValue initial integer value shown in the dialog
051             * @param maxValue maximal allowed integer value to be entered by the user
052             * @param okText the text for the OK button
053             * @param cancelText the text for the cancel button
054             * @return the specified integer value or null if the Cancel button was pressed
055             */
056            public static Integer getInteger(Frame owner, String title, String message,
057                    int minValue, int initialValue, int maxValue, String okText,
058                    String cancelText)
059            {
060                    IntegerDialog dialog = new IntegerDialog(owner, title, message,
061                            minValue, initialValue, maxValue, okText, cancelText);
062                    dialog.show();
063                    return dialog.getValue();
064            }
065    }