/[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 1871 - (show annotations) (download)
Sun Mar 22 18:11:39 2009 UTC (15 years, 1 month ago) by iliev
File size: 3723 byte(s)
* Mac OS integration, work in progress:
* Added option to use native file choosers
  (choose Edit/Preferences, then click the `View' tab)

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2009 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 java.io.File;
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.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 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
134 try {
135 FileOutputStream fos = new FileOutputStream(f);
136 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 }

  ViewVC Help
Powered by ViewVC