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

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

[Visualization] interface quite finish

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