001: package org.objectweb.salome_tmf.ihm.main;
002:
003: import java.awt.Color;
004: import java.awt.Dimension;
005: import java.awt.Rectangle;
006: import java.awt.event.WindowEvent;
007: import java.awt.event.WindowFocusListener;
008: import java.awt.event.WindowListener;
009:
010: import javax.swing.JDialog;
011: import javax.swing.JLabel;
012: import javax.swing.JPanel;
013: import javax.swing.JProgressBar;
014:
015: //public class ProgressBar extends JFrame {
016: public class ProgressBar extends JDialog implements WindowListener,
017: WindowFocusListener {
018: private JProgressBar progress;
019: private JLabel label1;
020: private JPanel topPanel;
021:
022: int iCtr = 0;
023: int nbTask = 0;
024: boolean isDisposed = false;
025:
026: public ProgressBar(String title, String label, int nbTask) {
027: super (SalomeTMFContext.getInstance().getSalomeFrame());
028: setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
029: setResizable(false);
030: setTitle(title);
031: //setModal(true);
032: setSize(310, 130);
033: setBackground(Color.gray);
034: this .nbTask = nbTask;
035: topPanel = new JPanel();
036: topPanel.setPreferredSize(new Dimension(310, 130));
037: getContentPane().add(topPanel);
038:
039: // Create a label and progress bar
040: label1 = new JLabel(label);
041: label1.setPreferredSize(new Dimension(280, 24));
042: topPanel.add(label1);
043:
044: progress = new JProgressBar();
045: progress.setPreferredSize(new Dimension(300, 20));
046: progress.setMinimum(0);
047: progress.setMaximum(nbTask);
048: progress.setValue(0);
049: progress.setBounds(20, 35, 260, 20);
050: topPanel.add(progress);
051: addWindowListener(this );
052:
053: //this.setLocation(300,300);
054: this .setLocationRelativeTo(this .getParent());
055: pack();
056:
057: }
058:
059: public void Show() {
060: if (SalomeTMFContext.getInstance().getSalomeFrame() != null) {
061: show();
062: }
063: }
064:
065: public void doTask(String task) {
066: iCtr++;
067: // Update the progress indicator and label
068: label1.setText("Performing task " + task);
069: Rectangle labelRect = label1.getBounds();
070: labelRect.x = 0;
071: labelRect.y = 0;
072: label1.paintImmediately(labelRect);
073:
074: progress.setValue(iCtr);
075: Rectangle progressRect = progress.getBounds();
076: progressRect.x = 0;
077: progressRect.y = 0;
078: progress.paintImmediately(progressRect);
079: }
080:
081: /*public synchronized void show(){
082: super.show();
083: }*/
084:
085: public void finishAllTask() {
086: isDisposed = true;
087: dispose();
088: }
089:
090: public void windowActivated(WindowEvent e) {
091: }
092:
093: public void windowClosed(WindowEvent e) {
094: if (!isDisposed) {
095: setVisible(true);
096: toFront();
097: }
098: }
099:
100: public void windowClosing(WindowEvent e) {
101: if (!isDisposed) {
102: setVisible(true);
103: toFront();
104: }
105: }
106:
107: public void windowDeactivated(WindowEvent e) {
108: toFront();
109: }
110:
111: public void windowDeiconified(WindowEvent e) {
112: }
113:
114: public void windowIconified(WindowEvent e) {
115: toFront();
116: }
117:
118: public void windowOpened(WindowEvent e) {
119: }
120:
121: public void windowGainedFocus(WindowEvent e) {
122: toFront();
123: }
124:
125: public void windowLostFocus(WindowEvent e) {
126: toFront();
127: }
128: }
|