001         package com.croftsoft.core.gui;
002    
003         import java.awt.*;
004         import java.awt.event.*;
005         import javax.swing.*;
006    
007         import com.croftsoft.core.gui.WindowLib;
008         import com.croftsoft.core.lang.NullArgumentException;
009         import com.croftsoft.core.math.MathConstants;
010    
011         /*********************************************************************
012         * Displays a license agreement and an accept/decline button choice.
013         *
014         * @version
015         *   2002-01-27
016         * @since
017         *   2001-07-24
018         * @author
019         *   <a href="https://www.croftsoft.com/">David Wallace Croft</a>
020         *********************************************************************/
021    
022         public final class  LicenseFrame
023           extends JFrame
024         //////////////////////////////////////////////////////////////////////
025         //////////////////////////////////////////////////////////////////////
026         {
027    
028         private static final String  DEFAULT_FRAME_TITLE
029           = "License Agreement";
030    
031         /*********************************************************************
032         * Main constructor.
033         *
034         * @param  licenseAgreementText
035         *
036         *    Must not be null.
037         *
038         * @param  acceptActionListener
039         *
040         *    Called when the Accept button is clicked.  Must not be null.
041         *
042         * @param  declineActionListener
043         *
044         *    If null, the Decline button will simply trigger System.exit(0).
045         *
046         * @param  panelBackgroundColor
047         *
048         *    May be null.
049         *
050         * @param  frameTitle
051         *
052         *    May be null.
053         *
054         * @param  size
055         *
056         *    May be null.
057         *
058         * @param  frameIconImage
059         *
060         *    May be null.
061         *
062         * @param  splashImage
063         *
064         *    May be null.
065         *********************************************************************/
066         public  LicenseFrame (
067           String          licenseAgreementText,
068           ActionListener  acceptActionListener,
069           ActionListener  declineActionListener,
070           Color           panelBackgroundColor,
071           String          frameTitle,
072           Dimension       size,
073           Image           frameIconImage,
074           Image           splashImage )
075         //////////////////////////////////////////////////////////////////////
076         {
077           super ( frameTitle != null ? frameTitle : DEFAULT_FRAME_TITLE );
078    
079           LicensePanel  licensePanel = new LicensePanel (
080             licenseAgreementText,
081             acceptActionListener,
082             declineActionListener,
083             panelBackgroundColor,
084             splashImage );
085    
086           getContentPane ( ).add ( licensePanel );
087    
088    // This doesn't seem to work in Java 1.3.
089    //
090    //     getRootPane ( ).setDefaultButton (
091    //       licensePanel.getAcceptJButton ( ) );
092    
093           setDefaultCloseOperation ( WindowConstants.DO_NOTHING_ON_CLOSE );
094    
095           addWindowListener ( new ShutdownWindowListener ( ) );
096    
097           if ( frameIconImage != null )
098           {
099             setIconImage ( frameIconImage );
100           }
101    
102           if ( size == null )
103           {
104             size = Toolkit.getDefaultToolkit ( ).getScreenSize ( );
105    
106             if ( splashImage != null )
107             {
108               int  imageWidth = splashImage.getWidth ( this );
109    
110               if ( imageWidth < 0.8 * size.width )
111               {
112                 size.width = imageWidth;
113               }
114               else
115               {
116                 size.width *= 0.8;
117               }
118    
119               int  goldenHeight
120                 = ( int ) ( size.width * MathConstants.GOLDEN_RATIO );
121    
122               if ( goldenHeight < 0.8 * size.height )
123               {
124                 size.height = goldenHeight;
125               }
126               else
127               {
128                 size.height *= 0.8;
129               }
130             }
131             else
132             {
133               size.width  *= 0.8;
134    
135               size.height *= 0.8;
136             }
137           }
138    
139           WindowLib.centerOnScreen ( this, size );
140         }
141    
142         /*********************************************************************
143         * Convenience constructor.
144         *********************************************************************/
145         public  LicenseFrame (
146           String          licenseAgreementText,
147           ActionListener  acceptActionListener,
148           Color           panelBackgroundColor )
149         //////////////////////////////////////////////////////////////////////
150         {
151           this (
152             licenseAgreementText,
153             acceptActionListener,
154             ( ActionListener ) null,
155             panelBackgroundColor,
156             ( String    ) null,
157             ( Dimension ) null,
158             ( Image     ) null,
159             ( Image     ) null );
160         }
161    
162         /*********************************************************************
163         * Convenience constructor.
164         *********************************************************************/
165         public  LicenseFrame (
166           String          licenseAgreementText,
167           ActionListener  acceptActionListener )
168         //////////////////////////////////////////////////////////////////////
169         {
170           this (
171             licenseAgreementText,
172             acceptActionListener,
173             ( Color ) null );
174         }
175    
176         //////////////////////////////////////////////////////////////////////
177         //////////////////////////////////////////////////////////////////////
178         }