1 |
iliev |
1286 |
/* |
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 javax.swing.table.AbstractTableModel; |
26 |
|
|
|
27 |
|
|
import org.jsampler.CC; |
28 |
|
|
import org.jsampler.MidiInstrumentMap; |
29 |
|
|
import org.jsampler.MidiInstrumentMapList; |
30 |
|
|
import org.jsampler.SamplerModel; |
31 |
|
|
|
32 |
|
|
import org.jsampler.event.ListEvent; |
33 |
|
|
import org.jsampler.event.ListListener; |
34 |
|
|
import org.jsampler.event.MidiInstrumentMapEvent; |
35 |
|
|
import org.jsampler.event.MidiInstrumentMapListener; |
36 |
|
|
|
37 |
|
|
import static org.jsampler.JSI18n.i18n; |
38 |
|
|
|
39 |
|
|
/** |
40 |
|
|
* A tabular data model for representing MIDI instrument maps. |
41 |
|
|
* @author Grigor Iliev |
42 |
|
|
*/ |
43 |
|
|
public class MidiMapTableModel extends AbstractTableModel { |
44 |
|
|
|
45 |
|
|
/** |
46 |
|
|
* Creates a new instance of <code>MidiMapTableModel</code>. |
47 |
|
|
*/ |
48 |
|
|
public |
49 |
|
|
MidiMapTableModel() { |
50 |
|
|
SamplerModel sm = CC.getSamplerModel(); |
51 |
|
|
|
52 |
|
|
for(int i = 0; i < sm.getMidiInstrumentMapCount(); i++) { |
53 |
|
|
sm.getMidiInstrumentMap(i).addMidiInstrumentMapListener(getHandler()); |
54 |
|
|
} |
55 |
|
|
|
56 |
|
|
sm.addMidiInstrumentMapListListener(getHandler()); |
57 |
|
|
|
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
/** |
61 |
|
|
* Gets the number of columns in the model. |
62 |
|
|
* @return The number of columns in the model. |
63 |
|
|
*/ |
64 |
|
|
public int |
65 |
|
|
getColumnCount() { return 1; } |
66 |
|
|
|
67 |
|
|
/** |
68 |
|
|
* Gets the number of rows in the model. |
69 |
|
|
* @return The number of rows in the model. |
70 |
|
|
*/ |
71 |
|
|
public int |
72 |
|
|
getRowCount() { return CC.getSamplerModel().getMidiInstrumentMapCount(); } |
73 |
|
|
|
74 |
|
|
/** |
75 |
|
|
* Gets the name of the column at <code>columnIndex</code>. |
76 |
|
|
* @return The name of the column at <code>columnIndex</code>. |
77 |
|
|
*/ |
78 |
|
|
public String |
79 |
|
|
getColumnName(int col) { return i18n.getLabel("MidiMapTableModel.title"); } |
80 |
|
|
|
81 |
|
|
/** |
82 |
|
|
* Gets the value for the cell at <code>columnIndex</code> and |
83 |
|
|
* <code>rowIndex</code>. |
84 |
|
|
* @param row The row whose value is to be queried. |
85 |
|
|
* @param col The column whose value is to be queried. |
86 |
|
|
* @return The value for the cell at <code>columnIndex</code> and |
87 |
|
|
* <code>rowIndex</code>. |
88 |
|
|
*/ |
89 |
|
|
public Object |
90 |
|
|
getValueAt(int row, int col) { |
91 |
|
|
return CC.getSamplerModel().getMidiInstrumentMap(row); |
92 |
|
|
} |
93 |
|
|
|
94 |
|
|
/** |
95 |
|
|
* Sets the value in the cell at <code>col</code> |
96 |
|
|
* and <code>row</code> to <code>value</code>. |
97 |
|
|
*/ |
98 |
|
|
public void |
99 |
|
|
setValueAt(Object value, int row, int col) { |
100 |
|
|
|
101 |
|
|
fireTableCellUpdated(row, col); |
102 |
|
|
} |
103 |
|
|
|
104 |
|
|
/** |
105 |
|
|
* Returns <code>true</code> if the cell at |
106 |
|
|
* <code>row</code> and <code>col</code> is editable. |
107 |
|
|
*/ |
108 |
|
|
public boolean |
109 |
|
|
isCellEditable(int row, int col) { return false; } |
110 |
|
|
|
111 |
|
|
|
112 |
|
|
private final Handler eventHandler = new Handler(); |
113 |
|
|
|
114 |
|
|
private Handler |
115 |
|
|
getHandler() { return eventHandler; } |
116 |
|
|
|
117 |
|
|
private class Handler implements ListListener<MidiInstrumentMap>, MidiInstrumentMapListener { |
118 |
|
|
/** Invoked when an orchestra is added to the orchestra list. */ |
119 |
|
|
public void |
120 |
|
|
entryAdded(ListEvent<MidiInstrumentMap> e) { |
121 |
|
|
e.getEntry().addMidiInstrumentMapListener(getHandler()); |
122 |
|
|
fireTableDataChanged(); |
123 |
|
|
} |
124 |
|
|
|
125 |
|
|
/** Invoked when an orchestra is removed from the orchestra list. */ |
126 |
|
|
public void |
127 |
|
|
entryRemoved(ListEvent<MidiInstrumentMap> e) { |
128 |
|
|
e.getEntry().removeMidiInstrumentMapListener(getHandler()); |
129 |
|
|
fireTableDataChanged(); |
130 |
|
|
} |
131 |
|
|
|
132 |
|
|
public void |
133 |
|
|
nameChanged(MidiInstrumentMapEvent e) { |
134 |
|
|
MidiInstrumentMap m = (MidiInstrumentMap)e.getSource(); |
135 |
|
|
int idx = CC.getSamplerModel().getMidiInstrumentMapIndex(m); |
136 |
|
|
fireTableRowsUpdated(idx, idx); |
137 |
|
|
} |
138 |
|
|
|
139 |
|
|
public void |
140 |
|
|
instrumentAdded(MidiInstrumentMapEvent e) { } |
141 |
|
|
|
142 |
|
|
public void |
143 |
|
|
instrumentRemoved(MidiInstrumentMapEvent e) { } |
144 |
|
|
} |
145 |
|
|
} |