PageRenderTime 36ms CodeModel.GetById 12ms app.highlight 19ms RepoModel.GetById 2ms app.codeStats 0ms

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