1 |
iliev |
1286 |
/* |
2 |
|
|
* JSampler - a java front-end for LinuxSampler |
3 |
|
|
* |
4 |
iliev |
1871 |
* Copyright (C) 2005-2009 Grigor Iliev <grigor@grigoriliev.com> |
5 |
iliev |
1286 |
* |
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 |
iliev |
1871 |
import java.io.File; |
32 |
iliev |
1286 |
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.JPanel; |
42 |
|
|
import javax.swing.JScrollPane; |
43 |
|
|
import javax.swing.JTextPane; |
44 |
|
|
|
45 |
|
|
import org.jsampler.CC; |
46 |
|
|
import org.jsampler.HF; |
47 |
|
|
import org.jsampler.JSPrefs; |
48 |
|
|
|
49 |
|
|
import static org.jsampler.view.std.StdI18n.i18n; |
50 |
|
|
|
51 |
|
|
|
52 |
|
|
/** |
53 |
|
|
* |
54 |
|
|
* @author Grigor Iliev |
55 |
|
|
*/ |
56 |
|
|
public class JSLscpScriptDlg extends JDialog { |
57 |
|
|
private final JTextPane textPane = new JTextPane(); |
58 |
|
|
private final JButton btnSaveAs = |
59 |
|
|
new JButton(i18n.getButtonLabel("JSLscpScriptDlg.btnSaveAs")); |
60 |
|
|
private final JButton btnClose = new JButton(i18n.getButtonLabel("close")); |
61 |
|
|
|
62 |
|
|
|
63 |
|
|
/** |
64 |
|
|
* Creates a new instance of <code>JSLscpScriptDlg</code>. |
65 |
|
|
*/ |
66 |
|
|
public |
67 |
|
|
JSLscpScriptDlg() { this(CC.getMainFrame()); } |
68 |
|
|
|
69 |
|
|
/** |
70 |
|
|
* Creates a new instance of <code>JSLscpScriptDlg</code>. |
71 |
|
|
*/ |
72 |
|
|
public |
73 |
|
|
JSLscpScriptDlg(Frame owner) { |
74 |
|
|
super(owner); |
75 |
|
|
|
76 |
|
|
JPanel mainPane = new JPanel(); |
77 |
|
|
|
78 |
|
|
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); |
79 |
|
|
mainPane.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); |
80 |
|
|
|
81 |
|
|
JScrollPane sp = new JScrollPane(textPane); |
82 |
|
|
sp.setAlignmentX(JPanel.RIGHT_ALIGNMENT); |
83 |
|
|
mainPane.add(sp); |
84 |
|
|
|
85 |
|
|
mainPane.add(Box.createRigidArea(new Dimension(0, 17))); |
86 |
|
|
|
87 |
|
|
JPanel p = new JPanel(); |
88 |
|
|
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
89 |
|
|
p.add(btnSaveAs); |
90 |
|
|
p.add(Box.createRigidArea(new Dimension(6, 0))); |
91 |
|
|
p.add(btnClose); |
92 |
|
|
p.setAlignmentX(JPanel.RIGHT_ALIGNMENT); |
93 |
|
|
|
94 |
|
|
mainPane.add(p); |
95 |
|
|
add(mainPane); |
96 |
|
|
|
97 |
|
|
pack(); |
98 |
|
|
setSize(500, 400); |
99 |
|
|
setLocationRelativeTo(getOwner()); |
100 |
|
|
|
101 |
|
|
btnSaveAs.addActionListener(new ActionListener() { |
102 |
|
|
public void |
103 |
|
|
actionPerformed(ActionEvent e) { saveScript(); } |
104 |
|
|
}); |
105 |
|
|
|
106 |
|
|
btnClose.addActionListener(new ActionListener() { |
107 |
|
|
public void |
108 |
|
|
actionPerformed(ActionEvent e) { setVisible(false); } |
109 |
|
|
}); |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
private JSPrefs |
113 |
|
|
preferences() { return CC.getViewConfig().preferences(); } |
114 |
|
|
|
115 |
|
|
public void |
116 |
|
|
setCommands(String[] commands) { |
117 |
|
|
StringBuffer sb = new StringBuffer(); |
118 |
|
|
|
119 |
|
|
for(String s : commands) sb.append(s).append("\n"); |
120 |
|
|
|
121 |
|
|
textPane.setText(sb.toString()); |
122 |
|
|
} |
123 |
|
|
|
124 |
|
|
private void |
125 |
|
|
saveScript() { |
126 |
iliev |
1871 |
File f = StdUtils.showSaveLscpFileChooser(this); |
127 |
|
|
if(f == null) return; |
128 |
|
|
|
129 |
|
|
if(f.exists()) { |
130 |
|
|
String msg = i18n.getMessage("JSLscpScriptDlg.overwriteFile?"); |
131 |
|
|
if(!HF.showYesNoDialog(CC.getMainFrame(), msg)) return; |
132 |
|
|
} |
133 |
iliev |
1286 |
|
134 |
|
|
try { |
135 |
iliev |
1871 |
FileOutputStream fos = new FileOutputStream(f); |
136 |
iliev |
1286 |
fos.write(textPane.getText().getBytes("US-ASCII")); |
137 |
|
|
fos.close(); |
138 |
|
|
} catch(Exception e) { |
139 |
|
|
CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e); |
140 |
|
|
HF.showErrorMessage(e); |
141 |
|
|
} |
142 |
|
|
} |
143 |
|
|
} |