KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > birt > chart > examples > api > preference > LabelStyleProcessor


1 /*******************************************************************************
2  * Copyright (c) 2004 Actuate Corporation.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * Actuate Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.birt.chart.examples.api.preference;
12 import java.util.Iterator JavaDoc;
13
14 import org.eclipse.birt.chart.model.Chart;
15 import org.eclipse.birt.chart.model.attribute.ColorDefinition;
16 import org.eclipse.birt.chart.model.attribute.FontDefinition;
17 import org.eclipse.birt.chart.model.attribute.HorizontalAlignment;
18 import org.eclipse.birt.chart.model.attribute.Image;
19 import org.eclipse.birt.chart.model.attribute.Insets;
20 import org.eclipse.birt.chart.model.attribute.Style;
21 import org.eclipse.birt.chart.model.attribute.StyleMap;
22 import org.eclipse.birt.chart.model.attribute.StyledComponent;
23 import org.eclipse.birt.chart.model.attribute.TextAlignment;
24 import org.eclipse.birt.chart.model.attribute.VerticalAlignment;
25 import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionImpl;
26 import org.eclipse.birt.chart.model.attribute.impl.FontDefinitionImpl;
27 import org.eclipse.birt.chart.model.attribute.impl.InsetsImpl;
28 import org.eclipse.birt.chart.model.attribute.impl.TextAlignmentImpl;
29 import org.eclipse.birt.chart.style.IStyle;
30 import org.eclipse.birt.chart.style.IStyleProcessor;
31 import org.eclipse.birt.chart.style.SimpleStyle;
32 import org.eclipse.emf.ecore.util.EcoreUtil;
33
34 /**
35  * SimpleProcessor
36  */

37 public final class LabelStyleProcessor implements IStyleProcessor
38 {
39
40     private static SimpleStyle sstyle = null;
41
42     /**
43      * The constructor.
44      */

45     public LabelStyleProcessor( String JavaDoc fontName, float size, boolean bBold,
46             boolean bItalic, ColorDefinition cd )
47     {
48         TextAlignment ta = TextAlignmentImpl.create( );
49         ta.setHorizontalAlignment( HorizontalAlignment.RIGHT_LITERAL );
50         ta.setVerticalAlignment( VerticalAlignment.BOTTOM_LITERAL );
51
52         FontDefinition font = FontDefinitionImpl.create( ( fontName == null ) ? "Arial" : fontName, //$NON-NLS-1$
53
( size <= 0 ) ? (float)16.0 : size,
54                 bBold,
55                 bItalic,
56                 false,
57                 false,
58                 true,
59                 0.0,
60                 ta );
61
62         sstyle = new SimpleStyle( font,
63                 cd,
64                 ColorDefinitionImpl.CREAM( ),
65                 null,
66                 InsetsImpl.create( 1.0, 1.0, 1.0, 1.0 ) );
67
68     }
69
70     /*
71      * (non-Javadoc)
72      *
73      * @see org.eclipse.birt.chart.style.IStyleProcessor#getStyle(org.eclipse.birt.chart.model.attribute.StyledComponent)
74      */

75     public IStyle getStyle( Chart model, StyledComponent name )
76     {
77         if ( model != null && model.getStyles( ).size( ) > 0 )
78         {
79             for ( Iterator JavaDoc itr = model.getStyles( ).iterator( ); itr.hasNext( ); )
80             {
81                 StyleMap sm = (StyleMap) itr.next( );
82
83                 if ( sm.getComponentName( ).equals( name ) )
84                 {
85                     Style style = sm.getStyle( );
86
87                     SimpleStyle rt = new SimpleStyle( sstyle );
88
89                     if ( style.getFont( ) != null )
90                     {
91                         rt.setFont( (FontDefinition) EcoreUtil.copy( style.getFont( ) ) );
92                     }
93                     if ( style.getColor( ) != null )
94                     {
95                         rt.setColor( (ColorDefinition) EcoreUtil.copy( style.getColor( ) ) );
96                     }
97                     if ( style.getBackgroundColor( ) != null )
98                     {
99                         rt.setBackgroundColor( (ColorDefinition) EcoreUtil.copy( style.getBackgroundColor( ) ) );
100                     }
101                     if ( style.getBackgroundImage( ) != null )
102                     {
103                         rt.setBackgroundImage( (Image) EcoreUtil.copy( style.getBackgroundImage( ) ) );
104                     }
105                     if ( style.getPadding( ) != null )
106                     {
107                         rt.setPadding( (Insets) EcoreUtil.copy( style.getPadding( ) ) );
108                     }
109
110                     return rt;
111                 }
112             }
113         }
114
115         return sstyle.copy( );
116
117     }
118 }
Popular Tags