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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1204 - (show 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 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com>
5 *
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 import javax.swing.SwingUtilities;
40
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 ProgressDlg() {
64 super((Frame)null, "", true);
65
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 setLocation(JuifeUtils.centerLocation(this, CC.getMainFrame()));
98 }
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 net.sf.juife.Task t = CC.getTaskQueue().getRunningTask();
115 if(t != null) t.stop();
116
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 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 /** Starts to indicate that an operation is ongoing. */
139 public void
140 start() {
141 setLocation(JuifeUtils.centerLocation(this, CC.getMainFrame()));
142
143 SwingUtilities.invokeLater(new Runnable() {
144 public void
145 run() {
146 initProgressDlg();
147 setVisible(true);
148 }
149 });
150 }
151
152 /** Stops the indication that an operation is ongoing. */
153 public void
154 stop() {
155 SwingUtilities.invokeLater(new Runnable() {
156 public void
157 run() { dispose(); }
158 });
159 }
160 }

  ViewVC Help
Powered by ViewVC