blob: 287460060497f65ca74196355d4a376914252f63 [file] [log] [blame]
<?xml version="1.0" encoding="utf-8"?>
<!--
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.
-->
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:textEditBar="textEditBar.*"
addedToStage="onAddedToStage()" removedFromStage="onRemovedFromStage()">
<mx:Metadata>
<!-- event generated by this component -->
[Event(name="change", type="textEditBar.StyleChangeEvent")]
<!-- undocumented -->
[DefaultTriggerEvent("change")]
</mx:Metadata>
<mx:Script>
<![CDATA[
import flashx.textLayout.edit.SelectionManager;
import mx.collections.ArrayCollection;
import flashx.textLayout.elements.TextFlow;
import flashx.textLayout.edit.SelectionFormat;
import flashx.textLayout.edit.ISelectionManager;
import flashx.textLayout.edit.SelectionManager;
import flashx.textLayout.edit.ElementRange;
import flash.display.BlendMode;
private const FOCUS:String = "focus";
private const NOFOCUS:String = "noFocus";
private const INACTIVE:String = "inactive";
private var _curState:String = FOCUS;
[Bindable]
public var blendingArray:ArrayCollection = new ArrayCollection([
{label:"Add", data:BlendMode.ADD},
{label:"Alpha", data:BlendMode.ALPHA},
{label:"Darken", data:BlendMode.DARKEN},
{label:"Difference", data:BlendMode.DIFFERENCE},
{label:"Erase", data:BlendMode.ERASE},
{label:"Hardlight", data:BlendMode.HARDLIGHT},
{label:"Invert", data:BlendMode.INVERT},
{label:"Layer", data:BlendMode.LAYER},
{label:"Lighten", data:BlendMode.LIGHTEN},
{label:"Multiply", data:BlendMode.MULTIPLY},
{label:"Normal", data:BlendMode.NORMAL},
{label:"Overlay", data:BlendMode.OVERLAY},
{label:"Screen", data:BlendMode.SCREEN},
{label:"Shader", data:BlendMode.SHADER},
{label:"Subtract", data:BlendMode.SUBTRACT}
]);
[Bindable]
public var selectionStateArray:ArrayCollection = new ArrayCollection([
{label:"Active Focus", data:FOCUS},
{label:"Active No Focus", data:NOFOCUS},
{label:"Inactive", data:INACTIVE}
]);
public function update(range:ElementRange):void
{
}
private var _activeFlow:TextFlow = null;
public function get activeFlow():TextFlow
{
return _activeFlow;
}
public function set activeFlow(t:TextFlow):void
{
_activeFlow = t;
}
private function setSelectionState():void
{
_curState = String(stateCombo.dataProvider[stateCombo.selectedIndex].data);
updateSelectionSettings(_activeFlow);
}
private function setBackgroundSelection():void
{
if (_activeFlow && _activeFlow.interactionManager)
{
var selMgr:ISelectionManager = _activeFlow.interactionManager;
var curSelectionFormat:SelectionFormat;
if (_curState == FOCUS)
curSelectionFormat = selMgr.focusedSelectionFormat;
else if (_curState == NOFOCUS)
curSelectionFormat = selMgr.unfocusedSelectionFormat;
else
curSelectionFormat = selMgr.inactiveSelectionFormat;
if ((curSelectionFormat.rangeColor != colorPicker.selectedColor) || (curSelectionFormat.rangeBlendMode != blendingCombo.text) || (curSelectionFormat.rangeAlpha != Number(alphaSetting.text)))
{
var newSelectionFormat:SelectionFormat = new SelectionFormat(colorPicker.selectedColor, Number(alphaSetting.text), String(blendingCombo.dataProvider[blendingCombo.selectedIndex].data));
if (_curState == FOCUS)
selMgr.focusedSelectionFormat = newSelectionFormat;
else if (_curState == NOFOCUS)
selMgr.unfocusedSelectionFormat = newSelectionFormat;
else
selMgr.inactiveSelectionFormat = newSelectionFormat;
}
}
}
private var onStage:Boolean = false;
private var addedFrameEventListener:Boolean = false;
private function onAddedToStage():void
{
// the dataProviders aren't set up yet - delay to the frame
onStage = true;
if (!addedFrameEventListener)
{
addedFrameEventListener = true;
addEventListener("enterFrame",onEnterFrame);
}
}
private function onEnterFrame(p:Event):void
{
this.removeEventListener("enterFrame",onEnterFrame);
addedFrameEventListener = false;
updateSelectionSettings(_activeFlow);
}
private function onRemovedFromStage():void
{
onStage = false;
}
protected function setComboSelection2(combo:ComboBox,val:String):void
{
var length:uint = combo.dataProvider.length;
for (var i:uint = 0; i < length; i++)
{
if (combo.dataProvider[i].data == val)
{
combo.selectedIndex = i;
return;
}
}
combo.selectedIndex = -1;
}
public function updateSelectionSettings(t:TextFlow):void
{
_activeFlow = t;
if (onStage)
{
var selMgr:ISelectionManager = _activeFlow ? _activeFlow.interactionManager : null;
if (selMgr)
{
visible = true;
var selFormat:SelectionFormat;
if (_curState == FOCUS)
selFormat = selMgr.focusedSelectionFormat;
else if (_curState == NOFOCUS)
selFormat = selMgr.unfocusedSelectionFormat;
else
selFormat = selMgr.inactiveSelectionFormat;
setComboSelection2(blendingCombo, selFormat.rangeBlendMode);
alphaSetting.text = String(selFormat.rangeAlpha);
colorPicker.selectedColor = Number(selFormat.rangeColor);
}
else
visible = false;
}
}
]]>
</mx:Script>
<mx:Label text="Selection State:" fontWeight="bold"/>
<mx:ComboBox id="stateCombo" width="140" editable="false"
paddingLeft="2" selectedIndex="0"
dataProvider = "{selectionStateArray}"
focusOut="setSelectionState();"
close="setSelectionState();"
keyFocusChange="setSelectionState();"
enter="setSelectionState();"/>
<mx:Label text="Color:" fontWeight="bold"/>
<mx:ColorPicker id="colorPicker" width="22" height="22"
close="setBackgroundSelection();"/>
<mx:Label text="Blending Mode:" fontWeight="bold"/>
<mx:ComboBox id="blendingCombo" width="140" editable="false"
paddingLeft="2" selectedIndex="3"
dataProvider = "{blendingArray}"
focusOut="setBackgroundSelection();"
close="setBackgroundSelection();"
keyFocusChange="setBackgroundSelection();"
enter="setBackgroundSelection();"/>
<mx:Label text="Alpha:" fontWeight="bold"/>
<mx:TextInput id="alphaSetting" width="70" text="1.0" focusOut="setBackgroundSelection();"
enter="setBackgroundSelection();"
keyFocusChange="setBackgroundSelection();"/>
</mx:HBox>