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