/* File Name: ProgressDialog.java */ package explorer.client.gui; import explorer.client.CrossXClientFactory; import java.awt.Frame; import java.awt.Color; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.Font; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.border.Border; import javax.swing.BorderFactory; import javax.swing.JWindow; import javax.swing.JFrame; import javax.swing.JProgressBar; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JLabel; import javax.swing.ImageIcon; import java.net.URL; /** * GUI to show the status of a file being copied or moved from the Source to * the Destination * */ public class ProgressDialog extends JWindow implements Runnable, ActionListener { private int value = 0; private JPanel contentPanel = null; private JPanel progressPanel = null; private JLabel imageLabel; private JLabel srcLabel; private JLabel destLabel; private JButton cmdOK; private JProgressBar progressBar; public ProgressDialog(JFrame parent, String strTitle, String srcFile, String destinationFile) { super(parent); value = 0; this.setSize(400, 200); this.setLocationRelativeTo(parent); contentPanel = (JPanel)this.getContentPane(); contentPanel.setBorder(BorderFactory.createRaisedBevelBorder()); contentPanel.setLayout(new BorderLayout(10, 10)); JPanel northPanel = new JPanel(); northPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); northPanel.setBackground(new Color(22, 88, 176)); JLabel titleLabel = new JLabel(strTitle, JLabel.LEFT); titleLabel.setBackground(new Color(22, 88, 176)); titleLabel.setForeground(new Color(255, 255, 255)); titleLabel.setFont(new Font("TimesNewRoman", Font.BOLD, 12)); titleLabel.setVisible(true); northPanel.add(titleLabel); contentPanel.add(northPanel, BorderLayout.NORTH); JPanel southPanel = new JPanel(); southPanel.setSize(15,15); cmdOK = new JButton("OK"); cmdOK.setEnabled(false); cmdOK.addActionListener(this); southPanel.add(cmdOK); contentPanel.add(southPanel, BorderLayout.SOUTH); JPanel westPanel = new JPanel(); westPanel.setSize(15,15); contentPanel.add(westPanel, BorderLayout.WEST); JPanel eastPanel = new JPanel(); eastPanel.setSize(15,15); contentPanel.add(eastPanel, BorderLayout.EAST); JPanel centerPanel = new JPanel(); centerPanel.setLayout(new BorderLayout(10, 10)); URL url= ClassLoader.getSystemResource("resources/copy1.gif"); centerPanel.add(new JLabel(new ImageIcon(url)), BorderLayout.CENTER); srcLabel = new JLabel(srcFile, JLabel.RIGHT); destLabel = new JLabel(destinationFile, JLabel.LEFT); centerPanel.add(srcLabel, BorderLayout.WEST); centerPanel.add(destLabel, BorderLayout.EAST); progressBar = new JProgressBar(0, 100); progressBar.setValue(value); progressBar.setVisible(true); centerPanel.add(progressBar, BorderLayout.SOUTH); contentPanel.add(centerPanel, BorderLayout.CENTER); contentPanel.updateUI(); this.setVisible(true); Thread processStart = new Thread(this); processStart.start(); } public void actionPerformed(ActionEvent ae) { this.dispose(); } public void run() { while(!CrossXClientFactory.blnEnd) { try { value += 10; if(value>100) { value = 0; } progressBar.setValue(value); progressBar.updateUI(); Thread.sleep(500); } catch(InterruptedException e) { e.printStackTrace(); } } progressBar.setValue(100); progressBar.updateUI(); cmdOK.setEnabled(true); CrossXClientFactory.blnEnd = false; } }