Coverage report

  %line %branch
tsukuba_bunko.peko.scenario.text.PageConfigurator
0% 
0% 

 1  
 /*
 2  
  * All Rights Reserved.
 3  
  * Copyright (C) 1999-2005 Tsukuba Bunko.
 4  
  *
 5  
  * Licensed under the BSD License ("the License"); you may not use
 6  
  * this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  *       http://www.tsukuba-bunko.org/licenses/LICENSE.txt
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  *
 17  
  * $Id: PageConfigurator.java,v 1.2 2005/07/24 20:55:57 ppoi Exp $
 18  
  */
 19  
 package tsukuba_bunko.peko.scenario.text;
 20  
 
 21  
 import	java.awt.Color;
 22  
 import	java.awt.Dimension;
 23  
 import	java.awt.Font;
 24  
 import	java.awt.Insets;
 25  
 import	java.awt.Point;
 26  
 
 27  
 import	java.awt.font.TextAttribute;
 28  
 
 29  
 import	java.util.Map;
 30  
 
 31  
 import	tsukuba_bunko.peko.Logger;
 32  
 
 33  
 import	tsukuba_bunko.peko.canvas.text.Page;
 34  
 
 35  
 import	tsukuba_bunko.peko.resource.ColorManager;
 36  
 import	tsukuba_bunko.peko.resource.DimensionDeserializer;
 37  
 import	tsukuba_bunko.peko.resource.FontManager;
 38  
 import	tsukuba_bunko.peko.resource.InsetsDeserializer;
 39  
 import	tsukuba_bunko.peko.resource.ResourceManager;
 40  
 import	tsukuba_bunko.peko.resource.PointDeserializer;
 41  
 
 42  
 import	tsukuba_bunko.peko.scenario.SceneContext;
 43  
 
 44  
 
 45  
 /**
 46  
  * {@link tsukuba_bunko.peko.canvas.text.Page} をシーンの設定を元にカスタマイズする機能を提供します。
 47  
  * @author	$Author: ppoi $
 48  
  * @version	$Revision: 1.2 $
 49  
  */
 50  
 public class PageConfigurator	{
 51  
 
 52  
 	/**
 53  
 	 * <code>PageConfigurator</code> のインスタンスを作成するために getInstance から呼ばれます。
 54  
 	 */
 55  
 	protected PageConfigurator()
 56  
 	{
 57  0
 		super();
 58  0
 	}
 59  
 
 60  
 
 61  
 	/**
 62  
 	 * <code>page</code> にシーンの設定を反映させます。
 63  
 	 * @param	page	ページ
 64  
 	 * @param	context	シーンコンテキスト
 65  
 	 */
 66  
 	public static void configure( Page page, SceneContext context )
 67  
 	{
 68  0
 		ResourceManager	resources = ResourceManager.getInstance();
 69  0
 		FontManager	fonts = FontManager.getInstance();
 70  0
 		ColorManager	colors = ColorManager.getInstance();
 71  
 
 72  0
 		boolean	set = false;
 73  
 
 74  0
 		String	value = context.getProperty( PropertyIDs.CANVAS_TEXT_BACKGROUND_TRANSPARENCY );
 75  0
 		if( value != null )	{
 76  
 			try	{
 77  0
 				page.setTransparency( Float.parseFloat(value) );
 78  0
 				set = true;
 79  
 			}
 80  0
 			catch( Exception e )	{
 81  0
 				Logger.warn( MessageIDs.SCN2006W );
 82  0
 			}
 83  
 		}
 84  0
 		if( !set )	{
 85  0
 			Float	trans = (Float)resources.getResource( ResourceIDs.CANVAS_TEXT_BACKGROUND_TRANSPARENCY );
 86  0
 			if( trans == null )	{
 87  0
 				Logger.warn( MessageIDs.SCN2005W, new Object[]{"0.5"} );
 88  0
 				page.setTransparency( 0.5f );
 89  0
 			}
 90  
 			else	{
 91  0
 				page.setTransparency( trans.floatValue() );
 92  
 			}
 93  
 		}
 94  
 
 95  0
 		set = false;
 96  0
 		value = context.getProperty( PropertyIDs.CANVAS_TEXT_BACKGROUND_COLOR );
 97  0
 		if( value == null )	{
 98  0
 			Color	c = (Color)resources.getResource( ResourceIDs.CANVAS_TEXT_BACKGROUND_COLOR );
 99  0
 			if( c == null )	{
 100  0
 				Logger.warn( MessageIDs.SCN2003W, new Object[]{"black"} );
 101  0
 				c = Color.black;
 102  
 			}
 103  0
 			page.setBackground( c );
 104  0
 		}
 105  
 		else	{
 106  0
 			page.setBackground( colors.getColor(value) );
 107  
 		}
 108  
 
 109  0
 		String	type = context.getProperty( PropertyIDs.CANVAS_TEXT_VIEWTYPE );
 110  0
 		if( type != null )	{
 111  0
 			if( !"window".equals(type) && !"full".equals(type) )	{
 112  0
 				Logger.warn( MessageIDs.SCN2014W );
 113  0
 				type = null;
 114  
 			}
 115  
 		}
 116  0
 		if( type == null )	{
 117  0
 			type = (String)resources.getResource( ResourceIDs.CANVAS_TEXT_VIEWTYPE );
 118  0
 			if( (type == null) || !("window".equals(type) || "full".equals(type)) )	{
 119  0
 				Logger.warn( MessageIDs.SCN2013W, new Object[]{"full"} );
 120  0
 				type = "full";
 121  
 			}
 122  
 		}
 123  
 
 124  0
 		Dimension	viewSize = null;
 125  0
 		if( type.equals("window") )	{
 126  0
 			value = context.getProperty( PropertyIDs.CANVAS_TEXT_SIZE );
 127  0
 			if( value != null )	{
 128  
 				try	{
 129  0
 					viewSize = DimensionDeserializer.parseDimension( value );
 130  
 				}
 131  0
 				catch( Exception e )	{
 132  0
 					Logger.warn( MessageIDs.SCN2016W );
 133  0
 				}
 134  
 			}
 135  0
 			if( viewSize == null )	{
 136  0
 				viewSize = (Dimension)resources.getResource( ResourceIDs.CANVAS_TEXT_SIZE );
 137  0
 				if( viewSize == null )	{
 138  0
 					Logger.warn( MessageIDs.SCN2015W, new Object[]{"600, 180"} );
 139  0
 					viewSize = new Dimension( 600, 180 );
 140  
 				}
 141  
 			}
 142  
 
 143  0
 			Point	location = null;
 144  0
 			value = context.getProperty( PropertyIDs.CANVAS_TEXT_LOCATION );
 145  0
 			if( value != null )	{
 146  
 				try	{
 147  0
 					location = PointDeserializer.parsePoint( value );
 148  
 				}
 149  0
 				catch( Exception e )	{
 150  0
 					Logger.warn( MessageIDs.SCN2018W, e );
 151  0
 				}
 152  
 			}
 153  0
 			if( location == null )	{
 154  0
 				location = (Point)resources.getResource( ResourceIDs.CANVAS_TEXT_LOCATION );
 155  0
 				if( location == null )	{
 156  0
 					Logger.warn( MessageIDs.SCN2017W, new Object[]{"0, 0"} );
 157  0
 					location = new Point( 0, 0 );
 158  
 				}
 159  
 			}
 160  
 
 161  0
 			page.setLocation( location.x, location.y );
 162  
 
 163  0
 		}
 164  
 		else	{
 165  0
 			page.setLocation( 0, 0 );
 166  0
 			viewSize = page.getTextCanvas().getSize();
 167  
 		}
 168  0
 		page.setSize( viewSize );
 169  
 
 170  0
 		Insets	padding = null;
 171  0
 		value = context.getProperty( PropertyIDs.CANVAS_TEXT_PADDING );
 172  0
 		if( value != null )	{
 173  
 			try	{
 174  0
 				padding = InsetsDeserializer.parseInsets( value );
 175  
 			}
 176  0
 			catch( Exception e )	{
 177  0
 				Logger.warn( MessageIDs.SCN2020W );
 178  0
 			}
 179  
 		}
 180  0
 		if( padding == null )	{
 181  0
 			padding = (Insets)resources.getResource( ResourceIDs.CANVAS_TEXT_PADDING );
 182  0
 			if( padding == null )	{
 183  0
 				Logger.warn( MessageIDs.SCN2019W, new Object[]{"10,40,10,10"} );
 184  0
 				padding = new Insets( 10, 40, 10, 10 );
 185  
 			}
 186  
 		}
 187  0
 		page.setPadding( padding.top, padding.left, padding.bottom, padding.right );
 188  
 
 189  
 
 190  0
 		Map	fontAttrs = new java.util.HashMap( 17 );
 191  0
 		Font	baseFont = (Font)resources.getResource( ResourceIDs.CANVAS_TEXT_FONT );
 192  0
 		if( baseFont == null )	{
 193  0
 			Logger.warn( MessageIDs.SCN2011W, new Object[]{"Serif, 20"} );
 194  0
 			fontAttrs = new java.util.HashMap( 17 );
 195  0
 			fontAttrs.put( TextAttribute.FAMILY, "Serif" );
 196  0
 			fontAttrs.put( TextAttribute.SIZE, new Float(20f) );
 197  0
 			fontAttrs.put( TextAttribute.POSTURE, TextAttribute.POSTURE_REGULAR );
 198  0
 			fontAttrs.put( TextAttribute.WEIGHT, TextAttribute.WEIGHT_REGULAR );
 199  0
 		}
 200  
 		else	{
 201  0
 			fontAttrs.putAll( baseFont.getAttributes() );
 202  
 		}
 203  
 
 204  0
 		value = context.getProperty( PropertyIDs.CANVAS_TEXT_FONT_FAMILY );
 205  0
 		if( value != null )	{
 206  0
 			fontAttrs.put( TextAttribute.FAMILY, value );
 207  
 		}
 208  
 
 209  0
 		value = context.getProperty( PropertyIDs.CANVAS_TEXT_FONT_SIZE );
 210  0
 		if( value != null )	{
 211  
 			try	{
 212  0
 				fontAttrs.put( TextAttribute.SIZE, Float.valueOf(value) );
 213  
 			}
 214  0
 			catch( Exception e )	{
 215  0
 				Logger.warn( MessageIDs.SCN2012W, new Object[]{"size"} );
 216  0
 			}
 217  
 		}
 218  
 
 219  0
 		value = context.getProperty( PropertyIDs.CANVAS_TEXT_FONT_STYLE );
 220  0
 		if( value != null )	{
 221  0
 			if( "italic".equals(value) )	{
 222  0
 				fontAttrs.put( TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE );
 223  0
 			}
 224  0
 			else if( "normal".equals(value) )	{
 225  0
 				fontAttrs.put( TextAttribute.POSTURE, TextAttribute.POSTURE_REGULAR );
 226  0
 			}
 227  
 			else	{
 228  0
 				Logger.warn( MessageIDs.SCN2012W, new Object[]{"style"} );
 229  
 			}
 230  
 		}
 231  
 
 232  0
 		value = context.getProperty( PropertyIDs.CANVAS_TEXT_FONT_WEIGHT );
 233  0
 		if( value != null )	{
 234  0
 			if( "bold".equals(value) )	{
 235  0
 				fontAttrs.put( TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD );
 236  0
 			}
 237  0
 			else if( "normal".equals(value) )	{
 238  0
 				fontAttrs.put( TextAttribute.WEIGHT, TextAttribute.WEIGHT_REGULAR );
 239  
 			}
 240  
 		}
 241  
 
 242  0
 		page.setDefaultFont( fonts.getFont(fontAttrs) );
 243  
 
 244  
 
 245  0
 		value = context.getProperty( PropertyIDs.CANVAS_TEXT_FOREGROUND_COLOR );
 246  0
 		if( value == null )	{
 247  0
 			Color	c = (Color)resources.getResource( ResourceIDs.CANVAS_TEXT_FOREGROUND_COLOR );
 248  0
 			if( c == null )	{
 249  0
 				Logger.warn( MessageIDs.SCN2007W, new Object[]{"white"} );
 250  0
 				c = Color.white;
 251  
 			}
 252  0
 			page.setForeground( c );
 253  0
 		}
 254  
 		else	{
 255  0
 			page.setForeground( colors.getColor(value) );
 256  
 		}
 257  
 
 258  0
 		value = context.getProperty( PropertyIDs.CANVAS_TEXT_FOREGROUND_SHADOW );
 259  0
 		if( value == null )	{
 260  0
 			Color	c = (Color)resources.getResource( ResourceIDs.CANVAS_TEXT_FOREGROUND_SHADOW );
 261  0
 			if( c == null )	{
 262  0
 				Logger.warn( MessageIDs.SCN2007W, new Object[]{"black"} );
 263  0
 				c = Color.black;
 264  
 			}
 265  0
 			page.setShadow( c );
 266  0
 		}
 267  
 		else	{
 268  0
 			page.setShadow( colors.getColor(value) );
 269  
 		}
 270  
 
 271  0
 		page.updateCanvas();
 272  0
 	}
 273  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.