1 import java.awt.*; 2 import java.awt.event.*; 3 import javax.swing.*; 4 import javax.swing.border.*; 5 6 public class StatusWindow extends JFrame 7 { 8 9 private JProgressBar progressBar = null; 10 private JTextField statusLabel = null; 11 private JButton cancelButton = null; 12 private JFrame statusWindow = null; 13 private PostNewsgroup mainWindow = null; 14 15 private final int MAXPROGRESS = 13; 16 private final int MINPROGRESS = 0; 17 18 19 public StatusWindow( PostNewsgroup mw, String title, int parentX, int parentY ) 20 { 21 this.setTitle( title ); 22 this.setLocation( parentX + 100, parentY + 100 ); 23 statusWindow = this; 24 mainWindow = mw; 25 26 mainWindow.enableButtons( false ); 27 28 statusWindow.addWindowListener( new WindowAdapter() 29 { 30 public void windowClosing( WindowEvent event ) { 31 mainWindow.enableButtons( true ); 32 } 33 }); 34 35 progressBar = new JProgressBar(); 36 progressBar.setStringPainted( true ); 37 progressBar.setMaximum( MAXPROGRESS ); 38 progressBar.setMinimum( MINPROGRESS ); 39 progressBar.setSize( 30, 400 ); 40 41 JLabel progLabel = new JLabel( "Progress:" ); 42 43 JPanel progressPanel = new JPanel(); 44 progressPanel.setLayout( new BorderLayout( 10, 0 ) ); 45 progressPanel.add( progLabel, "West" ); 46 progressPanel.add( progressBar, "East" ); 47 48 statusLabel = new JTextField(); 49 statusLabel.setColumns( 25 ); 50 statusLabel.setEditable( false ); 51 statusLabel.setBorder( null ); 52 //statusLabel.setBorder( LineBorder.createGrayLineBorder() ); 53 JPanel statusPanel = new JPanel(); 54 //statusPanel.setBorder( LineBorder.createBlackLineBorder() ); 55 statusPanel.setLayout( new BorderLayout() ); 56 statusPanel.add( statusLabel, "West" ); 57 58 cancelButton = new JButton( "Cancel" ); 59 cancelButton.setSize( 30, 100 ); 60 cancelButton.setEnabled( false ); 61 cancelButton.addActionListener( new ActionListener() 62 { 63 public void actionPerformed( ActionEvent event ) { 64 // cancelling actions 65 mainWindow.enableButtons( true ); 66 statusWindow.dispose(); 67 } 68 }); 69 70 JPanel buttonPanel = new JPanel(); 71 buttonPanel.setLayout( new BorderLayout( 0, 5 ) ); 72 buttonPanel.add( cancelButton, "East" ); 73 buttonPanel.add( new JSeparator( SwingConstants.HORIZONTAL ), "North" ); 74 75 Container container = getContentPane(); 76 container.setLayout( new GridBagLayout() ); 77 GridBagConstraints constraints = new GridBagConstraints(); 78 constraints.fill = GridBagConstraints.BOTH; 79 80 constraints.gridx = 0; 81 constraints.gridy = 0; 82 constraints.gridwidth = 1; 83 constraints.gridheight = 1; 84 constraints.insets = new Insets( 15, 15, 10, 15 ); 85 container.add( progressPanel, constraints ); 86 87 constraints.gridx = 0; 88 constraints.gridy = 1; 89 constraints.gridwidth = 1; 90 constraints.gridheight = 1; 91 constraints.insets = new Insets( 10, 15, 10, 15 ); 92 container.add( statusPanel, constraints ); 93 94 constraints.gridx = 0; 95 constraints.gridy = 2; 96 constraints.gridwidth = 1; 97 constraints.gridheight = 1; 98 constraints.insets = new Insets( 10, 15, 5, 15 ); 99 container.add( buttonPanel, constraints ); 100 101 this.pack(); 102 this.setResizable( false ); 103 //this.setVisible( true ); 104 105 } 106 107 108 public void setStatus( int progress, String status ) 109 { 110 progressBar.setValue( progress ); 111 statusLabel.setText( status ); 112 statusLabel.setToolTipText( status ); 113 if( progress == MAXPROGRESS ) 114 { 115 cancelButton.setEnabled( true ); 116 cancelButton.setText( "Close" ); 117 } 118 update( getGraphics() ); 119 mainWindow.update( mainWindow.getGraphics() ); 120 } 121 122 123 public void enableCancelButton( boolean enable ) 124 { 125 if( enable ) 126 { 127 cancelButton.setEnabled( true ); 128 cancelButton.setText( "Finish" ); 129 } 130 else 131 { 132 cancelButton.setEnabled( false ); 133 cancelButton.setText( "Cancel" ); 134 } 135 136 } 137 138 } 139