Ignore:
Timestamp:
08/23/11 16:52:29 (13 years ago)
Author:
vmipsl
Message:

[Visualization] latitude/longitude axeType

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ether_megapoli/trunk/service/implementation/com/ether/EtherPlotServiceImpl.java

    r130 r132  
    22 
    33import gov.noaa.pmel.sgt.JPane; 
    4 import gov.noaa.pmel.sgt.dm.SGTData; 
    54import gov.noaa.pmel.sgt.swing.JPlotLayout; 
    65import org.apache.commons.logging.Log; 
     
    2423        implements EtherPlotService 
    2524{ 
     25    public static Integer getMaxWidth() 
     26    { 
     27        final Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); 
     28        return Math.min( Double.valueOf( screenSize.getWidth() ).intValue(), MAX_WIDTH ); 
     29    } 
     30 
     31    public static Integer getMaxHeight() 
     32    { 
     33        final Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); 
     34        return Math.min( Double.valueOf( screenSize.getHeight() ).intValue(), MAX_HEIGHT ); 
     35    } 
     36 
    2637    /** 
    2738     * Create the main JPane with the 3 jPanes 
     
    3445    public BufferedImage createMainPane( @NotNull final MegapoliPlot megapoliPlot, @Nullable final Locale locale ) 
    3546    { 
    36 //        JPane jPane = new JPane( "Main jPane", new Dimension( MAIN_WIDTH, MAIN_HEIGHT ) ); 
    37         JPane jPane = new JPane( "Main jPane", new Dimension( MAIN_WIDTH, 700 ) ); 
    38         if( null != megapoliPlot.getWidth() && null != megapoliPlot.getHeight() ) 
    39             jPane = new JPane( "Main jPane", new Dimension( megapoliPlot.getWidth(), megapoliPlot.getHeight() ) ); 
    40  
     47        final Integer maxWidth = getMaxWidth(); 
     48        final Integer maxHeight = getMaxHeight(); 
     49 
     50        final JPane jPane = new JPane( "Main jPane", new Dimension( maxWidth, maxHeight ) ); 
    4151        jPane.setLayout( new BorderLayout() ); 
    4252        jPane.setBackground( Color.white ); 
    43         jPane.setBorder( BorderFactory.createLineBorder( Color.black, 2 ) ); 
    4453        jPane.setOpaque( true ); 
    4554 
    4655        // Top Pane 
    47 //        final JPane jPaneTop = createTopPane( megapoliPlot ); 
    48 //        jPane.add( jPaneTop, BorderLayout.NORTH ); 
     56        final JPane jPaneTop = createTopPane( megapoliPlot ); 
     57        jPane.add( jPaneTop, BorderLayout.NORTH ); 
     58 
     59        final Integer valuesNumber = megapoliPlot.getData().getYArray().length; 
     60 
     61        // Bottom Pane 
     62        final JPane jPaneBottom = createBottomPane( valuesNumber, locale ); 
     63        jPane.add( jPaneBottom, BorderLayout.SOUTH ); 
    4964 
    5065        // Center Pane 
    51         final Integer valuesNumber = megapoliPlot.getData().getYArray().length; 
     66        final Integer centerHeight = maxHeight - jPaneTop.getHeight() - jPaneBottom.getHeight(); 
    5267        final JPane jPaneCenter; 
    5368        if( valuesNumber > 0 ) 
    54             jPaneCenter = createCenterPane( megapoliPlot.getData() ); 
     69            jPaneCenter = createCenterPane( megapoliPlot, maxWidth, centerHeight ); 
    5570        else 
    5671            jPaneCenter = createEmptyCenterPane( locale ); 
    5772        jPane.add( jPaneCenter, BorderLayout.CENTER ); 
    5873 
    59         // Bottom Pane 
    60 //        final JPane jPaneBottom = createBottomPane( valuesNumber, locale ); 
    61 //        jPane.add( jPaneBottom, BorderLayout.SOUTH ); 
    6274 
    6375        final JPanelToImageManager jPanelToImageManager = new JPanelToImageManager( jPane ); 
     
    105117     * Create the center JPane with the graph 
    106118     * 
    107      * @param data 
    108      * @return 
    109      */ 
    110     @NotNull 
    111     public JPane createCenterPane( @NotNull final SGTData data ) 
    112     { 
    113 //        final JPane jPaneCenter = new JPane( "Center jPane", new Dimension( 0, 1000 ) ); 
     119     * @param megapoliPlot 
     120     * @param maxWidth 
     121     * @param maxHeight 
     122     * @return 
     123     */ 
     124    @NotNull 
     125    public JPane createCenterPane( @NotNull final MegapoliPlot megapoliPlot, @NotNull final Integer maxWidth, @NotNull final Integer maxHeight ) 
     126    { 
     127        final Integer plotWidth = Math.min( maxWidth - MARGIN_LEFT_RIGHT, maxWidth ); 
     128        final Integer plotHeight = Math.min( maxHeight - MARGIN_LEFT_RIGHT, maxHeight ); 
    114129 
    115130        // Graph 
    116         final JPlotLayout jPlotLayout = new JPlotLayout( false, true, false, "Trajectory data", null, false ); 
     131        final JPlotLayout jPlotLayout = new JPlotLayout( false, true, false, "Trajectory data", null, megapoliPlot.isLegendToHide() ); 
    117132        jPlotLayout.setTitles( "", "", "" ); 
    118         jPlotLayout.addData( data, data.getTitle() ); 
    119 //        jPlotLayout.setSize( 800, 1 ); 
     133        // Add data and legend 
     134        jPlotLayout.addData( megapoliPlot.getData(), megapoliPlot.getData().getTitle() ); 
     135        jPlotLayout.setSize( plotWidth, plotHeight ); 
    120136        jPlotLayout.setVisible( true ); 
    121137 
    122138        jPlotLayout.addNotify(); 
    123139        jPlotLayout.validate(); 
     140        jPlotLayout.setOpaque( true ); 
    124141 
    125142        // TODO : remove this change to bufferedImage to insert directly the jPlotLayout !!!! 
    126 //        final BufferedImage bufferedImage = new BufferedImage( jPlotLayout.getWidth(), jPlotLayout.getHeight(), BufferedImage.TYPE_INT_RGB ); 
    127143        final BufferedImage bufferedImage = new BufferedImage( jPlotLayout.getWidth(), jPlotLayout.getHeight(), BufferedImage.TYPE_INT_RGB ); 
    128144        final Graphics2D graphics2D = bufferedImage.createGraphics(); 
     
    130146 
    131147        final ImageIcon imageIcon = new ImageIcon( bufferedImage ); 
    132         final JLabel jLabel = new JLabel( imageIcon, JLabel.CENTER ); 
    133         jLabel.setBorder( BorderFactory.createLineBorder( Color.blue, 2 ) ); 
    134  
    135 //        final JPane jPaneCenter = new JPane( "Center jPane", new Dimension( jPlotLayout.getWidth(), jPlotLayout.getHeight() ) ); 
    136         final JPane jPaneCenter = new JPane(); 
    137         jPaneCenter.setLayout( new BorderLayout() ); 
    138         jPaneCenter.add( jLabel, BorderLayout.CENTER ); 
     148        final JLabel jLabelPlot = new JLabel( imageIcon, JLabel.CENTER ); 
     149        jLabelPlot.setBorder( BorderFactory.createLineBorder( Color.black, 1 ) ); 
     150 
     151        final JPane jPaneCenter = new JPane( "Center jPane", new Dimension( jPlotLayout.getWidth(), jPlotLayout.getHeight() ) ); 
     152        jPaneCenter.setLayout( new GridBagLayout() ); 
     153        jPaneCenter.add( jLabelPlot, 
     154                new GridBagConstraints( 0, 0, 1, 1, 0, 0, 
     155                        GridBagConstraints.CENTER, 
     156                        GridBagConstraints.CENTER, 
     157                        new Insets( 0, 0, 0, 0 ), 0, 0 ) ); 
    139158 
    140159        return jPaneCenter; 
     
    206225     */ 
    207226    @NotNull 
    208     public BufferedImage createErrorPane( @NotNull final String mainError, @NotNull final String errorText, @Nullable final Locale locale ) 
     227    public BufferedImage createErrorPane( @NotNull final String mainError, @Nullable final String errorText, @Nullable final Locale locale ) 
    209228    { 
    210229        // Image 
     
    215234        final ResourceBundle bundle = WebHelper.getBundle( locale ); 
    216235        final String mainMessage = bundle.getString( "plot.errorMessage" ); 
    217         final JLabel jLabelError = new JLabel( "<html>" + mainMessage + "<br><br>" + mainError + "<br>" + errorText + "</html>", JLabel.CENTER ); 
     236 
     237        final JLabel jLabelError; 
     238        if( null != errorText ) 
     239            jLabelError = new JLabel( "<html>" + mainMessage + "<br><br>" + mainError + "<br>" + errorText + "</html>", JLabel.CENTER ); 
     240        else 
     241            jLabelError = new JLabel( "<html>" + mainMessage + "<br><br>" + mainError + "</html>", JLabel.CENTER ); 
     242 
    218243        final Font police = new Font( "Arial", Font.BOLD, ERROR_FONT_SIZE ); 
    219244        jLabelError.setFont( police ); 
    220245 
    221246        // jPane 
    222         final JPane jPane = new JPane( "jPane", new Dimension( MAIN_WIDTH, errorImage.getIconHeight() ) ); 
     247        final JPane jPane = new JPane( "jPane", new Dimension( MAX_WIDTH, errorImage.getIconHeight() ) ); 
    223248        jPane.setLayout( new BorderLayout() ); 
    224249        jPane.setBackground( Color.white ); 
     
    243268    } 
    244269 
    245     public static final int TOP_HEIGHT = 110; 
    246     public static final int CENTER_HEIGHT = 400; 
    247     public static final int BOTTOM_HEIGHT = 50; 
    248  
    249270    private static final Log LOGGER = LogFactory.getLog( EtherPlotServiceImpl.class ); 
    250271 
    251272    // Dimensions of the jPanes 
    252     private static final int MAIN_WIDTH = 800; 
    253     private static final int MAIN_HEIGHT = 800; 
     273    private static final int MAX_WIDTH = 800; 
     274    private static final int MAX_HEIGHT = 700; 
     275    private static final int MARGIN_LEFT_RIGHT = 50; 
    254276 
    255277    private static final int TITLE_FONT_SIZE = 20; 
Note: See TracChangeset for help on using the changeset viewer.