001: package com.xoetrope.carousel.langed;
002:
003: import java.awt.BorderLayout;
004: import java.awt.Color;
005: import java.awt.Dimension;
006: import java.awt.Window;
007: import java.awt.event.ActionEvent;
008: import java.awt.event.ActionListener;
009:
010: import javax.swing.BorderFactory;
011: import javax.swing.JButton;
012: import javax.swing.JDialog;
013: import javax.swing.JFrame;
014: import javax.swing.JPanel;
015: import javax.swing.JProgressBar;
016: import javax.swing.border.Border;
017:
018: /**
019: * <p>Title: LanguageEditor</p>
020: * <p>Description: Language Resource Translation Utility</p>
021: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
022: * the GNU Public License (GPL), please see license.txt for more details. If
023: * you make commercial use of this software you must purchase a commercial
024: * license from Xoetrope.</p>
025: * <p> $Revision: 1.4 $</p>
026: * @author Luan O'Carroll
027: */
028: public class ProgressDialog extends JDialog implements ActionListener {
029: private BorderLayout borderLayout1 = new BorderLayout();
030:
031: private JPanel progressPanel = new JPanel();
032: private int progress = 0;
033: private JPanel jPanel1 = new JPanel();
034: private JProgressBar progressBar = new JProgressBar();
035: private BorderLayout borderLayout2 = new BorderLayout();
036: private Border border1;
037: private Border border2;
038: private JPanel jPanel2 = new JPanel();
039: private JButton stopBtn = new JButton();
040:
041: private boolean isOk = true;
042:
043: public ProgressDialog(String title, boolean modal) {
044: super ((JFrame) null);
045: setTitle(title);
046: setModal(modal);
047: try {
048: jbInit();
049: LanguageEditorApplication.setDefaultFont(this );
050: setSize(300, 115);
051: doLayout();
052: } catch (Exception ex) {
053: ex.printStackTrace();
054: }
055: }
056:
057: public ProgressDialog() {
058: super ();
059: setTitle("");
060: setModal(false);
061: }
062:
063: private void jbInit() throws Exception {
064: border1 = BorderFactory.createCompoundBorder(BorderFactory
065: .createEtchedBorder(Color.white, new Color(165, 163,
066: 151)), BorderFactory.createEmptyBorder(6, 6, 6,
067: 6));
068: border2 = BorderFactory.createEmptyBorder(6, 6, 6, 6);
069: progressPanel.setLayout(borderLayout1);
070: progressBar.setValue(0);
071: progressBar.setMinimumSize(new Dimension(250, 18));
072: progressBar.setSize(new Dimension(250, 18));
073: jPanel1.setLayout(borderLayout2);
074: jPanel1.setBorder(border1);
075: progressPanel.setBorder(border2);
076: stopBtn.setMnemonic('S');
077: stopBtn.setText("Stop");
078: progressPanel.add(jPanel2, BorderLayout.CENTER);
079: jPanel2.add(stopBtn, null);
080: progressPanel.add(jPanel1, BorderLayout.NORTH);
081: jPanel1.add(progressBar, BorderLayout.CENTER);
082: getContentPane().add(progressPanel);
083:
084: stopBtn.addActionListener(this );
085: }
086:
087: //Close the dialog on a button event
088: public void actionPerformed(ActionEvent e) {
089: if (e.getSource() == stopBtn) {
090: isOk = false;
091: setVisible(false);
092: }
093: }
094:
095: public boolean isOk() {
096: return isOk;
097: }
098:
099: public void incrementProgress() {
100: progressBar.setValue(progress++);
101: }
102:
103: public void finished() {
104: stopBtn.setText("Finished");
105: }
106:
107: public void setProgressMaxValue(int maxValue) {
108: progressBar.getModel().setMaximum(maxValue);
109: progress = 0;
110: getContentPane().add(progressPanel);
111: }
112: }
|