- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- Graphics2D g2 = (Graphics2D)g;
- for (int c = 0; c < 1000; c += 20) {
- for (int r = 0; r < 200; r += 20) {
- box = new Rectangle(r, c, 20, 20);
- g2.setColor(Color.gray);
- g2.draw(box);
- }
+ /**
+ * Adds a standard note to this track.
+ */
+ private void addStandardNote() {
+ int row = (popupY - insets.top) / NOTE_HEIGHT;
+ long timestamp = (long)(ticksPerSixteenth * row);
+ addNote(new MooNote(title.getChannel(), 60, 100, timestamp, Moosique.getSequence().getResolution() / 4));
+ }
+
+ /**
+ * Removes the given note element from the view and its note from the current track.
+ * @param elem the note element to remove
+ */
+ public void removeNote(MooNoteElement elem) {
+ elem.getNote().removeFrom(track);
+ remove(elem);
+ Rectangle r = new Rectangle();
+ r = elem.getBounds(r);
+ rects.remove(r);
+ Moosique.setEdited();
+ repaint();
+ }
+
+ /**
+ * Deselects all notes.
+ */
+ public void selectNote(MooNoteElement elem) {
+ selected.add(elem);
+ }
+
+ /**
+ * Deselects all notes.
+ */
+ public void deselectNote(MooNoteElement elem) {
+ selected.remove(selected.indexOf(elem));
+ }
+
+ /**
+ * Deselects all notes.
+ */
+ public void deselectAllNotes() {
+ Iterator it = selected.iterator();
+ while(it.hasNext()) {
+ ((MooNoteElement)it.next()).deselect();
+ }
+ selected.clear();
+ }
+
+ /**
+ * Determines if the given MooNoteElement is the only one in the track view that is selected.
+ * @return if the given element is the only selected one
+ */
+ public boolean isTheOnlySelected(MooNoteElement elem) {
+ Iterator it = selected.iterator();
+ while(it.hasNext()) {
+ if (!it.next().equals(elem)) return false;
+ }
+ return true;
+ }
+
+ /**
+ * Shows a popup-menu with options for the current selection of note elements.
+ * @param c the component over which to display the menu
+ * @param x the x-coordinate in which to display the menu
+ * @param y the y-coordinate in which to display the menu
+ */
+ public void showSelectionPopup(Component c, int x, int y) {
+ selPopup.show(c, x, y);
+ }
+
+ /**
+ * Transposes all selected notes the given number of halftones.
+ */
+ private void transposeSelectedNotes(int halftones) {
+ Iterator it = selected.iterator();
+ while(it.hasNext()) {
+ MooNoteElement elem = (MooNoteElement)it.next();
+ elem.getNote().transpose(halftones);
+ elem.update();
+ }
+ }
+
+ /**
+ * 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);