<commit_before>/*
 *  GenericObjView.scala
 *  (Mellite)
 *
 *  Copyright (c) 2012-2020 <NAME>. All rights reserved.
 *
 *  This software is published under the GNU Affero General Public License v3+
 *
 *
 *  For further information, please contact <NAME> at
 *  <EMAIL>
 */

package de.sciss.mellite.impl.objview

import de.sciss.icons.raphael
import de.sciss.lucre.{Ident, Obj, Source, SpanLikeObj, Txn => LTxn}
import de.sciss.lucre.synth.Txn
import de.sciss.mellite.GraphemeView.Mode
import de.sciss.mellite.impl.ObjGraphemeViewImpl
import de.sciss.mellite.impl.timeline.ObjTimelineViewBasicImpl
import de.sciss.mellite.{GraphemeRendering, GraphemeView, Insets, ObjGraphemeView, ObjListView, ObjTimelineView, ObjView}
import de.sciss.proc.Grapheme
import javax.swing.Icon

import scala.swing.{Component, Graphics2D, Label}

object GenericObjView extends NoMakeListObjViewFactory with ObjGraphemeView.Factory {
  val icon: Icon        = ObjViewImpl.raphaelIcon(raphael.Shapes.No)
  val prefix            = "Generic"
  def humanName: String = prefix
  def tpe: Obj.Type     = ???  // RRR
  val category          = "None"

  type E[T <: LTxn[T]]  = Obj[T]

  def mkTimelineView[T <: Txn[T]](id: Ident[T], span: SpanLikeObj[T], obj: Obj[T])(implicit tx: T): ObjTimelineView[T] = {
    val res = new TimelineImpl[T](tx.newHandle(obj)).initAttrs(id, span, obj)
    res
  }

  def mkGraphemeView[T <: Txn[T]](entry: Grapheme.Entry[T], value: Obj[T], mode: Mode)
                                 (implicit tx: T): ObjGraphemeView[T] = {
    val res = new GraphemeImpl[T](tx.newHandle(entry), tx.newHandle(entry.value)).initAttrs(entry)
    res
  }

  def mkListView[T <: Txn[T]](obj: Obj[T])(implicit tx: T): ObjListView[T] =
    new ListImpl(tx.newHandle(obj)).initAttrs(obj)

  private trait Impl[T <: LTxn[T]] extends ObjViewImpl.Impl[T] {

    type Repr = Obj[T]

    def factory: ObjView.Factory = GenericObjView

    final def value: Any = ()

    final def configureListCellRenderer(label: Label): Component = label
  }

  private final class ListImpl[T <: Txn[T]](val objH: Source[T, Obj[T]])
    extends Impl[T] with ObjListView[T] with ObjListViewImpl.NonEditable[T] with ObjViewImpl.NonViewable[T]

  private final class TimelineImpl[T <: Txn[T]](val objH : Source[T, Obj[T]])
    extends Impl[T] with ObjTimelineViewBasicImpl[T] with ObjViewImpl.NonViewable[T]
<commit_msg>fixes #118 - although a bit ugly<commit_after>/*
 *  GenericObjView.scala
 *  (Mellite)
 *
 *  Copyright (c) 2012-2020 <NAME>. All rights reserved.
 *
 *  This software is published under the GNU Affero General Public License v3+
 *
 *
 *  For further information, please contact <NAME> at
 *  <EMAIL>
 */

package de.sciss.mellite.impl.objview

import de.sciss.icons.raphael
import de.sciss.lucre.swing.Window
import de.sciss.lucre.synth.Txn
import de.sciss.lucre.{Ident, Obj, Source, SpanLikeObj, Txn => LTxn}
import de.sciss.mellite.GraphemeView.Mode
import de.sciss.mellite.impl.ObjGraphemeViewImpl
import de.sciss.mellite.impl.timeline.ObjTimelineViewBasicImpl
import de.sciss.mellite.{GraphemeRendering, GraphemeView, Insets, ObjGraphemeView, ObjListView, ObjTimelineView, ObjView}
import de.sciss.proc.{Grapheme, Universe}

import javax.swing.Icon
import scala.swing.{Component, Graphics2D, Label}

object GenericObjView extends NoMakeListObjViewFactory with ObjGraphemeView.Factory {
  val icon: Icon        = ObjViewImpl.raphaelIcon(raphael.Shapes.No)
  val prefix            = "Generic"
  def humanName: String = prefix
  def tpe: Obj.Type     = ???  // RRR
  val category          = "None"

  type E[T <: LTxn[T]]  = Obj[T]

  def mkTimelineView[T <: Txn[T]](id: Ident[T], span: SpanLikeObj[T], obj: Obj[T])
                                 (implicit tx: T): ObjTimelineView[T] = {
    val peer  = ObjListView(obj)
    val res   = new TimelineImpl[T](peer).initAttrs(id, span, obj)
    res
  }

  def mkGraphemeView[T <: Txn[T]](entry: Grapheme.Entry[T], value: Obj[T], mode: Mode)
                                 (implicit tx: T): ObjGraphemeView[T] = {
    val res = new GraphemeImpl[T](tx.newHandle(entry), tx.newHandle(entry.value)).initAttrs(entry)
    res
  }

  def mkListView[T <: Txn[T]](obj: Obj[T])(implicit tx: T): ObjListView[T] =
    new ListImpl(tx.newHandle(obj)).initAttrs(obj)

  private trait Impl[T <: LTxn[T]] extends ObjViewImpl.Impl[T] {

    type Repr = Obj[T]

    def factory: ObjView.Factory = GenericObjView
  }

  private final class ListImpl[T <: Txn[T]](val objH: Source[T, Obj[T]])
    extends Impl[T] with ObjListView[T] with ObjListViewImpl.NonEditable[T] with ObjViewImpl.NonViewable[T] {

    def value: Any = ()

    def configureListCellRenderer(label: Label): Component = label
  }

  private final class TimelineImpl[T <: Txn[T]](peer: ObjView[T])
    extends Impl[T] with ObjTimelineViewBasicImpl[T] {

    def objH: Source[T, Obj[T]] = peer.objH

    def isViewable: Boolean = peer.isViewable

    def openView(parent: Option[Window[T]])(implicit tx: T, universe: Universe[T]): Option[Window[T]] =
      peer.openView(parent)
  }

{'fraction_non_alphanumeric': 0.12852912142152023, 'fraction_numerical': 0.004540967423494571, 'mean_word_length': 3.8339694656488548, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3957572', 'n_tokens_mistral': 1942, 'n_tokens_neox': 1885, 'n_words': 406}