1 11 12 package org.eclipse.birt.chart.examples.api.interactivity; 13 14 import java.util.HashMap ; 15 import java.util.Map ; 16 17 import com.ibm.icu.util.ULocale; 18 19 import org.eclipse.birt.chart.exception.ChartException; 20 import org.eclipse.birt.chart.device.EmptyUpdateNotifier; 21 import org.eclipse.birt.chart.device.IDeviceRenderer; 22 import org.eclipse.birt.chart.device.IUpdateNotifier; 23 import org.eclipse.birt.chart.factory.GeneratedChartState; 24 import org.eclipse.birt.chart.factory.Generator; 25 import org.eclipse.birt.chart.factory.RunTimeContext; 26 import org.eclipse.birt.chart.model.Chart; 27 import org.eclipse.birt.chart.model.attribute.Bounds; 28 import org.eclipse.birt.chart.model.attribute.impl.BoundsImpl; 29 import org.eclipse.birt.chart.util.PluginSettings; 30 31 import org.eclipse.swt.SWT; 32 import org.eclipse.swt.browser.Browser; 33 import org.eclipse.swt.events.SelectionEvent; 34 import org.eclipse.swt.events.SelectionListener; 35 import org.eclipse.swt.layout.GridData; 36 import org.eclipse.swt.layout.GridLayout; 37 import org.eclipse.swt.layout.RowLayout; 38 import org.eclipse.swt.widgets.Button; 39 import org.eclipse.swt.widgets.Combo; 40 import org.eclipse.swt.widgets.Composite; 41 import org.eclipse.swt.widgets.Display; 42 import org.eclipse.swt.widgets.Label; 43 import org.eclipse.swt.widgets.Shell; 44 45 public class SvgInteractivityViewer extends Composite implements 46 IUpdateNotifier, 47 SelectionListener 48 { 49 50 private static final long serialVersionUID = 1L; 51 52 private IDeviceRenderer idr = null; 53 54 private static Combo cbType = null; 55 56 private static Button btn = null; 57 58 private static Display display = null; 59 60 private GeneratedChartState gcs = null; 61 62 private Chart cm = null; 63 64 private Map contextMap; 65 66 SvgInteractivityViewer( Composite parent, int style ) 67 { 68 super( parent, style ); 69 contextMap = new HashMap ( ); 70 71 PluginSettings.instance( ).registerDevice( "dv.SVG", "org.eclipse.birt.chart.device.svg.SVGRendererImpl" ); cm = InteractivityCharts.createHSChart( ); 74 75 } 76 77 public static void main( String args[] ) 78 { 79 display = Display.getDefault( ); 80 Shell shell = new Shell( display ); 81 shell.setSize( 220, 80 ); 82 shell.setLocation( display.getClientArea( ).width / 2 - 110, 83 display.getClientArea( ).height / 2 - 40); 84 shell.setLayout( new GridLayout( ) ); 85 86 SvgInteractivityViewer siv = new SvgInteractivityViewer( shell, 87 SWT.NONE ); 88 GridData gd = new GridData( GridData.BEGINNING ); 89 gd.widthHint = 1; 90 gd.heightHint = 1; 91 siv.setLayoutData( gd ); 92 93 Composite cBottom = new Composite( shell, SWT.NONE ); 94 cBottom.setLayoutData( new GridData( GridData.CENTER ) ); 95 cBottom.setLayout( new RowLayout( ) ); 96 97 Label la = new Label( cBottom, SWT.NONE ); 98 la.setText( "Choose: " ); 100 cbType = new Combo( cBottom, SWT.DROP_DOWN | SWT.READ_ONLY ); 101 cbType.add( "Highlight Series" ); cbType.add( "Show Tooltip" ); cbType.add( "Toggle Visibility" ); cbType.add( "URL Redirect" ); cbType.select( 0 ); 106 107 btn = new Button( cBottom, SWT.NONE ); 108 btn.setText( "Show" ); btn.addSelectionListener( siv ); 110 111 shell.open( ); 112 while ( !shell.isDisposed( ) ) 113 { 114 if ( !display.readAndDispatch( ) ) 115 display.sleep( ); 116 } 117 display.dispose( ); 118 } 119 120 125 public void widgetSelected( SelectionEvent e ) 126 { 127 if ( e.widget == btn ) 128 { 129 int i = cbType.getSelectionIndex( ); 130 switch ( i ) 131 { 132 case 0 : 133 cm = InteractivityCharts.createHSChart( ); 134 break; 135 case 1 : 136 cm = InteractivityCharts.createSTChart( ); 137 break; 138 case 2 : 139 cm = InteractivityCharts.createTVChart( ); 140 break; 141 case 3 : 142 cm = InteractivityCharts.createURChart( ); 143 break; 144 } 145 146 try 147 { 148 149 RunTimeContext rtc = new RunTimeContext( ); 150 rtc.setULocale( ULocale.getDefault( ) ); 151 152 idr = PluginSettings.instance( ).getDevice( "dv.SVG" ); Generator gr = Generator.instance( ); 154 GeneratedChartState gcs = null; 155 Bounds bo = BoundsImpl.create( 0, 0, 450, 300 ); 156 gcs = gr.build( idr.getDisplayServer( ), 157 cm, 158 bo, 159 null, 160 rtc, 161 null ); 162 163 idr.setProperty( IDeviceRenderer.FILE_IDENTIFIER, "c:/test.svg" ); idr.setProperty( IDeviceRenderer.UPDATE_NOTIFIER, 165 new EmptyUpdateNotifier( cm, gcs.getChartModel( ) ) ); 166 167 gr.render( idr, gcs ); 168 } 169 catch ( ChartException ce ) 170 { 171 ce.printStackTrace( ); 172 } 173 174 Shell shell = new Shell( display ); 175 shell.setSize( 620, 450 ); 176 shell.setLayout( new GridLayout( ) ); 177 178 Browser br = new Browser( shell, SWT.NONE ); 179 br.setLayoutData( new GridData( GridData.FILL_BOTH ) ); 180 br.setUrl( "c:/test.svg" ); br.setVisible( true ); 182 183 shell.open( ); 184 } 185 } 186 187 190 public void widgetDefaultSelected( SelectionEvent e ) 191 { 192 194 } 195 196 201 public Object getContext( Object key ) 202 { 203 return contextMap.get( key ); 204 } 205 206 209 public Chart getDesignTimeModel( ) 210 { 211 return cm; 212 } 213 214 217 public Chart getRunTimeModel( ) 218 { 219 return gcs.getChartModel( ); 220 } 221 222 225 public Object peerInstance( ) 226 { 227 return this; 228 } 229 230 233 public Object putContext( Object key, Object value ) 234 { 235 return contextMap.put( key, value ); 236 } 237 238 241 public void regenerateChart( ) 242 { 243 245 } 246 247 250 public Object removeContext( Object key ) 251 { 252 return contextMap.remove( key ); 253 } 254 255 258 public void repaintChart( ) 259 { 260 262 } 263 } 264 | Popular Tags |