1 |
iliev |
1144 |
/* |
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; |
24 |
|
|
|
25 |
|
|
import java.awt.Component; |
26 |
|
|
|
27 |
|
|
import javax.swing.BorderFactory; |
28 |
|
|
import javax.swing.DefaultCellEditor; |
29 |
|
|
import javax.swing.JTable; |
30 |
|
|
import javax.swing.JTextField; |
31 |
|
|
import javax.swing.ListSelectionModel; |
32 |
|
|
|
33 |
|
|
import javax.swing.table.TableCellEditor; |
34 |
|
|
|
35 |
|
|
import org.jsampler.SamplerChannelModel; |
36 |
|
|
|
37 |
|
|
import org.jsampler.event.EffectSendsEvent; |
38 |
|
|
import org.jsampler.event.EffectSendsListener; |
39 |
|
|
|
40 |
|
|
import org.linuxsampler.lscp.FxSend; |
41 |
|
|
|
42 |
|
|
|
43 |
|
|
/** |
44 |
|
|
* A table for representing effect sends. |
45 |
|
|
* @author Grigor Iliev |
46 |
|
|
*/ |
47 |
|
|
public class FxSendTable extends JTable { |
48 |
|
|
private final DefaultCellEditor defaultEditor; |
49 |
|
|
private final JTextField tfEditor = new JTextField(); |
50 |
|
|
|
51 |
|
|
/** |
52 |
|
|
* Creates a new instance of <code>FxSendTable</code>. |
53 |
|
|
* @param channelModel The <code>SamplerChannelModel</code>, which |
54 |
|
|
* effect sends should be represented by this table. |
55 |
|
|
*/ |
56 |
|
|
public |
57 |
|
|
FxSendTable(SamplerChannelModel channelModel) { |
58 |
|
|
setModel(new FxSendTableModel(channelModel)); |
59 |
|
|
setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
60 |
|
|
|
61 |
|
|
channelModel.addEffectSendsListener(getHandler()); |
62 |
|
|
|
63 |
|
|
tfEditor.setBorder(BorderFactory.createEmptyBorder()); |
64 |
|
|
defaultEditor = new DefaultCellEditor(tfEditor); |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
/** |
68 |
|
|
* Gets the selected effect send. |
69 |
|
|
* @return The selected effect send, or |
70 |
|
|
* <code>null</code> if no effect send is selected. |
71 |
|
|
*/ |
72 |
|
|
public FxSend |
73 |
|
|
getSelectedFxSend() { |
74 |
|
|
int i = getSelectedRow(); |
75 |
|
|
if(i == -1) return null; |
76 |
|
|
|
77 |
|
|
return ((FxSendTableModel)getModel()).getFxSend(i); |
78 |
|
|
} |
79 |
|
|
|
80 |
|
|
/** |
81 |
|
|
* Sets the selected effect send. |
82 |
|
|
* @param fxSend The effect send to select. |
83 |
|
|
*/ |
84 |
|
|
public void |
85 |
|
|
setSelectedFxSend(FxSend fxSend) { |
86 |
|
|
int i = ((FxSendTableModel)getModel()).getFxSendPosition(fxSend); |
87 |
|
|
if(i != -1) getSelectionModel().setSelectionInterval(i, i); |
88 |
|
|
} |
89 |
|
|
|
90 |
|
|
public void |
91 |
|
|
editSelectedFxSend() { |
92 |
|
|
FxSend fxSend = getSelectedFxSend(); |
93 |
|
|
if(fxSend == null) return; |
94 |
|
|
editCellAt(((FxSendTableModel)getModel()).getFxSendPosition(fxSend), 0); |
95 |
|
|
|
96 |
|
|
Component c = defaultEditor.getComponent(); |
97 |
|
|
c.requestFocus(); |
98 |
|
|
if(c instanceof JTextField) ((JTextField)c).selectAll(); |
99 |
|
|
} |
100 |
|
|
|
101 |
|
|
public TableCellEditor |
102 |
|
|
getCellEditor(int row, int column) { return defaultEditor; } |
103 |
|
|
|
104 |
|
|
private final Handler eventHandler = new Handler(); |
105 |
|
|
|
106 |
|
|
private Handler |
107 |
|
|
getHandler() { return eventHandler; } |
108 |
|
|
|
109 |
|
|
private class Handler implements EffectSendsListener { |
110 |
|
|
/** Invoked when a new effect send is added to a sampler channel. */ |
111 |
|
|
public void |
112 |
|
|
effectSendAdded(EffectSendsEvent e) { |
113 |
|
|
setSelectedFxSend(e.getFxSend()); |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
/** Invoked when an effect send is removed from a sampler channel. */ |
117 |
|
|
public void |
118 |
|
|
effectSendRemoved(EffectSendsEvent e) { } |
119 |
|
|
|
120 |
|
|
/** Invoked when an effect send's setting are changed. */ |
121 |
|
|
public void |
122 |
|
|
effectSendChanged(EffectSendsEvent e) { } |
123 |
|
|
} |
124 |
|
|
} |