/[svn]/jsampler/trunk/src/org/jsampler/view/fantasia/LSConsoleFrame.java
ViewVC logotype

Contents of /jsampler/trunk/src/org/jsampler/view/fantasia/LSConsoleFrame.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1786 - (show annotations) (download)
Wed Oct 8 22:38:15 2008 UTC (15 years, 6 months ago) by iliev
File size: 4792 byte(s)
* Implemented option to launch the backend if it is not yet started
  (choose Edit/Preferences, then click the `Backend' tab)
* LSCP scripts can now be run by passing them to jsampler
  as command-line arguments
* The scripts in the `scripts' directory now pass the command-line
  arguments to the respective jsampler distribution
* ant: the default target is now build-fantasia
* bugfix: backend address was always set to 127.0.0.1 when adding
  backend to the backend list

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2007 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.fantasia;
24
25 import java.awt.Dimension;
26 import java.awt.Rectangle;
27
28 import java.awt.event.ActionEvent;
29 import java.awt.event.ActionListener;
30 import java.awt.event.WindowAdapter;
31 import java.awt.event.WindowEvent;
32
33 import javax.swing.JFrame;
34 import javax.swing.JMenu;
35 import javax.swing.JMenuBar;
36 import javax.swing.JMenuItem;
37
38 import org.jsampler.CC;
39 import org.jsampler.view.std.JSLscpScriptDlg;
40 import org.jsampler.view.std.StdUtils;
41
42 import static org.jsampler.view.fantasia.FantasiaI18n.i18n;
43 import static org.jsampler.view.fantasia.FantasiaPrefs.preferences;
44
45 /**
46 *
47 * @author Grigor Iliev
48 */
49 public class LSConsoleFrame extends JFrame {
50 private final JMenuBar menuBar = new JMenuBar();
51 private final LSConsolePane lsConsolePane = new LSConsolePane(this);
52
53 /**
54 * Creates a new instance of <code>LSConsoleFrame</code>
55 */
56 public
57 LSConsoleFrame() {
58 setTitle(i18n.getLabel("LSConsoleFrame.title"));
59 if(Res.iconAppIcon != null) setIconImage(Res.iconLSConsole.getImage());
60
61 add(lsConsolePane);
62 addMenu();
63 pack();
64 setSavedSize();
65
66 addWindowListener(new WindowAdapter() {
67 public void
68 windowClosing(WindowEvent we) { onWindowClose(); }
69 });
70 }
71
72 private void
73 addMenu() {
74 JMenu m;
75 JMenuItem mi;
76
77 setJMenuBar(menuBar);
78
79 // Actions
80 m = new JMenu(i18n.getMenuLabel("lsconsole.actions"));
81 m.setFont(m.getFont().deriveFont(java.awt.Font.BOLD));
82 menuBar.add(m);
83
84 JMenu clearMenu = new JMenu(i18n.getMenuLabel("lsconsole.clear"));
85
86 mi = new JMenuItem(i18n.getMenuLabel("lsconsole.clearConsole"));
87 clearMenu.add(mi);
88 mi.addActionListener(lsConsolePane.clearConsoleAction);
89
90 mi = new JMenuItem(i18n.getMenuLabel("lsconsole.clearSessionHistory"));
91 clearMenu.add(mi);
92 mi.addActionListener(lsConsolePane.clearSessionHistoryAction);
93
94 m.add(clearMenu);
95
96 JMenu exportMenu = new JMenu(i18n.getMenuLabel("lsconsole.export"));
97
98 mi = new JMenuItem(i18n.getMenuLabel("lsconsole.export.session"));
99 exportMenu.add(mi);
100 mi.addActionListener(new ActionListener() {
101 public void
102 actionPerformed(ActionEvent e) {
103 JSLscpScriptDlg dlg = new JSLscpScriptDlg();
104 dlg.setCommands(lsConsolePane.getModel().getSessionHistory());
105 dlg.setVisible(true);
106 }
107 });
108
109 mi = new JMenuItem(i18n.getMenuLabel("lsconsole.export.commandHistory"));
110 exportMenu.add(mi);
111 mi.addActionListener(new ActionListener() {
112 public void
113 actionPerformed(ActionEvent e) {
114 JSLscpScriptDlg dlg = new JSLscpScriptDlg();
115 dlg.setCommands(lsConsolePane.getModel().getCommandHistory());
116 dlg.setVisible(true);
117 }
118 });
119
120 m.add(exportMenu);
121
122 m.addSeparator();
123
124 mi = new JMenuItem(i18n.getMenuLabel("lsconsole.runScript"));
125 m.add(mi);
126 mi.addActionListener(new ActionListener() {
127 public void
128 actionPerformed(ActionEvent e) {
129 ((MainFrame)CC.getMainFrame()).runScript();
130 }
131 });
132 }
133
134 /** Invoked when this window is about to close. */
135 private void
136 onWindowClose() {
137 boolean b = (getExtendedState() & MAXIMIZED_BOTH) == MAXIMIZED_BOTH;
138 preferences().setBoolProperty("LSConsoleFrame.windowMaximized", b);
139 if(b) return;
140
141 StdUtils.saveWindowBounds("LSConsoleFrame", getBounds());
142 }
143
144 private void
145 setDefaultSize() {
146 Dimension dimension = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
147 double width = dimension.getWidth();
148 double height = dimension.getHeight();
149 setBounds(100, 100, (int) width - 200, (int) height - 200);
150 }
151
152 private void
153 setSavedSize() {
154 Rectangle r = StdUtils.getWindowBounds("LSConsoleFrame");
155 if(r == null) {
156 setDefaultSize();
157 return;
158 }
159
160 setBounds(r);
161 }
162
163 @Override
164 public void
165 setVisible(boolean b) {
166 if(b == isVisible()) return;
167
168 super.setVisible(b);
169
170 if(b && preferences().getBoolProperty("LSConsoleFrame.windowMaximized")) {
171 setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
172 }
173 }
174
175 protected LSConsolePane
176 getLSConsolePane() { return lsConsolePane; }
177 }

  ViewVC Help
Powered by ViewVC