de.sciss.mellite.impl.timeline.tool.BasicTimelineTool.scala Maven / Gradle / Ivy
/*
* BasicTimelineTool.scala
* (Mellite)
*
* Copyright (c) 2012-2023 Hanns Holger Rutz. All rights reserved.
*
* This software is published under the GNU Affero General Public License v3+
*
*
* For further information, please contact Hanns Holger Rutz at
* [email protected]
*/
package de.sciss.mellite.impl.timeline.tool
import java.awt.event.MouseEvent
import de.sciss.lucre.synth.Txn
import de.sciss.mellite.BasicTool.{DragAdjust, DragBegin, DragEnd}
import de.sciss.mellite.ObjTimelineView
import de.sciss.mellite.impl.tool.DraggingTool
/** Most common implementation of a timeline tool, based on region selection and
* mouse dragging. It implements `handleSelect` by instantiating a `Drag`
* object. Double-clicks result in the abstract method `dialog` being called.
* Sub-classes may choose to provide a custom dialog for double clicks by
* and thus may return `Some` data if the dialog is positively confirmed.
*/
trait BasicTimelineTool[T <: Txn[T], A] extends CollectionImpl[T, A] with DraggingTool[T, A, Int] {
protected type Initial = ObjTimelineView[T]
final protected def handleSelect(e: MouseEvent, pos: Long, modelY: Int, child: C): Unit =
if (e.getClickCount == 2) {
handleDoubleClick()
} else {
new Drag(e, modelY, pos, child)
}
protected def dialog(): Option[A]
final protected def handleDoubleClick(): Unit =
dialog().foreach { p =>
dispatch(DragBegin)
dispatch(DragAdjust(p))
dispatch(DragEnd)
}
// protected def showDialog(message: AnyRef): Boolean = {
// val op = OptionPane(message = message, messageType = OptionPane.Message.Question,
// optionType = OptionPane.Options.OkCancel)
// val result = Window.showDialog(op -> name)
// result == OptionPane.Result.Ok
// }
}