/[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 1286 - (show annotations) (download)
Fri Aug 10 20:24:23 2007 UTC (16 years, 8 months ago) by iliev
File size: 5491 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-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
27 import java.awt.event.ActionEvent;
28 import java.awt.event.ActionListener;
29 import java.awt.event.WindowAdapter;
30 import java.awt.event.WindowEvent;
31
32 import java.util.logging.Level;
33
34 import javax.swing.JFrame;
35 import javax.swing.JMenu;
36 import javax.swing.JMenuBar;
37 import javax.swing.JMenuItem;
38
39 import org.jsampler.CC;
40 import org.jsampler.view.std.JSLscpScriptDlg;
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 java.awt.Point p = getLocation();
142 Dimension d = getSize();
143 StringBuffer sb = new StringBuffer();
144 sb.append(p.x).append(',').append(p.y).append(',');
145 sb.append(d.width).append(',').append(d.height);
146 String s = "LSConsoleFrame.windowSizeAndLocation";
147 preferences().setStringProperty(s, sb.toString());
148 }
149
150 private void
151 setDefaultSize() {
152 Dimension dimension = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
153 double width = dimension.getWidth();
154 double height = dimension.getHeight();
155 setBounds(100, 100, (int) width - 200, (int) height - 200);
156 }
157
158 private void
159 setSavedSize() {
160 String sp = "LSConsoleFrame.windowSizeAndLocation";
161 String s = preferences().getStringProperty(sp, null);
162 if(s == null) {
163 setDefaultSize();
164 return;
165 }
166
167 try {
168 int i = s.indexOf(',');
169 int x = Integer.parseInt(s.substring(0, i));
170
171 s = s.substring(i + 1);
172 i = s.indexOf(',');
173 int y = Integer.parseInt(s.substring(0, i));
174
175 s = s.substring(i + 1);
176 i = s.indexOf(',');
177 int width = Integer.parseInt(s.substring(0, i));
178
179 s = s.substring(i + 1);
180 int height = Integer.parseInt(s);
181
182 setBounds(x, y, width, height);
183 } catch(Exception x) {
184 String msg = "Parsing of window size and location string failed";
185 CC.getLogger().log(Level.INFO, msg, x);
186 setDefaultSize();
187 }
188
189 if(preferences().getBoolProperty("LSConsoleFrame.windowMaximized")) {
190 setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
191 }
192 }
193
194 protected LSConsolePane
195 getLSConsolePane() { return lsConsolePane; }
196 }

  ViewVC Help
Powered by ViewVC