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.classic; |
24 |
|
25 |
import java.awt.Dimension; |
26 |
import java.awt.Window; |
27 |
|
28 |
import java.awt.event.ActionEvent; |
29 |
import java.awt.event.ActionListener; |
30 |
|
31 |
import javax.swing.AbstractAction; |
32 |
import javax.swing.Action; |
33 |
import javax.swing.BorderFactory; |
34 |
import javax.swing.Box; |
35 |
import javax.swing.BoxLayout; |
36 |
import javax.swing.JButton; |
37 |
import javax.swing.JMenu; |
38 |
import javax.swing.JMenuItem; |
39 |
import javax.swing.JPanel; |
40 |
import javax.swing.JPopupMenu; |
41 |
|
42 |
import javax.swing.border.EtchedBorder; |
43 |
|
44 |
import org.jsampler.CC; |
45 |
import org.jsampler.view.std.JSLSConsolePane; |
46 |
|
47 |
import static org.jsampler.view.classic.ClassicI18n.i18n; |
48 |
import org.jsampler.view.std.JSLscpScriptDlg; |
49 |
|
50 |
/** |
51 |
* |
52 |
* @author Grigor Iliev |
53 |
*/ |
54 |
public class LSConsolePane extends JSLSConsolePane { |
55 |
private final JButton btnMenu = new ToolbarButton(); |
56 |
private JPopupMenu menu = new JPopupMenu(); |
57 |
|
58 |
private final LSConsoleViewMode lsConsoleViewMode; |
59 |
|
60 |
|
61 |
/** |
62 |
* Creates a new instance of <code>LSConsolePane</code> |
63 |
*/ |
64 |
public |
65 |
LSConsolePane(Window owner) { |
66 |
super(owner); |
67 |
|
68 |
lsConsoleViewMode = new LSConsoleViewMode(); |
69 |
|
70 |
setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); |
71 |
|
72 |
JPanel p = new JPanel(); |
73 |
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
74 |
p.add(Box.createGlue()); |
75 |
|
76 |
btnMenu.setIcon(Res.iconDown16); |
77 |
btnMenu.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); |
78 |
btnMenu.setFocusPainted(false); |
79 |
p.add(btnMenu); |
80 |
p.setMaximumSize(new Dimension(Short.MAX_VALUE, p.getPreferredSize().height)); |
81 |
|
82 |
add(p, java.awt.BorderLayout.NORTH); |
83 |
|
84 |
initMenu(owner); |
85 |
} |
86 |
|
87 |
private void |
88 |
initMenu(Window owner) { |
89 |
JMenuItem mi = new JMenuItem(lsConsoleViewMode); |
90 |
menu.add(mi); |
91 |
|
92 |
menu.addSeparator(); |
93 |
|
94 |
JMenu clearMenu = new JMenu(i18n.getMenuLabel("LSConsolePane.clear")); |
95 |
|
96 |
mi = new JMenuItem(i18n.getMenuLabel("LSConsolePane.clearConsole")); |
97 |
clearMenu.add(mi); |
98 |
mi.addActionListener(new Actions(Actions.CLEAR_CONSOLE)); |
99 |
|
100 |
mi = new JMenuItem(i18n.getMenuLabel("LSConsolePane.clearSessionHistory")); |
101 |
clearMenu.add(mi); |
102 |
mi.addActionListener(new Actions(Actions.CLEAR_SESSION_HISTORY)); |
103 |
|
104 |
menu.add(clearMenu); |
105 |
|
106 |
JMenu exportMenu = new JMenu(i18n.getMenuLabel("LSConsolePane.export")); |
107 |
|
108 |
mi = new JMenuItem(i18n.getMenuLabel("LSConsolePane.exportSession")); |
109 |
exportMenu.add(mi); |
110 |
mi.addActionListener(new ActionListener() { |
111 |
public void |
112 |
actionPerformed(ActionEvent e) { |
113 |
JSLscpScriptDlg dlg = new JSLscpScriptDlg(); |
114 |
dlg.setCommands(getModel().getSessionHistory()); |
115 |
dlg.setVisible(true); |
116 |
} |
117 |
}); |
118 |
|
119 |
mi = new JMenuItem(i18n.getMenuLabel("LSConsolePane.exportCommandHistory")); |
120 |
exportMenu.add(mi); |
121 |
mi.addActionListener(new ActionListener() { |
122 |
public void |
123 |
actionPerformed(ActionEvent e) { |
124 |
JSLscpScriptDlg dlg = new JSLscpScriptDlg(); |
125 |
dlg.setCommands(getModel().getCommandHistory()); |
126 |
dlg.setVisible(true); |
127 |
} |
128 |
}); |
129 |
|
130 |
menu.add(exportMenu); |
131 |
|
132 |
mi = new JMenuItem(i18n.getMenuLabel("LSConsolePane.runScript")); |
133 |
menu.add(mi); |
134 |
mi.addActionListener(new ActionListener() { |
135 |
public void |
136 |
actionPerformed(ActionEvent e) { |
137 |
((MainFrame)CC.getMainFrame()).runScript(); |
138 |
} |
139 |
}); |
140 |
|
141 |
btnMenu.addActionListener(new ActionListener() { |
142 |
public void |
143 |
actionPerformed(ActionEvent e) { |
144 |
int x = (int)btnMenu.getMinimumSize().getWidth(); |
145 |
x -= (int)menu.getPreferredSize().getWidth(); |
146 |
int y = (int)btnMenu.getMinimumSize().getHeight() + 1; |
147 |
menu.show(btnMenu, x, y); |
148 |
} |
149 |
}); |
150 |
} |
151 |
|
152 |
protected void |
153 |
quitSession() { |
154 |
super.quitSession(); |
155 |
((MainFrame)CC.getMainFrame()).setLSConsoleVisible(false); |
156 |
} |
157 |
|
158 |
private class LSConsoleViewMode extends AbstractAction { |
159 |
LSConsoleViewMode() { } |
160 |
|
161 |
public void |
162 |
actionPerformed(ActionEvent e) { |
163 |
MainFrame mainFrame = (MainFrame)CC.getMainFrame(); |
164 |
mainFrame.setLSConsolePopOut(!mainFrame.isLSConsolePopOut()); |
165 |
|
166 |
setName(mainFrame.isLSConsolePopOut()); |
167 |
} |
168 |
|
169 |
private void |
170 |
setName(boolean b) { |
171 |
if(b) { |
172 |
putValue(Action.NAME, i18n.getMenuLabel("LSConsolePane.popin")); |
173 |
} else { |
174 |
putValue(Action.NAME, i18n.getMenuLabel("LSConsolePane.popout")); |
175 |
} |
176 |
} |
177 |
} |
178 |
|
179 |
/** |
180 |
* Updates the text of the menu item responsible for changing the pop-out/pop-in mode. |
181 |
*/ |
182 |
public void |
183 |
updateLSConsoleViewMode() { |
184 |
if(getOwner() instanceof LSConsoleDlg) lsConsoleViewMode.setName(true); |
185 |
else if(getOwner() instanceof MainFrame) { |
186 |
lsConsoleViewMode.setName(((MainFrame)getOwner()).isLSConsolePopOut()); |
187 |
} |
188 |
} |
189 |
} |