1 |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
4 |
* Copyright (C) 2005-2006 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.Frame; |
27 |
|
28 |
import javax.swing.DefaultCellEditor; |
29 |
import javax.swing.JComboBox; |
30 |
import javax.swing.JScrollPane; |
31 |
import javax.swing.JTable; |
32 |
|
33 |
import javax.swing.table.AbstractTableModel; |
34 |
import javax.swing.table.TableColumn; |
35 |
import javax.swing.table.JTableHeader; |
36 |
|
37 |
import net.sf.juife.InformationDialog; |
38 |
import net.sf.juife.JuifeUtils; |
39 |
|
40 |
import org.jsampler.AudioDeviceModel; |
41 |
import org.jsampler.CC; |
42 |
import org.jsampler.task.Channel.SetAudioOutputChannel; |
43 |
|
44 |
import org.linuxsampler.lscp.SamplerChannel; |
45 |
|
46 |
import static org.jsampler.view.classic.ClassicI18n.i18n; |
47 |
|
48 |
|
49 |
/** |
50 |
* |
51 |
* @author Grigor Iliev |
52 |
*/ |
53 |
public class ChannelOutputRoutingDlg extends InformationDialog { |
54 |
private final ChannelRoutingTable channelRoutingTable; |
55 |
private SamplerChannel channel; |
56 |
|
57 |
|
58 |
/** Creates a new instance of ChannelOutputRoutingDlg */ |
59 |
public |
60 |
ChannelOutputRoutingDlg(Frame owner, SamplerChannel channel) { |
61 |
super(owner, i18n.getLabel("ChannelOutputRoutingDlg.title")); |
62 |
this.channel = channel; |
63 |
|
64 |
channelRoutingTable = new ChannelRoutingTable(); |
65 |
JScrollPane sp = new JScrollPane(channelRoutingTable); |
66 |
|
67 |
sp.setPreferredSize ( |
68 |
JuifeUtils.getUnionSize(sp.getMinimumSize(), new Dimension(200, 150)) |
69 |
); |
70 |
|
71 |
setMainPane(sp); |
72 |
|
73 |
|
74 |
} |
75 |
|
76 |
class ChannelRoutingTable extends JTable { |
77 |
private String[] columnToolTips = { |
78 |
i18n.getLabel("ChannelOutputRoutingDlg.ttAudioOut", channel.getChannelId()), |
79 |
i18n.getLabel("ChannelOutputRoutingDlg.ttAudioIn"), |
80 |
}; |
81 |
|
82 |
ChannelRoutingTable() { |
83 |
super(new ChannelRoutingTableModel()); |
84 |
|
85 |
JComboBox cb = new JComboBox(); |
86 |
int devId = channel.getAudioOutputDevice(); |
87 |
AudioDeviceModel adm = CC.getSamplerModel().getAudioDeviceById(devId); |
88 |
|
89 |
if(adm == null) { |
90 |
setEnabled(false); |
91 |
} else { |
92 |
int chns = adm.getDeviceInfo().getAudioChannelCount(); |
93 |
for(Integer i = 0; i < chns; i++) cb.addItem(i); |
94 |
} |
95 |
|
96 |
TableColumn column = getColumnModel().getColumn(1); |
97 |
column.setCellEditor(new DefaultCellEditor(cb)); |
98 |
} |
99 |
|
100 |
protected JTableHeader |
101 |
createDefaultTableHeader() { |
102 |
return new JTableHeader(columnModel) { |
103 |
public String getToolTipText(java.awt.event.MouseEvent e) { |
104 |
java.awt.Point p = e.getPoint(); |
105 |
int i = columnModel.getColumnIndexAtX(p.x); |
106 |
i = columnModel.getColumn(i).getModelIndex(); |
107 |
return columnToolTips[i]; |
108 |
} |
109 |
}; |
110 |
} |
111 |
} |
112 |
|
113 |
class ChannelRoutingTableModel extends AbstractTableModel { |
114 |
private String[] columnNames = { |
115 |
i18n.getLabel("ChannelOutputRoutingDlg.audioOut"), |
116 |
i18n.getLabel("ChannelOutputRoutingDlg.audioIn") |
117 |
}; |
118 |
|
119 |
ChannelRoutingTableModel() { |
120 |
|
121 |
} |
122 |
|
123 |
public int |
124 |
getColumnCount() { return columnNames.length; } |
125 |
|
126 |
public String |
127 |
getColumnName(int column) { return columnNames[column]; } |
128 |
|
129 |
public int |
130 |
getRowCount() { return channel.getAudioOutputChannels(); } |
131 |
|
132 |
public Object |
133 |
getValueAt(int row, int column) { |
134 |
switch(column) { |
135 |
case 0: |
136 |
return row; |
137 |
case 1: |
138 |
return channel.getAudioOutputRouting()[row]; |
139 |
default: return null; |
140 |
} |
141 |
|
142 |
} |
143 |
|
144 |
public boolean |
145 |
isCellEditable(int row, int column) { |
146 |
switch(column) { |
147 |
case 0: |
148 |
return false; |
149 |
case 1: |
150 |
return true; |
151 |
default: return false; |
152 |
} |
153 |
} |
154 |
|
155 |
public void |
156 |
setValueAt(Object value, int row, int column) { |
157 |
if(column == 0) return; |
158 |
int c = channel.getChannelId(); |
159 |
int o = (Integer)getValueAt(row, 0); |
160 |
int i = (Integer)value; |
161 |
CC.getTaskQueue().add(new SetAudioOutputChannel(c, o, i)); |
162 |
channel.getAudioOutputRouting()[row] = i; |
163 |
|
164 |
fireTableCellUpdated(row, column); |
165 |
} |
166 |
} |
167 |
} |