All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.sciss.mellite.gui.impl.component.SelectionModelImpl.scala Maven / Gradle / Ivy

/*
 *  SelectionModelImpl.scala
 *  (Mellite)
 *
 *  Copyright (c) 2012-2016 Hanns Holger Rutz. All rights reserved.
 *
 *  This software is published under the GNU General Public License v3+
 *
 *
 *  For further information, please contact Hanns Holger Rutz at
 *  [email protected]
 */

package de.sciss.mellite.gui.impl.component

import de.sciss.lucre.stm.Sys
import de.sciss.mellite.gui.SelectionModel
import de.sciss.model.impl.ModelImpl

final class SelectionModelImpl[S <: Sys[S], Repr]
  extends SelectionModel[S, Repr] with ModelImpl[SelectionModel.Update[S, Repr]] {

  import de.sciss.mellite.gui.SelectionModel.Update

  // no sync because we assume the model is only used on the event thread
  private var set = Set.empty[Repr]

  def contains(view: Repr): Boolean = set.contains(view)

  def iterator: Iterator[Repr] = set.iterator

  def isEmpty   = set.isEmpty
  def nonEmpty  = set.nonEmpty

  def +=(view: Repr): Unit =
    if (!set.contains(view)) {
      set += view
      dispatch(Update(added = Set(view), removed = Set.empty))
    }

  def -=(view: Repr): Unit =
    if (set.contains(view)) {
      set -= view
      dispatch(Update(added = Set.empty, removed = Set(view)))
    }

  def clear(): Unit =
    if (set.nonEmpty) {
      val removed = set
      set = Set.empty
      dispatch(Update(added = Set.empty, removed = removed))
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy