1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005, 2006 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.Dialog; |
26 |
import java.awt.Dimension; |
27 |
import java.awt.Frame; |
28 |
|
29 |
import java.awt.event.ActionEvent; |
30 |
import java.awt.event.ActionListener; |
31 |
|
32 |
import java.io.FileOutputStream; |
33 |
|
34 |
import java.util.logging.Level; |
35 |
|
36 |
import javax.swing.BorderFactory; |
37 |
import javax.swing.Box; |
38 |
import javax.swing.BoxLayout; |
39 |
import javax.swing.JButton; |
40 |
import javax.swing.JDialog; |
41 |
import javax.swing.JFileChooser; |
42 |
import javax.swing.JPanel; |
43 |
import javax.swing.JScrollPane; |
44 |
import javax.swing.JTextPane; |
45 |
|
46 |
import org.jsampler.CC; |
47 |
import org.jsampler.HF; |
48 |
|
49 |
import org.jsampler.view.LscpFileFilter; |
50 |
|
51 |
import static org.jsampler.view.classic.ClassicI18n.i18n; |
52 |
|
53 |
|
54 |
/** |
55 |
* |
56 |
* @author Grigor Iliev |
57 |
*/ |
58 |
public class LscpScriptDlg extends JDialog { |
59 |
private final JTextPane textPane = new JTextPane(); |
60 |
private final JButton btnSaveAs = |
61 |
new JButton(i18n.getButtonLabel("LscpScriptDlg.btnSaveAs")); |
62 |
private final JButton btnClose = new JButton(i18n.getButtonLabel("close")); |
63 |
|
64 |
|
65 |
/** Creates a new instance of <code>LscpScriptDlg</code>. */ |
66 |
public |
67 |
LscpScriptDlg() { this(CC.getMainFrame()); } |
68 |
|
69 |
/** Creates a new instance of <code>LscpScriptDlg</code>. */ |
70 |
public |
71 |
LscpScriptDlg(Frame owner) { |
72 |
super(owner); |
73 |
|
74 |
JPanel mainPane = new JPanel(); |
75 |
|
76 |
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); |
77 |
mainPane.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); |
78 |
|
79 |
JScrollPane sp = new JScrollPane(textPane); |
80 |
sp.setAlignmentX(JPanel.RIGHT_ALIGNMENT); |
81 |
mainPane.add(sp); |
82 |
|
83 |
mainPane.add(Box.createRigidArea(new Dimension(0, 17))); |
84 |
|
85 |
JPanel p = new JPanel(); |
86 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
87 |
p.add(btnSaveAs); |
88 |
p.add(Box.createRigidArea(new Dimension(6, 0))); |
89 |
p.add(btnClose); |
90 |
p.setAlignmentX(JPanel.RIGHT_ALIGNMENT); |
91 |
|
92 |
mainPane.add(p); |
93 |
add(mainPane); |
94 |
|
95 |
pack(); |
96 |
setSize(500, 400); |
97 |
setLocationRelativeTo(getOwner()); |
98 |
|
99 |
btnSaveAs.addActionListener(new ActionListener() { |
100 |
public void |
101 |
actionPerformed(ActionEvent e) { saveScript(); } |
102 |
}); |
103 |
|
104 |
btnClose.addActionListener(new ActionListener() { |
105 |
public void |
106 |
actionPerformed(ActionEvent e) { setVisible(false); } |
107 |
}); |
108 |
} |
109 |
|
110 |
public void |
111 |
setCommands(String[] commands) { |
112 |
StringBuffer sb = new StringBuffer(); |
113 |
|
114 |
for(String s : commands) sb.append(s).append("\n"); |
115 |
|
116 |
textPane.setText(sb.toString()); |
117 |
} |
118 |
|
119 |
private void |
120 |
saveScript() { |
121 |
JFileChooser fc = new JFileChooser(); |
122 |
fc.setFileFilter(new LscpFileFilter()); |
123 |
int result = fc.showSaveDialog(this); |
124 |
if(result != JFileChooser.APPROVE_OPTION) return; |
125 |
|
126 |
try { |
127 |
FileOutputStream fos = new FileOutputStream(fc.getSelectedFile()); |
128 |
fos.write(textPane.getText().getBytes("US-ASCII")); |
129 |
fos.close(); |
130 |
} catch(Exception e) { |
131 |
CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
132 |
HF.showErrorMessage(e); |
133 |
} |
134 |
} |
135 |
} |