001 /* 002 Copyright (C) 2003 Adam Olsen 003 004 This program is free software; you can redistribute it and/or modify 005 it under the terms of the GNU General Public License as published by 006 the Free Software Foundation; either version 1, or (at your option) 007 any later version. 008 009 This program is distributed in the hope that it will be useful, 010 but WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 GNU General Public License for more details. 013 014 You should have received a copy of the GNU General Public License 015 along with this program; if not, write to the Free Software 016 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 017 */ 018 019 package com.valhalla.gui; 020 021 import javax.swing.*; 022 import javax.swing.event.*; 023 import java.awt.event.*; 024 import java.awt.*; 025 026 /** 027 * Displays a JDialog with a progress bar in it 028 * 029 * @author Adam Olsen 030 * @version 1.0 031 */ 032 public class ProgressDialog extends JProgressBar 033 { 034 private JButton cancelButton = new JButton( "Cancel" ); 035 private JDialog container; 036 private JPanel mainPanel; 037 private JLabel messageLabel = new JLabel( "", SwingConstants.CENTER ); 038 039 /** 040 * @param message the message to display 041 * @param min the minimum value of the progress bar 042 * @param max the maximum value of the progress bar 043 */ 044 public ProgressDialog( String message, int min, int max ) 045 { 046 super( min, max ); 047 048 container = new JDialog(); 049 messageLabel.setText( message ); 050 container.setTitle( message ); 051 052 mainPanel = (JPanel)container.getContentPane(); 053 mainPanel.setLayout( new BorderLayout() ); 054 mainPanel.add( messageLabel, BorderLayout.NORTH ); 055 056 JPanel progressPanel = new JPanel(); 057 progressPanel.setLayout( new BoxLayout( progressPanel, BoxLayout.Y_AXIS ) ); 058 progressPanel.add( this ); 059 progressPanel.add( Box.createVerticalGlue() ); 060 progressPanel.setBorder( BorderFactory.createEmptyBorder( 5, 5, 5, 5 ) ); 061 062 mainPanel.add( progressPanel, BorderLayout.CENTER ); 063 mainPanel.setBorder( BorderFactory.createEmptyBorder( 10, 10, 10, 10 ) ); 064 065 JPanel buttonPanel = new JPanel(); 066 buttonPanel.setLayout( new BoxLayout( buttonPanel, BoxLayout.X_AXIS ) ); 067 buttonPanel.add( Box.createHorizontalGlue() ); 068 buttonPanel.add( cancelButton ); 069 buttonPanel.add( Box.createHorizontalGlue() ); 070 setStringPainted( true ); 071 072 mainPanel.add( buttonPanel, BorderLayout.SOUTH ); 073 container.pack(); 074 075 container.setSize( new Dimension( 300, 120 ) ); 076 container.setLocationRelativeTo( null ); 077 container.show(); 078 container.addWindowListener( new WindowAdapter() 079 { 080 public void windowClosing( WindowEvent e ) { } 081 } ); 082 } 083 084 /** 085 * Returns the cancel button in the dialog 086 * @return the dialog's cancel button 087 */ 088 public JButton getButton() { return cancelButton; } 089 090 /** 091 * Deletes the dialog 092 */ 093 public void delete() { container.dispose(); } 094 }