1 |
/* |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
* |
4 |
* Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com> |
* Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
* |
6 |
* This file is part of JSampler. |
* This file is part of JSampler. |
7 |
* |
* |
65 |
import org.jsampler.view.OrchestraTable; |
import org.jsampler.view.OrchestraTable; |
66 |
import org.jsampler.view.OrchestraTableModel; |
import org.jsampler.view.OrchestraTableModel; |
67 |
|
|
68 |
|
import org.jsampler.view.std.JSManageOrchestrasPane; |
69 |
|
import org.jsampler.view.std.JSOrchestraPane; |
70 |
|
|
71 |
import static org.jsampler.view.classic.ClassicI18n.i18n; |
import static org.jsampler.view.classic.ClassicI18n.i18n; |
72 |
|
import org.jsampler.view.std.JSAddOrEditOrchestraDlg; |
73 |
|
|
74 |
|
|
75 |
/** |
/** |
78 |
*/ |
*/ |
79 |
public class ManageOrchestrasPage extends NavigationPage { |
public class ManageOrchestrasPage extends NavigationPage { |
80 |
private final JComponent manageOrchestrasPane; |
private final JComponent manageOrchestrasPane; |
81 |
|
OrchestraTable orchestraTable; |
|
// Manage Orchestra |
|
|
private final ToolbarButton btnAddOrchestra = new ToolbarButton(new AddOrchestra()); |
|
|
private final ToolbarButton btnEditOrchestra = new ToolbarButton(new EditOrchestra()); |
|
|
private final ToolbarButton btnDeleteOrchestra = new ToolbarButton(new DeleteOrchestra()); |
|
|
private final ToolbarButton btnOrchestraUp = new ToolbarButton(new OrchestraUp()); |
|
|
private final ToolbarButton btnOrchestraDown = new ToolbarButton(new OrchestraDown()); |
|
|
|
|
|
private OrchestraTable orchestraTable; |
|
|
|
|
|
private final ToolbarButton btnAddInstrument = new ToolbarButton(new AddInstrument()); |
|
|
private final ToolbarButton btnEditInstrument = new ToolbarButton(new EditInstrument()); |
|
|
private final ToolbarButton btnDeleteInstrument = new ToolbarButton(new DeleteInstrument()); |
|
|
private final ToolbarButton btnInstrumentUp = new ToolbarButton(new InstrumentUp()); |
|
|
private final ToolbarButton btnInstrumentDown = new ToolbarButton(new InstrumentDown()); |
|
82 |
|
|
83 |
private LinkButton lnkOrchestras = |
private LinkButton lnkOrchestras = |
84 |
new LinkButton(i18n.getButtonLabel("ManageOrchestrasPage.lnkOrchestras")); |
new LinkButton(i18n.getButtonLabel("ManageOrchestrasPage.lnkOrchestras")); |
85 |
|
|
86 |
private InstrumentTable instrumentTable; |
private OrchestraPane orchestraPane = new OrchestraPane(); |
|
private OrchestraModel orchestraModel; |
|
87 |
|
|
88 |
|
|
89 |
/** Creates a new instance of <code>ManageOrchestrasPage</code>. */ |
/** Creates a new instance of <code>ManageOrchestrasPage</code>. */ |
98 |
installListeneres(); |
installListeneres(); |
99 |
} |
} |
100 |
|
|
101 |
private JComponent |
class ManageOrchestrasPane extends JSManageOrchestrasPane { |
102 |
createManageOrchestrasPane() { |
ManageOrchestrasPane() { |
103 |
JPanel p = new JPanel(); |
actionAddOrchestra.putValue(Action.SMALL_ICON, Res.iconNew16); |
104 |
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
actionEditOrchestra.putValue(Action.SMALL_ICON, Res.iconEdit16); |
105 |
//p.add(Box.createRigidArea(new Dimension(0, 5))); |
actionDeleteOrchestra.putValue(Action.SMALL_ICON, Res.iconDelete16); |
106 |
|
actionOrchestraUp.putValue(Action.SMALL_ICON, Res.iconUp16); |
107 |
JToolBar tb = new JToolBar(); |
actionOrchestraDown.putValue(Action.SMALL_ICON, Res.iconDown16); |
108 |
tb.add(btnAddOrchestra); |
|
109 |
tb.add(btnEditOrchestra); |
removeAll(); |
110 |
tb.add(btnDeleteOrchestra); |
|
111 |
|
JToolBar toolBar = new JToolBar(); |
112 |
tb.addSeparator(); |
toolBar.add(new ToolbarButton(actionAddOrchestra)); |
113 |
|
toolBar.add(new ToolbarButton(actionEditOrchestra)); |
114 |
tb.add(btnOrchestraUp); |
toolBar.add(new ToolbarButton(actionDeleteOrchestra)); |
115 |
tb.add(btnOrchestraDown); |
|
116 |
|
toolBar.addSeparator(); |
117 |
tb.setMaximumSize(new Dimension(Short.MAX_VALUE, tb.getPreferredSize().height)); |
|
118 |
tb.setFloatable(false); |
toolBar.add(new ToolbarButton(actionOrchestraUp)); |
119 |
tb.setAlignmentX(LEFT_ALIGNMENT); |
toolBar.add(new ToolbarButton(actionOrchestraDown)); |
120 |
|
|
121 |
p.add(tb); |
toolBar.setFloatable(false); |
122 |
|
add(toolBar, java.awt.BorderLayout.NORTH); |
|
orchestraTable = new OrchestraTable(new OrchestraTableModel(CC.getOrchestras())); |
|
|
JScrollPane sp = new JScrollPane(orchestraTable); |
|
|
|
|
|
sp.getViewport().addMouseListener(new MouseAdapter() { |
|
|
public void |
|
|
mouseClicked(MouseEvent e) { orchestraTable.clearSelection(); } |
|
|
}); |
|
|
|
|
|
Dimension d; |
|
|
d = new Dimension(sp.getMinimumSize().width, sp.getPreferredSize().height); |
|
|
sp.setPreferredSize(d); |
|
123 |
|
|
124 |
sp.setAlignmentX(LEFT_ALIGNMENT); |
JScrollPane sp = new JScrollPane(orchestraTable); |
125 |
p.add(sp); |
Dimension d; |
126 |
|
d = new Dimension(sp.getMinimumSize().width, sp.getPreferredSize().height); |
127 |
|
sp.setPreferredSize(d); |
128 |
|
|
129 |
|
add(sp); |
130 |
|
|
131 |
|
ManageOrchestrasPage.this.orchestraTable = this.orchestraTable; |
132 |
|
} |
133 |
|
} |
134 |
|
|
135 |
|
class OrchestraPane extends JSOrchestraPane { |
136 |
|
OrchestraPane() { |
137 |
|
actionAddInstrument.putValue(Action.SMALL_ICON, Res.iconNew16); |
138 |
|
actionEditInstrument.putValue(Action.SMALL_ICON, Res.iconEdit16); |
139 |
|
actionDeleteInstrument.putValue(Action.SMALL_ICON, Res.iconDelete16); |
140 |
|
actionInstrumentUp.putValue(Action.SMALL_ICON, Res.iconUp16); |
141 |
|
actionInstrumentDown.putValue(Action.SMALL_ICON, Res.iconDown16); |
142 |
|
|
143 |
|
removeAll(); |
144 |
|
|
145 |
|
JToolBar toolBar = new JToolBar(); |
146 |
|
toolBar.add(new ToolbarButton(actionAddInstrument)); |
147 |
|
toolBar.add(new ToolbarButton(actionEditInstrument)); |
148 |
|
toolBar.add(new ToolbarButton(actionDeleteInstrument)); |
149 |
|
|
150 |
|
toolBar.addSeparator(); |
151 |
|
|
152 |
|
toolBar.add(new ToolbarButton(actionInstrumentUp)); |
153 |
|
toolBar.add(new ToolbarButton(actionInstrumentDown)); |
154 |
|
|
155 |
|
toolBar.setFloatable(false); |
156 |
|
add(toolBar, java.awt.BorderLayout.NORTH); |
157 |
|
|
158 |
|
JScrollPane sp = new JScrollPane(instrumentTable); |
159 |
|
Dimension d; |
160 |
|
d = new Dimension(sp.getMinimumSize().width, sp.getPreferredSize().height); |
161 |
|
sp.setPreferredSize(d); |
162 |
|
|
163 |
|
add(sp); |
164 |
|
} |
165 |
|
} |
166 |
|
|
167 |
|
private JComponent |
168 |
|
createManageOrchestrasPane() { |
169 |
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
170 |
splitPane.setContinuousLayout(true); |
splitPane.setContinuousLayout(true); |
171 |
splitPane.setTopComponent(p); |
splitPane.setTopComponent(new ManageOrchestrasPane()); |
172 |
|
splitPane.setBottomComponent(orchestraPane); |
|
p = new JPanel(); |
|
|
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
|
|
//p.add(Box.createRigidArea(new Dimension(0, 5))); |
|
|
|
|
|
tb = new JToolBar(); |
|
|
btnAddInstrument.setEnabled(false); |
|
|
tb.add(btnAddInstrument); |
|
|
tb.add(btnEditInstrument); |
|
|
tb.add(btnDeleteInstrument); |
|
|
|
|
|
tb.addSeparator(); |
|
|
|
|
|
tb.add(btnInstrumentUp); |
|
|
tb.add(btnInstrumentDown); |
|
|
|
|
|
tb.setMaximumSize(new Dimension(Short.MAX_VALUE, tb.getPreferredSize().height)); |
|
|
tb.setFloatable(false); |
|
|
tb.setAlignmentX(JPanel.LEFT_ALIGNMENT); |
|
|
|
|
|
p.add(tb); |
|
|
|
|
|
orchestraModel = new DefaultOrchestraModel(); |
|
|
instrumentTable = new InstrumentTable(new InstrumentTableModel(orchestraModel)); |
|
|
sp = new DnDScrollPane(instrumentTable); |
|
|
sp.setAlignmentX(LEFT_ALIGNMENT); |
|
|
p.add(sp); |
|
|
|
|
|
//p.add(lnkOrchestras); |
|
|
//p.add(Box.createRigidArea(new Dimension(0, 5))); |
|
|
|
|
|
splitPane.setBottomComponent(p); |
|
173 |
splitPane.setDividerSize(3); |
splitPane.setDividerSize(3); |
174 |
splitPane.setDividerLocation(180); |
splitPane.setDividerLocation(180); |
175 |
|
|
187 |
|
|
188 |
OrchestraSelectionHandler l = new OrchestraSelectionHandler(); |
OrchestraSelectionHandler l = new OrchestraSelectionHandler(); |
189 |
orchestraTable.getSelectionModel().addListSelectionListener(l); |
orchestraTable.getSelectionModel().addListSelectionListener(l); |
|
|
|
|
orchestraTable.addMouseListener(new MouseAdapter() { |
|
|
public void |
|
|
mouseClicked(MouseEvent e) { |
|
|
if(e.getClickCount() < 2) return; |
|
|
|
|
|
if(orchestraTable.getSelectedOrchestra() == null) return; |
|
|
btnEditOrchestra.doClick(0); |
|
|
} |
|
|
}); |
|
|
|
|
|
InstrumentSelectionHandler l2 = new InstrumentSelectionHandler(); |
|
|
instrumentTable.getSelectionModel().addListSelectionListener(l2); |
|
|
|
|
|
instrumentTable.addMouseListener(new MouseAdapter() { |
|
|
public void |
|
|
mouseClicked(MouseEvent e) { |
|
|
if(e.getClickCount() < 2) return; |
|
|
|
|
|
if(instrumentTable.getSelectedInstrument() == null) return; |
|
|
btnEditInstrument.doClick(0); |
|
|
} |
|
|
}); |
|
190 |
} |
} |
191 |
|
|
192 |
public class DnDScrollPane extends JScrollPane { |
public class DnDScrollPane extends JScrollPane { |
210 |
public boolean |
public boolean |
211 |
canImport(JComponent comp, DataFlavor[] flavors) { |
canImport(JComponent comp, DataFlavor[] flavors) { |
212 |
if(instrumentTable.isPerformingDnD()) return false; |
if(instrumentTable.isPerformingDnD()) return false; |
213 |
if(!btnAddInstrument.isEnabled()) return false; |
|
214 |
|
if(orchestraPane.getSelectedInstrument() == null) { |
215 |
|
return false; |
216 |
|
} |
217 |
|
|
218 |
return super.canImport(comp, flavors); |
return super.canImport(comp, flavors); |
219 |
} |
} |
243 |
valueChanged(ListSelectionEvent e) { |
valueChanged(ListSelectionEvent e) { |
244 |
if(e.getValueIsAdjusting()) return; |
if(e.getValueIsAdjusting()) return; |
245 |
|
|
246 |
if(orchestraTable.getSelectedOrchestra() == null) { |
orchestraPane.setOrchestra(orchestraTable.getSelectedOrchestra()); |
|
btnEditOrchestra.setEnabled(false); |
|
|
btnDeleteOrchestra.setEnabled(false); |
|
|
btnAddInstrument.setEnabled(false); |
|
|
btnOrchestraUp.setEnabled(false); |
|
|
btnOrchestraDown.setEnabled(false); |
|
|
instrumentTable.setModel(new InstrumentTableModel()); |
|
|
return; |
|
|
} |
|
|
|
|
|
btnEditOrchestra.setEnabled(true); |
|
|
btnDeleteOrchestra.setEnabled(true); |
|
|
btnAddInstrument.setEnabled(true); |
|
|
|
|
|
orchestraModel = orchestraTable.getSelectedOrchestra(); |
|
|
int idx = orchestraTable.getSelectedRow(); |
|
|
btnOrchestraUp.setEnabled(idx != 0); |
|
|
btnOrchestraDown.setEnabled(idx != orchestraTable.getRowCount() - 1); |
|
|
|
|
|
instrumentTable.getModel().setOrchestraModel(orchestraModel); |
|
|
} |
|
|
} |
|
|
|
|
|
private class InstrumentSelectionHandler implements ListSelectionListener { |
|
|
public void |
|
|
valueChanged(ListSelectionEvent e) { |
|
|
if(e.getValueIsAdjusting()) return; |
|
|
|
|
|
if(instrumentTable.getSelectedInstrument() == null) { |
|
|
btnEditInstrument.setEnabled(false); |
|
|
btnDeleteInstrument.setEnabled(false); |
|
|
btnInstrumentUp.setEnabled(false); |
|
|
btnInstrumentDown.setEnabled(false); |
|
|
return; |
|
|
} |
|
|
|
|
|
btnEditInstrument.setEnabled(true); |
|
|
btnDeleteInstrument.setEnabled(true); |
|
|
|
|
|
int idx = instrumentTable.getSelectedRow(); |
|
|
btnInstrumentUp.setEnabled(idx != 0); |
|
|
btnInstrumentDown.setEnabled(idx != instrumentTable.getRowCount() - 1); |
|
|
} |
|
|
} |
|
|
|
|
|
private class AddOrchestra extends AbstractAction { |
|
|
AddOrchestra() { |
|
|
super(""); |
|
|
|
|
|
String s = i18n.getLabel("ManageOrchestrasPage.ttAddOrchestra"); |
|
|
putValue(SHORT_DESCRIPTION, s); |
|
|
putValue(Action.SMALL_ICON, Res.iconNew16); |
|
|
} |
|
|
|
|
|
public void |
|
|
actionPerformed(ActionEvent e) { |
|
|
AddOrchestraDlg dlg = new AddOrchestraDlg(); |
|
|
dlg.setVisible(true); |
|
|
|
|
|
if(dlg.isCancelled()) return; |
|
|
|
|
|
OrchestraModel om = orchestraTable.getSelectedOrchestra(); |
|
|
int idx = CC.getOrchestras().getOrchestraIndex(om); |
|
|
if(idx < 0) CC.getOrchestras().addOrchestra(dlg.getOrchestra()); |
|
|
else CC.getOrchestras().insertOrchestra(dlg.getOrchestra(), idx); |
|
|
|
|
|
orchestraTable.setSelectedOrchestra(dlg.getOrchestra()); |
|
|
} |
|
|
} |
|
|
|
|
|
private class EditOrchestra extends AbstractAction { |
|
|
EditOrchestra() { |
|
|
super(""); |
|
|
|
|
|
String s = i18n.getLabel("ManageOrchestrasPage.ttEditOrchestra"); |
|
|
putValue(SHORT_DESCRIPTION, s); |
|
|
putValue(Action.SMALL_ICON, Res.iconEdit16); |
|
|
|
|
|
setEnabled(false); |
|
|
} |
|
|
|
|
|
public void |
|
|
actionPerformed(ActionEvent e) { |
|
|
OrchestraModel m = orchestraTable.getSelectedOrchestra(); |
|
|
AddOrchestraDlg dlg = new AddOrchestraDlg(m); |
|
|
dlg.setVisible(true); |
|
|
} |
|
|
} |
|
|
|
|
|
private class DeleteOrchestra extends AbstractAction { |
|
|
DeleteOrchestra() { |
|
|
super(""); |
|
|
|
|
|
String s = i18n.getLabel("ManageOrchestrasPage.ttDeleteOrchestra"); |
|
|
putValue(SHORT_DESCRIPTION, s); |
|
|
putValue(Action.SMALL_ICON, Res.iconDelete16); |
|
|
|
|
|
setEnabled(false); |
|
|
} |
|
|
|
|
|
public void |
|
|
actionPerformed(ActionEvent e) { |
|
|
OrchestraModel om = orchestraTable.getSelectedOrchestra(); |
|
|
if(om == null) return; |
|
|
if(om.getInstrumentCount() > 0) { |
|
|
String s = i18n.getMessage("ManageOrchestrasPage.removeOrchestra?"); |
|
|
if(!HF.showYesNoDialog(CC.getMainFrame(), s)) return; |
|
|
} |
|
|
|
|
|
CC.getOrchestras().removeOrchestra(om); |
|
|
} |
|
|
} |
|
|
|
|
|
private class OrchestraUp extends AbstractAction { |
|
|
OrchestraUp() { |
|
|
super(""); |
|
|
|
|
|
String s = i18n.getLabel("ManageOrchestrasPage.OrchestraUp"); |
|
|
putValue(SHORT_DESCRIPTION, s); |
|
|
putValue(Action.SMALL_ICON, Res.iconUp16); |
|
|
|
|
|
setEnabled(false); |
|
|
} |
|
|
|
|
|
public void |
|
|
actionPerformed(ActionEvent e) { |
|
|
OrchestraModel om = orchestraTable.getSelectedOrchestra(); |
|
|
CC.getOrchestras().moveOrchestraUp(om); |
|
|
orchestraTable.setSelectedOrchestra(om); |
|
|
} |
|
|
} |
|
|
|
|
|
private class OrchestraDown extends AbstractAction { |
|
|
OrchestraDown() { |
|
|
super(""); |
|
|
|
|
|
String s = i18n.getLabel("ManageOrchestrasPage.OrchestraDown"); |
|
|
putValue(SHORT_DESCRIPTION, s); |
|
|
putValue(Action.SMALL_ICON, Res.iconDown16); |
|
|
|
|
|
setEnabled(false); |
|
|
} |
|
|
|
|
|
public void |
|
|
actionPerformed(ActionEvent e) { |
|
|
OrchestraModel om = orchestraTable.getSelectedOrchestra(); |
|
|
CC.getOrchestras().moveOrchestraDown(om); |
|
|
orchestraTable.setSelectedOrchestra(om); |
|
|
} |
|
|
} |
|
|
|
|
|
private class AddInstrument extends AbstractAction { |
|
|
AddInstrument() { |
|
|
super(""); |
|
|
|
|
|
String s = i18n.getLabel("ManageOrchestrasPage.ttAddInstrument"); |
|
|
putValue(SHORT_DESCRIPTION, s); |
|
|
|
|
|
try { |
|
|
putValue(Action.SMALL_ICON, Res.iconNew16); |
|
|
} catch(Exception x) { |
|
|
CC.getLogger().log(Level.INFO, HF.getErrorMessage(x), x); |
|
|
} |
|
|
} |
|
|
|
|
|
public void |
|
|
actionPerformed(ActionEvent e) { |
|
|
AddInstrumentDlg dlg = new AddInstrumentDlg(); |
|
|
dlg.setVisible(true); |
|
|
|
|
|
if(dlg.isCancelled()) return; |
|
|
|
|
|
orchestraModel.addInstrument(dlg.getInstrument()); |
|
|
} |
|
|
} |
|
|
|
|
|
private class EditInstrument extends AbstractAction { |
|
|
EditInstrument() { |
|
|
super(""); |
|
|
|
|
|
String s = i18n.getLabel("ManageOrchestrasPage.ttEditInstrument"); |
|
|
putValue(SHORT_DESCRIPTION, s); |
|
|
putValue(Action.SMALL_ICON, Res.iconEdit16); |
|
|
|
|
|
setEnabled(false); |
|
|
} |
|
|
|
|
|
public void |
|
|
actionPerformed(ActionEvent e) { |
|
|
Instrument instr = instrumentTable.getSelectedInstrument(); |
|
|
AddInstrumentDlg dlg = new AddInstrumentDlg(instr); |
|
|
dlg.setVisible(true); |
|
|
} |
|
|
} |
|
|
|
|
|
private class DeleteInstrument extends AbstractAction { |
|
|
DeleteInstrument() { |
|
|
super(""); |
|
|
|
|
|
String s = i18n.getLabel("ManageOrchestrasPage.ttDeleteInstrument"); |
|
|
putValue(SHORT_DESCRIPTION, s); |
|
|
putValue(Action.SMALL_ICON, Res.iconDelete16); |
|
|
|
|
|
setEnabled(false); |
|
|
} |
|
|
|
|
|
public void |
|
|
actionPerformed(ActionEvent e) { |
|
|
Instrument instr = instrumentTable.getSelectedInstrument(); |
|
|
if(instr == null) return; |
|
|
orchestraModel.removeInstrument(instr); |
|
|
} |
|
|
} |
|
|
|
|
|
private class InstrumentUp extends AbstractAction { |
|
|
InstrumentUp() { |
|
|
super(""); |
|
|
|
|
|
String s = i18n.getLabel("ManageOrchestrasPage.InstrumentUp"); |
|
|
putValue(SHORT_DESCRIPTION, s); |
|
|
putValue(Action.SMALL_ICON, Res.iconUp16); |
|
|
|
|
|
setEnabled(false); |
|
|
} |
|
|
|
|
|
public void |
|
|
actionPerformed(ActionEvent e) { |
|
|
Instrument instr = instrumentTable.getSelectedInstrument(); |
|
|
instrumentTable.getModel().getOrchestraModel().moveInstrumentUp(instr); |
|
|
instrumentTable.setSelectedInstrument(instr); |
|
|
} |
|
|
} |
|
|
|
|
|
private class InstrumentDown extends AbstractAction { |
|
|
InstrumentDown() { |
|
|
super(""); |
|
|
|
|
|
String s = i18n.getLabel("ManageOrchestrasPage.InstrumentDown"); |
|
|
putValue(SHORT_DESCRIPTION, s); |
|
|
putValue(Action.SMALL_ICON, Res.iconDown16); |
|
|
|
|
|
setEnabled(false); |
|
|
} |
|
|
|
|
|
public void |
|
|
actionPerformed(ActionEvent e) { |
|
|
Instrument instr = instrumentTable.getSelectedInstrument(); |
|
|
instrumentTable.getModel().getOrchestraModel().moveInstrumentDown(instr); |
|
|
instrumentTable.setSelectedInstrument(instr); |
|
247 |
} |
} |
248 |
} |
} |
249 |
} |
} |