-
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- Graphics2D g2 = (Graphics2D)g;
- box = new Rectangle(0,0,20,20);
- g2.draw(box);
- box2 = new Rectangle(20,0,20,20);
- g2.draw(box2);
+ }
+
+ /**
+ * Draws the grid that is on the background.
+ * @param g The Graphics object used to draw the grid.
+ */
+ public void paintComponent(Graphics g) {
+ super.paintComponent(g);
+ Graphics2D g2 = (Graphics2D)g;
+ for (int c = 0; c < viewLength || c < getHeight(); c += NOTE_HEIGHT) {
+ for (int r = 0; r < (10 * NOTE_WIDTH); r += NOTE_WIDTH) {
+ box = new Rectangle(r, c, NOTE_WIDTH, NOTE_HEIGHT);
+ g2.setColor(Color.gray);
+ g2.draw(box);
+ }
+ }
+ }
+
+ /**
+ * The adapter used to listen on mouse actions
+ */
+ class MAdapter extends MouseAdapter {
+
+ /**
+ * Deselects all note on click, adds a standard note on double click.
+ */
+ public void mouseClicked(MouseEvent e) {
+ deselectAll();
+ if (e.getClickCount() == 2) {
+ popupY = e.getY();
+ addStandardNote();
+ }
+ }
+
+ public void mousePressed(MouseEvent e) {
+ maybeShowPopup(e);
+ }
+
+ public void mouseReleased(MouseEvent e) {
+ maybeShowPopup(e);
+ }
+
+ /**
+ * Selects the notes within the area that was selected.
+ */
+ public void mouseDragged(MouseEvent e) {
+
+ }
+
+ /**
+ * Shows the menu if an OS-specific popup-trigger was activated.
+ */
+ private void maybeShowPopup(MouseEvent e) {
+ if (e.isPopupTrigger()) {
+ popupY = e.getY();
+ popup.show(e.getComponent(), e.getX(), e.getY());
+ }
+ }
+
+ /**
+ * Grabs the focus when the mouse has entered.
+ */
+ public void mouseEntered(MouseEvent e) {
+ // Moosique.setActiveChannel(track.getChannel());
+ grabFocus();
+ }
+ }
+
+ /**
+ * Listens on actions on the popupmenu and executes the appropriate action.
+ */
+ class PopupListener implements ActionListener {
+ public void actionPerformed(ActionEvent e) {
+ Object source = e.getSource();
+ if (source == popupAdd) {
+ addStandardNote();
+ }
+ // new MooNote(int channel, int pitch, int velocity, long timestamp, int duration)