Skip to content

Commit

Permalink
Summary: Refactoring code for extra work.(T55182)
Browse files Browse the repository at this point in the history
Bugzilla Bugs Resolved:

Description:
Refactoring code for extra work.(T55182)
  • Loading branch information
heli committed Dec 13, 2012
1 parent f6b84be commit b750b33
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package org.eclipse.birt.chart.reportitem.ui;

import org.eclipse.birt.chart.model.Chart;
import org.eclipse.birt.chart.reportitem.ChartReportItemImpl;
import org.eclipse.birt.chart.ui.swt.ChartUIFactory;
import org.eclipse.birt.chart.ui.swt.interfaces.IChartDataSheet;
import org.eclipse.birt.chart.ui.swt.interfaces.IDataServiceProvider;
Expand Down Expand Up @@ -94,4 +95,17 @@ public ISectionHelper updateChartPageSectionHelper( ISectionHelper sectionHelper
{
return sectionHelper;
}

/**
* Creates Figure used for edit part in layout editor.
*
* @param crii
* report item
* @return figure instance
* @since 3.7
*/
public DesignerRepresentation createFigure( ChartReportItemImpl crii )
{
return new DesignerRepresentation( crii );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public final IFigure createFigure( final ExtendedItemHandle eih )
try
{
final ChartReportItemImpl iri = (ChartReportItemImpl) eih.getReportItem( );
final DesignerRepresentation dr = new DesignerRepresentation( iri );
final DesignerRepresentation dr = ChartReportItemUIFactory.instance( ).createFigure( iri );
refreshBackgroundImage( eih, dr );
iri.setDesignerRepresentation( dr ); // UPDATE LINK

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.eclipse.birt.chart.reportitem.api.ChartCubeUtil;
import org.eclipse.birt.chart.reportitem.api.ChartReportItemConstants;
import org.eclipse.birt.chart.reportitem.ui.i18n.Messages;
import org.eclipse.birt.chart.script.ScriptHandler;
import org.eclipse.birt.chart.ui.swt.wizard.ChartAdapter;
import org.eclipse.birt.chart.ui.util.ChartUIUtil;
import org.eclipse.birt.chart.util.ChartUtil;
Expand Down Expand Up @@ -73,10 +74,10 @@
/**
*
*/
public final class DesignerRepresentation extends ReportElementFigure
public class DesignerRepresentation extends ReportElementFigure
{

private static ILogger logger = Logger.getLogger( "org.eclipse.birt.chart.reportitem/trace" ); //$NON-NLS-1$
protected static ILogger logger = Logger.getLogger( "org.eclipse.birt.chart.reportitem/trace" ); //$NON-NLS-1$

private final static String ERROR_MSG = Messages.getString( "DesignerRepresentation.error.Error" ); //$NON-NLS-1$

Expand All @@ -88,14 +89,14 @@ public final class DesignerRepresentation extends ReportElementFigure
/**
*
*/
private final ChartReportItemImpl crii;
protected final ChartReportItemImpl crii;

private transient Chart cm;
protected transient Chart cm;

/**
*
*/
private Image imgChart = null;
protected Image imgChart = null;

/**
*
Expand Down Expand Up @@ -123,7 +124,7 @@ public final class DesignerRepresentation extends ReportElementFigure
*
* @param crii
*/
DesignerRepresentation( ChartReportItemImpl crii )
protected DesignerRepresentation( ChartReportItemImpl crii )
{
this.crii = crii;
updateChartModel( );
Expand Down Expand Up @@ -355,73 +356,81 @@ public final void paintClientArea( Graphics g )
}
bPainting = true;

Color backgroundColor = Display.getDefault( )
.getSystemColor( SWT.COLOR_LIST_BACKGROUND );
if ( bDirty )
{
bDirty = false;
imgChart = paintChart( g, r.getSize( ) );
}

final Display d = Display.getCurrent( );
Dimension dSize = r.getSize( );
if ( imgChart != null )
{
g.drawImage( imgChart, r.x, r.y );
}

// OFFSCREEN IMAGE CREATION STRATEGY
if ( imgChart == null
|| imgChart.getImageData( ).width != dSize.width
|| imgChart.getImageData( ).height != dSize.height )
{
if ( gc != null )
{
gc.dispose( );
}
if ( imgChart != null )
{
imgChart.dispose( );
}
bDirty = true;
bPainting = false;
}

// FILL IMAGE WITH TRANSPARENCY
final ImageData ida = new ImageData( dSize.width,
dSize.height,
32,
PALETTE_DATA );
ida.transparentPixel = ida.palette.getPixel( backgroundColor.getRGB( ) );
protected Image paintChart( Graphics g, Dimension dSize )
{
Color backgroundColor = Display.getDefault( )
.getSystemColor( SWT.COLOR_LIST_BACKGROUND );

imgChart = new Image( d, ida );
gc = new GC( imgChart );
}
final Display d = Display.getCurrent( );

// bug 288169
if ( Platform.OS_MACOSX.equals( Platform.getOS( ) )
&& gc != null
&& !gc.isDisposed( ) )
// OFFSCREEN IMAGE CREATION STRATEGY
if ( imgChart == null
|| imgChart.getImageData( ).width != dSize.width
|| imgChart.getImageData( ).height != dSize.height
|| gc == null
|| gc.isDisposed( ) )
{
if ( gc != null )
{
gc.dispose( );
gc = new GC( imgChart );
}

final Color clrPreviousBG = gc.getBackground( );
gc.setBackground( backgroundColor );
gc.fillRectangle( 0,
0,
imgChart.getImageData( ).width,
imgChart.getImageData( ).height );
gc.setBackground( clrPreviousBG ); // RESTORE

if ( cm == null )
{
showNullChart( dSize );
}
else
if ( imgChart != null )
{
showChart( dSize );
imgChart.dispose( );
}

// FILL IMAGE WITH TRANSPARENCY
final ImageData ida = new ImageData( dSize.width,
dSize.height,
32,
PALETTE_DATA );
ida.transparentPixel = ida.palette.getPixel( backgroundColor.getRGB( ) );

imgChart = new Image( d, ida );
gc = new GC( imgChart );
}

if ( imgChart != null )
// bug 288169
if ( Platform.OS_MACOSX.equals( Platform.getOS( ) )
&& gc != null
&& !gc.isDisposed( ) )
{
g.drawImage( imgChart, r.x, r.y );
gc.dispose( );
gc = new GC( imgChart );
}
bPainting = false;

final Color clrPreviousBG = gc.getBackground( );
gc.setBackground( backgroundColor );
gc.fillRectangle( 0,
0,
imgChart.getImageData( ).width,
imgChart.getImageData( ).height );
gc.setBackground( clrPreviousBG ); // RESTORE

if ( cm == null )
{
showNullChart( dSize );
}
else
{
showChart( dSize );
}

return imgChart;
}

private void showNullChart( Dimension dSize )
Expand Down Expand Up @@ -513,72 +522,12 @@ private void showChart( Dimension dSize )
gr.setDefaultBackground( cd );
}

ChartAdapter.beginIgnoreNotifications( );
cm.clearSections( IConstants.RUN_TIME ); // REMOVE OLD TRANSIENT
// RUNTIME SERIES
cm.createSampleRuntimeSeries( ); // USING SAMPLE DATA STORED IN
ChartAdapter.endIgnoreNotifications( );

// MODEL
try
{
Chart cmRunTime = cm.copyInstance( );
// Update auto title
ChartReportItemUIFactory.instance( )
.createUIHelper( )
.updateDefaultTitle( cmRunTime, crii.getHandle( ) );
removeScaleInfoForSample( cmRunTime );

RunTimeContext rtc = new RunTimeContext( );
rtc.setScriptingEnabled( false );
rtc.setMessageLookup( new BIRTDesignerMessageLookup( crii.getHandle( ) ) );

// Set direction from model to chart runtime context
rtc.setRightToLeft( crii.isLayoutDirectionRTL( ) );
// Set text direction from StyleHandle to chart runtime context
rtc.setRightToLeftText( crii.getHandle( ).isDirectionRTL( ) );

rtc.setResourceFinder( crii );
rtc.setExternalizer( crii );

// Create shared scale if needed
boolean bPlotChart = ChartCubeUtil.isPlotChart( crii.getHandle( ) );
if ( bPlotChart )
{
rtc.setSharedScale( createSharedScaleFromSampleData( ) );
}

// Here we override updateChart method to force updating chart with
// default value to ensure we can get a chart figure.
ChartReportStyleProcessor crsp = new ChartReportStyleProcessor( crii.getHandle( ),
true ) {

/* (non-Javadoc)
* @see org.eclipse.birt.chart.reportitem.ChartReportStyleProcessor#updateChart(org.eclipse.birt.chart.model.Chart, java.lang.Object)
*/
@Override
public boolean updateChart( Chart model, Object obj )
{
if ( styleProcessorProxy != null )
{
// Enforce update chart with default value for image chart.
styleProcessorProxy.updateChart( model, true );
return true;
}
return false;
}

/* (non-Javadoc)
* @see org.eclipse.birt.chart.reportitem.ChartReportStyleProcessor#needChartBasicStyles()
*/
public boolean needInheritingStyles( )
{
// Since the designer presentation is still rendering chart
// with SWT, it is image chart, it still returns true for
// updating chart with necessary styles.
return true;
}
};
Chart cmRunTime = constructRuntimeModel( );
RunTimeContext rtc = constructRuntimeContext( );
ChartReportStyleProcessor crsp = constructStyleProcessor( );
gr.render( idr, gr.build( idr.getDisplayServer( ),
cmRunTime,
bo,
Expand All @@ -592,6 +541,78 @@ public boolean needInheritingStyles( )
}
}

protected final Chart constructRuntimeModel( )
{
ChartAdapter.beginIgnoreNotifications( );
cm.clearSections( IConstants.RUN_TIME ); // REMOVE OLD TRANSIENT
// RUNTIME SERIES
cm.createSampleRuntimeSeries( ); // USING SAMPLE DATA STORED IN
ChartAdapter.endIgnoreNotifications( );

Chart cmRunTime = cm.copyInstance( );

// Update auto title
ChartReportItemUIFactory.instance( )
.createUIHelper( )
.updateDefaultTitle( cmRunTime, crii.getHandle( ) );
removeScaleInfoForSample( cmRunTime );

return cmRunTime;
}

protected final RunTimeContext constructRuntimeContext( )
{
RunTimeContext rtc = new RunTimeContext( );
rtc.setScriptingEnabled( false );
rtc.setScriptHandler( new ScriptHandler( ) );
rtc.setMessageLookup( new BIRTDesignerMessageLookup( crii.getHandle( ) ) );

// Set direction from model to chart runtime context
rtc.setRightToLeft( crii.isLayoutDirectionRTL( ) );
// Set text direction from StyleHandle to chart runtime context
rtc.setRightToLeftText( crii.getHandle( ).isDirectionRTL( ) );

rtc.setResourceFinder( crii );
rtc.setExternalizer( crii );

// Create shared scale if needed
boolean bPlotChart = ChartCubeUtil.isPlotChart( crii.getHandle( ) );
if ( bPlotChart )
{
rtc.setSharedScale( createSharedScaleFromSampleData( ) );
}

return rtc;
}

protected final ChartReportStyleProcessor constructStyleProcessor( )
{
// Here we override updateChart method to force updating chart with
// default value to ensure we can get a chart figure.
return new ChartReportStyleProcessor( crii.getHandle( ), true ) {

/*
* (non-Javadoc)
*
* @see org.eclipse.birt.chart.reportitem.ChartReportStyleProcessor
* #updateChart(org.eclipse.birt.chart.model.Chart,
* java.lang.Object)
*/
@Override
public boolean updateChart( Chart model, Object obj )
{
if ( styleProcessorProxy != null )
{
// Enforce update chart with default value for image
// chart.
styleProcessorProxy.updateChart( model, false );
return true;
}
return false;
}
};
}

/**
* Show the exception message that prevented to draw the chart
*
Expand Down Expand Up @@ -657,16 +678,22 @@ private final void showException( GC g2d, Exception ex )
*/
public final void dispose( )
{
if ( imgChart != null )
if ( gc != null )
{
gc.dispose( );
imgChart.dispose( );
idr.dispose( );
gc = null;
imgChart = null;
bDirty = true;
}
if ( idr != null )
{
idr.dispose( );
idr = null;
}
if ( imgChart != null )
{
imgChart.dispose( );
imgChart = null;
}
bDirty = true;
}

private static String[] splitOnBreaks( String s, Font font, double maxSize )
Expand Down

0 comments on commit b750b33

Please sign in to comment.