KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > birt > chart > examples > api > interactivity > SvgInteractivityViewer


1 /***********************************************************************
2  * Copyright (c) 2004 Actuate Corporation.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * Actuate Corporation - initial API and implementation
10  ***********************************************************************/

11
12 package org.eclipse.birt.chart.examples.api.interactivity;
13
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
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 JavaDoc contextMap;
65
66     SvgInteractivityViewer( Composite parent, int style )
67     {
68         super( parent, style );
69         contextMap = new HashMap JavaDoc( );
70
71         PluginSettings.instance( ).registerDevice( "dv.SVG", //$NON-NLS-1$
72
"org.eclipse.birt.chart.device.svg.SVGRendererImpl" ); //$NON-NLS-1$
73
cm = InteractivityCharts.createHSChart( );
74
75     }
76
77     public static void main( String JavaDoc 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: " );//$NON-NLS-1$
99

100         cbType = new Combo( cBottom, SWT.DROP_DOWN | SWT.READ_ONLY );
101         cbType.add( "Highlight Series" );//$NON-NLS-1$
102
cbType.add( "Show Tooltip" );//$NON-NLS-1$
103
cbType.add( "Toggle Visibility" );//$NON-NLS-1$
104
cbType.add( "URL Redirect" );//$NON-NLS-1$
105
cbType.select( 0 );
106
107         btn = new Button( cBottom, SWT.NONE );
108         btn.setText( "Show" );//$NON-NLS-1$
109
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     /*
121      * (non-Javadoc)
122      *
123      * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
124      */

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" ); //$NON-NLS-1$
153
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" ); //$NON-NLS-1$
164
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" );//$NON-NLS-1$
181
br.setVisible( true );
182
183             shell.open( );
184         }
185     }
186
187     /* (non-Javadoc)
188      * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
189      */

190     public void widgetDefaultSelected( SelectionEvent e )
191     {
192         // TODO Auto-generated method stub
193

194     }
195
196     /*
197      * (non-Javadoc)
198      *
199      * @see org.eclipse.birt.chart.device.IUpdateNotifier#getContext(java.lang.Object)
200      */

201     public Object JavaDoc getContext( Object JavaDoc key )
202     {
203         return contextMap.get( key );
204     }
205
206     /* (non-Javadoc)
207      * @see org.eclipse.birt.chart.device.IUpdateNotifier#getDesignTimeModel()
208      */

209     public Chart getDesignTimeModel( )
210     {
211         return cm;
212     }
213
214     /* (non-Javadoc)
215      * @see org.eclipse.birt.chart.device.IUpdateNotifier#getRunTimeModel()
216      */

217     public Chart getRunTimeModel( )
218     {
219         return gcs.getChartModel( );
220     }
221
222     /* (non-Javadoc)
223      * @see org.eclipse.birt.chart.device.IUpdateNotifier#peerInstance()
224      */

225     public Object JavaDoc peerInstance( )
226     {
227         return this;
228     }
229
230     /* (non-Javadoc)
231      * @see org.eclipse.birt.chart.device.IUpdateNotifier#putContext(java.lang.Object, java.lang.Object)
232      */

233     public Object JavaDoc putContext( Object JavaDoc key, Object JavaDoc value )
234     {
235         return contextMap.put( key, value );
236     }
237
238     /* (non-Javadoc)
239      * @see org.eclipse.birt.chart.device.IUpdateNotifier#regenerateChart()
240      */

241     public void regenerateChart( )
242     {
243         // TODO Auto-generated method stub
244

245     }
246
247     /* (non-Javadoc)
248      * @see org.eclipse.birt.chart.device.IUpdateNotifier#removeContext(java.lang.Object)
249      */

250     public Object JavaDoc removeContext( Object JavaDoc key )
251     {
252         return contextMap.remove( key );
253     }
254
255     /* (non-Javadoc)
256      * @see org.eclipse.birt.chart.device.IUpdateNotifier#repaintChart()
257      */

258     public void repaintChart( )
259     {
260         // TODO Auto-generated method stub
261

262     }
263 }
264
Popular Tags