Logo Search packages:      
Sourcecode: javamorph version File versions  Download package

CProgress.java

package javamorph;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * @version 1.1
 * <br/>
 * @author claus.erhard.wimmer@googlemail.com
 * <br/>
 * Program: JavaMorph V 1.1.
 * <br/>
 * Class: CProgress.
 * <br/>
 * License: GPLv2.
 * <br/>
 * Description: Shows a dialog with the progress bar during morphing.
 * <br/>
 * Hint: Dialog blocks the caller, that's why morph process is an own thread.
 */
00022 public class CProgress extends JDialog 
    implements ActionListener{
    /** Due to java API. */
00025     private static final long serialVersionUID = 1L;
    /** Size of the progrssbar on screen. */
00027     public static final Dimension PREF_SIZE = new Dimension(250, 25);
    /** Color of the elapsed time. */
00029     public static final Color FOREGROUND = Color.red;
    /** Color of the remaining time. */
00031     public static final Color BACKGROUND = Color.white;
    /** Parent JFrame to enable modal behavior. */
00033     private JFrame parent;
    /** Break button for user abort. */
00035     private JButton b_break = new JButton("Break!");
    /** Progress bar JComponent. */
00037     private JProgressBar b_progress = new JProgressBar();
    /**
     * Constructor.
     * @param parent Parent JFrame to enable modal behavior.
     */
00042     public CProgress(JFrame parent){
        super(parent, "Morph Progress", true);
        this.parent = parent;
        this.b_break.addActionListener(this);
        this.getContentPane().setLayout(new BorderLayout());
        this.getContentPane().add("Center", b_progress);
        this.add("East", b_break);
        this.b_progress.setForeground(FOREGROUND);
        this.b_progress.setBackground(BACKGROUND);
        this.setUndecorated(true);
        this.pack();
    }
    /**
     * Show the progress bar.
     */
00057     public void open(){
        this.b_progress.setValue(0);
        this.setLocation
        (parent.getLocation().x + 10, parent.getLocation().y + 10);
        this.setSize(PREF_SIZE);
        this.setResizable(false);
        this.setVisible(true);
        this.setResizable(true);
    }
    /**
     * Close the progress bar when morphing is finnished.
     */
00069     public void close(){
        this.setVisible(false);
    }
    /**
     * Set function.
     * @param progress Elapsed steps.
     * @param min Offset. Normally zero.
     * @param max Number of steps.
     */
00078     public void setProgress(int progress, int min, int max){
        this.b_progress.setValue(progress);
        this.b_progress.setMinimum(min);
        this.b_progress.setMaximum(max);
    }
    /**
     * User has clicked the abort button.
     */
00086     public void actionPerformed(ActionEvent e) {
        if(this.b_break == e.getSource()){
            CMorphOperator.doBreak();
            this.close();
        }
    }
}

Generated by  Doxygen 1.6.0   Back to index