/[svn]/jsampler/trunk/src/org/jsampler/view/std/JSLscpScriptDlg.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/std/JSLscpScriptDlg.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1286 - (show annotations) (download)
Fri Aug 10 20:24:23 2007 UTC (16 years, 8 months ago) by iliev
File size: 3964 byte(s)
- Updated to version 0.6a. The Fantasia distribution is now
  capable of controlling all features available in LinuxSampler

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.std;
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 import org.jsampler.JSPrefs;
49
50 import org.jsampler.view.LscpFileFilter;
51
52 import static org.jsampler.view.std.StdI18n.i18n;
53
54
55 /**
56 *
57 * @author Grigor Iliev
58 */
59 public class JSLscpScriptDlg extends JDialog {
60 private final JTextPane textPane = new JTextPane();
61 private final JButton btnSaveAs =
62 new JButton(i18n.getButtonLabel("JSLscpScriptDlg.btnSaveAs"));
63 private final JButton btnClose = new JButton(i18n.getButtonLabel("close"));
64
65
66 /**
67 * Creates a new instance of <code>JSLscpScriptDlg</code>.
68 */
69 public
70 JSLscpScriptDlg() { this(CC.getMainFrame()); }
71
72 /**
73 * Creates a new instance of <code>JSLscpScriptDlg</code>.
74 */
75 public
76 JSLscpScriptDlg(Frame owner) {
77 super(owner);
78
79 JPanel mainPane = new JPanel();
80
81 mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
82 mainPane.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6));
83
84 JScrollPane sp = new JScrollPane(textPane);
85 sp.setAlignmentX(JPanel.RIGHT_ALIGNMENT);
86 mainPane.add(sp);
87
88 mainPane.add(Box.createRigidArea(new Dimension(0, 17)));
89
90 JPanel p = new JPanel();
91 p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
92 p.add(btnSaveAs);
93 p.add(Box.createRigidArea(new Dimension(6, 0)));
94 p.add(btnClose);
95 p.setAlignmentX(JPanel.RIGHT_ALIGNMENT);
96
97 mainPane.add(p);
98 add(mainPane);
99
100 pack();
101 setSize(500, 400);
102 setLocationRelativeTo(getOwner());
103
104 btnSaveAs.addActionListener(new ActionListener() {
105 public void
106 actionPerformed(ActionEvent e) { saveScript(); }
107 });
108
109 btnClose.addActionListener(new ActionListener() {
110 public void
111 actionPerformed(ActionEvent e) { setVisible(false); }
112 });
113 }
114
115 private JSPrefs
116 preferences() { return CC.getViewConfig().preferences(); }
117
118 public void
119 setCommands(String[] commands) {
120 StringBuffer sb = new StringBuffer();
121
122 for(String s : commands) sb.append(s).append("\n");
123
124 textPane.setText(sb.toString());
125 }
126
127 private void
128 saveScript() {
129 String s = preferences().getStringProperty("lastScriptLocation");
130 JFileChooser fc = new JFileChooser(s);
131 fc.setFileFilter(new LscpFileFilter());
132 int result = fc.showSaveDialog(this);
133 if(result != JFileChooser.APPROVE_OPTION) return;
134
135 String path = fc.getCurrentDirectory().getAbsolutePath();
136 preferences().setStringProperty("lastScriptLocation", path);
137
138 try {
139 FileOutputStream fos = new FileOutputStream(fc.getSelectedFile());
140 fos.write(textPane.getText().getBytes("US-ASCII"));
141 fos.close();
142 } catch(Exception e) {
143 CC.getLogger().log(Level.FINE, HF.getErrorMessage(e), e);
144 HF.showErrorMessage(e);
145 }
146 }
147 }

  ViewVC Help
Powered by ViewVC