1*cd519653SAndrew Rist /**************************************************************
2*cd519653SAndrew Rist  *
3*cd519653SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*cd519653SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*cd519653SAndrew Rist  * distributed with this work for additional information
6*cd519653SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*cd519653SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*cd519653SAndrew Rist  * "License"); you may not use this file except in compliance
9*cd519653SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*cd519653SAndrew Rist  *
11*cd519653SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*cd519653SAndrew Rist  *
13*cd519653SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*cd519653SAndrew Rist  * software distributed under the License is distributed on an
15*cd519653SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*cd519653SAndrew Rist  * KIND, either express or implied.  See the License for the
17*cd519653SAndrew Rist  * specific language governing permissions and limitations
18*cd519653SAndrew Rist  * under the License.
19*cd519653SAndrew Rist  *
20*cd519653SAndrew Rist  *************************************************************/
21*cd519653SAndrew Rist 
22cdf0e10cSrcweir import java.awt.*;
23cdf0e10cSrcweir import java.awt.event.*;
24cdf0e10cSrcweir import javax.swing.*;
25cdf0e10cSrcweir import javax.swing.border.*;
26cdf0e10cSrcweir 
27cdf0e10cSrcweir public class StatusWindow extends JFrame
28cdf0e10cSrcweir {
29cdf0e10cSrcweir 
30cdf0e10cSrcweir 	private JProgressBar progressBar = null;
31cdf0e10cSrcweir 	private JTextField statusLabel = null;
32cdf0e10cSrcweir 	private JButton cancelButton = null;
33cdf0e10cSrcweir 	private JFrame statusWindow = null;
34cdf0e10cSrcweir 	private PostNewsgroup mainWindow = null;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir 	private final int MAXPROGRESS = 13;
37cdf0e10cSrcweir 	private final int MINPROGRESS = 0;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 
StatusWindow( PostNewsgroup mw, String title, int parentX, int parentY )40cdf0e10cSrcweir 	public StatusWindow( PostNewsgroup mw, String title, int parentX, int parentY )
41cdf0e10cSrcweir 	{
42cdf0e10cSrcweir 		this.setTitle( title );
43cdf0e10cSrcweir 		this.setLocation( parentX + 100, parentY + 100 );
44cdf0e10cSrcweir 		statusWindow = this;
45cdf0e10cSrcweir 		mainWindow = mw;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 		mainWindow.enableButtons( false );
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 		statusWindow.addWindowListener( new WindowAdapter()
50cdf0e10cSrcweir 		{
51cdf0e10cSrcweir 			public void windowClosing( WindowEvent event ) {
52cdf0e10cSrcweir 				mainWindow.enableButtons( true );
53cdf0e10cSrcweir 			}
54cdf0e10cSrcweir 		});
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 		progressBar = new JProgressBar();
57cdf0e10cSrcweir 		progressBar.setStringPainted( true );
58cdf0e10cSrcweir 		progressBar.setMaximum( MAXPROGRESS );
59cdf0e10cSrcweir 		progressBar.setMinimum( MINPROGRESS );
60cdf0e10cSrcweir 		progressBar.setSize( 30, 400 );
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 		JLabel progLabel = new JLabel( "Progress:" );
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 		JPanel progressPanel = new JPanel();
65cdf0e10cSrcweir 		progressPanel.setLayout( new BorderLayout( 10, 0 ) );
66cdf0e10cSrcweir 		progressPanel.add( progLabel, "West" );
67cdf0e10cSrcweir 		progressPanel.add( progressBar, "East" );
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 		statusLabel = new JTextField();
70cdf0e10cSrcweir 		statusLabel.setColumns( 25 );
71cdf0e10cSrcweir 		statusLabel.setEditable( false );
72cdf0e10cSrcweir 		statusLabel.setBorder( null );
73cdf0e10cSrcweir 		//statusLabel.setBorder( LineBorder.createGrayLineBorder() );
74cdf0e10cSrcweir 		JPanel statusPanel = new JPanel();
75cdf0e10cSrcweir 		//statusPanel.setBorder( LineBorder.createBlackLineBorder() );
76cdf0e10cSrcweir 		statusPanel.setLayout( new BorderLayout() );
77cdf0e10cSrcweir 		statusPanel.add( statusLabel, "West" );
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 		cancelButton = new JButton( "Cancel" );
80cdf0e10cSrcweir 		cancelButton.setSize( 30, 100 );
81cdf0e10cSrcweir 		cancelButton.setEnabled( false );
82cdf0e10cSrcweir 		cancelButton.addActionListener( new ActionListener()
83cdf0e10cSrcweir 		{
84cdf0e10cSrcweir                         public void actionPerformed( ActionEvent event ) {
85cdf0e10cSrcweir                                 // cancelling actions
86cdf0e10cSrcweir 				mainWindow.enableButtons( true );
87cdf0e10cSrcweir 				statusWindow.dispose();
88cdf0e10cSrcweir                         }
89cdf0e10cSrcweir                 });
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 		JPanel buttonPanel = new JPanel();
92cdf0e10cSrcweir 		buttonPanel.setLayout( new BorderLayout( 0, 5 ) );
93cdf0e10cSrcweir 		buttonPanel.add( cancelButton, "East" );
94cdf0e10cSrcweir 		buttonPanel.add( new JSeparator( SwingConstants.HORIZONTAL ), "North" );
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 		Container container = getContentPane();
97cdf0e10cSrcweir 		container.setLayout( new GridBagLayout() );
98cdf0e10cSrcweir 		GridBagConstraints constraints = new GridBagConstraints();
99cdf0e10cSrcweir 		constraints.fill = GridBagConstraints.BOTH;
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 		constraints.gridx = 0;
102cdf0e10cSrcweir 		constraints.gridy = 0;
103cdf0e10cSrcweir 		constraints.gridwidth = 1;
104cdf0e10cSrcweir 		constraints.gridheight = 1;
105cdf0e10cSrcweir 		constraints.insets = new Insets( 15, 15, 10, 15 );
106cdf0e10cSrcweir 		container.add( progressPanel, constraints );
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 		constraints.gridx = 0;
109cdf0e10cSrcweir 		constraints.gridy = 1;
110cdf0e10cSrcweir 		constraints.gridwidth = 1;
111cdf0e10cSrcweir 		constraints.gridheight = 1;
112cdf0e10cSrcweir 		constraints.insets = new Insets( 10, 15, 10, 15 );
113cdf0e10cSrcweir 		container.add( statusPanel, constraints );
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 		constraints.gridx = 0;
116cdf0e10cSrcweir 		constraints.gridy = 2;
117cdf0e10cSrcweir 		constraints.gridwidth = 1;
118cdf0e10cSrcweir 		constraints.gridheight = 1;
119cdf0e10cSrcweir 		constraints.insets = new Insets( 10, 15, 5, 15 );
120cdf0e10cSrcweir 		container.add( buttonPanel, constraints );
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 		this.pack();
123cdf0e10cSrcweir 		this.setResizable( false );
124cdf0e10cSrcweir 		//this.setVisible( true );
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 	}
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 
setStatus( int progress, String status )129cdf0e10cSrcweir 	public void setStatus( int progress, String status )
130cdf0e10cSrcweir 	{
131cdf0e10cSrcweir 		progressBar.setValue( progress );
132cdf0e10cSrcweir 		statusLabel.setText( status );
133cdf0e10cSrcweir 		statusLabel.setToolTipText( status );
134cdf0e10cSrcweir 		if( progress == MAXPROGRESS )
135cdf0e10cSrcweir 		{
136cdf0e10cSrcweir                 	cancelButton.setEnabled( true );
137cdf0e10cSrcweir                 	cancelButton.setText( "Close" );
138cdf0e10cSrcweir 		}
139cdf0e10cSrcweir 		update( getGraphics() );
140cdf0e10cSrcweir 		mainWindow.update( mainWindow.getGraphics() );
141cdf0e10cSrcweir 	}
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 
enableCancelButton( boolean enable )144cdf0e10cSrcweir 	public void enableCancelButton( boolean enable )
145cdf0e10cSrcweir 	{
146cdf0e10cSrcweir 		if( enable )
147cdf0e10cSrcweir 		{
148cdf0e10cSrcweir 			cancelButton.setEnabled( true );
149cdf0e10cSrcweir 			cancelButton.setText( "Finish" );
150cdf0e10cSrcweir 		}
151cdf0e10cSrcweir 		else
152cdf0e10cSrcweir 		{
153cdf0e10cSrcweir 			cancelButton.setEnabled( false );
154cdf0e10cSrcweir 			cancelButton.setText( "Cancel" );
155cdf0e10cSrcweir 		}
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 	}
158cdf0e10cSrcweir 
159cdf0e10cSrcweir }
160