/[svn]/jsampler/trunk/src/org/jsampler/view/classic/ProgressDlg.java
ViewVC logotype

Diff of /jsampler/trunk/src/org/jsampler/view/classic/ProgressDlg.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1284 by iliev, Thu May 24 21:43:45 2007 UTC revision 1285 by iliev, Fri Aug 10 19:55:03 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *   JSampler - a java front-end for LinuxSampler   *   JSampler - a java front-end for LinuxSampler
3   *   *
4   *   Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com>   *   Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com>
5   *   *
6   *   This file is part of JSampler.   *   This file is part of JSampler.
7   *   *
# Line 22  Line 22 
22    
23  package org.jsampler.view.classic;  package org.jsampler.view.classic;
24    
25  import java.awt.Dimension;  import org.jsampler.view.std.JSProgressDlg;
 import java.awt.Frame;  
   
 import java.awt.event.ActionEvent;  
 import java.awt.event.ActionListener;  
   
 import javax.swing.BorderFactory;  
 import javax.swing.Box;  
 import javax.swing.BoxLayout;  
 import javax.swing.JButton;  
 import javax.swing.JDialog;  
 import javax.swing.JLabel;  
 import javax.swing.JPanel;  
 import javax.swing.JProgressBar;  
 import javax.swing.SwingUtilities;  
   
 import org.jsampler.CC;  
 import org.jsampler.HF;  
 import org.jsampler.view.JSProgress;  
   
 import net.sf.juife.JuifeUtils;  
   
 import static org.jsampler.view.classic.ClassicI18n.i18n;  
   
26    
27  /**  /**
28   *   *
29   * @author Grigor Iliev   * @author Grigor Iliev
30   */   */
31  public class ProgressDlg extends JDialog implements JSProgress {  public class ProgressDlg extends JSProgressDlg {
         private final JPanel mainPane = new JPanel();  
         private final JLabel l = new JLabel(" ");  
         private JProgressBar pb  = new JProgressBar();  
         private final JButton btnCancel = new JButton(i18n.getButtonLabel("cancel"));  
           
           
         /** Creates a new instance of ProgressDlg */  
         public  
         ProgressDlg() {  
                 super((Frame)null, "", true);  
                   
                 pb.setIndeterminate(true);  
                 //pb.setStringPainted(true);  
                   
                 l.setAlignmentX(CENTER_ALIGNMENT);  
                 pb.setAlignmentX(CENTER_ALIGNMENT);  
                 btnCancel.setAlignmentX(CENTER_ALIGNMENT);  
                   
                 mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));  
                   
                 mainPane.add(l);  
                 mainPane.add(Box.createRigidArea(new Dimension(0, 6)));  
                 mainPane.add(pb);  
                 mainPane.add(Box.createRigidArea(new Dimension(0, 17)));  
                 mainPane.add(btnCancel);  
                   
                 mainPane.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));  
                 add(mainPane);  
                   
                 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);  
                   
                 btnCancel.addActionListener(new ActionListener() {  
                         public void  
                         actionPerformed(ActionEvent e) { onCancel(); }  
                 });  
                   
                 pack();  
                 Dimension d = getPreferredSize();  
                 d.width = d.width > 300 ? d.width : 300;  
                 setSize(d);  
                 setResizable(false);  
                   
                 setLocation(JuifeUtils.centerLocation(this, CC.getMainFrame()));  
         }  
           
         private void  
         onCancel() {  
                 int i = CC.getTaskQueue().getPendingTaskCount();  
                 if(i > 0) {  
                         String s;  
                         if(i == 1) s = i18n.getMessage("ProgressDlg.cancel?");  
                         else s = i18n.getMessage("ProgressDlg.cancel2?", i);  
                         if(!HF.showYesNoDialog(CC.getMainFrame(), s)) {  
                                 CC.getTaskQueue().start();  
                                 return;  
                         }  
                 }  
                   
                 CC.getTaskQueue().removePendingTasks();  
                 net.sf.juife.Task t = CC.getTaskQueue().getRunningTask();  
                 if(t != null) t.stop();  
                   
                 setVisible(false);  
         }  
           
         /**  
          * Sets the progress string.  
          * @param s The value of the progress string.  
          */  
         public void  
         setString(String s) { l.setText(s); }  
           
         private void  
         initProgressDlg() {  
                 pack();  
                 Dimension d = getPreferredSize();  
                 d.width = d.width > 300 ? d.width : 300;  
                 setSize(d);  
                 setResizable(false);  
                   
                 setLocation(JuifeUtils.centerLocation(this, CC.getMainFrame()));  
         }  
           
         /** Starts to indicate that an operation is ongoing. */  
         public void  
         start() {  
                 setLocation(JuifeUtils.centerLocation(this, CC.getMainFrame()));  
                   
                 SwingUtilities.invokeLater(new Runnable() {  
                         public void  
                         run() {  
                                 initProgressDlg();  
                                 setVisible(true);  
                         }  
                 });  
         }  
32                    
         /** Stops the indication that an operation is ongoing. */  
         public void  
         stop() {  
                 SwingUtilities.invokeLater(new Runnable() {  
                         public void  
                         run() { dispose(); }  
                 });  
         }  
33  }  }

Legend:
Removed from v.1284  
changed lines
  Added in v.1285

  ViewVC Help
Powered by ViewVC