/razpub/test_src/com/razie/pub/draw/test/SampleDrawable.java

http://razpub.googlecode.com/ · Java · 120 lines · 81 code · 22 blank · 17 comment · 0 complexity · 770fbd481b12c8189c747dfceca84e63 MD5 · raw file

  1. /**
  2. * Razvan's public code. Copyright 2008 based on Apache license (share alike) see LICENSE.txt for
  3. * details.
  4. */
  5. package com.razie.pub.draw.test;
  6. import razie.base.ActionItem;
  7. import razie.base.ActionToInvoke;
  8. import razie.base.AttrAccessImpl;
  9. import razie.draw.DrawSequence;
  10. import razie.draw.DrawStream;
  11. import razie.draw.Renderer;
  12. import razie.draw.Technology;
  13. import razie.draw.widgets.DrawError;
  14. import razie.draw.widgets.DrawForm;
  15. import razie.draw.widgets.DrawSelection;
  16. import razie.draw.widgets.DrawToString;
  17. import razie.draw.widgets.NavButton;
  18. import razie.draw.widgets.NavLink;
  19. import razie.draw.widgets.SimpleButton;
  20. import razie.draw.widgets.NavLink.Size;
  21. import razie.draw.widgets.NavLink.Style;
  22. import com.razie.pub.comms.SimpleActionToInvoke;
  23. import com.razie.pub.resources.RazIcons;
  24. /**
  25. * this is a sample model drawable - it has one label and two buttons
  26. *
  27. * a model drawable, ideally will ignore the technology and the stream, just use widgets and ask
  28. * them to render
  29. *
  30. * @version $Revision: 1.63 $
  31. * @author $Author: davidx $
  32. * @since $Date: 2005/04/01 16:22:12 $
  33. */
  34. public class SampleDrawable extends razie.draw.Drawable.Widget {
  35. /** shortcut to render self - don't like controllers that much */
  36. public Object render(Technology technology, DrawStream stream) {
  37. DrawSequence seq = new razie.draw.DrawSequence();
  38. ActionItem AI = new ActionItem("lightsoa/service/echo", RazIcons.FILE.name());
  39. AI.label = "echo something...";
  40. ActionToInvoke ATI = new SimpleActionToInvoke(AI, "msg", "echo...");
  41. seq.write("\nno action label vvv\n");
  42. seq.write(new NavLink(AI, (String) null).style(NavLink.Style.JUST_LABEL));
  43. seq.write("\nno action label ^^^\n");
  44. seq.write("\n action label vvv\n");
  45. seq.write(new NavLink(ATI).style(Style.JUST_LABEL));
  46. seq.write("\n action label ^^^\n");
  47. seq.write("\n just icon vvv\n");
  48. seq.write(new NavLink(ATI).style(NavLink.Style.JUST_ICON, Size.TINY));
  49. seq.write(new NavLink(ATI).style(NavLink.Style.JUST_ICON, Size.SMALL));
  50. seq.write(new NavLink(ATI).style(NavLink.Style.JUST_ICON, Size.NORMAL));
  51. seq.write(new NavLink(ATI).style(NavLink.Style.JUST_ICON, Size.LARGE));
  52. seq.write("\n just icon ^^^\n");
  53. seq.write("\n nice link vvv\n");
  54. seq.write(new NavLink(ATI));
  55. seq.write("\n nice link ^^^\n");
  56. seq.write("\nno action button vvv\n");
  57. seq.write(new SimpleButton(AI, (String) null));
  58. seq.write("\nno action button ^^^\n");
  59. seq.write("\n action button vvv\n");
  60. seq.write(new SimpleButton(ATI));
  61. seq.write("\n action button ^^^\n");
  62. seq.write("\n nav button vvv\n");
  63. seq.write(new NavButton(ATI));
  64. seq.write("\n nav button ^^^\n");
  65. seq.write("\n tiny nav button vvv\n");
  66. NavButton b = new NavButton(ATI);
  67. b.setTiny(true);
  68. seq.write(b);
  69. seq.write("\n tiny nav button ^^^\n");
  70. seq.write("\n selection vvv\n");
  71. DrawSelection sel = new DrawSelection("samplesel", ATI, ATI, ATI);
  72. seq.write(sel);
  73. seq.write("\n selection ^^^\n");
  74. seq.write("\nToString vvv\n");
  75. seq.write(new DrawToString("some text"));
  76. seq.write("\nToString ^^^\n");
  77. seq.write("\nDrawError vvv\n");
  78. try {
  79. justThrow();
  80. } catch (Throwable t) {
  81. seq.write(new DrawError(t));
  82. }
  83. seq.write("\nDrawError ^^^\n");
  84. seq.write("\nDrawForm vvv\n");
  85. DrawForm df = new DrawForm(AI, ATI,
  86. new AttrAccessImpl("url", "http://www.google.com", "filter:script", "<write script here>"));
  87. seq.write(df);
  88. seq.write("\nDrawForm ^^^\n");
  89. seq.write("\nDrawLater vvv\n");
  90. // TODO 0 enable this seq.write(new DrawLater(ATI));
  91. seq.write("\nDrawLater ^^^\n");
  92. // for actual rendering, ask the widget
  93. return seq.render(technology, stream);
  94. }
  95. private void justThrow() {
  96. throw new RuntimeException("exc");
  97. }
  98. }