001 package com.croftsoft.core.gui;
002
003 import java.awt.*;
004 import java.awt.event.*;
005 import javax.swing.*;
006 import javax.swing.border.*;
007
008 import com.croftsoft.core.lang.NullArgumentException;
009
010 /*********************************************************************
011 * Displays a license agreement and an accept/decline button choice.
012 *
013 * @version
014 * 2002-01-27
015 * @since
016 * 2001-07-20
017 * @author
018 * <a href="https://www.croftsoft.com/">David Wallace Croft</a>
019 *********************************************************************/
020
021 public final class LicensePanel
022 extends JPanel
023 implements ActionListener
024 //////////////////////////////////////////////////////////////////////
025 //////////////////////////////////////////////////////////////////////
026 {
027
028 private final JButton acceptJButton;
029
030 private final JButton declineJButton;
031
032 //////////////////////////////////////////////////////////////////////
033 //////////////////////////////////////////////////////////////////////
034
035 /*********************************************************************
036 * Main constructor.
037 *
038 * @param licenseAgreementText
039 *
040 * Must not be null.
041 *
042 * @param acceptActionListener
043 *
044 * Called when the Accept button is clicked. Must not be null.
045 *
046 * @param declineActionListener
047 *
048 * If null, the Decline button will simply trigger System.exit(0).
049 *
050 * @param panelBackgroundColor
051 *
052 * May be null.
053 *
054 * @param splashImage
055 *
056 * May be null.
057 *********************************************************************/
058 public LicensePanel (
059 String licenseAgreementText,
060 ActionListener acceptActionListener,
061 ActionListener declineActionListener,
062 Color panelBackgroundColor,
063 Image splashImage )
064 //////////////////////////////////////////////////////////////////////
065 {
066 super ( new BorderLayout ( ), true ); // isDoubleBuffered
067
068 NullArgumentException.check ( licenseAgreementText );
069
070 NullArgumentException.check ( acceptActionListener );
071
072 if ( panelBackgroundColor != null )
073 {
074 setBackground ( panelBackgroundColor );
075 }
076
077 if ( splashImage != null )
078 {
079 add ( new JLabel ( new ImageIcon ( splashImage ) ), BorderLayout.NORTH );
080 }
081
082 JTextArea jTextArea = new JTextArea ( );
083
084 jTextArea.setEditable ( false );
085
086 jTextArea.setLineWrap ( true );
087
088 jTextArea.setWrapStyleWord ( true );
089
090 // How can I set the border to 2 characters wide?
091
092 jTextArea.setBorder ( new EmptyBorder ( 4, 4, 4, 4 ) );
093
094 jTextArea.setText ( licenseAgreementText );
095
096 add ( new JScrollPane ( jTextArea ), BorderLayout.CENTER );
097
098 acceptJButton = new JButton ( "Accept" );
099
100 acceptJButton.addActionListener ( acceptActionListener );
101
102 declineJButton = new JButton ( "Decline" );
103
104 if ( declineActionListener == null )
105 {
106 declineActionListener = this;
107 }
108
109 declineJButton.addActionListener ( declineActionListener );
110
111 JButton [ ] jButtons
112 = new JButton [ ] { declineJButton, acceptJButton };
113
114 add ( new ButtonPanel2 ( jButtons ), BorderLayout.SOUTH );
115 }
116
117 /*********************************************************************
118 * Convenience constructor.
119 *********************************************************************/
120 public LicensePanel (
121 String licenseAgreementText,
122 ActionListener acceptActionListener,
123 Color panelBackgroundColor )
124 //////////////////////////////////////////////////////////////////////
125 {
126 this (
127 licenseAgreementText,
128 acceptActionListener,
129 ( ActionListener ) null,
130 panelBackgroundColor,
131 ( Image ) null );
132 }
133
134 /*********************************************************************
135 * Convenience constructor.
136 *********************************************************************/
137 public LicensePanel (
138 String licenseAgreementText,
139 ActionListener acceptActionListener )
140 //////////////////////////////////////////////////////////////////////
141 {
142 this (
143 licenseAgreementText,
144 acceptActionListener,
145 ( Color ) null );
146 }
147
148 //////////////////////////////////////////////////////////////////////
149 //////////////////////////////////////////////////////////////////////
150
151 public JButton getAcceptJButton ( ) { return acceptJButton; }
152
153 public JButton getDeclineJButton ( ) { return declineJButton; }
154
155 //////////////////////////////////////////////////////////////////////
156 //////////////////////////////////////////////////////////////////////
157
158 public void actionPerformed ( ActionEvent actionEvent )
159 //////////////////////////////////////////////////////////////////////
160 {
161 if ( actionEvent.getSource ( ) == declineJButton )
162 {
163 System.exit ( 0 );
164 }
165 }
166
167 //////////////////////////////////////////////////////////////////////
168 //////////////////////////////////////////////////////////////////////
169 }