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