Changeset 182 for ether_megapoli


Ignore:
Timestamp:
09/06/11 15:11:09 (13 years ago)
Author:
vmipsl
Message:

Servlet _ contour et line ok

Location:
ether_megapoli/trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • ether_megapoli/trunk/applets/src/com/ether/AppletTimeSerie.java

    r178 r182  
    8282 
    8383        // Graph Pane 
    84         final JPane jPaneGraph = _etherPlotService.createTimeSeriePlot( megapoliPlot ); 
     84        final JPane jPaneGraph = _etherPlotService.createTimeSeriePlot( megapoliPlot, 600, 600 ); 
    8585        add( jPaneGraph, BorderLayout.CENTER ); 
    8686    } 
  • ether_megapoli/trunk/service/implementation/com/ether/EtherPlotServiceImpl.java

    r181 r182  
    22 
    33import com.medias.megapoli.utils.MegapoliInitialisation; 
    4 import gov.noaa.pmel.sgt.CartesianGraph; 
    5 import gov.noaa.pmel.sgt.ColorMap; 
    6 import gov.noaa.pmel.sgt.ContourLevels; 
    7 import gov.noaa.pmel.sgt.Graph; 
    8 import gov.noaa.pmel.sgt.GridAttribute; 
    9 import gov.noaa.pmel.sgt.IndexedColorMap; 
    104import gov.noaa.pmel.sgt.JPane; 
    11 import gov.noaa.pmel.sgt.Layer; 
    12 import gov.noaa.pmel.sgt.LineAttribute; 
    13 import gov.noaa.pmel.sgt.LineCartesianRenderer; 
    14 import gov.noaa.pmel.sgt.LineKey; 
    15 import gov.noaa.pmel.sgt.LinearTransform; 
    16 import gov.noaa.pmel.sgt.PlainAxis; 
    17 import gov.noaa.pmel.sgt.SGLabel; 
    18 import gov.noaa.pmel.sgt.StackedLayout; 
    19 import gov.noaa.pmel.sgt.TimeAxis; 
    20 import gov.noaa.pmel.sgt.demo.TestData; 
    21 import gov.noaa.pmel.sgt.dm.SGTData; 
    22 import gov.noaa.pmel.sgt.dm.SGTMetaData; 
    23 import gov.noaa.pmel.sgt.dm.SimpleGrid; 
    24 import gov.noaa.pmel.sgt.dm.SimpleLine; 
    25 import gov.noaa.pmel.sgt.swing.JPlotLayout; 
    26 import gov.noaa.pmel.util.Dimension2D; 
    27 import gov.noaa.pmel.util.GeoDate; 
    28 import gov.noaa.pmel.util.GeoDateArray; 
    29 import gov.noaa.pmel.util.IllegalTimeValue; 
    30 import gov.noaa.pmel.util.Point2D; 
    31 import gov.noaa.pmel.util.Range2D; 
    32 import gov.noaa.pmel.util.SoTPoint; 
    33 import gov.noaa.pmel.util.SoTRange; 
    34 import gov.noaa.pmel.util.TimeRange; 
    355import org.apache.commons.logging.Log; 
    366import org.apache.commons.logging.LogFactory; 
     
    399 
    4010import javax.swing.*; 
    41 import javax.swing.border.EtchedBorder; 
    4211import java.awt.*; 
    4312import java.awt.image.BufferedImage; 
    4413import java.util.Calendar; 
    45 import java.util.Date; 
    4614import java.util.Locale; 
    4715import java.util.ResourceBundle; 
     
    5220 */ 
    5321public class EtherPlotServiceImpl 
     22        extends EtherPlotContentServiceImpl 
    5423        implements EtherPlotService 
    5524{ 
     
    6736 
    6837    /** 
    69      * Create the main JPane with the 3 jPanes 
     38     * Create the main JPane with the 3 jPanes : top, center (graph) et bottom 
    7039     * 
    7140     * @param megapoliPlot 
     
    268237    public BufferedImage createCenterPane( @NotNull final MegapoliPlot megapoliPlot, @NotNull final Integer maxWidth, @NotNull final Integer maxHeight, @Nullable final Locale locale ) 
    269238    { 
    270 //        final Integer plotWidth = Math.min( maxWidth - MARGIN_LEFT_RIGHT, maxWidth ); 
    271 //        final Integer plotHeight = Math.min( maxHeight - MARGIN_LEFT_RIGHT, maxHeight ); 
    272  
    273 //        final JPlotLayout jPlotLayout; 
    274 //        final BufferedImage bufferedImage; 
    275 //        if( megapoliPlot.isTimeSerie() ) 
    276 //        { 
    277 //            jPlotLayout = createJPlotLayoutForTimeSerie( megapoliPlot, plotWidth, plotHeight ); 
    278 // 
    279 //            // TODO : remove this change to bufferedImage to insert directly the jPlotLayout !!!! 
    280 //            bufferedImage = new BufferedImage( jPlotLayout.getWidth(), jPlotLayout.getHeight(), BufferedImage.TYPE_INT_RGB ); 
    281 //            final Graphics2D graphics2D = bufferedImage.createGraphics(); 
    282 //            jPlotLayout.draw( graphics2D ); 
    283 //        } 
    284 //        else 
    285 //        { 
    286 //            jPlotLayout = createJPlotLayoutFor2D( megapoliPlot, plotWidth, plotHeight, locale ); 
    287 // 
    288 //            final JPanelToImageManager jPanelToImageManager = new JPanelToImageManager( jPlotLayout ); 
    289 //            bufferedImage = jPanelToImageManager.saveAsImage(); 
    290 //        } 
    291 // 
    292 //        final ImageIcon imageIcon = new ImageIcon( bufferedImage ); 
    293 //        final JLabel jLabelPlot = new JLabel( imageIcon, JLabel.CENTER ); 
    294 //        jLabelPlot.setBorder( BorderFactory.createLineBorder( Color.black, 1 ) ); 
    295 // 
    296 //        final JPane jPaneCenter = new JPane( "Center jPane", new Dimension( jPlotLayout.getWidth(), jPlotLayout.getHeight() ) ); 
    297 //        jPaneCenter.setLayout( new GridBagLayout() ); 
    298 //        jPaneCenter.add( jLabelPlot, 
    299 //                new GridBagConstraints( 0, 0, 1, 1, 0, 0, 
    300 //                        GridBagConstraints.CENTER, 
    301 //                        GridBagConstraints.CENTER, 
    302 //                        new Insets( 0, 0, 0, 0 ), 0, 0 ) ); 
    303 // 
    304 //        return jPaneCenter; 
    305  
    306         if( AxeTypeForFixedPlateform.TIME_LINE.name().equals( megapoliPlot.getAxeType() ) || AxeTypeForFixedPlateform.TIME_POINTS.name().equals( megapoliPlot.getAxeType() ) ) 
    307         { 
    308             final JPane jPaneGraph = createTimeSeriePlot( megapoliPlot ); 
    309             final BufferedImage bufferedImage = new BufferedImage( 600, 600, BufferedImage.TYPE_INT_ARGB ); 
    310             final Graphics2D graphics2D = bufferedImage.createGraphics(); 
    311 //        graphics2D.setBackground( Color.WHITE ); 
    312             jPaneGraph.addNotify(); 
    313             jPaneGraph.validate(); 
    314             jPaneGraph.draw( graphics2D ); 
    315             return bufferedImage; 
    316 //            final JPanelToImageManager jPanelToImageManager = new JPanelToImageManager( jPaneGraph ); 
    317 //            return jPanelToImageManager.saveAsImage(); 
    318         } 
    319         else 
    320         { 
    321             final JPane jPaneGraph = create2DPlot( megapoliPlot ); 
    322             final BufferedImage bufferedImage = new BufferedImage( 600, 600, BufferedImage.TYPE_INT_BGR ); 
    323             final Graphics2D graphics2D = bufferedImage.createGraphics(); 
    324             jPaneGraph.addNotify(); 
    325             jPaneGraph.validate(); 
    326             jPaneGraph.draw( graphics2D ); 
    327             return bufferedImage; 
    328         } 
    329     } 
    330  
    331     /** 
    332      * First layer contains axes, labels and the first set of data 
    333      * Others layers contains only the other sets of data 
    334      * 
    335      * @param megapoliPlot 
    336      * @return 
    337      */ 
    338     @NotNull 
    339     public JPane createTimeSeriePlot( @NotNull final MegapoliPlot megapoliPlot ) 
    340     { 
    341         final JPane mainPane = new JPane( "zz", new Dimension( 600, 600 ) ); 
    342         mainPane.setLayout( new StackedLayout() ); 
    343         mainPane.setBorder( BorderFactory.createLineBorder( Color.pink ) ); 
    344  
    345 //        // Graph 
    346 ////        final JPlotLayoutEther jPlotLayout = new JPlotLayoutEther( false, true, false, "Trajectory data", null, megapoliPlot.isLegendToHide() ); 
    347 //        final JPlotLayout jPlotLayout = new JPlotLayout( data, "Profile Demo", null, false ); 
    348 //        jPlotLayout.setTitles( "", "", "" ); 
    349  
    350         /** ***************************** **/ 
    351         /** *********** LINES ************ **/ 
    352         /** ***************************** **/ 
    353         final double[] dataArray = (double[]) megapoliPlot.getData().getFirstArray(); 
    354         final Date[] dateValues = (Date[]) megapoliPlot.getData().getSecondArray(); 
    355  
    356         final SimpleLine line0 = new SimpleLine( new GeoDateArray( dateValues ), dataArray, "legend" ); 
    357         SGTMetaData meta = new SGTMetaData( "", "", false, false ); 
    358         line0.setXMetaData( meta ); 
    359  
    360         meta = new SGTMetaData( megapoliPlot.getParameterName(), megapoliPlot.getParameterUnitCode(), false, false ); 
    361         line0.setYMetaData( meta ); 
    362  
    363  
    364         SimpleLine line; 
    365         GeoDate start = null; 
    366         GeoDate stop = null; 
    367         TimeRange tr; 
    368         TestData td; 
    369         try 
    370         { 
    371             start = new GeoDate( "1992-11-01", "yyyy-MM-dd" ); 
    372             stop = new GeoDate( "1993-02-20", "yyyy-MM-dd" ); 
    373         } 
    374         catch( IllegalTimeValue e ) 
    375         { 
    376         } 
    377         tr = new TimeRange( start, stop ); 
    378         td = new TestData( TestData.TIME_SERIES, tr, 1.0f, 
    379                 TestData.RANDOM, 1.2f, 0.5f, 30.0f ); 
    380         line = (SimpleLine) td.getSGTData(); 
    381  
    382  
    383         /** ***************************** **/ 
    384         /** *********** AXIS ************ **/ 
    385         /** ***************************** **/ 
    386         final SoTRange ynRange; 
    387         final SoTRange yRange; 
    388         final SoTRange tnRange; 
    389         final String yLabel; 
    390         yRange = line.getYRange(); 
    391 //        yRange.add( line2.getYRange() ); 
    392         tnRange = line.getXRange(); 
    393         final Integer intervalsNumber = 10; 
    394         ynRange = Graph.computeRange( yRange, intervalsNumber ); 
    395         yLabel = line.getYMetaData().getName(); 
    396  
    397  
    398         /** ***************************** **/ 
    399         /** *********** LAYERS ********** **/ 
    400         /** ***************************** **/ 
    401         /* 
    402         * xsize, ysize are the width and height in physical units 
    403         * of the Layer graphics region. 
    404         * 
    405         * xstart, xend are the start and end points for the TimeAxis 
    406         * ystart, yend are the start and end points for the Y axis 
    407         */ 
    408         final double xsize = 4.0; 
    409         final double xstart = 0.6; 
    410         final double xend = 3.25; 
    411         final double ysize = 4.0; 
    412         final double ystart = 0.6; 
    413         final double yend = 2.50; 
    414  
    415         Layer layer2; 
    416         SGLabel label, title, ytitle; 
    417         CartesianGraph graph, graph2; 
    418         LinearTransform xt, yt; 
    419         PlainAxis yleft; 
    420         TimeAxis xbot; 
    421         LineKey lkey; 
    422         GeoDate stime; 
    423  
    424         final Layer layer = new Layer( "First Layer", new Dimension2D( xsize, ysize ) ); 
    425  
    426         /** ***************************** **/ 
    427         /** *********** LEGENDS ********* **/ 
    428         /** ***************************** **/ 
    429         /* 
    430         * create a LineKey 
    431         * the LineKey will be a legend for the two lines created 
    432         * position the key in the upper right corner 
    433         * and add to the first layer 
    434         */ 
    435         lkey = new LineKey(); 
    436         lkey.setId( "Legend" ); 
    437         lkey.setLocationP( new Point2D.Double( xsize - 1, ysize - 1 ) ); 
    438         lkey.setVAlign( LineKey.TOP ); 
    439         lkey.setHAlign( LineKey.RIGHT ); 
    440         layer.addChild( lkey ); 
    441         /* 
    442         * add the first layer to the Pane 
    443         */ 
    444         mainPane.add( layer ); 
    445         /* 
    446         * create first CartesianGraph and transforms 
    447         */ 
    448         graph = new CartesianGraph( "First Graph" ); 
    449         xt = new LinearTransform( new Range2D( xstart, xend ), tnRange ); 
    450         graph.setXTransform( xt ); 
    451         yt = new LinearTransform( new Range2D( ystart, yend ), ynRange ); 
    452         graph.setYTransform( yt ); 
    453         /* 
    454         * Create the time axis, set its range in user units 
    455         * and its origin. Add the axis to the first graph. 
    456         */ 
    457         SoTPoint point = new SoTPoint( ynRange.getStart(), tnRange.getStart() ); 
    458         xbot = new TimeAxis( "Bottom Axis", TimeAxis.MONTH_YEAR ); 
    459         xbot.setRangeU( tnRange ); 
    460         xbot.setLocationU( point ); 
    461         Font xbfont = new Font( "Helvetica", Font.ITALIC, 14 ); 
    462         xbot.setLabelFont( xbfont ); 
    463         xbot.setMinorLabelInterval( 1 ); 
    464         graph.addXAxis( xbot ); 
    465         /* 
    466         * Create the vertical axis, set its range in user units 
    467         * and its origin.  Create the axis title and add the 
    468         * axis to the first graph. 
    469         */ 
    470         yleft = new PlainAxis( "Left Axis" ); 
    471         yleft.setRangeU( ynRange ); 
    472         yleft.setLocationU( point ); 
    473         yleft.setLabelFont( xbfont ); 
    474         ytitle = new SGLabel( "Y-Axis Title", yLabel, 
    475                 new Point2D.Double( 0.0, 0.0 ) ); 
    476         Font ytfont = new Font( "Helvetica", Font.PLAIN, 14 ); 
    477         ytitle.setFont( ytfont ); 
    478         ytitle.setHeightP( 0.2 ); 
    479         yleft.setTitle( ytitle ); 
    480         graph.addYAxis( yleft ); 
    481         /* 
    482         * Add the first graph to the first layer. 
    483         */ 
    484         layer.setGraph( graph ); 
    485         /* 
    486         * Create a LineAttribute for the display of the first 
    487         * line. Associate the attribute and the line with the 
    488         * first graph.  Add the line to the LineKey. 
    489         */ 
    490         LineAttribute attr; 
    491  
    492         attr = new LineAttribute( LineAttribute.MARK, 20, Color.red ); 
    493         attr.setMarkHeightP( 0.1 ); 
    494         graph.setData( line, attr ); 
    495         lkey.addLineGraph( (LineCartesianRenderer) graph.getRenderer(), 
    496                 new SGLabel( "1st line", "Red Data", 
    497                         new Point2D.Double( 0.0, 0.0 ) ) ); 
    498         /* 
    499         * Create the second layer and add it the the Pane. 
    500         * Create the second graph and associate it with the 
    501         * second layer. 
    502         */ 
    503 //        layer2 = new Layer( "Second Layer", new Dimension2D( xsize, ysize ) ); 
    504 //        mainPane.add( layer2 ); 
    505 //        graph2 = new CartesianGraph( "Second Graph", xt, yt ); 
    506 //        layer2.setGraph( graph2 ); 
    507         /* 
    508         * Create a LineAttribute for the display of the second 
    509         * line. Associate the attribute and the line with the 
    510         * second graph.  Add the line to the LineKey. 
    511         */ 
    512 //        LineAttribute attr2; 
    513 //        attr2 = new LineAttribute( LineAttribute.MARK, 2, Color.blue ); 
    514 //        attr2.setMarkHeightP( 0.1 ); 
    515 //        graph2.setData( line2, attr2 ); 
    516 //        lkey.addLineGraph( (LineCartesianRenderer) graph2.getRenderer(), 
    517 //                new SGLabel( "2nd line", "Blue Data", 
    518 //                        new Point2D.Double( 0.0, 0.0 ) ) ); 
    519  
    520         return mainPane; 
    521     } 
    522  
    523     @NotNull 
    524     public JPane create2DPlot( @NotNull final MegapoliPlot megapoliPlot ) 
    525     { 
    526         /* 
    527        * This example uses a pre-created "Layout" for raster time 
    528        * series to simplify the construction of a plot. The 
    529        * JPlotLayout can plot a single grid with 
    530        * a ColorKey, time series with a LineKey, point collection with a 
    531        * PointCollectionKey, and general X-Y plots with a 
    532        * LineKey. JPlotLayout supports zooming, object selection, and 
    533        * object editing. 
    534         */ 
    535         SGTData newData; 
    536         TestData td; 
    537         JPlotLayout rpl; 
    538         ContourLevels clevels; 
    539         /* 
    540        * Create a test grid with sinasoidal-ramp data. 
    541         */ 
    542         Range2D xr = new Range2D( 190.0f, 250.0f, 1.0f ); 
    543         Range2D yr = new Range2D( 0.0f, 45.0f, 1.0f ); 
    544         td = new TestData( TestData.XY_GRID, xr, yr, 
    545                 TestData.SINE_RAMP, 12.0f, 30.f, 5.0f ); 
    546         newData = td.getSGTData(); 
    547         /* 
    548        * Create the layout without a Logo image and with the 
    549        * ColorKey on a separate Pane object. 
    550         */ 
    551         rpl = new JPlotLayout( true, false, false, "JGridDemo Pane", null, true ); 
    552         rpl.setEditClasses( false ); 
    553         /* 
    554        * Create a GridAttribute for CONTOUR style. 
    555         */ 
    556         Range2D datar = new Range2D( -20.0f, 45.0f, 5.0f ); 
    557         clevels = ContourLevels.getDefault( datar ); 
    558         GridAttribute gridAttr_ = new GridAttribute( clevels ); 
    559         /* 
    560        * Create a ColorMap and change the style to RASTER_CONTOUR. 
    561         */ 
    562         ColorMap cmap = createColorMap( datar ); 
    563         gridAttr_.setColorMap( cmap ); 
    564         gridAttr_.setStyle( GridAttribute.RASTER_CONTOUR ); 
    565         /* 
    566        * Add the grid to the layout and give a label for 
    567        * the ColorKey. 
    568         */ 
    569         rpl.addData( newData, gridAttr_, "First Data" ); 
    570         /* 
    571        * Change the layout's three title lines. 
    572         */ 
    573         rpl.setTitles( "Raster Plot Demo", 
    574                 "using a JPlotLayout", 
    575                 "" ); 
    576         /* 
    577        * Resize the graph  and place in the "Center" of the frame. 
    578         */ 
    579         rpl.setSize( new Dimension( 600, 400 ) ); 
    580         /* 
    581        * Resize the key Pane, both the device size and the physical 
    582        * size. Set the size of the key in physical units and place 
    583        * the key pane at the "South" of the frame. 
    584         */ 
    585 //    rpl.setKeyLayerSizeP(new Dimension2D(6.0, 1.02)); 
    586 //    rpl.setKeyBoundsP(new Rectangle2D.Double(0.01, 1.01, 5.98, 1.0)); 
    587  
    588         return rpl; 
    589     } 
    590  
    591     @NotNull 
    592     public JPanel createControlPanel() 
    593     { 
    594         final JPanel controlPanel = new JPanel(); 
    595         final ButtonGroup gridtype = new ButtonGroup(); 
    596         final JCheckBox stacked = new JCheckBox(); 
    597         final JCheckBox grid = new JCheckBox(); 
    598  
    599         controlPanel.setLayout( new GridBagLayout() ); 
    600 //    controlPanel.setBackground(new java.awt.Color(200,200,200)); 
    601         controlPanel.setBounds( 0, 679, 426, 33 ); 
    602         controlPanel.setBorder( new EtchedBorder() ); 
    603         gridtype.add( stacked ); 
    604         stacked.setSelected( true ); 
    605         stacked.setText( "Overlayed" ); 
    606  
    607         GridBagConstraints gbc = new GridBagConstraints(); 
    608         gbc.gridx = 0; 
    609         gbc.gridy = 0; 
    610         gbc.gridwidth = 1; 
    611         gbc.gridheight = 1; 
    612         gbc.weightx = 0.0; 
    613         gbc.weighty = 1.0; 
    614         gbc.anchor = GridBagConstraints.EAST; 
    615         gbc.fill = GridBagConstraints.BOTH; 
    616         gbc.insets = new Insets( 5, 15, 5, 5 ); 
    617         gbc.ipadx = 0; 
    618         gbc.ipady = 0; 
    619         controlPanel.add( stacked, gbc ); 
    620         stacked.setBounds( 15, 5, 84, 23 ); 
    621         gridtype.add( grid ); 
    622         grid.setText( "Grid" ); 
    623  
    624         gbc.gridx = 1; 
    625         gbc.gridy = 0; 
    626         gbc.gridwidth = 1; 
    627         gbc.gridheight = 1; 
    628         gbc.weightx = 0.5; 
    629         gbc.weighty = 1.0; 
    630         gbc.anchor = GridBagConstraints.WEST; 
    631         gbc.fill = GridBagConstraints.VERTICAL; 
    632         gbc.insets = new Insets( 5, 5, 5, 0 ); 
    633         gbc.ipadx = 0; 
    634         gbc.ipady = 0; 
    635         controlPanel.add( grid, gbc ); 
    636         grid.setBounds( 109, 5, 53, 23 ); 
    637         final JButton showTree = new JButton(); 
    638         showTree.setText( "Show Class Tree" ); 
    639  
    640         gbc.gridx = 2; 
    641         gbc.gridy = 0; 
    642         gbc.gridwidth = 1; 
    643         gbc.gridheight = 1; 
    644         gbc.weightx = 1.0; 
    645         gbc.weighty = 1.0; 
    646         gbc.anchor = GridBagConstraints.EAST; 
    647         gbc.fill = GridBagConstraints.VERTICAL; 
    648         gbc.insets = new Insets( 5, 5, 5, 15 ); 
    649         gbc.ipadx = 0; 
    650         gbc.ipady = 0; 
    651         controlPanel.add( showTree, gbc ); 
    652         showTree.setBackground( Color.yellow.brighter() ); 
    653         showTree.setBounds( 302, 5, 109, 23 ); 
    654  
    655         final SymItem lSymItem = new SymItem( stacked, grid ); 
    656         stacked.addItemListener( lSymItem ); 
    657         grid.addItemListener( lSymItem ); 
    658 //        SymAction lSymAction = new SymAction(); 
    659 //        showTree.addActionListener( lSymAction ); 
    660  
    661         return controlPanel; 
    662     } 
    663  
    664     /** 
    665      * Create the center JPane with the graph 
    666      * 
    667      * @param megapoliPlot 
    668      * @param maxWidth 
    669      * @param maxHeight 
    670      * @return 
    671      */ 
    672     @NotNull 
    673     public JPane createCenterPaneOld( @NotNull final MegapoliPlot megapoliPlot, @NotNull final Integer maxWidth, @NotNull final Integer maxHeight, @Nullable final Locale locale ) 
    674     { 
    675239        final Integer plotWidth = Math.min( maxWidth - MARGIN_LEFT_RIGHT, maxWidth ); 
    676240        final Integer plotHeight = Math.min( maxHeight - MARGIN_LEFT_RIGHT, maxHeight ); 
    677241 
    678         final JPlotLayout jPlotLayout; 
    679         final BufferedImage bufferedImage; 
    680         if( megapoliPlot.isTimeSerie() ) 
    681         { 
    682             jPlotLayout = createJPlotLayoutForTimeSerie( megapoliPlot, plotWidth, plotHeight ); 
    683  
    684             // TODO : remove this change to bufferedImage to insert directly the jPlotLayout !!!! 
    685             bufferedImage = new BufferedImage( jPlotLayout.getWidth(), jPlotLayout.getHeight(), BufferedImage.TYPE_INT_RGB ); 
    686             final Graphics2D graphics2D = bufferedImage.createGraphics(); 
    687             jPlotLayout.draw( graphics2D ); 
    688         } 
     242        final JPane jPaneGraph; 
     243 
     244        if( AxeTypeForFixedPlateform.TIME_LINE.name().equals( megapoliPlot.getAxeType() ) || AxeTypeForFixedPlateform.TIME_POINTS.name().equals( megapoliPlot.getAxeType() ) ) 
     245            jPaneGraph = createTimeSeriePlot( megapoliPlot, plotWidth, plotHeight ); 
    689246        else 
    690         { 
    691             jPlotLayout = createJPlotLayoutFor2D( megapoliPlot, plotWidth, plotHeight, locale ); 
    692  
    693             final JPanelToImageManager jPanelToImageManager = new JPanelToImageManager( jPlotLayout ); 
    694             bufferedImage = jPanelToImageManager.saveAsImage(); 
    695         } 
    696  
    697         final ImageIcon imageIcon = new ImageIcon( bufferedImage ); 
    698         final JLabel jLabelPlot = new JLabel( imageIcon, JLabel.CENTER ); 
    699         jLabelPlot.setBorder( BorderFactory.createLineBorder( Color.black, 1 ) ); 
    700  
    701         final JPane jPaneCenter = new JPane( "Center jPane", new Dimension( jPlotLayout.getWidth(), jPlotLayout.getHeight() ) ); 
    702         jPaneCenter.setLayout( new GridBagLayout() ); 
    703         jPaneCenter.add( jLabelPlot, 
    704                 new GridBagConstraints( 0, 0, 1, 1, 0, 0, 
    705                         GridBagConstraints.CENTER, 
    706                         GridBagConstraints.CENTER, 
    707                         new Insets( 0, 0, 0, 0 ), 0, 0 ) ); 
    708  
    709         return jPaneCenter; 
    710     } 
    711  
    712     /** 
    713      * Change the Pane layout to StackedLayout. 
    714      * 
    715      * @param event 
    716      */ 
    717  
    718     void stacked_itemStateChanged( java.awt.event.ItemEvent event ) 
    719     { 
    720         /* 
    721         * Get the component list for mainPane_ and change 
    722         * the layout to StackedLayout. 
    723         */ 
    724 //        Component[] comps = mainPane_.getComponents(); 
    725 //        mainPane_.setBatch( true ); 
    726 //        mainPane_.setLayout( new StackedLayout() ); 
    727 //        /* 
    728 //        * Remove any axes that have been associated with 
    729 //        * the second graph.  With the layers overlayed it 
    730 //        * is not necessary to have duplicate axes. 
    731 //        */ 
    732 //        Graph gr2 = ( (Layer) comps[1] ).getGraph(); 
    733 //        ( (CartesianGraph) gr2 ).removeAllXAxes(); 
    734 //        ( (CartesianGraph) gr2 ).removeAllYAxes(); 
    735 //        /* 
    736 //        * Tell the Applet that the mainPane_ needs to 
    737 //        * be layed out and re-draw the mainPane_. 
    738 //        */ 
    739 //        if( isApplet_ ) 
    740 //        { 
    741 //            validate(); 
    742 //        } 
    743 //        else 
    744 //        { 
    745 //            frame.validate(); 
    746 //        } 
    747 //        mainPane_.setBatch( false ); 
    748 //        if( tree_ != null ) 
    749 //        { 
    750 //            if( tree_.isVisible() ) 
    751 //            { 
    752 //                tree_.setJPane( mainPane_ ); 
    753 //                tree_.expandTree(); 
    754 //            } 
    755 //        } 
    756     } 
    757  
    758     /** 
    759      * Change the Pane layout to GridLayout. 
    760      * 
    761      * @param event 
    762      */ 
    763  
    764     void grid_itemStateChanged( java.awt.event.ItemEvent event ) 
    765     { 
    766         /* 
    767         * Get the component list for mainPane_ and change 
    768         * the layout to GridLayout. 
    769         */ 
    770 //        Component[] comps = mainPane_.getComponents(); 
    771 //        mainPane_.setBatch( true ); 
    772 //        mainPane_.setLayout( new GridLayout( 2, 0 ) ); 
    773 //        /* 
    774 //        * Get the first and second graphs from the first 
    775 //        * and second layers, respectively. 
    776 //        */ 
    777 //        Graph gr = ( (Layer) comps[0] ).getGraph(); 
    778 //        Graph gr2 = ( (Layer) comps[1] ).getGraph(); 
    779 //        /* 
    780 //        * Create copies of all X-Axes associated with the first 
    781 //        * graph for the second graph. If the axes are not copied then 
    782 //        * the second graph will have the second line plotted, but without 
    783 //        * any axes. 
    784 //        */ 
    785 //        for( Enumeration xa = ( (CartesianGraph) gr ).xAxisElements(); xa.hasMoreElements(); ) 
    786 //        { 
    787 //            ( (CartesianGraph) gr2 ).addXAxis( ( (Axis) xa.nextElement() ).copy() ); 
    788 //        } 
    789 //        /* 
    790 //        * Create copies of all Y-Axes associated with the first 
    791 //        * graph for the second graph. 
    792 //        */ 
    793 //        for( Enumeration ya = ( (CartesianGraph) gr ).yAxisElements(); ya.hasMoreElements(); ) 
    794 //        { 
    795 //            ( (CartesianGraph) gr2 ).addYAxis( ( (Axis) ya.nextElement() ).copy() ); 
    796 //        } 
    797 //        /* 
    798 //        * Tell the Applet that the mainPane_ needs to 
    799 //        * be layed out and re-draw the mainPane_. 
    800 //        */ 
    801 //        if( isApplet_ ) 
    802 //        { 
    803 //            validate(); 
    804 //        } 
    805 //        else 
    806 //        { 
    807 //            frame.validate(); 
    808 //        } 
    809 //        //    mainPane_.draw(); 
    810 //        mainPane_.setBatch( false ); 
    811 //        if( tree_ != null ) 
    812 //        { 
    813 //            if( tree_.isVisible() ) 
    814 //            { 
    815 //                tree_.setJPane( mainPane_ ); 
    816 //                tree_.expandTree(); 
    817 //            } 
    818 //        } 
    819     } 
    820  
    821     void showTree_ActionPerformed( java.awt.event.ActionEvent event ) 
    822     { 
    823 //        /* 
    824 //        * Create the ClassTree dialog to display the classes used 
    825 //        * in the mainPane_ and allow editing. 
    826 //        */ 
    827 //        if( tree_ == null ) 
    828 //        { 
    829 //            tree_ = new JClassTree( "Classes for LayoutDemo" ); 
    830 //        } 
    831 //        tree_.setJPane( mainPane_ ); 
    832 //        tree_.show(); 
    833     } 
    834  
    835     @NotNull 
    836     private JPlotLayout createJPlotLayoutForTimeSerie( final MegapoliPlot megapoliPlot, final Integer plotWidth, final Integer plotHeight ) 
    837     { 
    838         final double[] dataArray = (double[]) megapoliPlot.getData().getFirstArray(); 
    839         final Date[] dateValues = (Date[]) megapoliPlot.getData().getSecondArray(); 
    840  
    841         final SimpleLine data = new SimpleLine( new GeoDateArray( dateValues ), dataArray, "legend" ); 
    842         SGTMetaData meta = new SGTMetaData( null, null, false, false ); 
    843         data.setXMetaData( meta ); 
    844  
    845         meta = new SGTMetaData( megapoliPlot.getParameterName(), megapoliPlot.getParameterUnitCode(), false, false ); 
    846         data.setYMetaData( meta ); 
    847  
    848         // Graph 
    849 //        final JPlotLayoutEther jPlotLayout = new JPlotLayoutEther( false, true, false, "Trajectory data", null, megapoliPlot.isLegendToHide() ); 
    850         final JPlotLayout jPlotLayout = new JPlotLayout( data, "Profile Demo", null, false ); 
    851         jPlotLayout.setTitles( "", "", "" ); 
    852  
    853         // Replace legend 
    854 //        final String legend = megapoliPlot.getData().getTitle(); 
    855 //        final Dimension2D layerSizeP = jPlotLayout.getLayerSizeP(); 
    856 //        final double factorForPlotWidthInPhysicalUnits = layerSizeP.getWidth() / Double.valueOf( plotWidth ); 
    857 //        final double legendSizeInPhysicalUnits = legend.length() * factorForPlotWidthInPhysicalUnits * 7; 
    858 //        jPlotLayout.setKeyLocationP( new Point2D.Double( layerSizeP.getWidth() - legendSizeInPhysicalUnits, layerSizeP.getHeight() - 0.1 ) ); 
    859  
    860         // Add data and legend 
    861         jPlotLayout.addData( data, "" ); 
    862         jPlotLayout.setSize( plotWidth, plotHeight ); 
    863         jPlotLayout.setVisible( true ); 
    864  
    865         jPlotLayout.addNotify(); 
    866         jPlotLayout.validate(); 
    867         jPlotLayout.setOpaque( true ); 
    868         return jPlotLayout; 
    869     } 
    870  
    871     @NotNull 
    872     private JPlotLayout createJPlotLayoutFor2D( final MegapoliPlot megapoliPlot, final Integer plotWidth, final Integer plotHeight, @Nullable final Locale locale ) 
    873     { 
    874         SGTData newData; 
    875         TestData td; 
    876         JPlotLayout rpl; 
    877         ContourLevels clevels; 
    878         /* 
    879        * Create a test grid with sinasoidal-ramp data. 
    880         */ 
    881         Range2D xr = new Range2D( 190.0f, 250.0f, 1.0f ); 
    882         Range2D yr = new Range2D( 0.0f, 45.0f, 1.0f ); 
    883         td = new TestData( TestData.XY_GRID, xr, yr, 
    884                 TestData.SINE_RAMP, 12.0f, 30.f, 5.0f ); 
    885         newData = td.getSGTData(); 
    886         /* 
    887        * Create the layout without a Logo image and with the 
    888        * ColorKey on a separate Pane object. 
    889         */ 
    890         rpl = new JPlotLayout( true, false, false, "JGridDemo Pane", null, true ); 
    891         rpl.setEditClasses( false ); 
    892         /* 
    893        * Create a GridAttribute for CONTOUR style. 
    894         */ 
    895         Range2D datar = new Range2D( -20.0f, 45.0f, 5.0f ); 
    896         clevels = ContourLevels.getDefault( datar ); 
    897         final GridAttribute gridAttr_ = new GridAttribute( clevels ); 
    898         /* 
    899        * Create a ColorMap and change the style to RASTER_CONTOUR. 
    900         */ 
    901         ColorMap cmap = createColorMap( datar ); 
    902         gridAttr_.setColorMap( cmap ); 
    903         gridAttr_.setStyle( GridAttribute.RASTER_CONTOUR ); 
    904         /* 
    905        * Add the grid to the layout and give a label for 
    906        * the ColorKey. 
    907         */ 
    908         rpl.addData( newData, gridAttr_, "First Data" ); 
    909         /* 
    910        * Change the layout's three title lines. 
    911         */ 
    912         rpl.setTitles( "Raster Plot Demo", "using a JPlotLayout", "" ); 
    913         /* 
    914        * Resize the graph  and place in the "Center" of the frame. 
    915         */ 
    916         rpl.setSize( new Dimension( 600, 400 ) ); 
    917         /* 
    918        * Resize the key Pane, both the device size and the physical 
    919        * size. Set the size of the key in physical units and place 
    920        * the key pane at the "South" of the frame. 
    921         */ 
    922 //    rpl.setKeyLayerSizeP(new Dimension2D(6.0, 1.02)); 
    923 //    rpl.setKeyBoundsP(new Rectangle2D.Double(0.01, 1.01, 5.98, 1.0)); 
    924  
    925         return rpl; 
    926     } 
    927  
    928     @NotNull 
    929     private JPlotLayout createJPlotLayoutFor2DOrig( final MegapoliPlot megapoliPlot, final Integer plotWidth, final Integer plotHeight, @Nullable final Locale locale ) 
    930     { 
    931         final ResourceBundle bundle = WebHelper.getBundle( locale ); 
    932  
    933         final double[] parameterArray = (double[]) megapoliPlot.getData().getFirstArray(); 
    934         final double[] latitudeArray = (double[]) megapoliPlot.getData().getSecondArray(); 
    935         final double[] longitudeValues = (double[]) megapoliPlot.getData().getThirdArray(); 
    936  
    937 //        final SimpleLine data = new SimpleLine( longitudeValues, latitudeArray, "legend" ); 
    938         final SimpleGrid data = new SimpleGrid( parameterArray, longitudeValues, latitudeArray, "Test Series" ); 
    939         SGTMetaData meta = new SGTMetaData( bundle.getString( "plot.longitude" ), bundle.getString( "plot.degres" ), false, true ); 
    940         // TODO : vérifier modulo = 360 
    941 //        meta.setModuloValue( 360 ); 
    942         data.setXMetaData( meta ); 
    943  
    944         meta = new SGTMetaData( bundle.getString( "plot.latitude" ), bundle.getString( "plot.degres" ), false, true ); 
    945         // TODO : vérifier modulo = 360 
    946 //        meta.setModuloValue( 360 ); 
    947         data.setYMetaData( meta ); 
    948  
    949         // Graph 
    950         final JPlotLayout jPlotLayout = new JPlotLayout( true, false, false, "JGridDemo Pane", null, true ); 
    951         jPlotLayout.setEditClasses( false ); 
    952         /* 
    953        * Create a GridAttribute for CONTOUR style. 
    954         */ 
    955         final Range2D datar = new Range2D( -20.0f, 45.0f, 5.0f ); 
    956         final ContourLevels clevels = ContourLevels.getDefault( datar ); 
    957         final GridAttribute gridAttr = new GridAttribute( clevels ); 
    958         /* 
    959        * Create a ColorMap and change the style to RASTER_CONTOUR. 
    960         */ 
    961         final ColorMap cmap = createColorMap( datar ); 
    962         gridAttr.setColorMap( cmap ); 
    963         gridAttr.setStyle( GridAttribute.RASTER_CONTOUR ); 
    964         /* 
    965        * Add the grid to the layout and give a label for 
    966        * the ColorKey. 
    967         */ 
    968         jPlotLayout.addData( data, gridAttr, "First Data" ); 
    969  
    970 //        final JPlotLayoutEther jPlotLayout = new JPlotLayoutEther( false, megapoliPlot.isXTime(), false, "Trajectory data", null, megapoliPlot.isLegendToHide() ); 
    971 //        jPlotLayout.setTitles( "", "", "" ); 
    972  
    973         // Replace legend 
    974 //        final String legend = megapoliPlot.getData().getTitle(); 
    975 //        final Dimension2D layerSizeP = jPlotLayout.getLayerSizeP(); 
    976 //        final double factorForPlotWidthInPhysicalUnits = layerSizeP.getWidth() / Double.valueOf( plotWidth ); 
    977 //        final double legendSizeInPhysicalUnits = legend.length() * factorForPlotWidthInPhysicalUnits * 7; 
    978 //        jPlotLayout.setKeyLocationP( new Point2D.Double( layerSizeP.getWidth() - legendSizeInPhysicalUnits, layerSizeP.getHeight() - 0.1 ) ); 
    979  
    980         // Add data and legend 
    981 //        jPlotLayout.addData( megapoliPlot.getData(), legend ); 
    982         jPlotLayout.setSize( plotWidth, plotHeight ); 
    983         jPlotLayout.setVisible( true ); 
    984  
    985         jPlotLayout.addNotify(); 
    986         jPlotLayout.validate(); 
    987         jPlotLayout.setOpaque( true ); 
    988         return jPlotLayout; 
    989     } 
    990  
    991     @NotNull 
    992     private String formatTitle( @Nullable final String title ) 
    993     { 
    994         if( null == title ) 
    995             return ""; 
    996         else 
    997         { 
    998             final String formatTitle = title.replaceAll( "\\n", "<br>" ); 
    999             return "<html>" + formatTitle + "</html>"; 
    1000         } 
    1001     } 
    1002  
    1003     @NotNull 
    1004     private ColorMap createColorMap( final Range2D datar ) 
    1005     { 
    1006         final int[] red = 
    1007                 {0, 0, 0, 0, 0, 0, 0, 0, 
    1008                         0, 0, 0, 0, 0, 0, 0, 0, 
    1009                         0, 0, 0, 0, 0, 0, 0, 0, 
    1010                         0, 7, 23, 39, 55, 71, 87, 103, 
    1011                         119, 135, 151, 167, 183, 199, 215, 231, 
    1012                         247, 255, 255, 255, 255, 255, 255, 255, 
    1013                         255, 255, 255, 255, 255, 255, 255, 255, 
    1014                         255, 246, 228, 211, 193, 175, 158, 140}; 
    1015         final int[] green = 
    1016                 {0, 0, 0, 0, 0, 0, 0, 0, 
    1017                         0, 11, 27, 43, 59, 75, 91, 107, 
    1018                         123, 139, 155, 171, 187, 203, 219, 235, 
    1019                         251, 255, 255, 255, 255, 255, 255, 255, 
    1020                         255, 255, 255, 255, 255, 255, 255, 255, 
    1021                         255, 247, 231, 215, 199, 183, 167, 151, 
    1022                         135, 119, 103, 87, 71, 55, 39, 23, 
    1023                         7, 0, 0, 0, 0, 0, 0, 0}; 
    1024         final int[] blue = 
    1025                 {0, 143, 159, 175, 191, 207, 223, 239, 
    1026                         255, 255, 255, 255, 255, 255, 255, 255, 
    1027                         255, 255, 255, 255, 255, 255, 255, 255, 
    1028                         255, 247, 231, 215, 199, 183, 167, 151, 
    1029                         135, 119, 103, 87, 71, 55, 39, 23, 
    1030                         7, 0, 0, 0, 0, 0, 0, 0, 
    1031                         0, 0, 0, 0, 0, 0, 0, 0, 
    1032                         0, 0, 0, 0, 0, 0, 0, 0}; 
    1033  
    1034         final IndexedColorMap cmap = new IndexedColorMap( red, green, blue ); 
    1035         cmap.setTransform( new LinearTransform( 0.0, (double) red.length, datar.start, datar.end ) ); 
    1036         return cmap; 
     247            jPaneGraph = create2DPlot( megapoliPlot, plotWidth, plotHeight ); 
     248 
     249        final BufferedImage bufferedImage = new BufferedImage( jPaneGraph.getWidth(), jPaneGraph.getHeight(), BufferedImage.TYPE_INT_ARGB ); 
     250        final Graphics2D graphics2D = bufferedImage.createGraphics(); 
     251        jPaneGraph.addNotify(); 
     252        jPaneGraph.validate(); 
     253        jPaneGraph.draw( graphics2D ); 
     254 
     255        return bufferedImage; 
    1037256    } 
    1038257 
    1039258    private static final Log LOGGER = LogFactory.getLog( EtherPlotServiceImpl.class ); 
    1040  
    1041     // Dimensions of the jPanes 
    1042     private static final int MAX_WIDTH = 800; 
    1043     private static final int MAX_HEIGHT = 700; 
    1044     private static final int MARGIN_LEFT_RIGHT = 50; 
    1045  
    1046     private static final int TITLE_FONT_SIZE = 20; 
    1047     private static final int FONT_SIZE = 12; 
    1048     private static final int ERROR_FONT_SIZE = 10; 
    1049259} 
  • ether_megapoli/trunk/service/interface/com/ether/EtherPlotService.java

    r179 r182  
    3535 
    3636    @NotNull 
    37     public JPane createTimeSeriePlot( @NotNull final MegapoliPlot megapoliPlot ); 
     37    public JPane createTimeSeriePlot( @NotNull final MegapoliPlot megapoliPlot, @NotNull final Integer plotWidth, @NotNull final Integer plotHeight ); 
    3838 
    3939    @NotNull 
    40     public JPane create2DPlot( @NotNull final MegapoliPlot megapoliPlot ); 
     40    public JPane create2DPlot( @NotNull final MegapoliPlot megapoliPlot, @NotNull final Integer plotWidth, @NotNull final Integer plotHeight ); 
    4141 
    4242    @NotNull 
Note: See TracChangeset for help on using the changeset viewer.