private void dragTimelinePosition( MouseEvent e )
{
int x = e.getX();
Span span, span2;
long position;
UndoableEdit edit;
// translate into a valid time offset
span = doc.timeline.getVisibleSpan();
position = span.getStart() + (long) ((double) x / (double) getWidth() *
span.getLength());
position = Math.max( 0, Math.min( doc.timeline.getLength(), position ));
if( shiftDrag ) {
span2 = doc.timeline.getSelectionSpan();
if( altDrag || span2.isEmpty() ) {
selectionStart = doc.timeline.getPosition();
altDrag = false;
} else if( selectionStart == -1 ) {
selectionStart = Math.abs( span2.getStart() - position ) >
Math.abs( span2.getStop() - position ) ?
span2.getStart() : span2.getStop();
}
span = new Span( Math.min( position, selectionStart ),
Math.max( position, selectionStart ));
edit = TimelineVisualEdit.select( this, doc, span ).perform();
} else {
if( altDrag ) {
edit = new CompoundEdit();
edit.addEdit( TimelineVisualEdit.select( this, doc, new Span() ).perform() );
edit.addEdit( TimelineVisualEdit.position( this, doc, position ).perform() );
((CompoundEdit) edit).end();
altDrag = false;
} else {
edit = TimelineVisualEdit.position( this, doc, position ).perform();
}