private Rectangle box;
private JPopupMenu popup;
- private JMenuItem menuItem;
+ private JMenuItem popupAdd;
private ArrayList rects;
protected static int viewLength = 0;
protected static int extraHeight = 0;
// Creates pop-up menu.
popup = new JPopupMenu();
- menuItem = new JMenuItem("Add note...");
- // menuItem.addActionListener();
- popup.add(menuItem);
+ PopupListener pList = new PopupListener();
+ popupAdd = new JMenuItem("Add note...");
+ popupAdd.addActionListener(pList);
+ popup.add(popupAdd);
// Adds listeners for popup menu and keyboard synthesizer.
addMouseListener(new MAdapter());
addKeyListener(new MooKeyboard());
}
- public void layoutElement(MooNoteElement elem, boolean old){
+ public void layoutElementMooNoteElement elem, boolean old){
// If the element is currently in the view, removes its coordinates from the list.
Rectangle r = new Rectangle();
if (old){
return false;
}
- public void remove(MooNoteElement elem) {
- remove((Component)elem);
+ public void addNote(MooNote mn) {
+ mn.addTo(track);
+ MooNoteElement elem = new MooNoteElement(this, mn);
+ add(elem);
+ layoutElement(elem, false);
+ setPreferredSize(new Dimension(VIEW_WIDTH, viewLength + extraHeight));
+ }
+
+ public void removeNote(MooNoteElement elem, MooNote mn) {
+ mn.removeFrom(track);
+ remove(elem);
elem.getNote().removeFrom(track);
validate();
repaint();
grabFocus();
}
}
-}
+
+ class PopupListener implements ActionListener {
+ public void actionPerformed(ActionEvent e) {
+ Object source = e.getSource();
+ if (source == popupAdd) {
+ addNote(new MooNote());
+ // int channel, int pitch, int velocity, long timestamp, int duration
+ }
+ }
+}
\ No newline at end of file