Subversion Repositories svn.mios

Rev

Rev 666 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
213 tk 1
/*
2
 * @(#)SIDV2librarian.java  beta1   2008/01/21
3
 *
4
 * Copyright (C) 2008    Rutger Vlek (rutgervlek@hotmail.com)
5
 *
6
 * This application is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 2 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This application is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this application; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 */
20
 
21
package org.midibox.sidlibr.gui;
22
 
23
import javax.swing.table.AbstractTableModel;
24
 
628 adamjking 25
import org.midibox.sidlibr.Bank;
26
 
27
public class BankTableModel extends AbstractTableModel {
666 rutgerv 28
    private String[] patchColumnNames = { "#", "Patch Name", "Engine" };
738 adamjking 29
    private String[] ensembleColumnNames = { "#", "Ensemble Name" };
213 tk 30
    private Object[][] data;
666 rutgerv 31
    private boolean isEnsembleBank;
628 adamjking 32
 
33
    public BankTableModel(Bank b) {
666 rutgerv 34
        if (b.isEnsembleBank()) {
35
            isEnsembleBank = true;
36
            data = new Object[b.bankSize][2];
37
            for (int c = 0; c < b.bankSize; c++) {
38
                data[c][0] = intToStr3(c + 1);
39
                data[c][1] = "Ensemble " + intToStr3(c + 1);
40
            }
41
        } else {
42
            isEnsembleBank = false;
43
            data = new Object[b.bankSize][3];
44
            for (int c = 0; c < b.bankSize; c++) {
45
                data[c][0] = intToStr3(c + 1);
46
                data[c][1] = b.getPatchAt(c).getPatchName();
47
                data[c][2] = b.getPatchAt(c).getEngineStr();
48
            }
628 adamjking 49
        }
213 tk 50
    }
51
 
628 adamjking 52
    public int getColumnCount() {
666 rutgerv 53
        return data[0].length;
628 adamjking 54
    }
213 tk 55
 
628 adamjking 56
    public int getRowCount() {
57
        return data.length;
58
    }
213 tk 59
 
628 adamjking 60
    public String getColumnName(int col) {
666 rutgerv 61
        if (isEnsembleBank) {
62
            return ensembleColumnNames[col];
63
        } else {
64
            return patchColumnNames[col];
65
        }
628 adamjking 66
    }
213 tk 67
 
628 adamjking 68
    public Object getValueAt(int row, int col) {
69
        return data[row][col];
70
    }
71
 
72
    public boolean isCellEditable(int row, int col) {
666 rutgerv 73
        if (col == 1 & !isEnsembleBank) {
628 adamjking 74
            return true;
75
        } else {
76
            return false;
77
        }
78
    }
79
 
80
    public void setValueAt(Object value, int row, int col) {
81
        data[row][col] = value;
82
        fireTableCellUpdated(row, col);
83
    }
84
 
85
    private String intToStr3(int i) {
86
        String s = Integer.toString(i);
87
        switch (s.length()) {
88
        case 1:
89
            s = "00" + s;
90
            break;
91
        case 2:
92
            s = "0" + s;
93
            break;
94
        }
95
        return s;
96
    }
213 tk 97
}