You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by pe...@apache.org on 2014/03/05 22:46:19 UTC
git commit: [flex-asjs] [refs/heads/develop] - Added format bead
classes and IFormatBead interface. Added view beads that are capable of
working with format beads. Beads created in MXML will trigger a "beadsAdded"
event.
Repository: flex-asjs
Updated Branches:
refs/heads/develop 84952edc9 -> 8fd96fcad
Added format bead classes and IFormatBead interface. Added view beads that are capable of working with format beads. Beads created in MXML will trigger a "beadsAdded" event.
Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/8fd96fca
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/8fd96fca
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/8fd96fca
Branch: refs/heads/develop
Commit: 8fd96fcad0daab1b667964247ab02e06b7e45b4d
Parents: 84952ed
Author: Peter Ent <pe...@apache.org>
Authored: Wed Mar 5 16:45:56 2014 -0500
Committer: Peter Ent <pe...@apache.org>
Committed: Wed Mar 5 16:45:56 2014 -0500
----------------------------------------------------------------------
.../as/projects/FlexJSUI/basic-manifest.xml | 2 +
.../as/projects/FlexJSUI/src/FlexJSUIClasses.as | 4 +-
.../src/org/apache/flex/core/IFormatBead.as | 69 +++++++++++++++
.../accessories/DateFormatMMDDYYYYBead.as | 72 +++++++++++++++-
.../html/staticControls/beads/DateFieldView.as | 16 +++-
.../staticControls/beads/FormatableLabelView.as | 90 ++++++++++++++++++++
.../beads/FormatableTextInputView.as | 89 +++++++++++++++++++
.../apache/flex/utils/MXMLDataInterpreter.as | 17 +++-
8 files changed, 350 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8fd96fca/frameworks/as/projects/FlexJSUI/basic-manifest.xml
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/basic-manifest.xml b/frameworks/as/projects/FlexJSUI/basic-manifest.xml
index 2708303..3e433a9 100644
--- a/frameworks/as/projects/FlexJSUI/basic-manifest.xml
+++ b/frameworks/as/projects/FlexJSUI/basic-manifest.xml
@@ -33,6 +33,8 @@
<component id="DateField" class="org.apache.flex.html.staticControls.DateField"/>
<component id="DropDownList" class="org.apache.flex.html.staticControls.DropDownList"/>
<component id="DropDownListList" class="org.apache.flex.html.staticControls.supportClasses.DropDownListList"/>
+ <component id="FormatableLabelView" class="org.apache.flex.html.staticControls.beads.FormatableLabelView"/>
+ <component id="FormatableTextInputView" class="org.apache.flex.html.staticControls.beads.FormatableTextInputView"/>
<component id="Image" class="org.apache.flex.html.staticControls.Image"/>
<component id="Label" class="org.apache.flex.html.staticControls.Label"/>
<component id="TextButton" class="org.apache.flex.html.staticControls.TextButton"/>
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8fd96fca/frameworks/as/projects/FlexJSUI/src/FlexJSUIClasses.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/src/FlexJSUIClasses.as b/frameworks/as/projects/FlexJSUI/src/FlexJSUIClasses.as
index 4d15da6..3091f39 100644
--- a/frameworks/as/projects/FlexJSUI/src/FlexJSUIClasses.as
+++ b/frameworks/as/projects/FlexJSUI/src/FlexJSUIClasses.as
@@ -42,7 +42,9 @@ internal class FlexJSUIClasses
import org.apache.flex.html.staticControls.beads.CSSTextButtonView; CSSTextButtonView;
import org.apache.flex.html.staticControls.beads.DateChooserView; DateChooserView;
import org.apache.flex.html.staticControls.beads.DateFieldView; DateFieldView;
- import org.apache.flex.html.staticControls.beads.DropDownListView; DropDownListView;
+ import org.apache.flex.html.staticControls.beads.DropDownListView; DropDownListView;
+ import org.apache.flex.html.staticControls.beads.FormatableLabelView; FormatableLabelView;
+ import org.apache.flex.html.staticControls.beads.FormatableTextInputView; FormatableTextInputView;
import org.apache.flex.html.staticControls.beads.ImageView; ImageView;
import org.apache.flex.html.staticControls.beads.ListView; ListView;
import org.apache.flex.html.staticControls.beads.NumericStepperView; NumericStepperView;
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8fd96fca/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IFormatBead.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IFormatBead.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IFormatBead.as
new file mode 100644
index 0000000..3880f5a
--- /dev/null
+++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/core/IFormatBead.as
@@ -0,0 +1,69 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.core
+{
+ import org.apache.flex.events.IEventDispatcher;
+
+ /**
+ * The IFormatBead interface should be implemented by any bead that
+ * provides a formatting service. When the bead instance is created it
+ * should listen for change events and set its formattedString property
+ * for later retrieveal.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion FlexJS 0.0
+ */
+ public interface IFormatBead extends IBead, IEventDispatcher
+ {
+ /**
+ * The name of the property for the source to be formatted.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion FlexJS 0.0
+ */
+ function get propertyName():String;
+ function set propertyName(value:String):void;
+
+ /**
+ * The name of the event to listen for, indicating that propertyName
+ * property has changed. The default event is propertyName+"Changed".
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion FlexJS 0.0
+ */
+ function get eventName():String;
+ function set eventName(value:String):void;
+
+ /**
+ * The formatted result.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion FlexJS 0.0
+ */
+ function get formattedString():String;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8fd96fca/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/staticControls/accessories/DateFormatMMDDYYYYBead.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/staticControls/accessories/DateFormatMMDDYYYYBead.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/staticControls/accessories/DateFormatMMDDYYYYBead.as
index 10c11d3..3b52c40 100644
--- a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/staticControls/accessories/DateFormatMMDDYYYYBead.as
+++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/staticControls/accessories/DateFormatMMDDYYYYBead.as
@@ -20,8 +20,10 @@ package org.apache.flex.html.staticControls.accessories
{
import org.apache.flex.core.IBead;
import org.apache.flex.core.IDateChooserModel;
+ import org.apache.flex.core.IFormatBead;
import org.apache.flex.core.IStrand;
import org.apache.flex.events.Event;
+ import org.apache.flex.events.EventDispatcher;
import org.apache.flex.html.staticControls.TextInput;
import org.apache.flex.html.staticControls.beads.DateFieldView;
@@ -33,7 +35,7 @@ package org.apache.flex.html.staticControls.accessories
* @playerversion AIR 2.6
* @productversion FlexJS 0.0
*/
- public class DateFormatMMDDYYYYBead implements IBead
+ public class DateFormatMMDDYYYYBead extends EventDispatcher implements IBead, IFormatBead
{
/**
* constructor.
@@ -47,6 +49,65 @@ package org.apache.flex.html.staticControls.accessories
{
}
+ private var _propertyName:String;
+ private var _eventName:String;
+ private var _formattedResult:String;
+
+ /**
+ * The name of the property on the model holding the value to be formatted.
+ * The default is selectedDate.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion FlexJS 0.0
+ */
+ public function get propertyName():String
+ {
+ if (_propertyName == null) {
+ return "selectedDate";
+ }
+ return _propertyName;
+ }
+ public function set propertyName(value:String):void
+ {
+ _propertyName = value;
+ }
+
+ /**
+ * The name of the event dispatched when the property changes. The
+ * default is selectedDateChanged.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion FlexJS 0.0
+ */
+ public function get eventName():String
+ {
+ if (_eventName == null) {
+ return _propertyName+"Changed";
+ }
+ return _eventName;
+ }
+ public function set eventName(value:String):void
+ {
+ _eventName = value;
+ }
+
+ /**
+ * The formatted result.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion FlexJS 0.0
+ */
+ public function get formattedString():String
+ {
+ return _formattedResult;
+ }
+
private var _strand:IStrand;
/**
@@ -71,8 +132,8 @@ package org.apache.flex.html.staticControls.accessories
private function handleTextChange(event:Event):void
{
var model:IDateChooserModel = _strand.getBeadByType(IDateChooserModel) as IDateChooserModel;
- var view:DateFieldView = _strand.getBeadByType(DateFieldView) as DateFieldView;
- var input:TextInput = view.textInput;
+ /*var view:DateFieldView = _strand.getBeadByType(DateFieldView) as DateFieldView;
+ var input:TextInput = view.textInput;*/
var d:Date = model.selectedDate;
var month:String = String(d.getMonth()+1);
@@ -80,7 +141,10 @@ package org.apache.flex.html.staticControls.accessories
var date:String = String(d.getDate());
if (Number(date)<10) date = "0"+date;
var fmt:String = month+"/"+date+"/"+String(d.getFullYear());
- input.text = fmt;
+ /*input.text = fmt;*/
+ _formattedResult = month+"/"+date+"/"+String(d.getFullYear());
+
+ dispatchEvent( new Event("formatChanged") );
}
}
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8fd96fca/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/staticControls/beads/DateFieldView.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/staticControls/beads/DateFieldView.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/staticControls/beads/DateFieldView.as
index 5de0218..441f204 100644
--- a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/staticControls/beads/DateFieldView.as
+++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/staticControls/beads/DateFieldView.as
@@ -23,6 +23,7 @@ package org.apache.flex.html.staticControls.beads
import org.apache.flex.core.IBeadView;
import org.apache.flex.core.IDateChooserModel;
+ import org.apache.flex.core.IFormatBead;
import org.apache.flex.core.IParent;
import org.apache.flex.core.IPopUpHost;
import org.apache.flex.core.IStrand;
@@ -106,14 +107,25 @@ package org.apache.flex.html.staticControls.beads
_textInput.width = 100;
_textInput.height = 18;
-
_button = new TextButton();
_button.text = "M";
IParent(_strand).addElement(_button);
_button.x = _textInput.width;
_button.y = _textInput.y;
- IEventDispatcher(_strand).dispatchEvent(new Event("viewChanged"));
+ IEventDispatcher(_strand).addEventListener("beadsAdded",handleBeadsAdded);
+ }
+
+ private function handleBeadsAdded(event:Event):void
+ {
+ var formatter:IFormatBead = _strand.getBeadByType(IFormatBead) as IFormatBead;
+ formatter.addEventListener("formatChanged",handleFormatChanged);
+ }
+
+ private function handleFormatChanged(event:Event):void
+ {
+ var formatter:IFormatBead = event.target as IFormatBead;
+ _textInput.text = formatter.formattedString;
}
private var _popUp:IStrand;
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8fd96fca/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/staticControls/beads/FormatableLabelView.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/staticControls/beads/FormatableLabelView.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/staticControls/beads/FormatableLabelView.as
new file mode 100644
index 0000000..1fc8e1a
--- /dev/null
+++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/staticControls/beads/FormatableLabelView.as
@@ -0,0 +1,90 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 org.apache.flex.core.IFormatBead;
+ import org.apache.flex.core.IStrand;
+ import org.apache.flex.events.Event;
+ import org.apache.flex.events.IEventDispatcher;
+
+ /**
+ * The FormatableLabelView class is a View bead that is capable of working
+ * with a format bead to display a formatted value. When the format bead has
+ * created a formatted string, it dispatches a formatChanged event that the
+ * FormatableLabelView class intercepts and displays in the label.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion FlexJS 0.0
+ */
+ public class FormatableLabelView extends TextFieldView
+ {
+ /**
+ * constructor
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion FlexJS 0.0
+ */
+ public function FormatableLabelView()
+ {
+ super();
+ }
+
+ private var _formatter:IFormatBead;
+
+ /**
+ * @copy org.apache.flex.core.IBead#strand
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion FlexJS 0.0
+ */
+ override public function set strand(value:IStrand):void
+ {
+ super.strand = value;
+ IEventDispatcher(value).addEventListener("beadsAdded",handleBeadsAdded);
+ }
+
+ /**
+ * @private
+ */
+ private function handleBeadsAdded(event:Event):void
+ {
+ _formatter = strand.getBeadByType(IFormatBead) as IFormatBead;
+ _formatter.addEventListener("formatChanged",formatReadyHandler);
+
+ // process any text set in the label at this moment
+ text = _formatter.formattedString;
+ }
+
+ /**
+ * @private
+ */
+ private function formatReadyHandler(event:Event):void
+ {
+ if (_formatter) {
+ text = _formatter.formattedString;
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8fd96fca/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/staticControls/beads/FormatableTextInputView.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/staticControls/beads/FormatableTextInputView.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/staticControls/beads/FormatableTextInputView.as
new file mode 100644
index 0000000..66fcab4
--- /dev/null
+++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/html/staticControls/beads/FormatableTextInputView.as
@@ -0,0 +1,89 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 org.apache.flex.core.IFormatBead;
+ import org.apache.flex.core.IStrand;
+ import org.apache.flex.events.Event;
+ import org.apache.flex.events.IEventDispatcher;
+
+ /**
+ * The FormatableTextInputView class is a View bead that extends TextInputWithBorderView
+ * and is capable of working with a format bead. When a format bead dispatches a
+ * formatChanged event, the FormatableTextInputView bead copies the formatted string to
+ * to the text field.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion FlexJS 0.0
+ */
+ public class FormatableTextInputView extends TextInputWithBorderView
+ {
+ /**
+ * constructor
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion FlexJS 0.0
+ */
+ public function FormatableTextInputView()
+ {
+ super();
+ }
+
+ private var _formatter:IFormatBead;
+
+ /**
+ * @copy org.apache.flex.core.IBead#strand
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion FlexJS 0.0
+ */
+ override public function set strand(value:IStrand):void
+ {
+ super.strand = value;
+ IEventDispatcher(value).addEventListener("beadsAdded",handleBeadsAdded);
+ }
+
+ /**
+ * @private
+ */
+ private function handleBeadsAdded(event:Event):void
+ {
+ _formatter = strand.getBeadByType(IFormatBead) as IFormatBead;
+ _formatter.addEventListener("formatChanged",formatChangedHandler);
+ }
+
+ /**
+ * @private
+ */
+ private function formatChangedHandler(event:Event):void
+ {
+ this.textField.text = _formatter.formattedString;
+
+ // move the cursor to the end
+ var l:int = this.textField.text.length;
+ this.textField.setSelection(l,l);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8fd96fca/frameworks/as/projects/FlexJSUI/src/org/apache/flex/utils/MXMLDataInterpreter.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/utils/MXMLDataInterpreter.as b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/utils/MXMLDataInterpreter.as
index eecfa53..40709c3 100644
--- a/frameworks/as/projects/FlexJSUI/src/org/apache/flex/utils/MXMLDataInterpreter.as
+++ b/frameworks/as/projects/FlexJSUI/src/org/apache/flex/utils/MXMLDataInterpreter.as
@@ -19,11 +19,13 @@
package org.apache.flex.utils
{
-import org.apache.flex.core.IStrand;
import org.apache.flex.core.IBead;
+import org.apache.flex.core.IContainer;
import org.apache.flex.core.IDocument;
import org.apache.flex.core.IParent;
-import org.apache.flex.core.IContainer;
+import org.apache.flex.core.IStrand;
+import org.apache.flex.events.Event;
+import org.apache.flex.events.IEventDispatcher;
/**
* The MXMLDataInterpreter class is the class that interprets the
@@ -137,6 +139,7 @@ public class MXMLDataInterpreter
var simple:*;
var value:Object;
var id:String = null;
+ var dispatchBeadsAdded:Boolean = false;
m = data[i++]; // num props
if (m > 0 && data[0] == "model")
@@ -197,6 +200,7 @@ public class MXMLDataInterpreter
{
var bead:IBead = beads[k] as IBead;
IStrand(comp).addBead(bead);
+ dispatchBeadsAdded = true;
}
}
m = data[i++]; // num styles
@@ -236,6 +240,7 @@ public class MXMLDataInterpreter
if (parent)
{
parent.addElement(comp);
+ dispatchBeadsAdded = true;
}
var children:Array = data[i++];
@@ -259,6 +264,10 @@ public class MXMLDataInterpreter
if (comp is IDocument)
comp.setDocument(document, id);
comps.push(comp);
+
+ if (dispatchBeadsAdded) {
+ IEventDispatcher(comp).dispatchEvent(new Event("beadsAdded"));
+ }
}
return comps;
}
@@ -355,6 +364,10 @@ public class MXMLDataInterpreter
IStrand(host).addBead(bead);
bead.strand = host as IStrand;
}
+
+ if (l>0) {
+ IEventDispatcher(host).dispatchEvent(new Event("beadsAdded"));
+ }
}
m = data[i++]; // num styles
for (j = 0; j < m; j++)