/[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 911 - (show annotations) (download)
Mon Aug 7 18:25:58 2006 UTC (17 years, 7 months ago) by iliev
File size: 3626 byte(s)
updating to JSampler 0.3a

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005 Grigor Kirilov Iliev
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
40 import org.jsampler.CC;
41 import org.jsampler.HF;
42 import org.jsampler.view.JSProgress;
43
44 import net.sf.juife.JuifeUtils;
45
46 import static org.jsampler.view.classic.ClassicI18n.i18n;
47
48
49 /**
50 *
51 * @author Grigor Iliev
52 */
53 public class ProgressDlg extends JDialog implements JSProgress {
54 private final JPanel mainPane = new JPanel();
55 private final JLabel l = new JLabel(" ");
56 private JProgressBar pb = new JProgressBar();
57 private final JButton btnCancel = new JButton(i18n.getButtonLabel("cancel"));
58
59
60 /** Creates a new instance of ProgressDlg */
61 public
62 ProgressDlg() {
63 super(CC.getMainFrame(), "", true);
64
65 pb.setIndeterminate(true);
66 //pb.setStringPainted(true);
67
68 l.setAlignmentX(CENTER_ALIGNMENT);
69 pb.setAlignmentX(CENTER_ALIGNMENT);
70 btnCancel.setAlignmentX(CENTER_ALIGNMENT);
71
72 mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
73
74 mainPane.add(l);
75 mainPane.add(Box.createRigidArea(new Dimension(0, 6)));
76 mainPane.add(pb);
77 mainPane.add(Box.createRigidArea(new Dimension(0, 17)));
78 mainPane.add(btnCancel);
79
80 mainPane.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
81 add(mainPane);
82
83 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
84
85 btnCancel.addActionListener(new ActionListener() {
86 public void
87 actionPerformed(ActionEvent e) { onCancel(); }
88 });
89
90 pack();
91 Dimension d = getPreferredSize();
92 d.width = d.width > 300 ? d.width : 300;
93 setSize(d);
94 setResizable(false);
95
96 setLocation(JuifeUtils.centerLocation(this, CC.getMainFrame()));
97 }
98
99 private void
100 onCancel() {
101 int i = CC.getTaskQueue().getPendingTaskCount();
102 if(i > 0) {
103 String s;
104 if(i == 1) s = i18n.getMessage("ProgressDlg.cancel?");
105 else s = i18n.getMessage("ProgressDlg.cancel2?", i);
106 if(!HF.showYesNoDialog(CC.getMainFrame(), s)) {
107 CC.getTaskQueue().start();
108 return;
109 }
110 }
111
112 CC.getTaskQueue().removePendingTasks();
113 net.sf.juife.Task t = CC.getTaskQueue().getRunningTask();
114 if(t != null) t.stop();
115
116 setVisible(false);
117 }
118
119 /**
120 * Sets the progress string.
121 * @param s The value of the progress string.
122 */
123 public void
124 setString(String s) { l.setText(s); }
125
126 /** Starts to indicate that an operation is ongoing. */
127 public void
128 start() {
129 setLocation(JuifeUtils.centerLocation(this, CC.getMainFrame()));
130 setVisible(true);
131 }
132
133 /** Stops the indication that an operation is ongoing. */
134 public void
135 stop() { setVisible(false); }
136 }

  ViewVC Help
Powered by ViewVC