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