de.sciss.mellite.impl.objview.LongObjView.scala Maven / Gradle / Ivy
/*
* LongObjView.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.objview
import de.sciss.desktop
import de.sciss.lucre.expr.graph.Ex
import de.sciss.lucre.synth.Txn
import de.sciss.lucre.{Expr, LongObj, Source, Txn => LTxn}
import de.sciss.mellite.impl.objview.ObjViewImpl.raphaelIcon
import de.sciss.mellite.{ObjListView, ObjView, Shapes}
import de.sciss.proc.{Code, Confluent, Universe}
import de.sciss.swingplus.Spinner
import org.rogach.scallop
import javax.swing.{Icon, SpinnerNumberModel}
import scala.util.Try
object LongObjView extends ObjListView.Factory with ProgramSupport {
type E[T <: LTxn[T]] = LongObj[T]
val icon : Icon = raphaelIcon(Shapes.IntegerNumber) // XXX TODO
val prefix : String = "Long"
def humanName : String = prefix
def category : String = ObjView.categPrimitives
type Elem = Long
def tpe : Expr.Type[Elem, E] = LongObj
val codeType: Code.TypeT[Unit, Ex[Elem]] = Code.Program.Long
override protected def scallopValueConverter: scallop.ValueConverter[Elem] = scallop.longConverter
def mkListView[T <: Txn[T]](obj: LongObj[T])(implicit tx: T): ObjListView[T] = {
val ex = obj
val value = ex.value
val isEditable = Expr.isVar(ex)
val isProgram = Expr.isProgram(ex)
val isViewable = isProgram || tx.isInstanceOf[Confluent.Txn]
new ListImpl[T](tx.newHandle(obj), value, isListCellEditable = isEditable, isProgram = isProgram,
isViewable = isViewable).init(obj)
}
override def initMakeDialog[T <: Txn[T]](window: Option[desktop.Window])
(implicit universe: Universe[T]): MakeResult[T] = {
val model = new SpinnerNumberModel(0L, Long.MinValue, Long.MaxValue, 1L)
val ggValue = new Spinner(model)
val codeValue0 = "0L"
showMakeDialog(ggValue = ggValue, codeValue0 = codeValue0, prefix = prefix,
window = window)(model.getNumber.longValue())
}
private final class ListImpl[T <: Txn[T]](val objH: Source[T, E[T]],
var value: Elem, val isProgram: Boolean,
override val isListCellEditable: Boolean, val isViewable: Boolean)
extends LongObjView[T]
with ListBase[T]
with ObjListViewImpl.SimpleExpr[T, Elem, E] with StringRenderer {
def convertEditValue(v: Any): Option[Long] = v match {
case num: Elem => Some(num)
case s: String => Try(s.toLong).toOption
case _ => None
}
}
}
trait LongObjView[T <: LTxn[T]] extends ObjView[T] {
type Repr = LongObj[T]
}