+
+ private JPopupMenu popup, selPopup;
+ private JMenu selPopupTranspUp, selPopupTranspDown;
+ private JMenuItem popupAdd, popupPaste;
+ private JMenuItem selPopupCopy, selPopupCut, selPopupRemove, selPopupTranspUpOct, selPopupTranspDownOct;
+
+ private ArrayList coords, selection, copyBuffer;
+ private Insets insets;
+ private int ticksPerSixteenth, popupY = 0;
+ private boolean leftMouseButtonPressed = false;
+ protected static int viewLength = 0;
+ protected static int extraHeight = 0;
+ public static final int NOTE_HEIGHT = 10, NOTE_WIDTH = 40, VIEW_WIDTH = 200;
+
+ /**
+ * Creates the trackview.
+ * @param track The track it represents graphically and operates on.
+ * @param title The object that is used to manipulate instrument, channel, solo, mute.
+ */
+ public MooTrackView (Track track, MooTrackTitle title) {
+ super(true);
+ this.track = track;
+ this.title = title;
+
+ // Creates instance variables
+ insets = getInsets();
+ coords = new ArrayList(track.size() / 2);
+ selection = new ArrayList();
+ copyBuffer = new ArrayList();
+
+ // Creates temporary variables
+ MidiEvent note;
+ MooNoteElement elem;
+ extraHeight = Toolkit.getDefaultToolkit().getScreenSize().height - 150;
+
+ // Configures panel
+ setBackground(Color.white);
+ setBorder(BorderFactory.createLineBorder(Color.black));
+ setLayout(null);
+ setPreferredSize(new Dimension(VIEW_WIDTH, 140 * NOTE_HEIGHT));
+
+ // Places note elements
+ for (int i = 0; i < track.size(); i++) {
+ note = track.get(i);
+ if (note instanceof MooNote) {
+ // Adds the note element to the note area and moves it to the appropriate place.
+ MooNote mn = (MooNote)note;
+ elem = new MooNoteElement(this, mn);
+ add(elem);
+ layoutElement(elem, false);
+ }
+ setPreferredSize(new Dimension(VIEW_WIDTH, viewLength + extraHeight));
+
+ }
+
+ // Creates panel pop-up menu.
+ popup = new JPopupMenu();
+ PopupListener pList = new PopupListener();
+ popupAdd = new JMenuItem("Add note...");
+ popupAdd.addActionListener(pList);
+ popup.add(popupAdd);
+ popupPaste = new JMenuItem("Paste");
+ popupPaste.addActionListener(pList);
+ popup.add(popupPaste);
+
+ // Creates selection pop-up menu.
+ selPopup = new JPopupMenu();
+ selPopupCopy = new JMenuItem("Copy selection");
+ selPopupCopy.addActionListener(pList);
+ selPopup.add(selPopupCopy);
+ selPopupCut = new JMenuItem("Cut selection");
+ selPopupCut.addActionListener(pList);
+ selPopup.add(selPopupCut);
+ selPopupRemove = new JMenuItem("Remove selection");
+ selPopupRemove.addActionListener(pList);
+ selPopup.add(selPopupRemove);
+ selPopupTranspUp = new JMenu("Transpose selection up");
+ selPopup.add(selPopupTranspUp);
+ selPopupTranspUpOct = new JMenuItem("One octave");
+ selPopupTranspUpOct.addActionListener(pList);
+ selPopupTranspUp.add(selPopupTranspUpOct);
+ selPopupTranspDown = new JMenu("Transpose selection down");
+ selPopup.add(selPopupTranspDown);
+ selPopupTranspDownOct = new JMenuItem("One octave");
+ selPopupTranspDownOct.addActionListener(pList);
+ selPopupTranspDown.add(selPopupTranspDownOct);
+
+ // Adds listeners for popup menu and keyboard synthesizer.
+ addMouseListener(new MAdapter());
+ addKeyListener(new MooKeyboard());