Subversion Repositories svn.mios

Rev

Rev 247 | Rev 666 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 247 Rev 628
Line 19... Line 19...
19
 */
19
 */
20
20
21
package org.midibox.sidlibr.gui;
21
package org.midibox.sidlibr.gui;
22
22
23
import java.awt.Dimension;
23
import java.awt.Dimension;
24
-
 
25
import javax.swing.event.*;
24
import java.awt.Font;
-
 
25
import java.awt.event.ActionEvent;
-
 
26
import java.awt.event.ActionListener;
26
import java.awt.event.*;
27
import java.awt.event.KeyEvent;
-
 
28
import java.awt.event.KeyListener;
27
import javax.swing.table.TableModel;
29
import java.awt.event.MouseEvent;
-
 
30
import java.awt.event.MouseListener;
28
import javax.swing.*;
31
import java.util.EventObject;
29
import java.util.Observable;
32
import java.util.Observable;
30
import java.util.Observer;
33
import java.util.Observer;
31
import java.util.EventObject;
-
 
32
import org.midibox.sidlibr.SIDLibController;
-
 
33
34
34
import javax.swing.JMenu;
35
import javax.swing.JMenu;
35
import javax.swing.JMenuItem;
36
import javax.swing.JMenuItem;
36
import javax.swing.JPanel;
37
import javax.swing.JPanel;
-
 
38
import javax.swing.JPopupMenu;
37
import javax.swing.JScrollPane;
39
import javax.swing.JScrollPane;
38
import javax.swing.JTable;
40
import javax.swing.JTable;
39
import javax.swing.KeyStroke;
41
import javax.swing.KeyStroke;
40
import javax.swing.ListSelectionModel;
42
import javax.swing.ListSelectionModel;
-
 
43
import javax.swing.event.ListSelectionEvent;
-
 
44
import javax.swing.event.ListSelectionListener;
-
 
45
import javax.swing.event.TableModelEvent;
-
 
46
import javax.swing.event.TableModelListener;
-
 
47
import javax.swing.table.TableModel;
-
 
48
41
import org.midibox.sidlibr.Bank;
49
import org.midibox.sidlibr.Bank;
42
import java.awt.Font;
50
import org.midibox.sidlibr.SIDLibController;
43
51
44
public class BankTable extends JPanel implements TableModelListener, ListSelectionListener, Observer, MouseListener, ActionListener, KeyListener {
52
public class BankTable extends JPanel implements TableModelListener,
-
 
53
        ListSelectionListener, Observer, MouseListener, ActionListener,
-
 
54
        KeyListener {
45
    private SIDLibController sidLibController;
55
    private SIDLibController sidLibController;
46
    JTable table;
56
    JTable table;
47
    JPopupMenu popupMenu;
57
    JPopupMenu popupMenu;
48
    int bankNumber;
58
    int bankNumber;
49
    int selectedBeforeDrag = 0;
59
    int selectedBeforeDrag = 0;
Line 53... Line 63...
53
        this.bankNumber = bankNumber;
63
        this.bankNumber = bankNumber;
54
        sidLibController.addObserver(this);
64
        sidLibController.addObserver(this);
55
       
65
56
        createPopupMenu();
66
        createPopupMenu();
57
       
67
58
        table = new JTable(new BankTableModel(sidLibController.getBank(bankNumber)));
68
        table = new JTable(new BankTableModel(sidLibController
-
 
69
                .getBank(bankNumber)));
59
        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
70
        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
60
        table.getModel().addTableModelListener(this);      
71
        table.getModel().addTableModelListener(this);
61
        table.addMouseListener(this);
72
        table.addMouseListener(this);
62
        table.addKeyListener(this);
73
        table.addKeyListener(this);
63
        table.getSelectionModel().addListSelectionListener(this);
74
        table.getSelectionModel().addListSelectionListener(this);
64
       
75
-
 
76
        table.getColumnModel().getColumn(1)
65
        table.getColumnModel().getColumn(1).setCellEditor(new PatchNameEditor());
77
                .setCellEditor(new PatchNameEditor());
66
        table.getColumnModel().getColumn(0).setPreferredWidth(30);
78
        table.getColumnModel().getColumn(0).setPreferredWidth(30);
67
        table.getColumnModel().getColumn(1).setPreferredWidth(170);
79
        table.getColumnModel().getColumn(1).setPreferredWidth(170);
68
        table.getColumnModel().getColumn(2).setPreferredWidth(70);
80
        table.getColumnModel().getColumn(2).setPreferredWidth(70);
69
       
81
70
        table.setPreferredScrollableViewportSize(new Dimension(table.getPreferredSize().width, Math.round(table.getPreferredSize().height/4)));
82
        table.setPreferredScrollableViewportSize(new Dimension(table
-
 
83
                .getPreferredSize().width, Math
-
 
84
                .round(table.getPreferredSize().height / 4)));
71
        // TK: temporary commented out - not available under MacOS, we need a replacement
85
        // TK: temporary commented out - not available under MacOS, we need a
-
 
86
        // replacement
72
        // table.setFillsViewportHeight(true);
87
        // table.setFillsViewportHeight(true);
73
       
88
74
        JScrollPane scrollPane = new JScrollPane(table);
89
        JScrollPane scrollPane = new JScrollPane(table);
-
 
90
        scrollPane.setPreferredSize(new Dimension(
75
        scrollPane.setPreferredSize(new Dimension(table.getPreferredSize().width, Math.round(table.getPreferredSize().height/4)));
91
                table.getPreferredSize().width, Math.round(table
-
 
92
                        .getPreferredSize().height / 4)));
76
       
93
77
        add(scrollPane);
94
        add(scrollPane);
78
    }
95
    }
79
   
96
80
    public void tableChanged(TableModelEvent e) {
97
    public void tableChanged(TableModelEvent e) {
81
        int row = e.getFirstRow();
98
        int row = e.getFirstRow();
82
        int column = e.getColumn();
99
        int column = e.getColumn();
83
        TableModel model = (TableModel)e.getSource();
100
        TableModel model = (TableModel) e.getSource();
84
        Object data = model.getValueAt(row, column);
101
        Object data = model.getValueAt(row, column);
-
 
102
        if ((column == 1)
85
        if ((column == 1) && !(sidLibController.getBank(bankNumber).getPatchAt(row).getPatchName().equals((String)data))) {
103
                && !(sidLibController.getBank(bankNumber).getPatchAt(row)
-
 
104
                        .getPatchName().equals((String) data))) {
86
            sidLibController.getBank(bankNumber).getPatchAt(row).setPatchName((String)data);
105
            sidLibController.getBank(bankNumber).getPatchAt(row).setPatchName(
-
 
106
                    (String) data);
87
        }
107
        }
88
    }
108
    }
89
   
109
90
    public void update(Observable observable, Object object) {
110
    public void update(Observable observable, Object object) {
91
        if (object=="Data changed") {
111
        if (object == "Data changed") {
Line 105... Line 125...
105
        return table.getSelectedRow();
125
        return table.getSelectedRow();
106
    }
126
    }
107
   
127
108
    private void maybeShowPopup(MouseEvent e) {
128
    private void maybeShowPopup(MouseEvent e) {
109
        if (e.isPopupTrigger()) {
129
        if (e.isPopupTrigger()) {
110
            popupMenu.show(e.getComponent(),
130
            popupMenu.show(e.getComponent(), e.getX(), e.getY());
111
                       e.getX(), e.getY());
-
 
112
        }
131
        }
113
    }
132
    }
114
   
133
115
    public void mousePressed(MouseEvent e) {
134
    public void mousePressed(MouseEvent e) {
116
        if (e.getButton() == MouseEvent.BUTTON1) {
135
        if (e.getButton() == MouseEvent.BUTTON1) {
Line 120... Line 139...
120
    }
139
    }
121
   
140
122
    public void mouseReleased(MouseEvent e) {
141
    public void mouseReleased(MouseEvent e) {
123
        if (e.getButton() == MouseEvent.BUTTON1) {
142
        if (e.getButton() == MouseEvent.BUTTON1) {
124
            if (table.getSelectedRow() != selectedBeforeDrag) {
143
            if (table.getSelectedRow() != selectedBeforeDrag) {
125
                sidLibController.editSwap(selectedBeforeDrag, table.getSelectedRow());
144
                sidLibController.editSwap(selectedBeforeDrag, table
-
 
145
                        .getSelectedRow());
126
            }
146
            }
127
        }
147
        }
128
        maybeShowPopup(e);
148
        maybeShowPopup(e);
129
    }
149
    }
130
150
131
    public void mouseEntered(MouseEvent e) {}
151
    public void mouseEntered(MouseEvent e) {
-
 
152
    }
132
153
133
    public void mouseExited(MouseEvent e) {}
154
    public void mouseExited(MouseEvent e) {
-
 
155
    }
134
156
135
    public void mouseClicked(MouseEvent e) {
157
    public void mouseClicked(MouseEvent e) {
136
        if ((e.getButton() == MouseEvent.BUTTON1) && (e.getClickCount()==2)) {
158
        if ((e.getButton() == MouseEvent.BUTTON1) && (e.getClickCount() == 2)) {
137
            sidLibController.editCurrentPatch();
159
            sidLibController.editCurrentPatch();
138
        }
160
        }
Line 142... Line 164...
142
        popupMenu = new JPopupMenu();
164
        popupMenu = new JPopupMenu();
143
        JMenu submenu;
165
        JMenu submenu;
144
        JMenuItem menuItem;
166
        JMenuItem menuItem;
145
       
167
146
        menuItem = new JMenuItem("Edit",KeyEvent.VK_E);
168
        menuItem = new JMenuItem("Edit", KeyEvent.VK_E);
147
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.CTRL_MASK));
169
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E,
-
 
170
                ActionEvent.CTRL_MASK));
148
        menuItem.setActionCommand("Edit");
171
        menuItem.setActionCommand("Edit");
149
        menuItem.addActionListener(this);
172
        menuItem.addActionListener(this);
150
        popupMenu.add(menuItem);
173
        popupMenu.add(menuItem);
151
       
174
152
        menuItem = new JMenuItem("Rename",KeyEvent.VK_R);
175
        menuItem = new JMenuItem("Rename", KeyEvent.VK_R);
153
        menuItem.setFont(menuItem.getFont().deriveFont(Font.PLAIN));
176
        menuItem.setFont(menuItem.getFont().deriveFont(Font.PLAIN));
154
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK));
177
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R,
-
 
178
                ActionEvent.CTRL_MASK));
155
        menuItem.setActionCommand("Rename");
179
        menuItem.setActionCommand("Rename");
156
        menuItem.addActionListener(this);
180
        menuItem.addActionListener(this);
157
        popupMenu.add(menuItem);
181
        popupMenu.add(menuItem);
158
       
182
159
        popupMenu.addSeparator();
183
        popupMenu.addSeparator();
160
       
184
161
        menuItem = new JMenuItem("Cut",KeyEvent.VK_U);
185
        menuItem = new JMenuItem("Cut", KeyEvent.VK_U);
162
        menuItem.setFont(menuItem.getFont().deriveFont(Font.PLAIN));
186
        menuItem.setFont(menuItem.getFont().deriveFont(Font.PLAIN));
163
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK));
187
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,
-
 
188
                ActionEvent.CTRL_MASK));
164
        menuItem.setActionCommand("Cut");
189
        menuItem.setActionCommand("Cut");
165
        menuItem.addActionListener(this);
190
        menuItem.addActionListener(this);
166
        popupMenu.add(menuItem);
191
        popupMenu.add(menuItem);
167
       
192
168
        menuItem = new JMenuItem("Copy",KeyEvent.VK_C);
193
        menuItem = new JMenuItem("Copy", KeyEvent.VK_C);
169
        menuItem.setFont(menuItem.getFont().deriveFont(Font.PLAIN));
194
        menuItem.setFont(menuItem.getFont().deriveFont(Font.PLAIN));
170
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
195
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,
-
 
196
                ActionEvent.CTRL_MASK));
171
        menuItem.setActionCommand("Copy");
197
        menuItem.setActionCommand("Copy");
172
        menuItem.addActionListener(this);
198
        menuItem.addActionListener(this);
173
        popupMenu.add(menuItem);
199
        popupMenu.add(menuItem);
174
       
200
175
        menuItem = new JMenuItem("Paste",KeyEvent.VK_P);
201
        menuItem = new JMenuItem("Paste", KeyEvent.VK_P);
176
        menuItem.setFont(menuItem.getFont().deriveFont(Font.PLAIN));
202
        menuItem.setFont(menuItem.getFont().deriveFont(Font.PLAIN));
177
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK));
203
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,
-
 
204
                ActionEvent.CTRL_MASK));
178
        menuItem.setActionCommand("Paste");
205
        menuItem.setActionCommand("Paste");
179
        menuItem.addActionListener(this);
206
        menuItem.addActionListener(this);
180
        popupMenu.add(menuItem);
207
        popupMenu.add(menuItem);
181
       
208
182
        menuItem = new JMenuItem("Clear",KeyEvent.VK_L);
209
        menuItem = new JMenuItem("Clear", KeyEvent.VK_L);
Line 288... Line 315...
288
        }
315
        }
289
        sidLibController.setCurrentPatchNumber(patchNumber);
316
        sidLibController.setCurrentPatchNumber(patchNumber);
290
    }
317
    }
291
   
318
292
    public void keyPressed(KeyEvent e) {
319
    public void keyPressed(KeyEvent e) {
-
 
320
        if ((e.getKeyCode() == KeyEvent.VK_E)
293
        if ((e.getKeyCode()==KeyEvent.VK_E) && (e.getModifiers()==ActionEvent.CTRL_MASK)) {
321
                && (e.getModifiers() == ActionEvent.CTRL_MASK)) {
294
            sidLibController.editCurrentPatch();
322
            sidLibController.editCurrentPatch();
-
 
323
        } else if ((e.getKeyCode() == KeyEvent.VK_R)
295
        } else if ((e.getKeyCode()==KeyEvent.VK_R) && (e.getModifiers()==ActionEvent.CTRL_MASK)) {
324
                && (e.getModifiers() == ActionEvent.CTRL_MASK)) {
296
            sidLibController.editRename();
325
            sidLibController.editRename();
-
 
326
        } else if ((e.getKeyCode() == KeyEvent.VK_X)
297
        } else if ((e.getKeyCode()==KeyEvent.VK_X) && (e.getModifiers()==ActionEvent.CTRL_MASK)) {
327
                && (e.getModifiers() == ActionEvent.CTRL_MASK)) {
298
            sidLibController.editCut();        
328
            sidLibController.editCut();
-
 
329
        } else if ((e.getKeyCode() == KeyEvent.VK_C)
299
        } else if ((e.getKeyCode()==KeyEvent.VK_C) && (e.getModifiers()==ActionEvent.CTRL_MASK)) {
330
                && (e.getModifiers() == ActionEvent.CTRL_MASK)) {
300
            sidLibController.editCopy();
331
            sidLibController.editCopy();
-
 
332
        } else if ((e.getKeyCode() == KeyEvent.VK_V)
301
        } else if ((e.getKeyCode()==KeyEvent.VK_V) && (e.getModifiers()==ActionEvent.CTRL_MASK)) {
333
                && (e.getModifiers() == ActionEvent.CTRL_MASK)) {
302
            sidLibController.editPaste();
334
            sidLibController.editPaste();
303
        } else if (e.getKeyCode()==KeyEvent.VK_DELETE) {
335
        } else if (e.getKeyCode() == KeyEvent.VK_DELETE) {
304
            sidLibController.editClear();
336
            sidLibController.editClear();
305
        }
337
        }
306
    }
338
    }
-
 
339
307
    public void keyReleased(KeyEvent e) {
340
    public void keyReleased(KeyEvent e) {
308
       
341
309
    }
342
    }
310
    public void keyTyped(KeyEvent e) {
-
 
311
       
343
-
 
344
    public void keyTyped(KeyEvent e) {
312
       
345
313
    }
346
    }
314
   
347
315
}
348
}