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