Subversion Repositories svn.mios

Rev

Rev 215 | Go to most recent revision | Details | 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
package org.midibox.sidedit.gui;
21
 
22
import java.awt.Dimension;
23
 
24
import javax.swing.event.*;
25
import java.awt.event.*;
26
 
27
import javax.swing.table.TableModel;
28
import javax.swing.*;
29
import java.util.Observable;
30
import java.util.Observer;
31
import java.util.EventObject;
32
import org.midibox.sidlibr.SIDLibController;
33
 
34
import javax.swing.JMenu;
35
import javax.swing.JMenuItem;
36
import javax.swing.JPanel;
37
import javax.swing.JScrollPane;
38
import javax.swing.JTable;
39
import javax.swing.KeyStroke;
40
import javax.swing.ListSelectionModel;
41
import org.midibox.sidlibr.Bank;
42
import java.awt.Font;
43
 
44
public class WTTable extends JPanel implements TableModelListener, ListSelectionListener, Observer, ActionListener {
45
    JTable table;
46
    JPopupMenu popupMenu;
47
    int bankNumber;
48
    int selectedBeforeDrag = 0;
49
    private int wtNumber;
50
    public WTTable(int wtNumber) {
51
        this.wtNumber = wtNumber;
52
        //sidLibController.addObserver(this);
53
 
54
        table = new JTable(new WTTableModel(wtNumber/*data in*/));
55
        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
56
        table.getModel().addTableModelListener(this);      
57
        table.getSelectionModel().addListSelectionListener(this);
58
 
59
        //table.getColumnModel().getColumn(1).setCellEditor(new PatchNameEditor());
60
        table.getColumnModel().getColumn(0).setPreferredWidth(30);
61
        for (int c=0;c<wtNumber;c++) {
62
            table.getColumnModel().getColumn(c+1).setPreferredWidth(10);
63
        }
64
        table.getColumnModel().getColumn(wtNumber+1).setPreferredWidth(70);
65
 
66
        table.setPreferredScrollableViewportSize(new Dimension(table.getPreferredSize().width, Math.round(table.getPreferredSize().height/4)));
67
        table.setFillsViewportHeight(true);
68
 
69
        JScrollPane scrollPane = new JScrollPane(table);
70
        scrollPane.setPreferredSize(new Dimension(table.getPreferredSize().width, Math.round(table.getPreferredSize().height/4)));
71
 
72
        add(scrollPane);
73
    }
74
 
75
    public void tableChanged(TableModelEvent e) {
76
        /*
77
        int row = e.getFirstRow();
78
        int column = e.getColumn();
79
        TableModel model = (TableModel)e.getSource();
80
        Object data = model.getValueAt(row, column);
81
        if ((column == 1) && !(sidLibController.getBank(bankNumber).getPatchAt(row).getPatchName().equals((String)data))) {
82
            sidLibController.getBank(bankNumber).getPatchAt(row).setPatchName((String)data);
83
        }
84
        */
85
    }
86
 
87
    public void update(Observable observable, Object object) {
88
        /*
89
        if (object=="Data changed") {
90
            Bank b = sidLibController.getBank(bankNumber);
91
            TableModel m = table.getModel();
92
            for (int c = 0; c < b.bankSize; c++) {
93
                m.setValueAt(b.getPatchAt(c).getPatchName(), c, 1);
94
                m.setValueAt(b.getPatchAt(c).getEngineStr(), c, 2);            
95
            }
96
        }
97
        if (object=="Rename") {
98
            table.editCellAt(table.getSelectedRow(), 1, new EventObject(this));
99
        }
100
        */
101
    }
102
 
103
    public int getSelectedRow() {
104
        return table.getSelectedRow();
105
    }
106
 
107
    public void actionPerformed(ActionEvent ae) {
108
        //sidLibController.actionPerformed(ae);
109
    }
110
 
111
    public void valueChanged(ListSelectionEvent event) {
112
        /*
113
        int patchNumber = table.getSelectedRow();
114
        if (patchNumber < 0) {
115
            patchNumber = 0;
116
        }
117
        sidLibController.setCurrentPatchNumber(patchNumber);
118
        */
119
    }  
120
}