You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Here is a starter to use Open Flash Charts and Wicket:

check: http://teethgrinder.co.uk/open-flash-chart-2/ http://code.google.com/p/ofcj/ http://code.google.com/p/swfobject/


/**
 * @see <a href="http://code.google.com/p/swfobject/">SWFObject</a>
 */
public class OpenFlashChart extends Panel implements IResourceListener
{
  static final ResourceReference SWF = new ResourceReference( OpenFlashChart.class, "open-flash-chart.swf" );
  
  final WebResource jsonResource;
  final SWFObject swf;
  final IModel<Chart> chart;

  public OpenFlashChart(final String id, final IModel<Chart> chart, final int width, final int height) 
  {
    this( id, chart, width+"", height+"" );
  }
  
  public OpenFlashChart(final String id, final IModel<Chart> chart, final String width, final String height) 
  {
    super(id);
    this.chart = chart;
    
    final IResourceStream json = new AbstractStringResourceStream( "text/plain") {
      @Override
      public String getString() {
        return chart.getObject().toString();
      }
    };

    jsonResource = new WebResource() {
      @Override
      public IResourceStream getResourceStream() {
        return json;
      }
    };
    jsonResource.setCacheable(false);
    
    String swfURL = RequestUtils.toAbsolutePath( urlFor( SWF ).toString() );
    swf = new SWFObject( "chart", swfURL, "500", "300" );
    add( swf );
  }
  
  @Override
  protected void onBeforeRender() {
    CharSequence dataPath = 
      RequestCycle.get().urlFor(OpenFlashChart.this, IResourceListener.INTERFACE); 
    
    String data = RequestUtils.toAbsolutePath( dataPath.toString() );
    
    swf.setFlashvar( "data-file", data );
    swf.setParam( "allowScriptAccess", "sameDomain" );
    
    super.onBeforeRender();
  }

  /**
   * Actually handle the request
   */
  public void onResourceRequested() {
    jsonResource.onResourceRequested();
  }
}

Here is the general component to show SWF data:

 hymmm, for some reason when i paste the code in here, it gets an error...
  • No labels