Changeset 179
- Timestamp:
- 09/06/11 14:19:20 (13 years ago)
- Location:
- ether_megapoli/trunk/service
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
ether_megapoli/trunk/service/implementation/com/ether/EtherPlotServiceImpl.java
r178 r179 95 95 96 96 // Center Pane 97 // final Integer centerHeight = maxHeight - jPaneTop.getHeight() - jPaneBottom.getHeight(); 98 // final JPane jPaneCenter; 99 // if( valuesNumber > 0 ) 100 // jPaneCenter = createCenterPane( megapoliPlot, maxWidth, centerHeight, locale ); 101 // else 102 // jPaneCenter = createEmptyCenterPane( locale ); 103 // jPane.add( jPaneCenter, BorderLayout.CENTER ); 104 105 if( AxeTypeForFixedPlateform.TIME_LINE.name().equals( megapoliPlot.getAxeType() ) || AxeTypeForFixedPlateform.TIME_POINTS.name().equals( megapoliPlot.getAxeType() ) ) 97 final Integer centerHeight = maxHeight - jPaneTop.getHeight() - jPaneBottom.getHeight(); 98 if( valuesNumber > 0 ) 106 99 { 107 final JPane jPaneGraph = createTimeSeriePlot( megapoliPlot ); 108 final BufferedImage bufferedImage = new BufferedImage( 600, 600, BufferedImage.TYPE_INT_BGR ); 109 final Graphics2D graphics2D = bufferedImage.createGraphics(); 110 // graphics2D.setBackground( Color.WHITE ); 111 jPaneGraph.addNotify(); 112 jPaneGraph.validate(); 113 jPaneGraph.draw( graphics2D ); 114 115 // final JPanelToImageManager jPanelToImageManager = new JPanelToImageManager( jPane ); 116 // return jPanelToImageManager.saveAsImage(); 117 return bufferedImage; 100 final BufferedImage jPaneCenterBufferedImage = createCenterPane( megapoliPlot, maxWidth, centerHeight, locale ); 101 102 final ImageIcon imageIcon = new ImageIcon( jPaneCenterBufferedImage ); 103 final JLabel jLabelPlot = new JLabel( imageIcon, JLabel.CENTER ); 104 jLabelPlot.setBorder( BorderFactory.createLineBorder( Color.black, 1 ) ); 105 106 final JPane jPaneCenter = new JPane( "Center jPane", new Dimension( jPaneCenterBufferedImage.getWidth(), jPaneCenterBufferedImage.getHeight() ) ); 107 jPaneCenter.setLayout( new GridBagLayout() ); 108 jPaneCenter.add( jLabelPlot, 109 new GridBagConstraints( 0, 0, 1, 1, 0, 0, 110 GridBagConstraints.CENTER, 111 GridBagConstraints.CENTER, 112 new Insets( 0, 0, 0, 0 ), 0, 0 ) ); 113 jPane.add( jPaneCenter, BorderLayout.CENTER ); 118 114 } 119 115 else 120 116 { 121 final JPane jPaneGraph = create2DPlot( megapoliPlot ); 122 final BufferedImage bufferedImage = new BufferedImage( 600, 600, BufferedImage.TYPE_INT_BGR ); 123 final Graphics2D graphics2D = bufferedImage.createGraphics(); 124 // graphics2D.setBackground( Color.WHITE ); 125 jPaneGraph.addNotify(); 126 jPaneGraph.validate(); 127 jPaneGraph.draw( graphics2D ); 128 129 // final JPanelToImageManager jPanelToImageManager = new JPanelToImageManager( jPane ); 130 // return jPanelToImageManager.saveAsImage(); 131 return bufferedImage; 117 final JPane jPaneCenter = createEmptyCenterPane( locale ); 118 jPane.add( jPaneCenter, BorderLayout.CENTER ); 132 119 } 120 121 final JPanelToImageManager jPanelToImageManager = new JPanelToImageManager( jPane ); 122 return jPanelToImageManager.saveAsImage(); 133 123 } 134 124 … … 168 158 169 159 return jPaneTop; 160 } 161 162 /** 163 * Create the bottom JPane with the text "published .. (date)" 164 * 165 * @param dataNumber : the number of datas extracted from the base 166 * @param locale 167 * @return 168 */ 169 @NotNull 170 public JPane createBottomPane( @Nullable final Integer dataNumber, @Nullable final Locale locale ) 171 { 172 final ResourceBundle bundle = WebHelper.getBundle( locale ); 173 174 final JPane jPaneBottom = new JPane(); 175 jPaneBottom.setLayout( new BorderLayout() ); 176 177 // Published 178 final Calendar calendar = Calendar.getInstance(); 179 final String messagePublished = bundle.getString( "plot.published" ); 180 final JLabel jLabel = new JLabel( messagePublished + ' ' + DateHelper.formatDate( calendar.getTime(), DateHelper.ENGLISH_DATE_PATTERN ) + " " ); 181 final Font police = new Font( "Arial", Font.BOLD, FONT_SIZE ); 182 jLabel.setFont( police ); 183 jPaneBottom.add( jLabel, BorderLayout.EAST ); 184 185 if( null != dataNumber ) 186 { 187 final String messageDataNumber = bundle.getString( "plot.dataNumber" ); 188 final JLabel jLabelDataNumber = new JLabel( messageDataNumber + ' ' + dataNumber ); 189 jLabelDataNumber.setFont( police ); 190 jPaneBottom.add( jLabelDataNumber, BorderLayout.WEST ); 191 } 192 193 return jPaneBottom; 194 } 195 196 /** 197 * Create an error JPane when plot can be created 198 * 199 * @param mainError 200 * @param errorText 201 * @param locale 202 * @return 203 */ 204 @NotNull 205 public BufferedImage createErrorPane( @NotNull final String mainError, @Nullable final String errorText, @Nullable final Locale locale ) 206 { 207 // Image 208 final ImageIcon errorImage = new ImageIcon( MegapoliInitialisation.pathImages + "/erreur.gif" ); 209 final JLabel jLabelErrorImage = new JLabel( errorImage ); 210 211 // Text 212 final ResourceBundle bundle = WebHelper.getBundle( locale ); 213 final String mainMessage = bundle.getString( "plot.errorMessage" ); 214 215 final JLabel jLabelError; 216 if( null != errorText ) 217 jLabelError = new JLabel( "<html>" + mainMessage + "<br><br>" + mainError + "<br>" + errorText + "</html>", JLabel.CENTER ); 218 else 219 jLabelError = new JLabel( "<html>" + mainMessage + "<br><br>" + mainError + "</html>", JLabel.CENTER ); 220 221 final Font police = new Font( "Arial", Font.BOLD, ERROR_FONT_SIZE ); 222 jLabelError.setFont( police ); 223 224 // jPane 225 final JPane jPane = new JPane( "jPane", new Dimension( MAX_WIDTH, errorImage.getIconHeight() ) ); 226 jPane.setLayout( new BorderLayout() ); 227 jPane.setBackground( Color.white ); 228 jPane.setOpaque( true ); 229 jPane.add( jLabelErrorImage, BorderLayout.WEST ); 230 jPane.add( jLabelError, BorderLayout.CENTER ); 231 232 final JPanelToImageManager jPanelToImageManager = new JPanelToImageManager( jPane ); 233 return jPanelToImageManager.saveAsImage(); 234 } 235 236 /** 237 * Create the center JPane with no graph (if no value) 238 * 239 * @param locale 240 * @return 241 */ 242 @NotNull 243 public JPane createEmptyCenterPane( @Nullable final Locale locale ) 244 { 245 final ResourceBundle bundle = WebHelper.getBundle( locale ); 246 final String messageData = bundle.getString( "plot.noData" ); 247 248 final JPane jPaneCenter = new JPane(); 249 jPaneCenter.setLayout( new BorderLayout() ); 250 251 final JLabel jLabelData = new JLabel( messageData, JLabel.CENTER ); 252 final Font police = new Font( "Arial", Font.BOLD, FONT_SIZE ); 253 jLabelData.setFont( police ); 254 255 jPaneCenter.add( jLabelData, BorderLayout.CENTER ); 256 return jPaneCenter; 170 257 } 171 258 … … 179 266 */ 180 267 @NotNull 181 public JPane createCenterPaneOld( @NotNull final MegapoliPlot megapoliPlot, @NotNull final Integer maxWidth, @NotNull final Integer maxHeight, @Nullable final Locale locale ) 182 { 183 final Integer plotWidth = Math.min( maxWidth - MARGIN_LEFT_RIGHT, maxWidth ); 184 final Integer plotHeight = Math.min( maxHeight - MARGIN_LEFT_RIGHT, maxHeight ); 185 186 final JPlotLayout jPlotLayout; 187 final BufferedImage bufferedImage; 188 if( megapoliPlot.isTimeSerie() ) 189 { 190 jPlotLayout = createJPlotLayoutForTimeSerie( megapoliPlot, plotWidth, plotHeight ); 191 192 // TODO : remove this change to bufferedImage to insert directly the jPlotLayout !!!! 193 bufferedImage = new BufferedImage( jPlotLayout.getWidth(), jPlotLayout.getHeight(), BufferedImage.TYPE_INT_RGB ); 194 final Graphics2D graphics2D = bufferedImage.createGraphics(); 195 jPlotLayout.draw( graphics2D ); 196 } 197 else 198 { 199 jPlotLayout = createJPlotLayoutFor2D( megapoliPlot, plotWidth, plotHeight, locale ); 200 201 final JPanelToImageManager jPanelToImageManager = new JPanelToImageManager( jPlotLayout ); 202 bufferedImage = jPanelToImageManager.saveAsImage(); 203 } 204 205 final ImageIcon imageIcon = new ImageIcon( bufferedImage ); 206 final JLabel jLabelPlot = new JLabel( imageIcon, JLabel.CENTER ); 207 jLabelPlot.setBorder( BorderFactory.createLineBorder( Color.black, 1 ) ); 208 209 final JPane jPaneCenter = new JPane( "Center jPane", new Dimension( jPlotLayout.getWidth(), jPlotLayout.getHeight() ) ); 210 jPaneCenter.setLayout( new GridBagLayout() ); 211 jPaneCenter.add( jLabelPlot, 212 new GridBagConstraints( 0, 0, 1, 1, 0, 0, 213 GridBagConstraints.CENTER, 214 GridBagConstraints.CENTER, 215 new Insets( 0, 0, 0, 0 ), 0, 0 ) ); 216 217 return jPaneCenter; 218 } 219 220 /** 221 * Create the center JPane with the graph 222 * 223 * @param megapoliPlot 224 * @param maxWidth 225 * @param maxHeight 226 * @return 227 */ 228 @NotNull 229 public JPane createCenterPane( @NotNull final MegapoliPlot megapoliPlot, @NotNull final Integer maxWidth, @NotNull final Integer maxHeight, @Nullable final Locale locale ) 230 { 231 232 final JPane jPaneTimeSeriePlot = createTimeSeriePlot( megapoliPlot ); 233 234 final Integer plotWidth = Math.min( maxWidth - MARGIN_LEFT_RIGHT, maxWidth ); 235 final Integer plotHeight = Math.min( maxHeight - MARGIN_LEFT_RIGHT, maxHeight ); 268 public BufferedImage createCenterPane( @NotNull final MegapoliPlot megapoliPlot, @NotNull final Integer maxWidth, @NotNull final Integer maxHeight, @Nullable final Locale locale ) 269 { 270 // final Integer plotWidth = Math.min( maxWidth - MARGIN_LEFT_RIGHT, maxWidth ); 271 // final Integer plotHeight = Math.min( maxHeight - MARGIN_LEFT_RIGHT, maxHeight ); 236 272 237 273 // final JPlotLayout jPlotLayout; … … 267 303 // 268 304 // return jPaneCenter; 269 return jPaneTimeSeriePlot; 270 } 271 272 /** 273 * Create the bottom JPane with the text "published .. (date)" 274 * 275 * @param dataNumber : the number of datas extracted from the base 276 * @param locale 277 * @return 278 */ 279 @NotNull 280 public JPane createBottomPane( @Nullable final Integer dataNumber, @Nullable final Locale locale ) 281 { 282 final ResourceBundle bundle = WebHelper.getBundle( locale ); 283 284 final JPane jPaneBottom = new JPane(); 285 jPaneBottom.setLayout( new BorderLayout() ); 286 287 // Published 288 final Calendar calendar = Calendar.getInstance(); 289 final String messagePublished = bundle.getString( "plot.published" ); 290 final JLabel jLabel = new JLabel( messagePublished + ' ' + DateHelper.formatDate( calendar.getTime(), DateHelper.ENGLISH_DATE_PATTERN ) + " " ); 291 final Font police = new Font( "Arial", Font.BOLD, FONT_SIZE ); 292 jLabel.setFont( police ); 293 jPaneBottom.add( jLabel, BorderLayout.EAST ); 294 295 if( null != dataNumber ) 305 306 if( AxeTypeForFixedPlateform.TIME_LINE.name().equals( megapoliPlot.getAxeType() ) || AxeTypeForFixedPlateform.TIME_POINTS.name().equals( megapoliPlot.getAxeType() ) ) 296 307 { 297 final String messageDataNumber = bundle.getString( "plot.dataNumber" ); 298 final JLabel jLabelDataNumber = new JLabel( messageDataNumber + ' ' + dataNumber ); 299 jLabelDataNumber.setFont( police ); 300 jPaneBottom.add( jLabelDataNumber, BorderLayout.WEST ); 308 final JPane jPaneGraph = createTimeSeriePlot( megapoliPlot ); 309 final BufferedImage bufferedImage = new BufferedImage( 600, 600, BufferedImage.TYPE_INT_BGR ); 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(); 301 318 } 302 303 return jPaneBottom;304 }305 306 /**307 * Create an error JPane when plot can be created308 *309 * @param mainError310 * @param errorText311 * @param locale312 * @return313 */314 @NotNull315 public BufferedImage createErrorPane( @NotNull final String mainError, @Nullable final String errorText, @Nullable final Locale locale )316 {317 // Image318 final ImageIcon errorImage = new ImageIcon( MegapoliInitialisation.pathImages + "/erreur.gif" );319 final JLabel jLabelErrorImage = new JLabel( errorImage );320 321 // Text322 final ResourceBundle bundle = WebHelper.getBundle( locale );323 final String mainMessage = bundle.getString( "plot.errorMessage" );324 325 final JLabel jLabelError;326 if( null != errorText )327 jLabelError = new JLabel( "<html>" + mainMessage + "<br><br>" + mainError + "<br>" + errorText + "</html>", JLabel.CENTER );328 319 else 329 jLabelError = new JLabel( "<html>" + mainMessage + "<br><br>" + mainError + "</html>", JLabel.CENTER ); 330 331 final Font police = new Font( "Arial", Font.BOLD, ERROR_FONT_SIZE ); 332 jLabelError.setFont( police ); 333 334 // jPane 335 final JPane jPane = new JPane( "jPane", new Dimension( MAX_WIDTH, errorImage.getIconHeight() ) ); 336 jPane.setLayout( new BorderLayout() ); 337 jPane.setBackground( Color.white ); 338 jPane.setOpaque( true ); 339 jPane.add( jLabelErrorImage, BorderLayout.WEST ); 340 jPane.add( jLabelError, BorderLayout.CENTER ); 341 342 final JPanelToImageManager jPanelToImageManager = new JPanelToImageManager( jPane ); 343 return jPanelToImageManager.saveAsImage(); 344 } 345 346 @NotNull 347 public JPanel createControlPanel() 348 { 349 final JPanel controlPanel = new JPanel(); 350 final ButtonGroup gridtype = new ButtonGroup(); 351 final JCheckBox stacked = new JCheckBox(); 352 final JCheckBox grid = new JCheckBox(); 353 354 controlPanel.setLayout( new GridBagLayout() ); 355 // controlPanel.setBackground(new java.awt.Color(200,200,200)); 356 controlPanel.setBounds( 0, 679, 426, 33 ); 357 controlPanel.setBorder( new EtchedBorder() ); 358 gridtype.add( stacked ); 359 stacked.setSelected( true ); 360 stacked.setText( "Overlayed" ); 361 362 GridBagConstraints gbc = new GridBagConstraints(); 363 gbc.gridx = 0; 364 gbc.gridy = 0; 365 gbc.gridwidth = 1; 366 gbc.gridheight = 1; 367 gbc.weightx = 0.0; 368 gbc.weighty = 1.0; 369 gbc.anchor = GridBagConstraints.EAST; 370 gbc.fill = GridBagConstraints.BOTH; 371 gbc.insets = new Insets( 5, 15, 5, 5 ); 372 gbc.ipadx = 0; 373 gbc.ipady = 0; 374 controlPanel.add( stacked, gbc ); 375 stacked.setBounds( 15, 5, 84, 23 ); 376 gridtype.add( grid ); 377 grid.setText( "Grid" ); 378 379 gbc.gridx = 1; 380 gbc.gridy = 0; 381 gbc.gridwidth = 1; 382 gbc.gridheight = 1; 383 gbc.weightx = 0.5; 384 gbc.weighty = 1.0; 385 gbc.anchor = GridBagConstraints.WEST; 386 gbc.fill = GridBagConstraints.VERTICAL; 387 gbc.insets = new Insets( 5, 5, 5, 0 ); 388 gbc.ipadx = 0; 389 gbc.ipady = 0; 390 controlPanel.add( grid, gbc ); 391 grid.setBounds( 109, 5, 53, 23 ); 392 final JButton showTree = new JButton(); 393 showTree.setText( "Show Class Tree" ); 394 395 gbc.gridx = 2; 396 gbc.gridy = 0; 397 gbc.gridwidth = 1; 398 gbc.gridheight = 1; 399 gbc.weightx = 1.0; 400 gbc.weighty = 1.0; 401 gbc.anchor = GridBagConstraints.EAST; 402 gbc.fill = GridBagConstraints.VERTICAL; 403 gbc.insets = new Insets( 5, 5, 5, 15 ); 404 gbc.ipadx = 0; 405 gbc.ipady = 0; 406 controlPanel.add( showTree, gbc ); 407 showTree.setBackground( Color.yellow.brighter() ); 408 showTree.setBounds( 302, 5, 109, 23 ); 409 410 final SymItem lSymItem = new SymItem( stacked, grid ); 411 stacked.addItemListener( lSymItem ); 412 grid.addItemListener( lSymItem ); 413 // SymAction lSymAction = new SymAction(); 414 // showTree.addActionListener( lSymAction ); 415 416 return controlPanel; 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 } 417 329 } 418 330 … … 609 521 } 610 522 523 @NotNull 611 524 public JPane create2DPlot( @NotNull final MegapoliPlot megapoliPlot ) 612 525 { … … 676 589 } 677 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 678 664 /** 679 * Create the center JPane with no graph (if no value)665 * Create the center JPane with the graph 680 666 * 681 * @param locale 667 * @param megapoliPlot 668 * @param maxWidth 669 * @param maxHeight 682 670 * @return 683 671 */ 684 public JPane createEmptyCenterPane( @Nullable final Locale locale ) 685 { 686 final ResourceBundle bundle = WebHelper.getBundle( locale ); 687 final String messageData = bundle.getString( "plot.noData" ); 688 689 final JPane jPaneCenter = new JPane(); 690 jPaneCenter.setLayout( new BorderLayout() ); 691 692 final JLabel jLabelData = new JLabel( messageData, JLabel.CENTER ); 693 final Font police = new Font( "Arial", Font.BOLD, FONT_SIZE ); 694 jLabelData.setFont( police ); 695 696 jPaneCenter.add( jLabelData, BorderLayout.CENTER ); 697 return jPaneCenter; 698 } 699 700 @NotNull 701 private JPlotLayout createJPlotLayoutForTimeSerie( final MegapoliPlot megapoliPlot, final Integer plotWidth, final Integer plotHeight ) 702 { 703 final double[] dataArray = (double[]) megapoliPlot.getData().getFirstArray(); 704 final Date[] dateValues = (Date[]) megapoliPlot.getData().getSecondArray(); 705 706 final SimpleLine data = new SimpleLine( new GeoDateArray( dateValues ), dataArray, "legend" ); 707 SGTMetaData meta = new SGTMetaData( null, null, false, false ); 708 data.setXMetaData( meta ); 709 710 meta = new SGTMetaData( megapoliPlot.getParameterName(), megapoliPlot.getParameterUnitCode(), false, false ); 711 data.setYMetaData( meta ); 712 713 // Graph 714 // final JPlotLayoutEther jPlotLayout = new JPlotLayoutEther( false, true, false, "Trajectory data", null, megapoliPlot.isLegendToHide() ); 715 final JPlotLayout jPlotLayout = new JPlotLayout( data, "Profile Demo", null, false ); 716 jPlotLayout.setTitles( "", "", "" ); 717 718 // Replace legend 719 // final String legend = megapoliPlot.getData().getTitle(); 720 // final Dimension2D layerSizeP = jPlotLayout.getLayerSizeP(); 721 // final double factorForPlotWidthInPhysicalUnits = layerSizeP.getWidth() / Double.valueOf( plotWidth ); 722 // final double legendSizeInPhysicalUnits = legend.length() * factorForPlotWidthInPhysicalUnits * 7; 723 // jPlotLayout.setKeyLocationP( new Point2D.Double( layerSizeP.getWidth() - legendSizeInPhysicalUnits, layerSizeP.getHeight() - 0.1 ) ); 724 725 // Add data and legend 726 jPlotLayout.addData( data, "" ); 727 jPlotLayout.setSize( plotWidth, plotHeight ); 728 jPlotLayout.setVisible( true ); 729 730 jPlotLayout.addNotify(); 731 jPlotLayout.validate(); 732 jPlotLayout.setOpaque( true ); 733 return jPlotLayout; 734 } 735 736 @NotNull 737 private JPlotLayout createJPlotLayoutFor2D( final MegapoliPlot megapoliPlot, final Integer plotWidth, final Integer plotHeight, @Nullable final Locale locale ) 738 { 739 SGTData newData; 740 TestData td; 741 JPlotLayout rpl; 742 ContourLevels clevels; 743 /* 744 * Create a test grid with sinasoidal-ramp data. 745 */ 746 Range2D xr = new Range2D( 190.0f, 250.0f, 1.0f ); 747 Range2D yr = new Range2D( 0.0f, 45.0f, 1.0f ); 748 td = new TestData( TestData.XY_GRID, xr, yr, 749 TestData.SINE_RAMP, 12.0f, 30.f, 5.0f ); 750 newData = td.getSGTData(); 751 /* 752 * Create the layout without a Logo image and with the 753 * ColorKey on a separate Pane object. 754 */ 755 rpl = new JPlotLayout( true, false, false, "JGridDemo Pane", null, true ); 756 rpl.setEditClasses( false ); 757 /* 758 * Create a GridAttribute for CONTOUR style. 759 */ 760 Range2D datar = new Range2D( -20.0f, 45.0f, 5.0f ); 761 clevels = ContourLevels.getDefault( datar ); 762 final GridAttribute gridAttr_ = new GridAttribute( clevels ); 763 /* 764 * Create a ColorMap and change the style to RASTER_CONTOUR. 765 */ 766 ColorMap cmap = createColorMap( datar ); 767 gridAttr_.setColorMap( cmap ); 768 gridAttr_.setStyle( GridAttribute.RASTER_CONTOUR ); 769 /* 770 * Add the grid to the layout and give a label for 771 * the ColorKey. 772 */ 773 rpl.addData( newData, gridAttr_, "First Data" ); 774 /* 775 * Change the layout's three title lines. 776 */ 777 rpl.setTitles( "Raster Plot Demo", "using a JPlotLayout", "" ); 778 /* 779 * Resize the graph and place in the "Center" of the frame. 780 */ 781 rpl.setSize( new Dimension( 600, 400 ) ); 782 /* 783 * Resize the key Pane, both the device size and the physical 784 * size. Set the size of the key in physical units and place 785 * the key pane at the "South" of the frame. 786 */ 787 // rpl.setKeyLayerSizeP(new Dimension2D(6.0, 1.02)); 788 // rpl.setKeyBoundsP(new Rectangle2D.Double(0.01, 1.01, 5.98, 1.0)); 789 790 return rpl; 791 } 792 793 @NotNull 794 private JPlotLayout createJPlotLayoutFor2DOrig( final MegapoliPlot megapoliPlot, final Integer plotWidth, final Integer plotHeight, @Nullable final Locale locale ) 795 { 796 final ResourceBundle bundle = WebHelper.getBundle( locale ); 797 798 final double[] parameterArray = (double[]) megapoliPlot.getData().getFirstArray(); 799 final double[] latitudeArray = (double[]) megapoliPlot.getData().getSecondArray(); 800 final double[] longitudeValues = (double[]) megapoliPlot.getData().getThirdArray(); 801 802 // final SimpleLine data = new SimpleLine( longitudeValues, latitudeArray, "legend" ); 803 final SimpleGrid data = new SimpleGrid( parameterArray, longitudeValues, latitudeArray, "Test Series" ); 804 SGTMetaData meta = new SGTMetaData( bundle.getString( "plot.longitude" ), bundle.getString( "plot.degres" ), false, true ); 805 // TODO : vérifier modulo = 360 806 // meta.setModuloValue( 360 ); 807 data.setXMetaData( meta ); 808 809 meta = new SGTMetaData( bundle.getString( "plot.latitude" ), bundle.getString( "plot.degres" ), false, true ); 810 // TODO : vérifier modulo = 360 811 // meta.setModuloValue( 360 ); 812 data.setYMetaData( meta ); 813 814 // Graph 815 final JPlotLayout jPlotLayout = new JPlotLayout( true, false, false, "JGridDemo Pane", null, true ); 816 jPlotLayout.setEditClasses( false ); 817 /* 818 * Create a GridAttribute for CONTOUR style. 819 */ 820 final Range2D datar = new Range2D( -20.0f, 45.0f, 5.0f ); 821 final ContourLevels clevels = ContourLevels.getDefault( datar ); 822 final GridAttribute gridAttr = new GridAttribute( clevels ); 823 /* 824 * Create a ColorMap and change the style to RASTER_CONTOUR. 825 */ 826 final ColorMap cmap = createColorMap( datar ); 827 gridAttr.setColorMap( cmap ); 828 gridAttr.setStyle( GridAttribute.RASTER_CONTOUR ); 829 /* 830 * Add the grid to the layout and give a label for 831 * the ColorKey. 832 */ 833 jPlotLayout.addData( data, gridAttr, "First Data" ); 834 835 // final JPlotLayoutEther jPlotLayout = new JPlotLayoutEther( false, megapoliPlot.isXTime(), false, "Trajectory data", null, megapoliPlot.isLegendToHide() ); 836 // jPlotLayout.setTitles( "", "", "" ); 837 838 // Replace legend 839 // final String legend = megapoliPlot.getData().getTitle(); 840 // final Dimension2D layerSizeP = jPlotLayout.getLayerSizeP(); 841 // final double factorForPlotWidthInPhysicalUnits = layerSizeP.getWidth() / Double.valueOf( plotWidth ); 842 // final double legendSizeInPhysicalUnits = legend.length() * factorForPlotWidthInPhysicalUnits * 7; 843 // jPlotLayout.setKeyLocationP( new Point2D.Double( layerSizeP.getWidth() - legendSizeInPhysicalUnits, layerSizeP.getHeight() - 0.1 ) ); 844 845 // Add data and legend 846 // jPlotLayout.addData( megapoliPlot.getData(), legend ); 847 jPlotLayout.setSize( plotWidth, plotHeight ); 848 jPlotLayout.setVisible( true ); 849 850 jPlotLayout.addNotify(); 851 jPlotLayout.validate(); 852 jPlotLayout.setOpaque( true ); 853 return jPlotLayout; 854 } 855 856 @NotNull 857 private String formatTitle( @Nullable final String title ) 858 { 859 if( null == title ) 860 return ""; 672 @NotNull 673 public JPane createCenterPaneOld( @NotNull final MegapoliPlot megapoliPlot, @NotNull final Integer maxWidth, @NotNull final Integer maxHeight, @Nullable final Locale locale ) 674 { 675 final Integer plotWidth = Math.min( maxWidth - MARGIN_LEFT_RIGHT, maxWidth ); 676 final Integer plotHeight = Math.min( maxHeight - MARGIN_LEFT_RIGHT, maxHeight ); 677 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 } 861 689 else 862 690 { 863 final String formatTitle = title.replaceAll( "\\n", "<br>" ); 864 return "<html>" + formatTitle + "</html>"; 691 jPlotLayout = createJPlotLayoutFor2D( megapoliPlot, plotWidth, plotHeight, locale ); 692 693 final JPanelToImageManager jPanelToImageManager = new JPanelToImageManager( jPlotLayout ); 694 bufferedImage = jPanelToImageManager.saveAsImage(); 865 695 } 866 } 867 868 @NotNull 869 private ColorMap createColorMap( final Range2D datar ) 870 { 871 final int[] red = 872 {0, 0, 0, 0, 0, 0, 0, 0, 873 0, 0, 0, 0, 0, 0, 0, 0, 874 0, 0, 0, 0, 0, 0, 0, 0, 875 0, 7, 23, 39, 55, 71, 87, 103, 876 119, 135, 151, 167, 183, 199, 215, 231, 877 247, 255, 255, 255, 255, 255, 255, 255, 878 255, 255, 255, 255, 255, 255, 255, 255, 879 255, 246, 228, 211, 193, 175, 158, 140}; 880 final int[] green = 881 {0, 0, 0, 0, 0, 0, 0, 0, 882 0, 11, 27, 43, 59, 75, 91, 107, 883 123, 139, 155, 171, 187, 203, 219, 235, 884 251, 255, 255, 255, 255, 255, 255, 255, 885 255, 255, 255, 255, 255, 255, 255, 255, 886 255, 247, 231, 215, 199, 183, 167, 151, 887 135, 119, 103, 87, 71, 55, 39, 23, 888 7, 0, 0, 0, 0, 0, 0, 0}; 889 final int[] blue = 890 {0, 143, 159, 175, 191, 207, 223, 239, 891 255, 255, 255, 255, 255, 255, 255, 255, 892 255, 255, 255, 255, 255, 255, 255, 255, 893 255, 247, 231, 215, 199, 183, 167, 151, 894 135, 119, 103, 87, 71, 55, 39, 23, 895 7, 0, 0, 0, 0, 0, 0, 0, 896 0, 0, 0, 0, 0, 0, 0, 0, 897 0, 0, 0, 0, 0, 0, 0, 0}; 898 899 final IndexedColorMap cmap = new IndexedColorMap( red, green, blue ); 900 cmap.setTransform( new LinearTransform( 0.0, (double) red.length, datar.start, datar.end ) ); 901 return cmap; 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; 902 710 } 903 711 … … 1025 833 } 1026 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; 1037 } 1038 1027 1039 private static final Log LOGGER = LogFactory.getLog( EtherPlotServiceImpl.class ); 1028 1040 -
ether_megapoli/trunk/service/interface/com/ether/EtherPlotService.java
r178 r179 23 23 24 24 @NotNull 25 public JPane createCenterPane( @NotNull final MegapoliPlot megapoliPlot, @NotNull final Integer maxWidth, @NotNull final Integer maxHeight, @Nullable final Locale locale );26 27 @NotNull28 25 public JPane createBottomPane( @Nullable final Integer dataNumber, @Nullable final Locale locale ); 29 26 … … 32 29 33 30 @NotNull 34 public JPanel createControlPanel(); 31 public JPane createEmptyCenterPane( @Nullable final Locale locale ); 32 33 @NotNull 34 public BufferedImage createCenterPane( @NotNull final MegapoliPlot megapoliPlot, @NotNull final Integer maxWidth, @NotNull final Integer maxHeight, @Nullable final Locale locale ); 35 35 36 36 @NotNull 37 37 public JPane createTimeSeriePlot( @NotNull final MegapoliPlot megapoliPlot ); 38 39 @NotNull 40 public JPane create2DPlot( @NotNull final MegapoliPlot megapoliPlot ); 41 42 @NotNull 43 public JPanel createControlPanel(); 38 44 }
Note: See TracChangeset
for help on using the changeset viewer.