- Timestamp:
- 08/23/11 16:52:29 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ether_megapoli/trunk/service/implementation/com/ether/EtherPlotServiceImpl.java
r130 r132 2 2 3 3 import gov.noaa.pmel.sgt.JPane; 4 import gov.noaa.pmel.sgt.dm.SGTData;5 4 import gov.noaa.pmel.sgt.swing.JPlotLayout; 6 5 import org.apache.commons.logging.Log; … … 24 23 implements EtherPlotService 25 24 { 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 26 37 /** 27 38 * Create the main JPane with the 3 jPanes … … 34 45 public BufferedImage createMainPane( @NotNull final MegapoliPlot megapoliPlot, @Nullable final Locale locale ) 35 46 { 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 ) ); 41 51 jPane.setLayout( new BorderLayout() ); 42 52 jPane.setBackground( Color.white ); 43 jPane.setBorder( BorderFactory.createLineBorder( Color.black, 2 ) );44 53 jPane.setOpaque( true ); 45 54 46 55 // 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 ); 49 64 50 65 // Center Pane 51 final Integer valuesNumber = megapoliPlot.getData().getYArray().length;66 final Integer centerHeight = maxHeight - jPaneTop.getHeight() - jPaneBottom.getHeight(); 52 67 final JPane jPaneCenter; 53 68 if( valuesNumber > 0 ) 54 jPaneCenter = createCenterPane( megapoliPlot .getData());69 jPaneCenter = createCenterPane( megapoliPlot, maxWidth, centerHeight ); 55 70 else 56 71 jPaneCenter = createEmptyCenterPane( locale ); 57 72 jPane.add( jPaneCenter, BorderLayout.CENTER ); 58 73 59 // Bottom Pane60 // final JPane jPaneBottom = createBottomPane( valuesNumber, locale );61 // jPane.add( jPaneBottom, BorderLayout.SOUTH );62 74 63 75 final JPanelToImageManager jPanelToImageManager = new JPanelToImageManager( jPane ); … … 105 117 * Create the center JPane with the graph 106 118 * 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 ); 114 129 115 130 // 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() ); 117 132 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 ); 120 136 jPlotLayout.setVisible( true ); 121 137 122 138 jPlotLayout.addNotify(); 123 139 jPlotLayout.validate(); 140 jPlotLayout.setOpaque( true ); 124 141 125 142 // 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 );127 143 final BufferedImage bufferedImage = new BufferedImage( jPlotLayout.getWidth(), jPlotLayout.getHeight(), BufferedImage.TYPE_INT_RGB ); 128 144 final Graphics2D graphics2D = bufferedImage.createGraphics(); … … 130 146 131 147 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 ) ); 139 158 140 159 return jPaneCenter; … … 206 225 */ 207 226 @NotNull 208 public BufferedImage createErrorPane( @NotNull final String mainError, @N otNullfinal String errorText, @Nullable final Locale locale )227 public BufferedImage createErrorPane( @NotNull final String mainError, @Nullable final String errorText, @Nullable final Locale locale ) 209 228 { 210 229 // Image … … 215 234 final ResourceBundle bundle = WebHelper.getBundle( locale ); 216 235 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 218 243 final Font police = new Font( "Arial", Font.BOLD, ERROR_FONT_SIZE ); 219 244 jLabelError.setFont( police ); 220 245 221 246 // jPane 222 final JPane jPane = new JPane( "jPane", new Dimension( MA IN_WIDTH, errorImage.getIconHeight() ) );247 final JPane jPane = new JPane( "jPane", new Dimension( MAX_WIDTH, errorImage.getIconHeight() ) ); 223 248 jPane.setLayout( new BorderLayout() ); 224 249 jPane.setBackground( Color.white ); … … 243 268 } 244 269 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 249 270 private static final Log LOGGER = LogFactory.getLog( EtherPlotServiceImpl.class ); 250 271 251 272 // 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; 254 276 255 277 private static final int TITLE_FONT_SIZE = 20;
Note: See TracChangeset
for help on using the changeset viewer.