source: ether_megapoli/trunk/applets/src/com/ether/AppletTimeSerie.java @ 198

Last change on this file since 198 was 198, checked in by vmipsl, 13 years ago

Servlet _ tooltip aide

File size: 8.7 KB
Line 
1package com.ether;
2
3import com.medias.database.objects.Parametre;
4import com.medias.database.objects.Unite;
5import gov.noaa.pmel.sgt.JPane;
6import org.jetbrains.annotations.NotNull;
7import org.jetbrains.annotations.Nullable;
8import org.springframework.context.support.ClassPathXmlApplicationContext;
9
10import javax.swing.*;
11import java.awt.*;
12import java.util.Calendar;
13import java.util.Date;
14import java.util.Locale;
15
16public class AppletTimeSerie
17        extends JApplet
18{
19    public void init()
20    {
21        // Appelée par la jsp :
22//        <%--this.plotWindow.getContent().innerHTML = '<applet code="AppletTimeSerie.class" codebase="<%=request.getContextPath()%>/applets" height="400px" width="400px"> ' +--%>
23//        <%--'<param name="plateformId" value="14"> ' +--%>
24//        <%--'<param name="parameterId" value="90"> ' +--%>
25//        <%--'<param name="dateBegin" value=""> ' +--%>
26//        <%--'<param name="dateEnd" value=""> ' +--%>
27//        <%--'<param name="title" value="zzzz"> ' +--%>
28//        <%--'<param name="axeType" value="MOBILE"> ' +--%>
29//        <%--'</applet>';--%>
30
31
32        String app_context1 = "classpath:dao-context.xml";
33        String app_context2 = "classpath:service-context.xml";
34        String app_context3 = "classpath:hibernate.cfg.xml";
35        String[] contextPaths = new String[]{app_context1, app_context2, app_context3};
36
37        final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( contextPaths );
38        _etherService = (EtherService) context.getBean( "etherService", EtherService.class );
39        _etherPlotService = (EtherPlotService) context.getBean( "etherPlotService", EtherPlotService.class );
40
41//        final String appletContext = "applet-context.xml";
42//        final String hibernateContext = "hibernate.cfg.xml";
43//        final String[] contextPaths = new String[]{appletContext, hibernateContext};
44//
45//        final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( contextPaths );
46//        _etherService = (EtherService) context.getBean( "etherService", EtherService.class );
47//        _etherPlotService = (EtherPlotService) context.getBean( "etherPlotService", EtherPlotService.class );
48
49        _locale = new Locale( "fr" );
50        _plateformId = 14;
51        _parameterId = 90;
52        _title = "Applet de merd....";
53        _axeType = AxeTypeForFixedPlateform.TIME_LINE.toString();
54        _dateBegin = null;
55        _dateEnd = null;
56
57        _maxWidth = EtherPlotServiceImpl.getMaxWidth();
58        _maxHeight = EtherPlotServiceImpl.getMaxHeight();
59
60//        final Integer plateformId = Integer.valueOf( getParameter( "plateformId" ) );
61//        final Integer parameterId = Integer.valueOf( getParameter( "parameterId" ) );
62//        final String title = getParameter( "title" );
63//        final String axeType = getParameter( "axeType" );
64//        final String dateBegin = getParameter( "dateBegin" );
65//        final String dateEnd = getParameter( "dateEnd" );
66//        final String locale = getParameter( "locale" );
67    }
68
69    public void start()
70    {
71        // Create megapoliPlot
72        final MegapoliPlot megapoliPlot = createMegapoliPlot();
73
74        // Create graph
75        setLayout( new BorderLayout( 0, 0 ) );
76        setBackground( Color.WHITE );
77//        setSize( _maxWidth, _maxHeight );
78        setSize( 800, 800 );
79
80        // Top Pane
81        final JPane jPaneTop = _etherPlotService.createTopPane( megapoliPlot );
82        add( jPaneTop, BorderLayout.NORTH );
83
84//        final Integer valuesNumber = megapoliPlot.getValuesNumber();
85        final Integer valuesNumber = 10;
86
87        // Bottom Pane
88        final JPane jPaneBottom = _etherPlotService.createBottomPane( valuesNumber, _locale );
89        add( jPaneBottom, BorderLayout.PAGE_END );
90
91        // Actions Panel
92//        final JPanel jPanelControl = _etherPlotService.createControlPanel();
93//        add( jPanelControl, BorderLayout.SOUTH );
94
95        // Graph Pane
96        final JPane jPaneGraph;
97//        try
98//        {
99//            jPaneGraph = _etherPlotService.createTimeSeriePlot( megapoliPlot, 600, 600 );
100//            add( jPaneGraph, BorderLayout.CENTER );
101//        }
102//        catch( ServiceException e )
103//        {
104//            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
105//        }
106    }
107
108    private MegapoliPlot createMegapoliPlot()
109    {
110        final Calendar calendar = Calendar.getInstance();
111        Date formatedDateBegin = null;
112        Date formatedDateEnd = null;
113        if( null != _dateBegin && null != _dateEnd && !"false".equals( _dateBegin ) && !"false".equals( _dateEnd ) )
114            try
115            {
116                calendar.setTimeInMillis( Long.valueOf( _dateBegin ) );
117                formatedDateBegin = calendar.getTime();
118                calendar.setTimeInMillis( Long.valueOf( _dateEnd ) );
119                formatedDateEnd = calendar.getTime();
120            }
121            catch( Exception e )
122            {
123                // TODO : gérer fenêtre d'erreur
124//                createErrorPane( response, request, WebException.WebCode.INVALID_DATE.toString(), e );
125//                flagException = true;
126//                throw new ServletException( WebException.WebCode.INVALID_DATE.toString(), e );
127            }
128
129        // Parameter
130//            final Parametre parametre = _etherService.getParameterById( parameterId );
131        final Parametre parametre = new Parametre();
132        parametre.setParametreNom( "Ozone" );
133        final Unite unit = new Unite();
134        unit.setUniteCode( "ppb" );
135        parametre.setUnite( unit );
136        if( null == parametre )
137        {
138            // TODO : gérer fenêtre d'erreur
139//            createErrorPane( response, request, WebException.WebCode.PARAMETER_IS_NULL.toString(), null );
140//            flagException = true;
141//            throw new ServletException( WebException.WebCode.PARAMETER_IS_NULL.toString(), null );
142        }
143
144        // Create plot
145        final MegapoliPlot megapoliPlot = new MegapoliPlot();
146        megapoliPlot.setTitle( _title );
147        megapoliPlot.setAxeType( _axeType );
148//        megapoliPlot.setParameterName( parametre.getParametreNom() );
149//        if( null != parametre.getUnite() && null != parametre.getUnite().getUniteCode() )
150//            megapoliPlot.setParameterUnitCode( parametre.getUnite().getUniteCode() );
151
152
153        if( AxeTypeForFixedPlateform.TIME_LINE.name().equals( _axeType ) || AxeTypeForFixedPlateform.TIME_POINTS.name().equals( _axeType ) )
154        {
155//            final Data valuesLists = _etherService.getListsByPlateformByParameterByPeriodForTimeSerie( plateformId, parameterId, formatedDateBegin, formatedDateEnd );
156            final double[] values = new double[50];
157            final Date[] dates = new Date[50];
158            final Calendar cal = Calendar.getInstance();
159
160            for( int i = 0; i < 50; i++ )
161            {
162                values[i] = (double) i;
163                cal.set( Calendar.MINUTE, 5 * i );
164                dates[i] = cal.getTime();
165            }
166            final Data valuesLists = new Data( values, dates );
167
168            megapoliPlot.setData( valuesLists );
169
170            megapoliPlot.setTimeSerie( true );
171            megapoliPlot.setLegendToHide( true );
172//            megapoliPlot.setValuesNumber( ( (double[]) valuesLists.getFirstArray() ).length );
173        }
174        else
175        {
176//            final Data valuesLists = _etherService.getListsByPlateformByParameterByPeriodFor2D( plateformId, parameterId, formatedDateBegin, formatedDateEnd );
177            final double[] latitudeValues = new double[50];
178            final double[] longitudeValues = new double[50];
179            final double[] parameterValues = new double[50];
180
181            for( int i = 0; i < 50; i++ )
182            {
183                parameterValues[i] = Math.random() * i;
184                latitudeValues[i] = Math.random() * i;
185                longitudeValues[i] = Math.random() * i;
186            }
187            final Data valuesLists = new Data( parameterValues, latitudeValues, longitudeValues );
188
189            megapoliPlot.setData( valuesLists );
190
191            megapoliPlot.setTimeSerie( false );
192            megapoliPlot.setLegendToHide( false );
193//            megapoliPlot.setValuesNumber( ( (double[]) valuesLists.getFirstArray() ).length );
194        }
195        return megapoliPlot;
196    }
197
198    private EtherService _etherService;
199    private EtherPlotService _etherPlotService;
200    @NotNull
201    private Locale _locale;
202    @NotNull
203    private Integer _plateformId;
204    @NotNull
205    private Integer _parameterId;
206    @Nullable
207    private String _title;
208    @NotNull
209    private String _axeType;
210    @Nullable
211    private String _dateBegin;
212    @Nullable
213    private String _dateEnd;
214    @NotNull
215    private Integer _maxWidth;
216    @NotNull
217    private Integer _maxHeight;
218}
Note: See TracBrowser for help on using the repository browser.