⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fsdefinetextfield.java

📁 利用opensource的开源jar实现生成flash文件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
 * FSDefineTextField.java
 * Transform
 * 
 * Copyright (c) 2001-2006 Flagstone Software Ltd. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 *
 *  * Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright notice, 
 *    this list of conditions and the following disclaimer in the documentation 
 *    and/or other materials provided with the distribution.
 *  * Neither the name of Flagstone Software Ltd. nor the names of its contributors 
 *    may be used to endorse or promote products derived from this software 
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package com.flagstone.transform;

import java.util.*;

/**
FSDefineTextField defines an editable text field. 
 
<p>The value entered into the text field is assigned to a specified variable 
allowing the creation of forms to accept values entered by a person viewing the 
Flash file.</p>

<p>The class contains a complex set of attributes which allows a high degree of 
control over how a text field is displayed:</p>

<table class="datasheet">

<tr><th align="left" colspan="2">Attributes</th></tr>

<tr>
<td><a name="FSDefineTextField_0">type</a></td>
<td>Identifies the data structure when it is encoded. Read-only.</td>
</tr>

<tr>
<td><a name="FSDefineTextField_1">identifier</a></td>
<td>An unique identifier for this object in the range 1..65535.</td>
</tr>
<tr>
<td><a name="FSDefineTextField_2">bounds</a></td>
<td>The bounding rectangle for the text field.</td>
</tr>
<tr>
<td><a name="FSDefineTextField_3">wordWrap</a></td>
<td>Indicates whether the text should be wrapped.</td>
</tr>
<tr>
<td><a name="FSDefineTextField_4">multiline</a></td>
<td>Indicates whether the text field contains multiple lines.</td>
</tr>
<tr>
<td><a name="FSDefineTextField_5">password</a></td>
<td>Indicates whether the text field will be used to display a password.</td>
</tr>
<tr>
<td><a name="FSDefineTextField_6">readOnly</a></td>
<td>Indicates whether the text field is read only.</td>
</tr>
<tr>
<td><a name="FSDefineTextField_7">selectable</a></td>
<td>Indicates whether the text field is selectable.</td>
</tr>
<tr>
<td><a name="FSDefineTextField_8">bordered</a></td>
<td>Indicates whether the text field is bordered.</td>
</tr>
<tr>
<td><a name="FSDefineTextField_9">HTML</a></td>
<td>Indicates whether the text field contains HTML.</td>
</tr>
<tr>
<td><a name="FSDefineTextField_10">fontIdentifier</a></td>
<td>The identifier of the font displayed in the text field.</td>
</tr>
<tr>
<td><a name="FSDefineTextField_11">height</a></td>
<td>The height of the characters in twips.</td>
</tr>
<tr>
<td><a name="FSDefineTextField_12">useFontGlyphs</a></td>
<td>Use either the glyphs defined in the movie to display the text or load the 
specified from the platform on which the Flash Player is hosted.</td>
</tr>
<tr>
<td><a name="FSDefineTextField_13">autosize</a></td>
<td>Indicates whether the text field will resize automatically to fit the text 
entered.</td>
</tr>
<tr>
<td><a name="FSDefineTextField_14">colour</a></td>
<td>The colour of the text. If set to null then the text colour defaults to 
black.</td>
</tr>
<tr>
<td><a name="FSDefineTextField_15">maxLength</a></td>
<td>The maximum length of the text field. May be set to zero is not maximum 
length is defined.</td>
</tr>
<tr>
<td><a name="FSDefineTextField_16">variableName</a></td>
<td>The name of the variable the text will be assigned to.</td>
</tr>
<tr>
<td><a name="FSDefineTextField_17">initialText</a></td>
<td>The default text displayed in the text field.</td>
</tr>
</table>

<p>Additional layout information for the spacing of the text relative to the 
text field borders can also be specified through the following set of 
attributes:</p>

<table class="datasheet">

<tr>
<td><a name="FSDefineTextField_17">alignment</a></td><td>Whether the text in the 
field is left-aligned, right-aligned, centred.</td>
</tr>
<tr>
<td><a name="FSDefineTextField_18">leftMargin</a></td><td>Left margin in 
twips.</td>
</tr>
<tr>
<td><a name="FSDefineTextField_19">rightMargin</a></td><td>Right margin in 
twips.</td>
</tr>
<tr>
<td><a name="FSDefineTextField_20">indent</a></td><td>Text indentation in 
twips.</td>
</tr>
<tr>
<td><a name="FSDefineTextField_21">leading</a></td><td>Leading in twips.</td>
</tr>
</table>

<p>The default values for the alignment is AlignLeft while the leftMargin, 
rightMargin indent and leading attributes are set to the constant
Transform.VALUE_NOT_SET. If the attributes remain unchanged then the layout 
information will not be encoded. If any of the values in this group are set then 
they must all have values assigned for the field to be displayed correctly
otherwise default values of 0 will be used.</p>

<p><b>HTML Support</b><br/>
Setting the HTML flag to true allows text marked up with a limited set of HTML 
tags to be displayed in the text field. The following tags are supported:</p>

<table class="datasheet">
<tr>
<td>&lt;p&gt;&lt;/p&gt;</td>
<td>Delimits a paragraph. Only the align attribute is supported:<br>
<p [align = left | right | center ]></p>
</td>
</tr>

<tr>
<td>&lt;br&gt;</td>
<td>Inserts a line break.></p></td>
</tr>

<tr>
<td>&lt;a&gt;&lt;/a&gt;</td>
<td>Define a hyperlink. Two attributes are supported:
<ul>
<li>href - the URL of the link.</li>
<li>target - name of a window or frame. (optional)</li>
</ul>
</td>
</tr>

<tr>
<td>&lt;font&gt;&lt;/font&gt;</td>
<td>Format enclosed text using the font. Three attributes are supported:
<ul>
<li>name - must match the name of a font defined using the FSDefineFont2 class.</li>
<li>size - the height of the font in twips.</li>
<li>color - the colour of the text in the hexadecimal format #RRGGBB.</li>
</ul>
</td>
</tr>

<tr>
<td>&lt;b&gt;&lt;/b&gt;</td>
<td>Delimits text that should be displayed in bold.</td>
</tr>

<tr>
<td>&lt;b&gt;&lt;/b&gt;</td>
<td>Delimits text that should be displayed in italics.</td>
</tr>

<tr>
<td>&lt;b&gt;&lt;/b&gt;</td>
<td>Delimits text that should be displayed underlined.</td>
</tr>

<tr>
<td>&lt;li&gt;&lt;/li&gt;</td>
<td>Display bulleted paragraph. Strictly speaking this is not an HTML list. 
The &lt;ul&gt; tag is not required and no other list format is supported.</td>
</tr>

</table>

<h1 class="datasheet">History</h1>

<p>FSDefineTextField class represents the DefineTextField from the Macromedia Flash (SWF) File Format Specification. It was introduced in Flash 4.</p>
 */  
public class FSDefineTextField extends FSDefineObject
{
/** Key used to identify the wordWrapped attribute. */
    public static final String WordWrapped = "WordWrapped";
/** Key used to identify the multiline attribute. */
    public static final String Multiline = "Multiline";
/** Key used to identify the password attribute. */
    public static final String Password = "Password";
/** Key used to identify the readOnly attribute. */
    public static final String ReadOnly = "ReadOnly";
/** Key used to identify the selectable attribute. */
    public static final String Selectable = "Selectable";
/** Key used to identify the bordered attribute. */
    public static final String Bordered = "Bordered";
/** Key used to identify the bordered attribute. */
    public static final String HTML = "HTML";
/** Key used to identify the useFontGlyphs attribute. */
    public static final String UseFontGlyphs = "UseFontGlyphs";
// Flash 6
/** Key used to identify the autoSize attribute. */
    public static final String AutoSize = "AutoSize";
// End Flash 6
/** Key used to identify the identifier attribute. */
    public static final String FontIdentifier = "FontIdentifier";
/** Key used to identify the fontHeight attribute. */
    public static final String FontHeight = "FontHeight";
/** Key used to identify the color attribute. */
    public static final String Color = "Color";
/** Key used to identify the maxLength attribute. */
    public static final String MaxLength = "MaxLength";
/** Key used to identify the leftMargin attribute. */
    public static final String LeftMargin = "LeftMargin";
/** Key used to identify the rightMargin attribute. */
    public static final String RightMargin = "RightMargin";
/** Key used to identify the indent attribute. */
    public static final String Indent = "Indent";
/** Key used to identify the leading attribute. */
    public static final String Leading = "Leading";
/** Key used to identify the variableName attribute. */
    public static final String VariableName = "VariableName";
/** Key used to identify the initialText attribute. */
    public static final String InitialText = "InitialText";


/** Defines that the text displayed in a text field is left aligned. */
    public static final int AlignLeft = 0;
/** Defines that the text displayed in a text field is right aligned. */
    public static final int AlignRight = 1;
/** Defines that the text displayed in a text field is centre aligned. */
    public static final int AlignCenter = 2;
/** Defines that the text displayed in a text field is justified. */
    public static final int AlignJustify = 3;
    
    private FSBounds bounds = null;
    private boolean wordWrapped = false;
    private boolean multiline = false;
    private boolean password = false;
    private boolean readOnly = false;
    private int reserved1 = 0;
    private boolean selectable = false;
    private boolean bordered = false;
    private boolean reserved2 = false;
    private boolean html = false;
    private boolean useFontGlyphs = false;
    private boolean autoSize = false;
    private int fontIdentifier = 0;
    private int fontHeight = 0;
    private FSColor color = null;
    private int maxLength = 0;
    private int alignment = Transform.VALUE_NOT_SET;
    private int leftMargin = Transform.VALUE_NOT_SET;
    private int rightMargin = Transform.VALUE_NOT_SET;
    private int indent = Transform.VALUE_NOT_SET;
    private int leading = Transform.VALUE_NOT_SET;
    private String variableName = "";
    private String initialText = "";

    /**
     * Construct an FSDefineTextField object, initalizing it with values decoded from
     * an encoded object.
     * 
     * @param coder an FSCoder containing the binary data.
     */
    public FSDefineTextField(FSCoder coder)
    {
        super(DefineTextField, 0);
        decode(coder);
    }
    /** Constructs an FSDefineTextField object with the specified identifier and with the size defined by the bounding rectangle. All other attributes are set to their default values which will result in a blank, single-line, editable text field. Any values entered will not be assigned to a variable. Since no font is specified the text will be displayed in a non-spaced font 20 twips in height.

        @param anIdentifier the unique identifier for this object.
        @param aBounds the bounding rectangle for the field which defines its size.
        */
    public FSDefineTextField(int anIdentifier, FSBounds aBounds)
    {
        super(DefineTextField, anIdentifier);
        setBounds(aBounds);
    }
    /** Constructs an FSDefineTextField object setting the attributes added to the Hashtable. Each entry consists of a key-value pair. The key is one of the pre-defined attribute names while the value is an instance of a wrapper class (Boolean, Integer or String) that will be assigned to the specified attribute.

        @param anIdentifier the unique identifier for this object.
        @param aBounds the bounding rectangle for the field which defines its size.
        @param attributes a collection of key-value pairs identifying the attributes to be set.
        */
    public FSDefineTextField(int anIdentifier, FSBounds aBounds, Hashtable attributes)
    {
        super(DefineTextField, anIdentifier);
        setBounds(aBounds);
        setAttributes(attributes);
    }
    /**
     * Constructs an FSDefineText object by copying values from an existing 
     * object.
     *
     * @param obj an FSDefineText object.
     */
    public FSDefineTextField(FSDefineTextField obj)
    {
        super(obj);
        bounds = new FSBounds(obj.bounds);
        wordWrapped = obj.wordWrapped;
        multiline = obj.multiline;
        password = obj.password;
        readOnly = obj.readOnly;
        reserved1 = obj.reserved1;
        selectable = obj.selectable;
        bordered = obj.bordered;
        reserved2 = obj.reserved2;
        html = obj.html;
        useFontGlyphs = obj.useFontGlyphs;
        autoSize = obj.autoSize;
        fontIdentifier = obj.fontIdentifier;
        fontHeight = obj.fontHeight;
        color = new FSColor(obj.color);
        maxLength = obj.maxLength;
        alignment = obj.alignment;
        leftMargin = obj.leftMargin;
        rightMargin = obj.rightMargin;
        indent = obj.indent;
        leading = obj.leading;
        variableName = new String(obj.variableName);
        initialText = new String(obj.initialText);
    }    

    /** Gets the bounding rectangle that completely encloses the text field.

        @return the bounding rectangle for the text field.
        */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -