1 package net.sourceforge.javalogging.installer; 2 3 import java.awt.*; 4 import java.awt.event.*; 5 import javax.swing.*; 6 7 8 public class ProgressDialog extends JDialog { 9 10 GridBagLayout gridBagLayout1 = new GridBagLayout(); 11 JScrollPane messageArea = new JScrollPane(); 12 JCheckBox checkExisting = new JCheckBox(); 13 JCheckBox installClasses = new JCheckBox(); 14 JCheckBox installProperties = new JCheckBox(); 15 JButton closeButton = new JButton(); 16 17 int exitCode; 18 19 public static final int CHECK_EXISTING = 0; 20 public static final int INSTALL_CLASSES = 1; 21 public static final int INSTALL_PROPERTIES = 2; 22 23 private JCheckBox[] boxes = { 24 checkExisting, 25 installClasses, 26 installProperties 27 }; 28 JTextArea messageText = new JTextArea(); 29 30 public void mark( final int item ) { 31 SwingUtilities.invokeLater( new Runnable () { public void run() { 32 boxes[ item ].setSelected( true ); 33 }}); 34 } 35 36 public void enableClose( int aCode ) { 37 exitCode = aCode; 38 closeButton.setEnabled( true ); 39 getGlassPane().setVisible( false ); 40 for ( int index = 0 ; index < boxes.length ; index++ ) { 41 boxes[ index ].setEnabled( false ); 42 } 43 } 44 45 public void enableClose( String aMessage, int aCode ) { 46 addMessage( aMessage ); 47 enableClose( aCode ); 48 } 49 50 public void addMessage( final String aMessage ) { 51 SwingUtilities.invokeLater( new Runnable () { public void run() { 52 messageText.setText( messageText.getText() + "\n" + aMessage ); 53 }}); 54 } 55 56 public ProgressDialog( Frame f ) { 57 super( f ); 58 init(); 59 } 60 61 public ProgressDialog() { 62 init(); 63 } 64 65 private void init() { 66 jbInit(); 67 closeButton.addActionListener( new ActionListener() { 68 public void actionPerformed( ActionEvent evt ) { 69 System.exit( exitCode ); 70 } 71 }); 72 Dimension dialogSize = new Dimension( 700, 250 ); 73 setSize( dialogSize ); 74 } 75 76 public void setVisible( boolean visible ) { 77 if ( visible ) { 78 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 79 Dimension dialogSize = getSize(); 80 setLocation( ( screenSize.width - dialogSize.width )/2, (screenSize.height - dialogSize.height)/2 ); 81 getGlassPane().setVisible( true ); 82 } 83 super.setVisible( visible ); 84 } 85 86 private void jbInit() { 87 this.setTitle("Install Lumberjack"); 88 this.getContentPane().setLayout(gridBagLayout1); 89 checkExisting.setRequestFocusEnabled(false); 90 installClasses.setRequestFocusEnabled(false); 91 installProperties.setRequestFocusEnabled(false); 92 checkExisting.setText("Check for existing installation"); 93 closeButton.setEnabled(false); 94 closeButton.setText("Close"); 95 installClasses.setText("Install classes"); 96 installProperties.setText("Install logging.properties"); 97 this.getContentPane().add(messageArea, new GridBagConstraints(2, 0, 1, 5, 1.0, 1.0 98 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 10, 10, 10), 0, 0)); 99 messageArea.getViewport().add(messageText, null); 100 this.getContentPane().add(checkExisting, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0 101 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 10, 10, 10), 0, 0)); 102 this.getContentPane().add(closeButton, new GridBagConstraints(2, 5, 1, 1, 0.0, 0.0 103 ,GridBagConstraints.SOUTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 10, 10), 0, 0)); 104 this.getContentPane().add(installClasses, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0 105 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 10, 10, 10), 0, 0)); 106 this.getContentPane().add(installProperties, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0 107 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(10, 10, 10, 10), 0, 0)); 108 } 109 } | Popular Tags |