* @param ticks the number of ticks to move the selection.
*/
public void moveSelectedNotes(int ticks) {
- Iterator it = selection.iterator();
- while(it.hasNext()) {
- MooNoteElement elem = (MooNoteElement)it.next();
- elem.getNote().setTick(elem.getNote().getTick() + ticks);
- layoutElement(elem, true);
+ if (ticks > 0) {
+ // If the selection should be moved downwards, traverses the list in the natural order.
+ Iterator it = selection.iterator();
+ while(it.hasNext()) {
+ MooNoteElement elem = (MooNoteElement)it.next();
+ elem.getNote().setTick(elem.getNote().getTick() + ticks);
+ layoutElement(elem, true);
+ }
+ } else {
+ // If the selection should be moved upwards, traverses the list in the opposite order.
+ ArrayList selectedList = new ArrayList(selection);
+ ListIterator it = selectedList.listIterator(selectedList.size());
+ while(it.hasPrevious()) {
+ MooNoteElement elem = (MooNoteElement)it.previous();
+ elem.getNote().setTick(elem.getNote().getTick() + ticks);
+ layoutElement(elem, true);
+ }
}
}