blob: 8a735f7df05105ba75da67e16eb1a948ea6af6b3 [file] [log] [blame]
////////////////////////////////////////////////////////////////////////////////
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (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.apache.org/licenses/LICENSE-2.0
//
// 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.
//
////////////////////////////////////////////////////////////////////////////////
package org.apache.flex.html.staticControls.beads
{
import flash.display.Shape;
import flash.display.SimpleButton;
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFieldType;
import org.apache.flex.core.IBead;
import org.apache.flex.core.IStrand;
import org.apache.flex.core.ITextBead;
import org.apache.flex.core.ITextModel;
public class TextButtonBead implements ITextButtonBead
{
public function TextButtonBead()
{
upTextField = new TextField();
downTextField = new TextField();
overTextField = new TextField();
upTextField.border = true;
downTextField.border = true;
overTextField.border = true;
upTextField.background = true;
downTextField.background = true;
overTextField.background = true;
upTextField.borderColor = 0;
downTextField.borderColor = 0;
overTextField.borderColor = 0;
upTextField.backgroundColor = 0xCCCCCC;
downTextField.backgroundColor = 0x808080;
overTextField.backgroundColor = 0xFFCCCC;
upTextField.selectable = false;
upTextField.type = TextFieldType.DYNAMIC;
downTextField.selectable = false;
downTextField.type = TextFieldType.DYNAMIC;
overTextField.selectable = false;
overTextField.type = TextFieldType.DYNAMIC;
upTextField.autoSize = "left";
downTextField.autoSize = "left";
overTextField.autoSize = "left";
}
private var textModel:ITextModel;
private var _strand:IStrand;
private var shape:Shape;
public function set strand(value:IStrand):void
{
_strand = value;
textModel = value.getBeadByType(ITextModel) as ITextModel;
textModel.addEventListener("textChange", textChangeHandler);
textModel.addEventListener("htmlChange", htmlChangeHandler);
shape = new Shape();
shape.graphics.beginFill(0xCCCCCC);
shape.graphics.drawRect(0, 0, 10, 10);
shape.graphics.endFill();
SimpleButton(value).upState = upTextField;
SimpleButton(value).downState = downTextField;
SimpleButton(value).overState = overTextField;
SimpleButton(value).hitTestState = shape;
if (textModel.text !== null)
text = textModel.text;
if (textModel.html !== null)
html = textModel.html;
}
private function textChangeHandler(event:Event):void
{
text = textModel.text;
}
private function htmlChangeHandler(event:Event):void
{
html = textModel.html;
}
private var upTextField:TextField;
private var downTextField:TextField;
private var overTextField:TextField;
public function get text():String
{
return upTextField.text;
}
public function set text(value:String):void
{
upTextField.text = value;
downTextField.text = value;
overTextField.text = value;
shape.graphics.clear();
shape.graphics.beginFill(0xCCCCCC);
shape.graphics.drawRect(0, 0, upTextField.textWidth, upTextField.textHeight);
shape.graphics.endFill();
}
public function get html():String
{
return upTextField.htmlText;
}
public function set html(value:String):void
{
upTextField.htmlText = value;
downTextField.htmlText = value;
overTextField.htmlText = value;
}
}
}