PageRenderTime 46ms CodeModel.GetById 20ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 1ms

/razpub/src/razie/assets/AssetImpl.scala

http://razpub.googlecode.com/
Scala | 118 lines | 67 code | 23 blank | 28 comment | 9 complexity | 37cac2d70b38699d8fad397dc6c65638 MD5 | raw file
  1/**
  2 * Razvan's public code. Copyright 2008 based on Apache license (share alike) see LICENSE.txt for
  3 * details. No warranty implied nor any liability assumed for this code.
  4 */
  5package razie.assets
  6
  7import razie.base.ActionItem;
  8import com.razie.pub.base._;
  9import razie.base.ScriptContext;
 10import com.razie.pub.comms.Agents;
 11import razie.draw._
 12import razie.draw.widgets.NavButton;
 13import razie.base._
 14
 15/**
 16 * not sure why i need this class on top of the SdkAsset...
 17 * 
 18 * @author razvanc
 19 */
 20class AssetImpl (b : AssetBrief) extends AssetBaseImpl(b) with DrawAsset {
 21   var nkey : AssetKey = super.key
 22
 23   override def key = nkey
 24   def key_= (k:AssetKey) = setKey (k)
 25
 26   def this (k : AssetKey) = {
 27      this (new FileAssetBriefImpl())
 28      setKey (k)
 29   }
 30   
 31   def this () = {
 32      this (new FileAssetBriefImpl())
 33   }
 34
 35   /** be sure to set the either a key or a brief before using it, eh? */
 36
 37   override def setKey(k:AssetKey ) {
 38      this.nkey = k;
 39      super.setKey(k);
 40      if (k != null) brief match {
 41         case b:FileAssetBriefImpl => {
 42              brief.asInstanceOf[FileAssetBriefImpl].setFileName(k.id);
 43              brief.asInstanceOf[FileAssetBriefImpl].setLocalDir(k.loc.localPath);
 44         }
 45      }
 46   }
 47
 48   override def getKey() : AssetKey = if (this.nkey  == null) super.getKey() else this.nkey
 49}
 50
 51/**
 52 * mix in this to get default painting. Any asset would have implemented the getBrief method
 53 * 
 54 * @author razvanc
 55 */
 56trait DrawAsset extends AssetBase with Drawable {
 57
 58   override def render(t:Technology , stream:DrawStream ) : AnyRef = 
 59      DrawAsset_.render (this, t, stream)
 60}
 61
 62/**
 63 * this is the defalut paint for any asset with a brief
 64 * 
 65 * @author razvanc
 66 */
 67object DrawAsset_ {
 68
 69   def render(who:{def getBrief() : AssetBrief}, t:Technology , stream:DrawStream ) : AnyRef = {
 70      val movie = who.getBrief
 71
 72//      if (ctx.isPopulated("series"))
 73//         movie.setSeries((AssetKey) ctx.getAttr("series"));
 74
 75      // TODO the remote paths come here without a / - fix that!
 76      movie match {
 77         case m : FileAssetBrief => if (m.localDir != null && m.localDir.startsWith("/")) {
 78            m.localDir = "/" + m.localDir
 79         }
 80         case _ =>
 81      }
 82
 83      val vert = new DrawList();
 84      vert.isVertical = true;
 85
 86      // DrawList vert2 = new DrawList();
 87      // vert2.isVertical = true;
 88
 89      val horiz = new DrawList();
 90      val actions = new DrawList();
 91
 92      horiz.write(new ABDrawable (movie, DetailLevel.FULL))
 93
 94       for (a <- razie.M apply AssetMgr.pres().makeAllButtons(movie, false))
 95          actions.write(a)
 96
 97      // add more links...
 98      val moreActions = new DrawList();
 99      moreActions.write(new NavButton(new ActionItem("google"), new AttrAccessImpl("q", "movie "
100            + movie.getName()).addToUrl("http://images.google.com/images")));
101      moreActions.write(new NavButton(new ActionItem("imdb"), new AttrAccessImpl("s", "all", "q", movie
102            .getName()).addToUrl("http://imdb.com/find")));
103      movie match {
104         case m : FileAssetBrief => 
105      moreActions.write(new NavButton(new ActionItem("savejpg"), Agents.me.url + "/mutant/cmd" + "/saveJpg/" + "Movie/" + m.localDir + movie.getKey().getId() + "&"));
106         case _ =>
107      }
108
109      // vert2.write(movie);
110      // vert2.write(actions);
111      horiz.write(actions);
112
113      vert.write(horiz);
114      vert.write(moreActions);
115
116      vert
117   }
118}