1 |
iliev |
1286 |
/* |
2 |
|
|
* JSampler - a java front-end for LinuxSampler |
3 |
|
|
* |
4 |
|
|
* Copyright (C) 2005-2007 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.std; |
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.std.StdI18n.i18n; |
48 |
|
|
|
49 |
|
|
|
50 |
|
|
/** |
51 |
|
|
* |
52 |
|
|
* @author Grigor Iliev |
53 |
|
|
*/ |
54 |
|
|
public class JSProgressDlg 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 |
|
|
/** |
62 |
|
|
* Creates a new instance of JSProgressDlg |
63 |
|
|
*/ |
64 |
|
|
public |
65 |
|
|
JSProgressDlg() { |
66 |
|
|
super((Frame)null, "", true); |
67 |
|
|
|
68 |
|
|
pb.setIndeterminate(true); |
69 |
|
|
//pb.setStringPainted(true); |
70 |
|
|
|
71 |
|
|
l.setAlignmentX(CENTER_ALIGNMENT); |
72 |
|
|
pb.setAlignmentX(CENTER_ALIGNMENT); |
73 |
|
|
btnCancel.setAlignmentX(CENTER_ALIGNMENT); |
74 |
|
|
|
75 |
|
|
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); |
76 |
|
|
|
77 |
|
|
mainPane.add(l); |
78 |
|
|
mainPane.add(Box.createRigidArea(new Dimension(0, 6))); |
79 |
|
|
mainPane.add(pb); |
80 |
|
|
mainPane.add(Box.createRigidArea(new Dimension(0, 17))); |
81 |
|
|
mainPane.add(btnCancel); |
82 |
|
|
|
83 |
|
|
mainPane.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); |
84 |
|
|
add(mainPane); |
85 |
|
|
|
86 |
|
|
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); |
87 |
|
|
|
88 |
|
|
btnCancel.addActionListener(new ActionListener() { |
89 |
|
|
public void |
90 |
|
|
actionPerformed(ActionEvent e) { onCancel(); } |
91 |
|
|
}); |
92 |
|
|
|
93 |
|
|
pack(); |
94 |
|
|
Dimension d = getPreferredSize(); |
95 |
|
|
d.width = d.width > 300 ? d.width : 300; |
96 |
|
|
setSize(d); |
97 |
|
|
setResizable(false); |
98 |
|
|
|
99 |
|
|
setLocation(JuifeUtils.centerLocation(this, CC.getMainFrame())); |
100 |
|
|
} |
101 |
|
|
|
102 |
|
|
private void |
103 |
|
|
onCancel() { |
104 |
|
|
int i = CC.getTaskQueue().getPendingTaskCount(); |
105 |
|
|
if(i > 0) { |
106 |
|
|
String s; |
107 |
|
|
if(i == 1) s = i18n.getMessage("JSProgressDlg.cancel?"); |
108 |
|
|
else s = i18n.getMessage("JSProgressDlg.cancel2?", i); |
109 |
|
|
if(!HF.showYesNoDialog(CC.getMainFrame(), s)) { |
110 |
|
|
CC.getTaskQueue().start(); |
111 |
|
|
return; |
112 |
|
|
} |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
CC.getTaskQueue().removePendingTasks(); |
116 |
|
|
net.sf.juife.Task t = CC.getTaskQueue().getRunningTask(); |
117 |
|
|
if(t != null) t.stop(); |
118 |
|
|
|
119 |
|
|
setVisible(false); |
120 |
|
|
} |
121 |
|
|
|
122 |
|
|
/** |
123 |
|
|
* Sets the progress string. |
124 |
|
|
* @param s The value of the progress string. |
125 |
|
|
*/ |
126 |
|
|
public void |
127 |
|
|
setString(String s) { l.setText(s); } |
128 |
|
|
|
129 |
|
|
private void |
130 |
|
|
initProgressDlg() { |
131 |
|
|
pack(); |
132 |
|
|
Dimension d = getPreferredSize(); |
133 |
|
|
d.width = d.width > 300 ? d.width : 300; |
134 |
|
|
setSize(d); |
135 |
|
|
setResizable(false); |
136 |
|
|
|
137 |
|
|
setLocation(JuifeUtils.centerLocation(this, CC.getMainFrame())); |
138 |
|
|
} |
139 |
|
|
|
140 |
|
|
/** Starts to indicate that an operation is ongoing. */ |
141 |
|
|
public void |
142 |
|
|
start() { |
143 |
|
|
setLocation(JuifeUtils.centerLocation(this, CC.getMainFrame())); |
144 |
|
|
|
145 |
|
|
SwingUtilities.invokeLater(new Runnable() { |
146 |
|
|
public void |
147 |
|
|
run() { |
148 |
|
|
initProgressDlg(); |
149 |
|
|
setVisible(true); |
150 |
|
|
} |
151 |
|
|
}); |
152 |
|
|
} |
153 |
|
|
|
154 |
|
|
/** Stops the indication that an operation is ongoing. */ |
155 |
|
|
public void |
156 |
|
|
stop() { |
157 |
|
|
SwingUtilities.invokeLater(new Runnable() { |
158 |
|
|
public void |
159 |
|
|
run() { dispose(); } |
160 |
|
|
}); |
161 |
|
|
} |
162 |
|
|
} |