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

Last change on this file since 294 was 294, checked in by vmipsl, 12 years ago

clean : suppression du EtherException?

File size: 33.5 KB
Line 
1package com.ether;
2
3import com.ether.annotation.ControllerMethod;
4import com.ether.annotation.Mandatory;
5import com.ether.annotation.ParamName;
6//import com.ether.tutorial.src.tutorial.Example1;
7//import com.ether.tutorial.src.tutorial.SBExample1;
8//import com.ether.tutorial.src.tutorial.SBExample2;
9//import com.ether.tutorial.src.tutorial.SBExample3;
10//import com.keypoint.PngEncoder;
11//import com.keypoint.PngEncoderB;
12import gov.noaa.pmel.sgt.JPane;
13import gov.noaa.pmel.sgt.LineAttribute;
14import gov.noaa.pmel.sgt.beans.*;
15import gov.noaa.pmel.sgt.dm.SGTMetaData;
16import gov.noaa.pmel.sgt.dm.SimpleLine;
17import gov.noaa.pmel.sgt.swing.JPlotLayout;
18import gov.noaa.pmel.util.GeoDateArray;
19import net.sf.json.JSONObject;
20import org.jetbrains.annotations.NotNull;
21import org.jetbrains.annotations.Nullable;
22import org.junit.Test;
23
24import javax.imageio.ImageIO;
25import javax.servlet.ServletException;
26import javax.servlet.http.HttpServletResponse;
27import javax.swing.*;
28import java.awt.*;
29import java.awt.image.BufferedImage;
30import java.io.File;
31import java.io.FileInputStream;
32import java.io.IOException;
33import java.text.ParseException;
34import java.util.Date;
35import java.util.Map;
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 MegapoliPlot timeSeriesPlot = new MegapoliPlot();
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 MegapoliPlot 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 MegapoliPlot timeSeriesPlot = new MegapoliPlot();
421        timeSeriesPlot.setTitle( "Keroppi title" );
422        timeSeriesPlot.setLogoMegapoli( "keroppi1.jpg" );
423//        timeSeriesPlot.setData( data );
424//        timeSeriesPlot.setLineAttribute( lineAttribute );
425
426        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    @ControllerMethod(jsonResult = true)
485    public JSONObject searchDatasByPlateformByParameterByPeriod(
486            @Mandatory @ParamName(ParameterConstants.PARAMETER_PLATEFORM_ID) final Integer plateformId,
487            @Mandatory @ParamName(ParameterConstants.PARAMETER_PARAMETER_ID) final Integer parameterId,
488            @ParamName(ParameterConstants.PARAMETER_DATE_BEGIN) final String dateBegin,
489            @ParamName(ParameterConstants.PARAMETER_DATE_END) final String dateEnd )
490            throws ServiceException, ParseException
491    {
492//        final String pofBegin = "2009-07-13 13:00";
493//        final String pofEnd = "2009-07-13 14:00";
494//        final Date formatedDateBegin = DateHelper.parseDate( pofBegin, DateHelper.ENGLISH_DATE_PATTERN );
495//        final Date formatedDateEnd = DateHelper.parseDate( pofEnd, DateHelper.ENGLISH_DATE_PATTERN );
496
497//        final Plateforme plateform = _etherService.getPlateformById( plateformId );
498//        final Parametre parameter = _etherService.getParameterById( parameterId );
499//        final List<Data> values = _etherService.getValuesByPlateformByParameterByPeriod( plateformId, parameterId, formatedDateBegin, formatedDateEnd );
500
501        //JPlotLayout layout = createLayout( plateform.getPlateformeNom(), parameter.getParametreNom() );
502//        final TimeSeriesPlot timeSeriesPlot = createPlot();
503//        final Image image = timeSeriesPlot.createImage( 400, 400 );
504
505//        BufferedImage bufferedImage = toBufferedImage( image );
506//        BASE64Encoder encoder = new BASE64Encoder();
507//        encoder.encode( bufferedImage );
508
509//        PngEncoder pngEncoder = new PngEncoder();
510//        pngEncoder.setImage( image );
511//        byte[] bytes = pngEncoder.pngEncode();
512
513        //final BufferedImage bufferedImage = ImageHelper.createBufferedImage( timeSeriesPlot );
514        final BufferedImage bufferedImage = new BufferedImage( 400, 400, BufferedImage.TYPE_INT_RGB );
515        final Graphics2D g2 = bufferedImage.createGraphics();
516//        timeSeriesPlot.paint( g2 );
517        g2.dispose();
518
519//        final PngEncoderB pngEncoderB = new PngEncoderB();
520//        pngEncoderB.setImage( bufferedImage );
521//        final byte[] bytesB = pngEncoderB.pngEncode();
522
523        final JSONObject result = new JSONObject();
524//        result.put( ParameterConstants.PARAMETER_IMAGE, bytesB );
525        return result;
526//        return new JSONObject();
527    }
528
529//    public void searchDatasByPlateformByParameterByPeriod( final HttpServletRequest request, final HttpServletResponse response )
530//            throws ParseException, ServiceException, IOException
531//    {
532//        final TimeSeriesPlot timeSeriesPlot = createPlot();
533//        final Image image = timeSeriesPlot.createImage( 400, 400 );
534//
535//        //final BufferedImage bufferedImage = ImageHelper.createBufferedImage( timeSeriesPlot );
536//        final BufferedImage bufferedImage = new BufferedImage( 400, 400, BufferedImage.TYPE_INT_RGB );
537//        final Graphics2D g2 = bufferedImage.createGraphics();
538//        timeSeriesPlot.paint( g2 );
539//        g2.dispose();
540//
541//        final PngEncoderB pngEncoderB = new PngEncoderB();
542//        pngEncoderB.setImage( bufferedImage );
543//        final byte[] bytesB = pngEncoderB.pngEncode();
544//
545//        ImageIO.write( (RenderedImage) image, "png", response.getOutputStream() );
546//    }
547//
548//    private TimeSeriesPlot createPlot()
549//            throws ParseException, ServiceException
550//    {
551//
552//        final String parameterName = "OZONE";
553//        final String parameterUnit = "ppbv";
554//        final boolean startToZero = true;
555//        final boolean markPoint = false;
556//
557//        final GeoDateArray dateArray = createTimeArray( 10, null );
558//        final double[] dataArray = createDataArray( 10, 5 );
559//
560//        final SimpleLine data = new SimpleLine( dateArray, dataArray, "legend" );
561//        SGTMetaData meta = new SGTMetaData( "Longitude", "degrees East", false, false );
562//        data.setXMetaData( meta );
563//
564//        meta = new SGTMetaData( parameterName, parameterUnit, false, false );
565//        data.setYMetaData( meta );
566//
567//        final LineAttribute lineAttribute = new LineAttribute( LineAttribute.SOLID, Color.red );
568//
569//        final TimeSeriesPlot timeSeriesPlot = new TimeSeriesPlot();
570//        timeSeriesPlot.setTitle( "Keroppi title" );
571//        timeSeriesPlot.setLogoMegapoli( "keroppi1.jpg" );
572//        timeSeriesPlot.setData( data );
573//        timeSeriesPlot.setLineAttribute( lineAttribute );
574//
575//        timeSeriesPlot.createTimeSeriesPlot();
576//        return timeSeriesPlot;
577//    }
578//
579//    private JPlotLayout createLayout( @Nullable final String plateformName, @Nullable final String parameterName )
580//    {
581//        final JFrame frame = new JFrame( "Frame principale" );
582//        final JPanel panel = new JPanel( new BorderLayout() );
583//
584//        final JLabel jlbHelloWorld = new JLabel( "Hello World" );
585//        panel.add( jlbHelloWorld, BorderLayout.SOUTH );
586//
587//        final ImageIcon ic = new ImageIcon( "kerropi1.jpg" );
588//        final JLabel jLabel = new JLabel( ic );
589//        panel.add( jLabel, BorderLayout.EAST );
590//
591//        final JPlotLayout jPlotLayout = new JPlotLayout( false, false, false, "Trajectory data", null, false );
592//        jPlotLayout.setTitles( plateformName, parameterName, "title3" );
593////            jPlotLayout.setTitleHeightP(0.2, 0.2);
594//        jPlotLayout.setVisible( true );
595//        panel.add( jPlotLayout, BorderLayout.NORTH );
596//
597//        panel.setVisible( true );
598//        frame.setContentPane( panel );
599//
600//        frame.setSize( 700, 550 );
601//        frame.setVisible( true );
602//
603//        return jPlotLayout;
604//    }
605
606//    @ControllerMethod(jsonResult = true)
607//    public JSONObject searchDatasByPlateformByParameterByPeriod(
608//              @Mandatory @ParamName(ParameterConstants.PARAMETER_PLATEFORM_ID) final Integer plateformId,
609//              @Mandatory @ParamName(ParameterConstants.PARAMETER_PARAMETER_ID) final Integer parameterId,
610//              @ParamName(ParameterConstants.PARAMETER_DATE_BEGIN) final String dateBegin,
611//              @ParamName(ParameterConstants.PARAMETER_DATE_END) final String dateEnd)
612//      throws ServiceException, EtherException, ParseException
613//    {
614//      final long time1 = Calendar.getInstance().getTimeInMillis();
615//      LOGGER.error("Date Controller begin : "+Calendar.getInstance().getTime());
616////            final Date formatedDateBegin = DateHelper.parseDate(dateBegin, DateHelper.ENGLISH_DATE_PATTERN_SHORT);
617////            final Date formatedDateEnd = DateHelper.parseDate(dateEnd, DateHelper.ENGLISH_DATE_PATTERN_SHORT);
618//
619//      final Date formatedDateBegin = null;
620//      final Date formatedDateEnd = null;
621//
622//      final long time2 = Calendar.getInstance().getTimeInMillis();
623//      LOGGER.error("Date Controller before request : "+Calendar.getInstance().getTime()+", Duration : "+(time2-time1));
624//              final List<Data> values = _etherService.getValuesByPlateformByParameterByPeriod(plateformId, parameterId, formatedDateBegin, formatedDateEnd);
625//      final long time3 = Calendar.getInstance().getTimeInMillis();
626//      LOGGER.error("Date Controller after request : "+Calendar.getInstance().getTime()+", Duration : "+(time3-time2));
627//
628//      final JSONObject result = new JSONObject();
629//      result.put( ParameterConstants.PARAMETER_VALUES, values );
630//      final long time4 = Calendar.getInstance().getTimeInMillis();
631//      LOGGER.error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
632//      LOGGER.error("Date Controller before return Result : "+Calendar.getInstance().getTime()+", Duration : "+(time4-time3)+", Total : "+(time4-time1)+", Taille : "+values.size());
633//      LOGGER.error("plateformId : "+plateformId+", parameterId : "+parameterId);
634//      LOGGER.error("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
635//      return result;
636//    }
637
638//      private void createPlot() {
639//              JPlotLayout layout_ = new JPlotLayout(false, false, false,
640//                              "Trajectory data", null, false);
641//              /*
642//               * Batch changes to layout.
643//               */
644//              layout_.setBatch(true);
645//              /*
646//               * Set the titles.
647//               */
648//              layout_.setTitles(
649//                              "Steller's Sea Lion Climate Research Profiling Floats",
650//                              "Trajectories", "");
651//              /*
652//               * Change the title sizes from the defaults. (0.25, 0.15)
653//               */
654//              layout_.setTitleHeightP(0.2, 0.2);
655//              /*
656//               * Use a BorderLayout for the JFrame and and the JPlotLayout to the
657//               * "Center". Pack the frame and make it visible.
658//               */
659//              JFrame pif = new JFrame();
660//              pif.getContentPane().setLayout(new BorderLayout());
661//              pif.getContentPane().add(layout_, BorderLayout.CENTER);
662//              pif.pack();
663//              pif.setVisible(true);
664//              /*
665//               * Read trajectory data from local file
666//               */
667//              SGTData data = readTrajectory("service/implementation/com/ether/tutorial/data/trajectory");
668//              /*
669//               * Add the trajectory data to the plot using the data title as the data
670//               * description. The description is used in the LineKey.
671//               */
672//              layout_.addData(data, data.getTitle());
673//              /*
674//               * Read the North Pacific hi-resolution coastline and add it to the
675//               * layout. Coastlines are handled differently by JPlotLayout. Coastlines
676//               * are not used to compute the X and Y ranges and are always clipped to
677//               * the axes.
678//               */
679//              // SGTLine coastLine = getCoastLine("support/npac_hi_rez", 120000);
680//              // layout_.setCoastLine(coastLine);
681//              /*
682//               * Turn batching off. All batched changes to the JPlotLayout will now be
683//               * executed.
684//               */
685//              layout_.setBatch(false);
686//      }
687
688
689//    public void doGet_OK( final HttpServletRequest request, final HttpServletResponse response )
690//            throws ServletException, IOException
691//    {
692//        final JFrame frame = new JFrame( "Frame principale" );
693//        final JPanel panel = new JPanel( new BorderLayout() );
694//
695//        final JLabel jlbHelloWorld = new JLabel( "Hello World" );
696//        panel.add( jlbHelloWorld, BorderLayout.SOUTH );
697//
698//        final ImageIcon ic = new ImageIcon( "/home_local/workspaces/Megapoli/kerropi1.jpg" );
699//        final JLabel jLabel = new JLabel( ic );
700//        panel.add( jLabel, BorderLayout.EAST );
701//
702//        final JPlotLayout jPlotLayout = new JPlotLayout( false, false, false, "Trajectory data", null, false );
703//        jPlotLayout.setTitles( "title1", "title2", "title3" );
704//        jPlotLayout.setVisible( true );
705//        panel.add( jPlotLayout, BorderLayout.NORTH );
706//
707//        panel.setVisible( true );
708//        frame.setContentPane( panel );
709//
710//        frame.setSize( MAIN_WIDTH, 550 );
711//        frame.setVisible( true );
712//
713//        final BufferedImage bufferedImage = new BufferedImage( frame.getWidth(), frame.getHeight(), BufferedImage.TYPE_INT_RGB );
714//
715//        final Graphics2D g2 = bufferedImage.createGraphics();
716//        frame.paint( g2 );
717//        g2.dispose();
718//
719//        try
720//        {
721//            final File out = new File( "/home_local/workspaces/Megapoli/test_JPlotLayout.jpg" );
722//            ImageIO.write( bufferedImage, "JPEG", out );
723//        }
724//        catch( Exception e )
725//        {
726//        }
727//        ImageIO.write( bufferedImage, "JPEG", response.getOutputStream() );
728//    }
729//
730//    public void doGet_OKK( final HttpServletRequest request, final HttpServletResponse response )
731//            throws ServletException, IOException
732//    {
733//        try
734//        {
735//            final GeoDateArray dateArray = createTimeArray( 10, null );
736//            final double[] dataArray = createDataArray( 10, 5 );
737//
738//            final SimpleLine data = new SimpleLine( dateArray, dataArray, "legend" );
739//            SGTMetaData meta = new SGTMetaData( "Longitude", "degrees East", false, false );
740//            data.setXMetaData( meta );
741//
742//            meta = new SGTMetaData( "parameterName", "parameterUnit", false, false );
743//            data.setYMetaData( meta );
744//
745//            final JPane jPane = new JPane();
746//
747//            final JLabel jlbHelloWorld = new JLabel( "Hello World" );
748//            jPane.add( jlbHelloWorld, BorderLayout.SOUTH );
749//
750//            final ImageIcon ic = new ImageIcon( "/home_local/workspaces/Megapoli/kerropi1.jpg" );
751//            final JLabel jLabel = new JLabel( ic );
752//            jPane.add( jLabel, BorderLayout.EAST );
753//
754//            final JPlotLayout jPlotLayout = new JPlotLayout( false, true, false, "Trajectory data", null, false );
755//            jPlotLayout.setTitles( "title1", "title2", "title3" );
756//            jPlotLayout.addData( data, data.getTitle() );
757//            jPlotLayout.setVisible( true );
758//            jPane.add( jPlotLayout, BorderLayout.EAST );
759//
760//            jPane.setVisible( true );
761//
762//
763//            final BufferedImage bufferedImage = new BufferedImage( jPlotLayout.getWidth(), jPlotLayout.getHeight(), BufferedImage.TYPE_INT_RGB );
764//            final Graphics2D graphics2D = bufferedImage.createGraphics();
765//            graphics2D.setBackground( Color.WHITE );
766//            jPlotLayout.getComponent().addNotify();
767//            jPlotLayout.getComponent().validate();
768//
769//            jPlotLayout.draw( graphics2D );
770//
771//            try
772//            {
773//                final File outFile = new File( "/home_local/workspaces/Megapoli/keroppi_out.jpg" );
774//                ImageIO.write( bufferedImage, "jpg", outFile );
775//            }
776//            catch( Exception e )
777//            {
778//                throw new IOException( e );
779//            }
780//            ImageIO.write( bufferedImage, "png", response.getOutputStream() );
781//        }
782//        catch( Exception e )
783//        {
784//            throw new IOException( e );
785//        }
786//    }
787
788
789    public void createTimeSeriesPlot()
790            throws ServiceException
791    {
792        // Enable WindowEvents. Set the layout of the content pane to a BorderLayout.
793//        enableEvents( AWTEvent.WINDOW_EVENT_MASK );
794//        getContentPane().setLayout( new BorderLayout() );
795//
796//        // Add the page object to graphicPanel
797//        getjPanel().add( getPage(), BorderLayout.CENTER );
798//
799//        // DATA MODEL
800//        getPage().setDataModel( getDataModel() );
801//
802//        // PANEL MODEL
803//        final PanelModel panelModel = extractPanelModel();
804//        setPanelModel( panelModel );
805//        getPage().setPanelModel( getPanelModel() );
806//
807//        // PANEL HOLDER
808//        final PanelHolder panelHolder = panelModel.findPanelHolder( PANEL_GRAPH );
809//        if( null != panelHolder )
810//        {
811//            changeTitle( getTitle(), panelHolder.getLabels() );
812//            changeLogos( panelHolder.getLabels() );
813//
814//
815//            final DataGroup dataGroup = panelHolder.findDataGroup( DATA_GROUP );
816//            final Legend timeLegend = panelHolder.findLegend( LEGEND );
817//            getDataModel().addData( getData(), getLineAttribute(), panelHolder, dataGroup, timeLegend );
818//        }
819//        else
820//            getDataModel().addData( getData(), getLineAttribute(), panelHolder, null, null );
821//
822////        final PanelHolder panelHolderImage = panelModel.findPanelHolder( PANEL_IMAGE );
823////        getDataModel().addData( getData(), getLineAttribute(), panelHolderImage, null, null);
824//
825//        // Add the graphic to the content pane of the JFrame.
826//        getContentPane().add( getjPanel(), BorderLayout.CENTER );
827    }
828
829//    private void changeTitle( @Nullable final String title, @Nullable final Map panelHolderLabels )
830//    {
831////        if( null != title && null != panelHolderLabels && null != panelHolderLabels.get( LABEL_TITLE ) )
832////        {
833////            final gov.noaa.pmel.sgt.beans.Label labelTitle = (gov.noaa.pmel.sgt.beans.Label) panelHolderLabels.get( LABEL_TITLE );
834////            labelTitle.setText( title );
835////        }
836//    }
837//
838//
839//    private void changeLogos( @Nullable final Map panelHolderLabels )
840//    {
841//        if( null != getLogoMegapoli() && null != panelHolderLabels && null != panelHolderLabels.get( LABEL_LOGO_MEGAPOLI ) )
842//        {
843//            final gov.noaa.pmel.sgt.beans.Label labelLogoMegapoli = (gov.noaa.pmel.sgt.beans.Label) panelHolderLabels.get( LABEL_LOGO_MEGAPOLI );
844//            labelLogoMegapoli.setText( getLogoMegapoli() );
845//        }
846//    }
847//
848//    /**
849//     * Create panelModel by de-serializing an existing PanelModel.
850//     * The file megapoli.xml was created using gov.noaa.pmel.sgt.beans.PanelModelEditor.
851//     */
852//    private PanelModel extractPanelModel()
853//            throws ServiceException
854//    {
855//        try
856//        {
857//            return PanelModel.loadFromXML( getClass().getResource( FILE_NAME ).openStream() );
858//        }
859//        catch( Exception e )
860//        {
861//            throw new ServiceException( ServiceException.ServiceCode.PANEL_MODEL_NOT_FOUND, e );
862//        }
863//    }
864
865    @NotNull
866    public LineAttribute createLineAttribute( final boolean markPoint )
867    {
868        final LineAttribute lineAttribute = new LineAttribute( LineAttribute.SOLID, Color.red );
869        if( markPoint )
870        {
871            lineAttribute.setStyle( LineAttribute.MARK );
872            // int to display cross
873            lineAttribute.setMark( 2 );
874        }
875        return lineAttribute;
876    }
877
878
879    // Dimensions of the jPanes
880    private static final int MAIN_WIDTH = 1000;
881    private static final int MAIN_HEIGHT = 1000;
882}
Note: See TracBrowser for help on using the repository browser.