1 |
/* |
/* |
2 |
* JSampler - a java front-end for LinuxSampler |
* JSampler - a java front-end for LinuxSampler |
3 |
* |
* |
4 |
* Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com> |
* Copyright (C) 2005-2009 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
* |
6 |
* This file is part of JSampler. |
* This file is part of JSampler. |
7 |
* |
* |
26 |
|
|
27 |
import org.jsampler.CC; |
import org.jsampler.CC; |
28 |
import org.jsampler.MidiInstrumentMap; |
import org.jsampler.MidiInstrumentMap; |
|
import org.jsampler.MidiInstrumentMapList; |
|
29 |
import org.jsampler.SamplerModel; |
import org.jsampler.SamplerModel; |
30 |
|
|
31 |
import org.jsampler.event.ListEvent; |
import org.jsampler.event.ListEvent; |
40 |
* @author Grigor Iliev |
* @author Grigor Iliev |
41 |
*/ |
*/ |
42 |
public class MidiMapTableModel extends AbstractTableModel { |
public class MidiMapTableModel extends AbstractTableModel { |
43 |
|
private final MidiMapTable table; |
44 |
/** |
/** |
45 |
* Creates a new instance of <code>MidiMapTableModel</code>. |
* Creates a new instance of <code>MidiMapTableModel</code>. |
46 |
*/ |
*/ |
47 |
public |
public |
48 |
MidiMapTableModel() { |
MidiMapTableModel(MidiMapTable table) { |
49 |
|
this.table = table; |
50 |
SamplerModel sm = CC.getSamplerModel(); |
SamplerModel sm = CC.getSamplerModel(); |
51 |
|
|
52 |
for(int i = 0; i < sm.getMidiInstrumentMapCount(); i++) { |
for(int i = 0; i < sm.getMidiInstrumentMapCount(); i++) { |
61 |
* Gets the number of columns in the model. |
* Gets the number of columns in the model. |
62 |
* @return The number of columns in the model. |
* @return The number of columns in the model. |
63 |
*/ |
*/ |
64 |
|
@Override |
65 |
public int |
public int |
66 |
getColumnCount() { return 1; } |
getColumnCount() { return 1; } |
67 |
|
|
69 |
* Gets the number of rows in the model. |
* Gets the number of rows in the model. |
70 |
* @return The number of rows in the model. |
* @return The number of rows in the model. |
71 |
*/ |
*/ |
72 |
|
@Override |
73 |
public int |
public int |
74 |
getRowCount() { return CC.getSamplerModel().getMidiInstrumentMapCount(); } |
getRowCount() { return CC.getSamplerModel().getMidiInstrumentMapCount(); } |
75 |
|
|
77 |
* Gets the name of the column at <code>columnIndex</code>. |
* Gets the name of the column at <code>columnIndex</code>. |
78 |
* @return The name of the column at <code>columnIndex</code>. |
* @return The name of the column at <code>columnIndex</code>. |
79 |
*/ |
*/ |
80 |
|
@Override |
81 |
public String |
public String |
82 |
getColumnName(int col) { return i18n.getLabel("MidiMapTableModel.title"); } |
getColumnName(int col) { return i18n.getLabel("MidiMapTableModel.title"); } |
83 |
|
|
89 |
* @return The value for the cell at <code>columnIndex</code> and |
* @return The value for the cell at <code>columnIndex</code> and |
90 |
* <code>rowIndex</code>. |
* <code>rowIndex</code>. |
91 |
*/ |
*/ |
92 |
|
@Override |
93 |
public Object |
public Object |
94 |
getValueAt(int row, int col) { |
getValueAt(int row, int col) { |
95 |
return CC.getSamplerModel().getMidiInstrumentMap(row); |
return CC.getSamplerModel().getMidiInstrumentMap(row); |
99 |
* Sets the value in the cell at <code>col</code> |
* Sets the value in the cell at <code>col</code> |
100 |
* and <code>row</code> to <code>value</code>. |
* and <code>row</code> to <code>value</code>. |
101 |
*/ |
*/ |
102 |
|
@Override |
103 |
public void |
public void |
104 |
setValueAt(Object value, int row, int col) { |
setValueAt(Object value, int row, int col) { |
105 |
|
|
110 |
* Returns <code>true</code> if the cell at |
* Returns <code>true</code> if the cell at |
111 |
* <code>row</code> and <code>col</code> is editable. |
* <code>row</code> and <code>col</code> is editable. |
112 |
*/ |
*/ |
113 |
|
@Override |
114 |
public boolean |
public boolean |
115 |
isCellEditable(int row, int col) { return false; } |
isCellEditable(int row, int col) { return false; } |
116 |
|
|
122 |
|
|
123 |
private class Handler implements ListListener<MidiInstrumentMap>, MidiInstrumentMapListener { |
private class Handler implements ListListener<MidiInstrumentMap>, MidiInstrumentMapListener { |
124 |
/** Invoked when an orchestra is added to the orchestra list. */ |
/** Invoked when an orchestra is added to the orchestra list. */ |
125 |
|
@Override |
126 |
public void |
public void |
127 |
entryAdded(ListEvent<MidiInstrumentMap> e) { |
entryAdded(ListEvent<MidiInstrumentMap> e) { |
128 |
e.getEntry().addMidiInstrumentMapListener(getHandler()); |
e.getEntry().addMidiInstrumentMapListener(getHandler()); |
129 |
fireTableDataChanged(); |
fireTableDataChanged(); |
130 |
|
table.setSelectedMidiInstrumentMap(e.getEntry()); |
131 |
} |
} |
132 |
|
|
133 |
/** Invoked when an orchestra is removed from the orchestra list. */ |
/** Invoked when an orchestra is removed from the orchestra list. */ |
134 |
|
@Override |
135 |
public void |
public void |
136 |
entryRemoved(ListEvent<MidiInstrumentMap> e) { |
entryRemoved(ListEvent<MidiInstrumentMap> e) { |
137 |
e.getEntry().removeMidiInstrumentMapListener(getHandler()); |
e.getEntry().removeMidiInstrumentMapListener(getHandler()); |
138 |
fireTableDataChanged(); |
fireTableDataChanged(); |
139 |
} |
} |
140 |
|
|
141 |
|
@Override |
142 |
public void |
public void |
143 |
nameChanged(MidiInstrumentMapEvent e) { |
nameChanged(MidiInstrumentMapEvent e) { |
144 |
MidiInstrumentMap m = (MidiInstrumentMap)e.getSource(); |
MidiInstrumentMap m = (MidiInstrumentMap)e.getSource(); |
146 |
fireTableRowsUpdated(idx, idx); |
fireTableRowsUpdated(idx, idx); |
147 |
} |
} |
148 |
|
|
149 |
|
@Override |
150 |
public void |
public void |
151 |
instrumentAdded(MidiInstrumentMapEvent e) { } |
instrumentAdded(MidiInstrumentMapEvent e) { } |
152 |
|
|
153 |
|
@Override |
154 |
public void |
public void |
155 |
instrumentRemoved(MidiInstrumentMapEvent e) { } |
instrumentRemoved(MidiInstrumentMapEvent e) { } |
156 |
} |
} |