1 11 12 package org.eclipse.birt.chart.examples.api.processor; 13 14 import java.util.Iterator ; 15 16 import org.eclipse.birt.chart.model.Chart; 17 import org.eclipse.birt.chart.model.attribute.ColorDefinition; 18 import org.eclipse.birt.chart.model.attribute.FontDefinition; 19 import org.eclipse.birt.chart.model.attribute.HorizontalAlignment; 20 import org.eclipse.birt.chart.model.attribute.Image; 21 import org.eclipse.birt.chart.model.attribute.Insets; 22 import org.eclipse.birt.chart.model.attribute.Style; 23 import org.eclipse.birt.chart.model.attribute.StyleMap; 24 import org.eclipse.birt.chart.model.attribute.StyledComponent; 25 import org.eclipse.birt.chart.model.attribute.TextAlignment; 26 import org.eclipse.birt.chart.model.attribute.VerticalAlignment; 27 import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionImpl; 28 import org.eclipse.birt.chart.model.attribute.impl.FontDefinitionImpl; 29 import org.eclipse.birt.chart.model.attribute.impl.InsetsImpl; 30 import org.eclipse.birt.chart.model.attribute.impl.TextAlignmentImpl; 31 import org.eclipse.birt.chart.style.IStyle; 32 import org.eclipse.birt.chart.style.IStyleProcessor; 33 import org.eclipse.birt.chart.style.SimpleStyle; 34 import org.eclipse.emf.ecore.util.EcoreUtil; 35 36 39 public final class StyleProcessor implements IStyleProcessor 40 { 41 42 private static final SimpleStyle sstyle; 43 44 private static StyleProcessor instance; 45 46 static 47 { 48 TextAlignment ta = TextAlignmentImpl.create( ); 49 ta.setHorizontalAlignment( HorizontalAlignment.RIGHT_LITERAL ); 50 ta.setVerticalAlignment( VerticalAlignment.BOTTOM_LITERAL ); 51 FontDefinition font = FontDefinitionImpl.create( "BookAntique", 14, true, true, true, true, true, 2.0, ta ); 53 54 sstyle = new SimpleStyle( font, 55 ColorDefinitionImpl.PINK( ), 56 ColorDefinitionImpl.CREAM( ), 57 null, 58 InsetsImpl.create( 1.0, 1.0, 1.0, 1.0 ) ); 59 } 60 61 64 synchronized public static StyleProcessor instance( ) 65 { 66 if ( instance == null ) 67 { 68 instance = new StyleProcessor( ); 69 } 70 71 return instance; 72 } 73 74 77 private StyleProcessor( ) 78 { 79 super( ); 80 } 81 82 87 public IStyle getStyle( Chart model, StyledComponent name ) 88 { 89 if ( model != null && model.getStyles( ).size( ) > 0 ) 90 { 91 for ( Iterator itr = model.getStyles( ).iterator( ); itr.hasNext( ); ) 92 { 93 StyleMap sm = (StyleMap) itr.next( ); 94 95 if ( sm.getComponentName( ).equals( name ) ) 96 { 97 Style style = sm.getStyle( ); 98 99 SimpleStyle rt = new SimpleStyle( sstyle ); 100 101 if ( style.getFont( ) != null ) 102 { 103 rt.setFont( (FontDefinition) EcoreUtil.copy( style.getFont( ) ) ); 104 } 105 if ( style.getColor( ) != null ) 106 { 107 rt.setColor( (ColorDefinition) EcoreUtil.copy( style.getColor( ) ) ); 108 } 109 if ( style.getBackgroundColor( ) != null ) 110 { 111 rt.setBackgroundColor( (ColorDefinition) EcoreUtil.copy( style.getBackgroundColor( ) ) ); 112 } 113 if ( style.getBackgroundImage( ) != null ) 114 { 115 rt.setBackgroundImage( (Image) EcoreUtil.copy( style.getBackgroundImage( ) ) ); 116 } 117 if ( style.getPadding( ) != null ) 118 { 119 rt.setPadding( (Insets) EcoreUtil.copy( style.getPadding( ) ) ); 120 } 121 122 return rt; 123 } 124 } 125 } 126 127 return sstyle.copy( ); 129 } 130 } | Popular Tags |