/*----------------------------------------------------------------------------- The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is Fever Framework code. The Initial Developer of the Original Code is Romain Ecarnot. Portions created by Initial Developer are Copyright (C) 2006 the Initial Developer. All Rights Reserved. Contributor(s): Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -----------------------------------------------------------------------------*/ import org.aswing.ASTextFormat; import fvaswing.structure.FvFont; /** * {@code FvTextFormat } class. * * @author Romain Ecarnot */ class fvaswing.structure.FvTextFormat extends ASTextFormat { //------------------------------------------------------------------------- // Private properties //------------------------------------------------------------------------- private var _shortcutIndex : Number; //------------------------------------------------------------------------- // Public API //------------------------------------------------------------------------- /** * use these create methods to get an ASTextFormat instance */ public static function getEmptyASTextFormat() : FvTextFormat { return new FvTextFormat(); } /** * Creates and returns {@link FvTextFormat} build with passed-in {@code name} font name. */ public static function getASTextFormatWithName( name : String ) : FvTextFormat { var asTF : FvTextFormat = new FvTextFormat(); asTF.setName(name); return asTF; } /** * Creates and returns {@link FvTextFormat} build with passed-in {@code name} * font name and {@code size} font size. */ public static function getASTextFormatWithNameSize( name : String , size : Number ) : FvTextFormat { var asTF : FvTextFormat = new FvTextFormat(); asTF.setName( name ); asTF.setSize( size ); return asTF; } /** * Creates and returns {@link FvTextFormat} build with passed-in {@code name} * font name and {@code color} font color. */ public static function getASTextFormatWithNameColor( name : String , color : Number ) : FvTextFormat { var asTF : FvTextFormat = new FvTextFormat(); asTF.setName( name ); asTF.setColor( color ); return asTF; } /** * Creates and returns {@link FvTextFormat} build with passed-in {@code name} * font name, {@code size} font size and {@code color} font color. */ public static function getASTextFormatWithNameSizeColor( name : String , size : Number , color : Number ) : FvTextFormat { var asTF : FvTextFormat = new FvTextFormat(); asTF.setName( name ); asTF.setSize( size ); asTF.setColor( color ); return asTF; } /** * Creates and returns {@link FvTextFormat} build with passed-in {@code font} * font instance. */ public static function getASTextFormatWithASFont( font : FvFont ) : FvTextFormat { var asTF : FvTextFormat = new FvTextFormat(); asTF.setASFont( font ); return asTF; } /** * Creates and returns {@link FvTextFormat} build with passed-in {@code tf} * text format. */ public static function getASTextFormatWithTextFormat( tf : TextFormat ) : FvTextFormat { var astf : FvTextFormat = new FvTextFormat(); astf.setName((tf.font != null) ? tf.font : ASTextFormat.DEFAULT_NAME); astf.setSize((tf.size != null) ? tf.size : ASTextFormat.DEFAULT_SIZE); astf.setBold((tf.bold != null) ? tf.bold : ASTextFormat.DEFAULT_BOLD); astf.setItalic((tf.italic != null) ? tf.italic : ASTextFormat.DEFAULT_ITALIC); astf.setUnderline((tf.underline != null) ? tf.underline : ASTextFormat.DEFAULT_UNDERLINE); switch(tf.align) { case "left": astf.setAlign(LEFT); break; case "center": astf.setAlign(CENTER); break; case "right": astf.setAlign(RIGHT); break; default: astf.setAlign(DEFAULT_ALIGN); break; } astf.setBlockIndent((tf.blockIndent != null) ? tf.blockIndent : ASTextFormat.DEFAULT_BLOCKINDENT); astf.setIndent((tf.indent != null) ? tf.indent : ASTextFormat.DEFAULT_INDENT); astf.setBullet((tf.bullet != null) ? tf.bullet : ASTextFormat.DEFAULT_BULLET); astf.setColor((tf.color != null) ? tf.color : ASTextFormat.DEFAULT_COLOR); astf.setLeftMargin((tf.leftMargin != null) ? tf.leftMargin : ASTextFormat.DEFAULT_LEFTMARGIN); astf.setRightMargin((tf.rightMargin != null) ? tf.rightMargin : ASTextFormat.DEFAULT_RIGHTMARGIN); return astf; } /** * Apply passed-in {@code font} properties */ public function setASFont( font : FvFont ) : Void { setName( font.getName() ); setSize( font.getSize() ); setBold( font.isBold() ); setItalic( font.isItalic() ); setUnderline( font.isUnderline() ); setEmbedFonts( font.isEmbedFonts() ); } /** * Returns {@link fvaswing.structure.FvFont} using current format * properties. */ public function getASFont() : FvFont { return new FvFont( getName(), getSize(), getBold(), getItalic(), getUnderline(), getEmbedFonts() ); } /** * Sets the shortcut marker index. */ public function setShortcutIndex( index : Number ) : Void { _shortcutIndex = index; } /** * Removes the shortcut marker index. */ public function removeShortcutIndex() : Void { _shortcutIndex = -1; } /** * Applies to the whole TextField and New coming text. */ public function applyToTextCurrentAndNew( text : TextField ) : Void { var tf : TextFormat = getTextFormat(); text.setTextFormat( tf ); text.setNewTextFormat( tf ); text.embedFonts = getEmbedFonts(); if( _shortcutIndex > -1 ) { var sf : TextFormat = getTextFormat(); sf.underline = true; text.setTextFormat( _shortcutIndex, _shortcutIndex + 1, sf ); } } //------------------------------------------------------------------------- // Private implementation //------------------------------------------------------------------------- /** * Constructor. */ private function FvTextFormat() { } }