Subversion Repositories svn.mios

Rev

Rev 247 | 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;
26
import java.awt.event.*;
25
import java.awt.event.ActionEvent;
27
import javax.swing.table.TableModel;
26
import java.awt.event.ActionListener;
28
import javax.swing.*;
27
import java.awt.event.KeyEvent;
29
import java.util.Observable;
28
import java.awt.event.KeyListener;
30
import java.util.Observer;
29
import java.awt.event.MouseEvent;
31
import java.util.EventObject;
30
import java.awt.event.MouseListener;
32
import org.midibox.sidlibr.SIDLibController;
-
 
33
31
34
import javax.swing.JMenu;
32
import javax.swing.JMenu;
35
import javax.swing.JMenuItem;
33
import javax.swing.JMenuItem;
36
import javax.swing.JPanel;
34
import javax.swing.JPanel;
-
 
35
import javax.swing.JPopupMenu;
37
import javax.swing.JScrollPane;
36
import javax.swing.JScrollPane;
38
import javax.swing.JTable;
37
import javax.swing.JTable;
39
import javax.swing.KeyStroke;
38
import javax.swing.KeyStroke;
40
import javax.swing.ListSelectionModel;
39
import javax.swing.ListSelectionModel;
41
import org.midibox.sidlibr.EnsBank;
40
import javax.swing.event.ListSelectionEvent;
42
import java.awt.Font;
41
import javax.swing.event.ListSelectionListener;
-
 
42
-
 
43
import org.midibox.sidlibr.SIDLibController;
43
44
44
public class EnsBankTable extends JPanel implements ListSelectionListener, MouseListener, ActionListener, KeyListener {
45
public class EnsBankTable extends JPanel implements ListSelectionListener,
-
 
46
        MouseListener, ActionListener, KeyListener {
45
    private SIDLibController sidLibController;
47
    private SIDLibController sidLibController;
46
    JTable table;
48
    JTable table;
47
    JPopupMenu popupMenu;
49
    JPopupMenu popupMenu;
48
    int selectedBeforeDrag = 0;
50
    int selectedBeforeDrag = 0;
49
   
51
50
    public EnsBankTable(SIDLibController sidLibController) {
52
    public EnsBankTable(SIDLibController sidLibController) {
51
        this.sidLibController = sidLibController;
53
        this.sidLibController = sidLibController;
52
       
54
53
        createPopupMenu();
55
        createPopupMenu();
54
       
56
-
 
57
        // table = new JTable(new
55
        //table = new JTable(new EnsBankTableModel(sidLibController.getEnsBank()));
58
        // EnsBankTableModel(sidLibController.getEnsBank()));
56
        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
59
        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
57
        table.addMouseListener(this);
60
        table.addMouseListener(this);
58
        table.addKeyListener(this);
61
        table.addKeyListener(this);
59
        table.getSelectionModel().addListSelectionListener(this);
62
        table.getSelectionModel().addListSelectionListener(this);
60
       
63
-
 
64
        table.getColumnModel().getColumn(1)
61
        table.getColumnModel().getColumn(1).setCellEditor(new PatchNameEditor());
65
                .setCellEditor(new PatchNameEditor());
62
        table.getColumnModel().getColumn(0).setPreferredWidth(30);
66
        table.getColumnModel().getColumn(0).setPreferredWidth(30);
63
        table.getColumnModel().getColumn(1).setPreferredWidth(170);
67
        table.getColumnModel().getColumn(1).setPreferredWidth(170);
64
        table.getColumnModel().getColumn(2).setPreferredWidth(70);
68
        table.getColumnModel().getColumn(2).setPreferredWidth(70);
65
       
69
66
        table.setPreferredScrollableViewportSize(new Dimension(table.getPreferredSize().width, Math.round(table.getPreferredSize().height/4)));
70
        table.setPreferredScrollableViewportSize(new Dimension(table
-
 
71
                .getPreferredSize().width, Math
-
 
72
                .round(table.getPreferredSize().height / 4)));
67
        // TK: temporary commented out - not available under MacOS, we need a replacement
73
        // TK: temporary commented out - not available under MacOS, we need a
-
 
74
        // replacement
68
        // table.setFillsViewportHeight(true);
75
        // table.setFillsViewportHeight(true);
69
       
76
70
        JScrollPane scrollPane = new JScrollPane(table);
77
        JScrollPane scrollPane = new JScrollPane(table);
-
 
78
        scrollPane.setPreferredSize(new Dimension(
71
        scrollPane.setPreferredSize(new Dimension(table.getPreferredSize().width, Math.round(table.getPreferredSize().height/4)));
79
                table.getPreferredSize().width, Math.round(table
-
 
80
                        .getPreferredSize().height / 4)));
72
       
81
73
        add(scrollPane);
82
        add(scrollPane);
74
    }
83
    }
75
   
84
76
    public int getSelectedRow() {
85
    public int getSelectedRow() {
77
        return table.getSelectedRow();
86
        return table.getSelectedRow();
78
    }
87
    }
79
   
88
80
    private void maybeShowPopup(MouseEvent e) {
89
    private void maybeShowPopup(MouseEvent e) {
81
        if (e.isPopupTrigger()) {
90
        if (e.isPopupTrigger()) {
82
            popupMenu.show(e.getComponent(),
91
            popupMenu.show(e.getComponent(), e.getX(), e.getY());
83
                       e.getX(), e.getY());
-
 
84
        }
92
        }
85
    }
93
    }
86
   
94
87
    public void mousePressed(MouseEvent e) {
95
    public void mousePressed(MouseEvent e) {
88
        if (e.getButton() == MouseEvent.BUTTON1) {
96
        if (e.getButton() == MouseEvent.BUTTON1) {
Line 92... Line 100...
92
    }
100
    }
93
   
101
94
    public void mouseReleased(MouseEvent e) {
102
    public void mouseReleased(MouseEvent e) {
95
        if (e.getButton() == MouseEvent.BUTTON1) {
103
        if (e.getButton() == MouseEvent.BUTTON1) {
96
            if (table.getSelectedRow() != selectedBeforeDrag) {
104
            if (table.getSelectedRow() != selectedBeforeDrag) {
97
                sidLibController.editSwap(selectedBeforeDrag, table.getSelectedRow());
105
                sidLibController.editSwap(selectedBeforeDrag, table
-
 
106
                        .getSelectedRow());
98
            }
107
            }
99
        }
108
        }
100
        maybeShowPopup(e);
109
        maybeShowPopup(e);
101
    }
110
    }
102
111
103
    public void mouseEntered(MouseEvent e) {}
112
    public void mouseEntered(MouseEvent e) {
-
 
113
    }
104
114
105
    public void mouseExited(MouseEvent e) {}
115
    public void mouseExited(MouseEvent e) {
-
 
116
    }
106
117
107
    public void mouseClicked(MouseEvent e) {
118
    public void mouseClicked(MouseEvent e) {
108
        if ((e.getButton() == MouseEvent.BUTTON1) && (e.getClickCount()==2)) {
119
        if ((e.getButton() == MouseEvent.BUTTON1) && (e.getClickCount() == 2)) {
109
            sidLibController.editCurrentPatch();
120
            sidLibController.editCurrentPatch();
110
        }
121
        }
Line 114... Line 125...
114
        popupMenu = new JPopupMenu();
125
        popupMenu = new JPopupMenu();
115
        JMenu submenu;
126
        JMenu submenu;
116
        JMenuItem menuItem;
127
        JMenuItem menuItem;
117
       
128
118
        menuItem = new JMenuItem("Edit",KeyEvent.VK_E);
129
        menuItem = new JMenuItem("Edit", KeyEvent.VK_E);
119
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.CTRL_MASK));
130
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E,
-
 
131
                ActionEvent.CTRL_MASK));
120
        menuItem.setActionCommand("Edit");
132
        menuItem.setActionCommand("Edit");
121
        menuItem.addActionListener(this);
133
        menuItem.addActionListener(this);
122
        popupMenu.add(menuItem);
134
        popupMenu.add(menuItem);
123
       
135
124
        menuItem = new JMenuItem("Rename",KeyEvent.VK_R);
136
        menuItem = new JMenuItem("Rename", KeyEvent.VK_R);
125
        menuItem.setFont(menuItem.getFont().deriveFont(Font.PLAIN));
137
        menuItem.setFont(menuItem.getFont().deriveFont(Font.PLAIN));
126
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK));
138
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R,
-
 
139
                ActionEvent.CTRL_MASK));
127
        menuItem.setActionCommand("Rename");
140
        menuItem.setActionCommand("Rename");
128
        menuItem.setEnabled(false);
141
        menuItem.setEnabled(false);
129
        menuItem.addActionListener(this);
142
        menuItem.addActionListener(this);
130
        popupMenu.add(menuItem);
143
        popupMenu.add(menuItem);
131
       
144
132
        popupMenu.addSeparator();
145
        popupMenu.addSeparator();
133
       
146
134
        menuItem = new JMenuItem("Cut",KeyEvent.VK_U);
147
        menuItem = new JMenuItem("Cut", KeyEvent.VK_U);
135
        menuItem.setFont(menuItem.getFont().deriveFont(Font.PLAIN));
148
        menuItem.setFont(menuItem.getFont().deriveFont(Font.PLAIN));
136
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK));
149
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,
-
 
150
                ActionEvent.CTRL_MASK));
137
        menuItem.setActionCommand("Cut");
151
        menuItem.setActionCommand("Cut");
138
        menuItem.addActionListener(this);
152
        menuItem.addActionListener(this);
139
        popupMenu.add(menuItem);
153
        popupMenu.add(menuItem);
140
       
154
141
        menuItem = new JMenuItem("Copy",KeyEvent.VK_C);
155
        menuItem = new JMenuItem("Copy", KeyEvent.VK_C);
142
        menuItem.setFont(menuItem.getFont().deriveFont(Font.PLAIN));
156
        menuItem.setFont(menuItem.getFont().deriveFont(Font.PLAIN));
143
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
157
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,
-
 
158
                ActionEvent.CTRL_MASK));
144
        menuItem.setActionCommand("Copy");
159
        menuItem.setActionCommand("Copy");
145
        menuItem.addActionListener(this);
160
        menuItem.addActionListener(this);
146
        popupMenu.add(menuItem);
161
        popupMenu.add(menuItem);
147
       
162
148
        menuItem = new JMenuItem("Paste",KeyEvent.VK_P);
163
        menuItem = new JMenuItem("Paste", KeyEvent.VK_P);
149
        menuItem.setFont(menuItem.getFont().deriveFont(Font.PLAIN));
164
        menuItem.setFont(menuItem.getFont().deriveFont(Font.PLAIN));
150
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK));
165
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,
-
 
166
                ActionEvent.CTRL_MASK));
151
        menuItem.setActionCommand("Paste");
167
        menuItem.setActionCommand("Paste");
152
        menuItem.addActionListener(this);
168
        menuItem.addActionListener(this);
153
        popupMenu.add(menuItem);
169
        popupMenu.add(menuItem);
154
       
170
155
        menuItem = new JMenuItem("Clear",KeyEvent.VK_L);
171
        menuItem = new JMenuItem("Clear", KeyEvent.VK_L);
Line 261... Line 277...
261
        }
277
        }
262
        sidLibController.setCurrentPatchNumber(patchNumber);
278
        sidLibController.setCurrentPatchNumber(patchNumber);
263
    }
279
    }
264
   
280
265
    public void keyPressed(KeyEvent e) {
281
    public void keyPressed(KeyEvent e) {
-
 
282
        if ((e.getKeyCode() == KeyEvent.VK_E)
266
        if ((e.getKeyCode()==KeyEvent.VK_E) && (e.getModifiers()==ActionEvent.CTRL_MASK)) {
283
                && (e.getModifiers() == ActionEvent.CTRL_MASK)) {
267
            sidLibController.editCurrentPatch();
284
            sidLibController.editCurrentPatch();
-
 
285
        } else if ((e.getKeyCode() == KeyEvent.VK_R)
268
        } else if ((e.getKeyCode()==KeyEvent.VK_R) && (e.getModifiers()==ActionEvent.CTRL_MASK)) {
286
                && (e.getModifiers() == ActionEvent.CTRL_MASK)) {
269
            sidLibController.editRename();
287
            sidLibController.editRename();
-
 
288
        } else if ((e.getKeyCode() == KeyEvent.VK_X)
270
        } else if ((e.getKeyCode()==KeyEvent.VK_X) && (e.getModifiers()==ActionEvent.CTRL_MASK)) {
289
                && (e.getModifiers() == ActionEvent.CTRL_MASK)) {
271
            sidLibController.editCut();        
290
            sidLibController.editCut();
-
 
291
        } else if ((e.getKeyCode() == KeyEvent.VK_C)
272
        } else if ((e.getKeyCode()==KeyEvent.VK_C) && (e.getModifiers()==ActionEvent.CTRL_MASK)) {
292
                && (e.getModifiers() == ActionEvent.CTRL_MASK)) {
273
            sidLibController.editCopy();
293
            sidLibController.editCopy();
-
 
294
        } else if ((e.getKeyCode() == KeyEvent.VK_V)
274
        } else if ((e.getKeyCode()==KeyEvent.VK_V) && (e.getModifiers()==ActionEvent.CTRL_MASK)) {
295
                && (e.getModifiers() == ActionEvent.CTRL_MASK)) {
275
            sidLibController.editPaste();
296
            sidLibController.editPaste();
276
        } else if (e.getKeyCode()==KeyEvent.VK_DELETE) {
297
        } else if (e.getKeyCode() == KeyEvent.VK_DELETE) {
277
            sidLibController.editClear();
298
            sidLibController.editClear();
278
        }
299
        }
279
    }
300
    }
-
 
301
280
    public void keyReleased(KeyEvent e) {
302
    public void keyReleased(KeyEvent e) {
281
       
303
282
    }
304
    }
283
    public void keyTyped(KeyEvent e) {
-
 
284
       
305
-
 
306
    public void keyTyped(KeyEvent e) {
285
       
307
286
    }
308
    }
287
   
309
288
}
310
}