source: ether_megapoli/trunk/service/test/com/ether/SGTTest.java @ 129

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

Commit intermédiaire : plot dynamique (version instable et pas clean)

File size: 29.9 KB
Line 
1package com.ether;
2
3import com.ether.annotation.ControllerMethod;
4import com.ether.annotation.Mandatory;
5import com.ether.annotation.ParamName;
6import com.ether.tutorial.src.tutorial.Example1;
7import com.ether.tutorial.src.tutorial.SBExample1;
8import com.ether.tutorial.src.tutorial.SBExample2;
9import com.ether.tutorial.src.tutorial.SBExample3;
10import com.keypoint.PngEncoder;
11import com.keypoint.PngEncoderB;
12import gov.noaa.pmel.sgt.JPane;
13import gov.noaa.pmel.sgt.LineAttribute;
14import gov.noaa.pmel.sgt.dm.SGTMetaData;
15import gov.noaa.pmel.sgt.dm.SimpleLine;
16import gov.noaa.pmel.sgt.swing.JPlotLayout;
17import gov.noaa.pmel.util.GeoDateArray;
18import net.sf.json.JSONObject;
19import org.jetbrains.annotations.NotNull;
20import org.jetbrains.annotations.Nullable;
21import org.junit.Test;
22
23import javax.imageio.ImageIO;
24import javax.servlet.ServletException;
25import javax.servlet.http.HttpServletRequest;
26import javax.servlet.http.HttpServletResponse;
27import javax.swing.*;
28import java.awt.*;
29import java.awt.image.BufferedImage;
30import java.awt.image.RenderedImage;
31import java.io.File;
32import java.io.FileInputStream;
33import java.io.IOException;
34import java.text.ParseException;
35import java.util.Date;
36
37/**
38 * @author vmipsl
39 * @date 31 may 2011
40 */
41public class SGTTest
42        extends EtherTest
43{
44    @Test
45    public void testImageKeroppi()
46            throws Exception
47    {
48        JFrame frame = new JFrame( "Test de superposition" );
49        JLayeredPane lp = frame.getLayeredPane();
50        JPanel p1 = new JPanel();
51        ImageIcon ic = new ImageIcon( "service/test/kerropi1.jpg" );
52        JLabel l = new JLabel( ic );
53        p1.setBounds( 0, 0, 640, 480 );
54
55        p1.add( l );
56        lp.add( p1, 1 );
57
58        p1.setVisible( true ); //Quand on met à false, le rectangle apparait !
59        frame.setSize( 700, 550 );
60        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
61        frame.setVisible( true );
62
63        copyToFile( frame, "service/test/test_ImageIcon.jpg" );
64    }
65
66    @Test
67    public void testJLabel()
68            throws Exception
69    {
70        final JFrame frame = new JFrame( "Frame principale" );
71        final JPanel panel = new JPanel( new BorderLayout() );
72
73        final JLabel jlbHelloWorld = new JLabel( "Hello World" );
74        panel.add( jlbHelloWorld, BorderLayout.EAST );
75        panel.setVisible( true );
76        frame.setContentPane( panel );
77
78        frame.setSize( 700, 550 );
79        frame.setVisible( true );
80
81        copyToFile( frame, "service/test/test_JLabel.jpg" );
82    }
83
84    @Test
85    public void testJPlotLayout()
86            throws Exception
87    {
88        final JFrame frame = new JFrame( "Frame principale" );
89        final JPanel panel = new JPanel( new BorderLayout() );
90
91        final JLabel jlbHelloWorld = new JLabel( "Hello World" );
92        panel.add( jlbHelloWorld, BorderLayout.SOUTH );
93
94        final ImageIcon ic = new ImageIcon( "service/test/kerropi1.jpg" );
95        final JLabel jLabel = new JLabel( ic );
96        panel.add( jLabel, BorderLayout.EAST );
97
98        final JPlotLayout jPlotLayout = new JPlotLayout( false, false, false, "Trajectory data", null, false );
99        jPlotLayout.setTitles( "title1", "title2", "title3" );
100        jPlotLayout.setVisible( true );
101        panel.add( jPlotLayout, BorderLayout.NORTH );
102
103        panel.setVisible( true );
104        frame.setContentPane( panel );
105
106        frame.setSize( 700, 550 );
107        frame.setVisible( true );
108
109        Thread.sleep( 100 );
110        copyToFile( frame, "service/test/test_JPlotLayout.jpg" );
111    }
112
113    @Test
114    public void testExample1()
115            throws Exception
116    {
117        new Example1();
118    }
119
120    @Test
121    public void testSBExamples()
122            throws Exception
123    {
124        final SBExample1 frame = new SBExample1();
125        frame.pack();
126        frame.setResizable( false );
127        frame.setVisible( true );
128        Thread.sleep( 100 );
129        copyToFile( frame, "service/test/test_SBExample1.jpg" );
130
131        final SBExample2 frame2 = new SBExample2();
132        frame2.pack();
133        frame2.setResizable( false );
134        frame2.setVisible( true );
135        Thread.sleep( 100 );
136        copyToFile( frame2, "service/test/test_SBExample2.jpg" );
137
138        final SBExample3 frame3 = new SBExample3();
139        frame3.pack();
140        //Center the window
141        final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
142        final Dimension frameSize = frame3.getSize();
143        if( frameSize.height > screenSize.height )
144        {
145            frameSize.height = screenSize.height;
146        }
147        if( frameSize.width > screenSize.width )
148        {
149            frameSize.width = screenSize.width;
150        }
151        frame3.setLocation( ( screenSize.width - frameSize.width ) / 2, ( screenSize.height - frameSize.height ) / 2 );
152        frame3.setResizable( false );
153        frame3.setVisible( true );
154        Thread.sleep( 100 );
155        copyToFile( frame3, "service/test/test_SBExample3.jpg" );
156    }
157
158    @Test
159    /**
160     * TODO :
161     *      - démarrer plot à (0,0)
162     *      - légende de l'axe des temps
163     *      - titre du graph ??
164     *      - légende générale
165     *
166     */
167    public void testTimeSeriePlot()
168            throws Exception
169    {
170        // Values to configure plot
171        final String parameterName = "OZONE";
172        final String parameterUnit = "ppbv";
173        final boolean startToZero = true;
174        final boolean markPoint = false;
175
176        final GeoDateArray dateArray = createTimeArray( 10, null );
177        final double[] dataArray = createDataArray( 10, 5 );
178
179//        for( int i = 0; i < dateArray.getLength(); i++ )
180//            System.out.println( dateArray.getGeoDate( i ).toString() );
181//
182//        for( int i = 0; i < dataArray.length; i++ )
183//            System.out.println( dataArray[i] );
184
185        SimpleLine data = new SimpleLine( dateArray, dataArray, "legend" );
186        SGTMetaData meta = new SGTMetaData( "Longitude", "degrees East", false, false );
187        data.setXMetaData( meta );
188
189        meta = new SGTMetaData( parameterName, parameterUnit, false, false );
190        data.setYMetaData( meta );
191
192        final LineAttribute lineAttribute = createLineAttribute( markPoint );
193
194        final TimeSeriesPlot timeSeriesPlot = new TimeSeriesPlot();
195        timeSeriesPlot.setTitle( "Keroppi title" );
196        timeSeriesPlot.setLogoMegapoli( "keroppi1.jpg" );
197        timeSeriesPlot.setData( data );
198        timeSeriesPlot.setLineAttribute( lineAttribute );
199
200//        getEtherPlotService().createTimeSeriesPlot( timeSeriesPlot );
201        timeSeriesPlot.createTimeSeriesPlot();
202
203        timeSeriesPlot.pack();
204        timeSeriesPlot.setResizable( false );
205        timeSeriesPlot.setVisible( true );
206
207        Thread.sleep( 100 );
208        copyToFile( timeSeriesPlot, "service/test/test_TimeSeriesFrameeee.jpg" );
209
210        final Image image = timeSeriesPlot.createImage( 400, 400 );
211
212//        BufferedImage bufferedImage = toBufferedImage( image );
213//        BASE64Encoder encoder = new BASE64Encoder();
214//        encoder.encode( bufferedImage );
215
216        PngEncoder pngEncoder = new PngEncoder();
217        pngEncoder.setImage( image );
218        byte[] bytes = pngEncoder.pngEncode();
219    }
220
221//    @Test
222//    public void testSerializationImage() throws Exception {
223//      Example1 example = new Example1();
224//
225//      Image createdImage = example.createImage(example.getWidth(), example.getHeight());
226//
227//      FileInputStream fichierKer = new FileInputStream("kerropi1.jpg");
228//              BufferedImage bImageKer = ImageIO.read(fichierKer);
229//              Image imageKer = bImageKer;
230//
231////            int w = createdImage.getWidth(null);
232////            int h = createdImage.getHeight(null);
233////            BufferedImage bImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
234//              BufferedImage bImage = ImageHelper.createBufferedImage(createdImage);
235//              BufferedImage bImageKer2 = ImageHelper.createBufferedImage(imageKer);
236//
237////            final byte[] bytes = createdImage.toString().getBytes();
238////            final String pif = Base64.encode(bytes);
239//
240//      try {
241//              File outKer = new File("outKer.jpg");
242//                      ImageIO.write(bImageKer2, "jpeg", outKer);
243//
244//              File out = new File("out.jpg");
245//                      ImageIO.write(bImage, "jpeg", out);
246//
247//
248////                    FileOutputStream flux = new FileOutputStream("bob_image.jpg");
249////                    BufferedOutputStream fluxBuf = new BufferedOutputStream(flux);
250////                    JPEGImageEncoder codec = JPEGCodec.createJPEGEncoder(fluxBuf, JPEGCodec.getDefaultJPEGEncodeParam(bImage));
251////                    codec.encode(bImage);
252////                    fluxBuf.close();
253//
254////                    FileWriter fichier = new FileWriter("bob_encode.gif");
255////                    BufferedWriter output = new BufferedWriter(fichier);
256////                    output.write(pif);
257////                    output.flush();
258////                    output.close();
259////
260////                    FileWriter fichier1 = new FileWriter("bob.gif");
261////                    BufferedWriter output1 = new BufferedWriter(fichier1);
262////                    String bytesS = new String(bytes);
263////                    output1.write(bytesS);
264////                    output1.flush();
265////                    output1.close();
266////
267////                    FileWriter fichier2 = new FileWriter("bob_decode.gif");
268////                    BufferedWriter output2 = new BufferedWriter(fichier2);
269////                    byte[] paf = Base64.decode(pif);
270////                    String bytesS2 = new String(paf);
271////                    output2.write(bytesS2);
272////                    output2.flush();
273////                    output2.close();
274//
275//      } catch (IOException e) {
276//              e.printStackTrace();
277//      }
278//    }
279
280
281//        Image createdImage = example.createImage(example.getWidth(), example.getHeight());
282//        final byte[] bytes = createdImage.toString().getBytes();
283//        final String pif = Base64.encode( bytes );
284//
285//        try {
286//            FileWriter fichier = new FileWriter("bob_encode.gif");
287//            fichier.write(pif);
288//
289//            FileWriter fichier1 = new FileWriter("bob.gif");
290//            String bytesS = new String(bytes);
291//            fichier.write(bytesS);
292//        } catch (IOException e) {
293//            e.printStackTrace();
294//        }
295
296    @Test
297    public void doGetImage()
298            throws Exception
299    {
300        // Appel .jsp
301        // <img src="plotEther?agentId=15" width="150px" height="150px"/>
302        final FileInputStream fichierKer = new FileInputStream( "/home_local/workspaces/Megapoli/service/test/kerropi1.jpg" );
303        final BufferedImage bImageKer = ImageIO.read( fichierKer );
304
305        if( bImageKer != null )
306        {
307            final PngEncoderB pngEncoderB = new PngEncoderB();
308            pngEncoderB.setImage( bImageKer );
309
310//            ImageIO.write( bImageKer, "png", response.getOutputStream() );
311        }
312    }
313
314    @Test
315    public void doGetImage_withFrame()
316            throws Exception
317    {
318        final GeoDateArray dateArray = createTimeArray( 10, null );
319        final double[] dataArray = createDataArray( 10, 5 );
320
321        final SimpleLine data = new SimpleLine( dateArray, dataArray, "legend" );
322        SGTMetaData meta = new SGTMetaData( "Longitude", "degrees East", false, false );
323        data.setXMetaData( meta );
324
325        meta = new SGTMetaData( "parameterName", "parameterUnit", false, false );
326        data.setYMetaData( meta );
327
328        final JFrame frame = new JFrame( "Frame principale" );
329        final JPane jPane = new JPane();
330
331        final JLabel jlbHelloWorld = new JLabel( "Hello World" );
332        jPane.add( jlbHelloWorld, BorderLayout.SOUTH );
333
334        final ImageIcon ic = new ImageIcon( "/home_local/workspaces/Megapoli/service/test/kerropi1.jpg" );
335        final JLabel jLabel = new JLabel( ic );
336        jPane.add( jLabel, BorderLayout.EAST );
337
338        final JPlotLayout jPlotLayout = new JPlotLayout( false, true, false, "Trajectory data", null, false );
339        jPlotLayout.setTitles( "title1", "title2", "title3" );
340        jPlotLayout.addData( data, data.getTitle() );
341        jPlotLayout.setVisible( true );
342        jPane.add( jPlotLayout, BorderLayout.EAST );
343
344        jPane.setVisible( true );
345        frame.setContentPane( jPane );
346
347        frame.setSize( 700, 550 );
348        frame.setEnabled( false );
349        frame.pack();
350        frame.setVisible( true );
351
352
353        final BufferedImage bufferedImage = new BufferedImage( jPlotLayout.getWidth(), jPlotLayout.getHeight(), BufferedImage.TYPE_INT_RGB );
354        final Graphics2D graphics2D = bufferedImage.createGraphics();
355        graphics2D.setBackground( Color.WHITE );
356        jPlotLayout.getComponent().addNotify();
357        jPlotLayout.getComponent().validate();
358
359        jPlotLayout.draw( graphics2D );
360
361        try
362        {
363            final File outFile = new File( "/home_local/workspaces/Megapoli/service/test/keroppi_out.jpg" );
364            ImageIO.write( bufferedImage, "jpg", outFile );
365        }
366        catch( Exception e )
367        {
368        }
369    }
370
371
372    protected GeoDateArray createTimeArray( @NotNull final Integer size, @Nullable String day )
373            throws ParseException
374    {
375        if( null == day )
376            day = "2009-07-13";
377
378        final Date[] dates = new Date[size];
379        for( int i = 0; i < size; i++ )
380        {
381            final String dateString = day + ' ' + i + ":32";
382            final Date date = DateHelper.parseDate( dateString, DateHelper.ENGLISH_DATE_PATTERN );
383            dates[i] = date;
384        }
385        return new GeoDateArray( dates );
386    }
387
388    @NotNull
389    protected double[] createDataArray( @NotNull final Integer size, @NotNull final Integer begin )
390            throws ParseException
391    {
392        final double[] datas = new double[size];
393        for( int i = 0; i < size; i++ )
394        {
395            datas[i] = Double.valueOf( i + begin );
396        }
397        return datas;
398    }
399
400    private TimeSeriesPlot createPlot()
401            throws ParseException, ServiceException
402    {
403        final String parameterName = "OZONE";
404        final String parameterUnit = "ppbv";
405        final boolean startToZero = true;
406        final boolean markPoint = false;
407
408        final GeoDateArray dateArray = createTimeArray( 10, null );
409        final double[] dataArray = createDataArray( 10, 5 );
410
411        final SimpleLine data = new SimpleLine( dateArray, dataArray, "legend" );
412        SGTMetaData meta = new SGTMetaData( "Longitude", "degrees East", false, false );
413        data.setXMetaData( meta );
414
415        meta = new SGTMetaData( parameterName, parameterUnit, false, false );
416        data.setYMetaData( meta );
417
418        final LineAttribute lineAttribute = new LineAttribute( LineAttribute.SOLID, Color.red );
419
420        final TimeSeriesPlot timeSeriesPlot = new TimeSeriesPlot();
421        timeSeriesPlot.setTitle( "Keroppi title" );
422        timeSeriesPlot.setLogoMegapoli( "keroppi1.jpg" );
423        timeSeriesPlot.setData( data );
424        timeSeriesPlot.setLineAttribute( lineAttribute );
425
426        timeSeriesPlot.createTimeSeriesPlot();
427        return timeSeriesPlot;
428    }
429
430    private JPlotLayout createLayout( @Nullable final String plateformName, @Nullable final String parameterName )
431    {
432        final JFrame frame = new JFrame( "Frame principale" );
433        final JPanel panel = new JPanel( new BorderLayout() );
434
435        final JLabel jlbHelloWorld = new JLabel( "Hello World" );
436        panel.add( jlbHelloWorld, BorderLayout.SOUTH );
437
438        final ImageIcon ic = new ImageIcon( "kerropi1.jpg" );
439        final JLabel jLabel = new JLabel( ic );
440        panel.add( jLabel, BorderLayout.EAST );
441
442        final JPlotLayout jPlotLayout = new JPlotLayout( false, false, false, "Trajectory data", null, false );
443        jPlotLayout.setTitles( plateformName, parameterName, "title3" );
444//              jPlotLayout.setTitleHeightP(0.2, 0.2);
445        jPlotLayout.setVisible( true );
446        panel.add( jPlotLayout, BorderLayout.NORTH );
447
448        panel.setVisible( true );
449        frame.setContentPane( panel );
450
451        frame.setSize( MAIN_WIDTH, 550 );
452        frame.setVisible( true );
453
454        return jPlotLayout;
455    }
456
457    public void doGet_Layout( final HttpServletResponse response, final SimpleLine data )
458            throws ServletException, IOException
459    {
460        try
461        {
462            final JPlotLayout jPlotLayout = new JPlotLayout( false, true, false, "Trajectory data", null, false );
463            jPlotLayout.setTitles( "title1", "title2", "title3" );
464            jPlotLayout.addData( data, data.getTitle() );
465            jPlotLayout.setVisible( true );
466
467            jPlotLayout.addNotify();
468            jPlotLayout.validate();
469
470            final BufferedImage bufferedImage = new BufferedImage( jPlotLayout.getWidth(), jPlotLayout.getHeight(), BufferedImage.TYPE_INT_RGB );
471            final Graphics2D graphics2D = bufferedImage.createGraphics();
472            graphics2D.setBackground( Color.red );
473            jPlotLayout.draw( graphics2D );
474
475            ImageIO.write( bufferedImage, "png", response.getOutputStream() );
476        }
477
478        catch( Exception e )
479        {
480            e.printStackTrace();
481        }
482    }
483
484
485
486    @ControllerMethod(jsonResult = true)
487    public JSONObject searchDatasByPlateformByParameterByPeriod(
488            @Mandatory @ParamName(ParameterConstants.PARAMETER_PLATEFORM_ID) final Integer plateformId,
489            @Mandatory @ParamName(ParameterConstants.PARAMETER_PARAMETER_ID) final Integer parameterId,
490            @ParamName(ParameterConstants.PARAMETER_DATE_BEGIN) final String dateBegin,
491            @ParamName(ParameterConstants.PARAMETER_DATE_END) final String dateEnd )
492            throws ServiceException, WebException, ParseException
493    {
494//        final String pofBegin = "2009-07-13 13:00";
495//        final String pofEnd = "2009-07-13 14:00";
496//        final Date formatedDateBegin = DateHelper.parseDate( pofBegin, DateHelper.ENGLISH_DATE_PATTERN );
497//        final Date formatedDateEnd = DateHelper.parseDate( pofEnd, DateHelper.ENGLISH_DATE_PATTERN );
498
499//        final Plateforme plateform = _etherService.getPlateformById( plateformId );
500//        final Parametre parameter = _etherService.getParameterById( parameterId );
501//        final List<Data> values = _etherService.getValuesByPlateformByParameterByPeriod( plateformId, parameterId, formatedDateBegin, formatedDateEnd );
502
503        //JPlotLayout layout = createLayout( plateform.getPlateformeNom(), parameter.getParametreNom() );
504        final TimeSeriesPlot timeSeriesPlot = createPlot();
505        final Image image = timeSeriesPlot.createImage( 400, 400 );
506
507//        BufferedImage bufferedImage = toBufferedImage( image );
508//        BASE64Encoder encoder = new BASE64Encoder();
509//        encoder.encode( bufferedImage );
510
511        PngEncoder pngEncoder = new PngEncoder();
512        pngEncoder.setImage( image );
513        byte[] bytes = pngEncoder.pngEncode();
514
515        //final BufferedImage bufferedImage = ImageHelper.createBufferedImage( timeSeriesPlot );
516        final BufferedImage bufferedImage = new BufferedImage( 400, 400, BufferedImage.TYPE_INT_RGB );
517        final Graphics2D g2 = bufferedImage.createGraphics();
518        timeSeriesPlot.paint( g2 );
519        g2.dispose();
520
521        final PngEncoderB pngEncoderB = new PngEncoderB();
522        pngEncoderB.setImage( bufferedImage );
523        final byte[] bytesB = pngEncoderB.pngEncode();
524
525        final JSONObject result = new JSONObject();
526        result.put( ParameterConstants.PARAMETER_IMAGE, bytesB );
527        return result;
528//        return new JSONObject();
529    }
530
531//    public void searchDatasByPlateformByParameterByPeriod( final HttpServletRequest request, final HttpServletResponse response )
532//            throws ParseException, ServiceException, IOException
533//    {
534//        final TimeSeriesPlot timeSeriesPlot = createPlot();
535//        final Image image = timeSeriesPlot.createImage( 400, 400 );
536//
537//        //final BufferedImage bufferedImage = ImageHelper.createBufferedImage( timeSeriesPlot );
538//        final BufferedImage bufferedImage = new BufferedImage( 400, 400, BufferedImage.TYPE_INT_RGB );
539//        final Graphics2D g2 = bufferedImage.createGraphics();
540//        timeSeriesPlot.paint( g2 );
541//        g2.dispose();
542//
543//        final PngEncoderB pngEncoderB = new PngEncoderB();
544//        pngEncoderB.setImage( bufferedImage );
545//        final byte[] bytesB = pngEncoderB.pngEncode();
546//
547//        ImageIO.write( (RenderedImage) image, "png", response.getOutputStream() );
548//    }
549//
550//    private TimeSeriesPlot createPlot()
551//            throws ParseException, ServiceException
552//    {
553//
554//        final String parameterName = "OZONE";
555//        final String parameterUnit = "ppbv";
556//        final boolean startToZero = true;
557//        final boolean markPoint = false;
558//
559//        final GeoDateArray dateArray = createTimeArray( 10, null );
560//        final double[] dataArray = createDataArray( 10, 5 );
561//
562//        final SimpleLine data = new SimpleLine( dateArray, dataArray, "legend" );
563//        SGTMetaData meta = new SGTMetaData( "Longitude", "degrees East", false, false );
564//        data.setXMetaData( meta );
565//
566//        meta = new SGTMetaData( parameterName, parameterUnit, false, false );
567//        data.setYMetaData( meta );
568//
569//        final LineAttribute lineAttribute = new LineAttribute( LineAttribute.SOLID, Color.red );
570//
571//        final TimeSeriesPlot timeSeriesPlot = new TimeSeriesPlot();
572//        timeSeriesPlot.setTitle( "Keroppi title" );
573//        timeSeriesPlot.setLogoMegapoli( "keroppi1.jpg" );
574//        timeSeriesPlot.setData( data );
575//        timeSeriesPlot.setLineAttribute( lineAttribute );
576//
577//        timeSeriesPlot.createTimeSeriesPlot();
578//        return timeSeriesPlot;
579//    }
580//
581//    private JPlotLayout createLayout( @Nullable final String plateformName, @Nullable final String parameterName )
582//    {
583//        final JFrame frame = new JFrame( "Frame principale" );
584//        final JPanel panel = new JPanel( new BorderLayout() );
585//
586//        final JLabel jlbHelloWorld = new JLabel( "Hello World" );
587//        panel.add( jlbHelloWorld, BorderLayout.SOUTH );
588//
589//        final ImageIcon ic = new ImageIcon( "kerropi1.jpg" );
590//        final JLabel jLabel = new JLabel( ic );
591//        panel.add( jLabel, BorderLayout.EAST );
592//
593//        final JPlotLayout jPlotLayout = new JPlotLayout( false, false, false, "Trajectory data", null, false );
594//        jPlotLayout.setTitles( plateformName, parameterName, "title3" );
595////            jPlotLayout.setTitleHeightP(0.2, 0.2);
596//        jPlotLayout.setVisible( true );
597//        panel.add( jPlotLayout, BorderLayout.NORTH );
598//
599//        panel.setVisible( true );
600//        frame.setContentPane( panel );
601//
602//        frame.setSize( 700, 550 );
603//        frame.setVisible( true );
604//
605//        return jPlotLayout;
606//    }
607
608//    @ControllerMethod(jsonResult = true)
609//    public JSONObject searchDatasByPlateformByParameterByPeriod(
610//              @Mandatory @ParamName(ParameterConstants.PARAMETER_PLATEFORM_ID) final Integer plateformId,
611//              @Mandatory @ParamName(ParameterConstants.PARAMETER_PARAMETER_ID) final Integer parameterId,
612//              @ParamName(ParameterConstants.PARAMETER_DATE_BEGIN) final String dateBegin,
613//              @ParamName(ParameterConstants.PARAMETER_DATE_END) final String dateEnd)
614//      throws ServiceException, WebException, ParseException
615//    {
616//      final long time1 = Calendar.getInstance().getTimeInMillis();
617//      LOGGER.error("Date Controller begin : "+Calendar.getInstance().getTime());
618////            final Date formatedDateBegin = DateHelper.parseDate(dateBegin, DateHelper.ENGLISH_DATE_PATTERN_SHORT);
619////            final Date formatedDateEnd = DateHelper.parseDate(dateEnd, DateHelper.ENGLISH_DATE_PATTERN_SHORT);
620//
621//      final Date formatedDateBegin = null;
622//      final Date formatedDateEnd = null;
623//
624//      final long time2 = Calendar.getInstance().getTimeInMillis();
625//      LOGGER.error("Date Controller before request : "+Calendar.getInstance().getTime()+", Duration : "+(time2-time1));
626//              final List<Data> values = _etherService.getValuesByPlateformByParameterByPeriod(plateformId, parameterId, formatedDateBegin, formatedDateEnd);
627//      final long time3 = Calendar.getInstance().getTimeInMillis();
628//      LOGGER.error("Date Controller after request : "+Calendar.getInstance().getTime()+", Duration : "+(time3-time2));
629//
630//      final JSONObject result = new JSONObject();
631//      result.put( ParameterConstants.PARAMETER_VALUES, values );
632//      final long time4 = Calendar.getInstance().getTimeInMillis();
633//      LOGGER.error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
634//      LOGGER.error("Date Controller before return Result : "+Calendar.getInstance().getTime()+", Duration : "+(time4-time3)+", Total : "+(time4-time1)+", Taille : "+values.size());
635//      LOGGER.error("plateformId : "+plateformId+", parameterId : "+parameterId);
636//      LOGGER.error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
637//      return result;
638//    }
639
640//      private void createPlot() {
641//              JPlotLayout layout_ = new JPlotLayout(false, false, false,
642//                              "Trajectory data", null, false);
643//              /*
644//               * Batch changes to layout.
645//               */
646//              layout_.setBatch(true);
647//              /*
648//               * Set the titles.
649//               */
650//              layout_.setTitles(
651//                              "Steller's Sea Lion Climate Research Profiling Floats",
652//                              "Trajectories", "");
653//              /*
654//               * Change the title sizes from the defaults. (0.25, 0.15)
655//               */
656//              layout_.setTitleHeightP(0.2, 0.2);
657//              /*
658//               * Use a BorderLayout for the JFrame and and the JPlotLayout to the
659//               * "Center". Pack the frame and make it visible.
660//               */
661//              JFrame pif = new JFrame();
662//              pif.getContentPane().setLayout(new BorderLayout());
663//              pif.getContentPane().add(layout_, BorderLayout.CENTER);
664//              pif.pack();
665//              pif.setVisible(true);
666//              /*
667//               * Read trajectory data from local file
668//               */
669//              SGTData data = readTrajectory("service/implementation/com/ether/tutorial/data/trajectory");
670//              /*
671//               * Add the trajectory data to the plot using the data title as the data
672//               * description. The description is used in the LineKey.
673//               */
674//              layout_.addData(data, data.getTitle());
675//              /*
676//               * Read the North Pacific hi-resolution coastline and add it to the
677//               * layout. Coastlines are handled differently by JPlotLayout. Coastlines
678//               * are not used to compute the X and Y ranges and are always clipped to
679//               * the axes.
680//               */
681//              // SGTLine coastLine = getCoastLine("support/npac_hi_rez", 120000);
682//              // layout_.setCoastLine(coastLine);
683//              /*
684//               * Turn batching off. All batched changes to the JPlotLayout will now be
685//               * executed.
686//               */
687//              layout_.setBatch(false);
688//      }
689
690
691//    public void doGet_OK( final HttpServletRequest request, final HttpServletResponse response )
692//            throws ServletException, IOException
693//    {
694//        final JFrame frame = new JFrame( "Frame principale" );
695//        final JPanel panel = new JPanel( new BorderLayout() );
696//
697//        final JLabel jlbHelloWorld = new JLabel( "Hello World" );
698//        panel.add( jlbHelloWorld, BorderLayout.SOUTH );
699//
700//        final ImageIcon ic = new ImageIcon( "/home_local/workspaces/Megapoli/kerropi1.jpg" );
701//        final JLabel jLabel = new JLabel( ic );
702//        panel.add( jLabel, BorderLayout.EAST );
703//
704//        final JPlotLayout jPlotLayout = new JPlotLayout( false, false, false, "Trajectory data", null, false );
705//        jPlotLayout.setTitles( "title1", "title2", "title3" );
706//        jPlotLayout.setVisible( true );
707//        panel.add( jPlotLayout, BorderLayout.NORTH );
708//
709//        panel.setVisible( true );
710//        frame.setContentPane( panel );
711//
712//        frame.setSize( MAIN_WIDTH, 550 );
713//        frame.setVisible( true );
714//
715//        final BufferedImage bufferedImage = new BufferedImage( frame.getWidth(), frame.getHeight(), BufferedImage.TYPE_INT_RGB );
716//
717//        final Graphics2D g2 = bufferedImage.createGraphics();
718//        frame.paint( g2 );
719//        g2.dispose();
720//
721//        try
722//        {
723//            final File out = new File( "/home_local/workspaces/Megapoli/test_JPlotLayout.jpg" );
724//            ImageIO.write( bufferedImage, "JPEG", out );
725//        }
726//        catch( Exception e )
727//        {
728//        }
729//        ImageIO.write( bufferedImage, "JPEG", response.getOutputStream() );
730//    }
731//
732//    public void doGet_OKK( final HttpServletRequest request, final HttpServletResponse response )
733//            throws ServletException, IOException
734//    {
735//        try
736//        {
737//            final GeoDateArray dateArray = createTimeArray( 10, null );
738//            final double[] dataArray = createDataArray( 10, 5 );
739//
740//            final SimpleLine data = new SimpleLine( dateArray, dataArray, "legend" );
741//            SGTMetaData meta = new SGTMetaData( "Longitude", "degrees East", false, false );
742//            data.setXMetaData( meta );
743//
744//            meta = new SGTMetaData( "parameterName", "parameterUnit", false, false );
745//            data.setYMetaData( meta );
746//
747//            final JPane jPane = new JPane();
748//
749//            final JLabel jlbHelloWorld = new JLabel( "Hello World" );
750//            jPane.add( jlbHelloWorld, BorderLayout.SOUTH );
751//
752//            final ImageIcon ic = new ImageIcon( "/home_local/workspaces/Megapoli/kerropi1.jpg" );
753//            final JLabel jLabel = new JLabel( ic );
754//            jPane.add( jLabel, BorderLayout.EAST );
755//
756//            final JPlotLayout jPlotLayout = new JPlotLayout( false, true, false, "Trajectory data", null, false );
757//            jPlotLayout.setTitles( "title1", "title2", "title3" );
758//            jPlotLayout.addData( data, data.getTitle() );
759//            jPlotLayout.setVisible( true );
760//            jPane.add( jPlotLayout, BorderLayout.EAST );
761//
762//            jPane.setVisible( true );
763//
764//
765//            final BufferedImage bufferedImage = new BufferedImage( jPlotLayout.getWidth(), jPlotLayout.getHeight(), BufferedImage.TYPE_INT_RGB );
766//            final Graphics2D graphics2D = bufferedImage.createGraphics();
767//            graphics2D.setBackground( Color.WHITE );
768//            jPlotLayout.getComponent().addNotify();
769//            jPlotLayout.getComponent().validate();
770//
771//            jPlotLayout.draw( graphics2D );
772//
773//            try
774//            {
775//                final File outFile = new File( "/home_local/workspaces/Megapoli/keroppi_out.jpg" );
776//                ImageIO.write( bufferedImage, "jpg", outFile );
777//            }
778//            catch( Exception e )
779//            {
780//                throw new IOException( e );
781//            }
782//            ImageIO.write( bufferedImage, "png", response.getOutputStream() );
783//        }
784//        catch( Exception e )
785//        {
786//            throw new IOException( e );
787//        }
788//    }
789
790
791    // Dimensions of the jPanes
792    private static final int MAIN_WIDTH = 1000;
793    private static final int MAIN_HEIGHT = 1000;
794}
Note: See TracBrowser for help on using the repository browser.