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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1204 - (hide annotations) (download)
Thu May 24 21:43:45 2007 UTC (16 years, 11 months ago) by iliev
File size: 4097 byte(s)
upgrading to version 0.5a

1 iliev 787 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4 iliev 1143 * Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com>
5 iliev 787 *
6     * This file is part of JSampler.
7     *
8     * JSampler is free software; you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License version 2
10     * as published by the Free Software Foundation.
11     *
12     * JSampler is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with JSampler; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20     * MA 02111-1307 USA
21     */
22    
23     package org.jsampler.view.classic;
24    
25     import java.awt.Dimension;
26     import java.awt.Frame;
27    
28     import java.awt.event.ActionEvent;
29     import java.awt.event.ActionListener;
30    
31     import javax.swing.BorderFactory;
32     import javax.swing.Box;
33     import javax.swing.BoxLayout;
34     import javax.swing.JButton;
35     import javax.swing.JDialog;
36     import javax.swing.JLabel;
37     import javax.swing.JPanel;
38     import javax.swing.JProgressBar;
39 iliev 1204 import javax.swing.SwingUtilities;
40 iliev 787
41     import org.jsampler.CC;
42     import org.jsampler.HF;
43     import org.jsampler.view.JSProgress;
44    
45     import net.sf.juife.JuifeUtils;
46    
47     import static org.jsampler.view.classic.ClassicI18n.i18n;
48    
49    
50     /**
51     *
52     * @author Grigor Iliev
53     */
54     public class ProgressDlg extends JDialog implements JSProgress {
55     private final JPanel mainPane = new JPanel();
56     private final JLabel l = new JLabel(" ");
57     private JProgressBar pb = new JProgressBar();
58     private final JButton btnCancel = new JButton(i18n.getButtonLabel("cancel"));
59    
60    
61     /** Creates a new instance of ProgressDlg */
62     public
63 iliev 911 ProgressDlg() {
64 iliev 1204 super((Frame)null, "", true);
65 iliev 787
66     pb.setIndeterminate(true);
67     //pb.setStringPainted(true);
68    
69     l.setAlignmentX(CENTER_ALIGNMENT);
70     pb.setAlignmentX(CENTER_ALIGNMENT);
71     btnCancel.setAlignmentX(CENTER_ALIGNMENT);
72    
73     mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
74    
75     mainPane.add(l);
76     mainPane.add(Box.createRigidArea(new Dimension(0, 6)));
77     mainPane.add(pb);
78     mainPane.add(Box.createRigidArea(new Dimension(0, 17)));
79     mainPane.add(btnCancel);
80    
81     mainPane.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
82     add(mainPane);
83    
84     setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
85    
86     btnCancel.addActionListener(new ActionListener() {
87     public void
88     actionPerformed(ActionEvent e) { onCancel(); }
89     });
90    
91     pack();
92     Dimension d = getPreferredSize();
93     d.width = d.width > 300 ? d.width : 300;
94     setSize(d);
95     setResizable(false);
96    
97 iliev 911 setLocation(JuifeUtils.centerLocation(this, CC.getMainFrame()));
98 iliev 787 }
99    
100     private void
101     onCancel() {
102     int i = CC.getTaskQueue().getPendingTaskCount();
103     if(i > 0) {
104     String s;
105     if(i == 1) s = i18n.getMessage("ProgressDlg.cancel?");
106     else s = i18n.getMessage("ProgressDlg.cancel2?", i);
107     if(!HF.showYesNoDialog(CC.getMainFrame(), s)) {
108     CC.getTaskQueue().start();
109     return;
110     }
111     }
112    
113     CC.getTaskQueue().removePendingTasks();
114 iliev 842 net.sf.juife.Task t = CC.getTaskQueue().getRunningTask();
115     if(t != null) t.stop();
116 iliev 787
117     setVisible(false);
118     }
119    
120     /**
121     * Sets the progress string.
122     * @param s The value of the progress string.
123     */
124     public void
125     setString(String s) { l.setText(s); }
126    
127 iliev 1204 private void
128     initProgressDlg() {
129     pack();
130     Dimension d = getPreferredSize();
131     d.width = d.width > 300 ? d.width : 300;
132     setSize(d);
133     setResizable(false);
134    
135     setLocation(JuifeUtils.centerLocation(this, CC.getMainFrame()));
136     }
137    
138 iliev 787 /** Starts to indicate that an operation is ongoing. */
139     public void
140 iliev 911 start() {
141     setLocation(JuifeUtils.centerLocation(this, CC.getMainFrame()));
142 iliev 1204
143     SwingUtilities.invokeLater(new Runnable() {
144     public void
145     run() {
146     initProgressDlg();
147     setVisible(true);
148     }
149     });
150 iliev 911 }
151 iliev 787
152     /** Stops the indication that an operation is ongoing. */
153     public void
154 iliev 1204 stop() {
155     SwingUtilities.invokeLater(new Runnable() {
156     public void
157     run() { dispose(); }
158     });
159     }
160 iliev 787 }

  ViewVC Help
Powered by ViewVC