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