source: ether_megapoli/trunk/service/test/com/ether/EtherTest.java @ 134

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

[Visualization] plot

File size: 3.3 KB
Line 
1package com.ether;
2
3import gov.noaa.pmel.sgt.LineAttribute;
4import gov.noaa.pmel.util.GeoDateArray;
5import org.jetbrains.annotations.NotNull;
6import org.jetbrains.annotations.Nullable;
7import org.junit.Test;
8
9import javax.imageio.ImageIO;
10import javax.swing.*;
11import java.awt.*;
12import java.awt.image.BufferedImage;
13import java.io.File;
14import java.io.Serializable;
15import java.text.ParseException;
16import java.util.Date;
17
18/**
19 * @author vmipsl
20 * @date 2011
21 */
22public class EtherTest
23{
24    /**
25     * @param day : jour au format yyyy-MM-dd
26     */
27//    @NotNull
28//    protected List<Data> createDataList( @NotNull final Integer sizeList, @Nullable String day )
29//            throws ParseException
30//    {
31//        if( null == day )
32//            day = "2009-07-13";
33//
34//        final List<Data> dataList = new ArrayList<Data>();
35//        for( int i = 0; i < sizeList; i++ )
36//        {
37//            final String dateString = day + " " + i + ":32";
38//            final Date date = DateHelper.parseDate( dateString, DateHelper.ENGLISH_DATE_PATTERN );
39//
40//            final Data data = new Data();
41//            data.setDate( date );
42//            data.setValue( i );
43//
44//            dataList.add( data );
45//        }
46//        return dataList;
47//    }
48
49    /**
50     * @param day : jour au format yyyy-MM-dd
51     */
52    @NotNull
53    protected GeoDateArray createTimeArray( @NotNull final Integer size, @Nullable String day )
54            throws ParseException
55    {
56        if( null == day )
57            day = "2009-07-13";
58
59        final Date[] dates = new Date[size];
60        for( int i = 0; i < size; i++ )
61        {
62            final String dateString = day + ' ' + i + ":32";
63            final Date date = DateHelper.parseDate( dateString, DateHelper.ENGLISH_DATE_PATTERN );
64            dates[i] = date;
65        }
66        return new GeoDateArray( dates );
67    }
68
69    @NotNull
70    protected double[] createDataArray( @NotNull final Integer size, @NotNull final Integer begin )
71            throws ParseException
72    {
73        final double[] datas = new double[size];
74        for( int i = 0; i < size; i++ )
75        {
76            datas[i] = Double.valueOf( i + begin );
77        }
78        return datas;
79    }
80
81    protected void copyToFile( @NotNull final JFrame frame, @NotNull final String fileName )
82    {
83        final BufferedImage image = new BufferedImage( frame.getWidth(), frame.getHeight(), BufferedImage.TYPE_INT_RGB );
84
85        final Graphics2D g2 = image.createGraphics();
86        frame.paint( g2 );
87        g2.dispose();
88
89        try
90        {
91            final File out = new File( fileName );
92            ImageIO.write( image, "JPEG", out );
93        }
94        catch( Exception e )
95        {
96        }
97    }
98
99    protected <T extends Serializable> void displayArray( @NotNull final T[] objectsArray )
100    {
101        for( int i = 0; i < objectsArray.length; i++ )
102            System.out.println( objectsArray[i].toString() );
103    }
104
105    @NotNull
106    public LineAttribute createLineAttribute( final boolean markPoint )
107    {
108        final LineAttribute lineAttribute = new LineAttribute( LineAttribute.SOLID, Color.red );
109        if( markPoint )
110        {
111            lineAttribute.setStyle( LineAttribute.MARK );
112            // int to display cross
113            lineAttribute.setMark( 2 );
114        }
115        return lineAttribute;
116    }
117
118
119}
Note: See TracBrowser for help on using the repository browser.