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 2013/06/24 21:47:49 UTC
git commit: [flex-asjs] [refs/heads/develop] - First draft of Spinner
control for ActionScript.
Updated Branches:
refs/heads/develop c7d57650e -> b48c8d480
First draft of Spinner control for ActionScript.
Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/b48c8d48
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/b48c8d48
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/b48c8d48
Branch: refs/heads/develop
Commit: b48c8d4809d09019268b6864aaf14cde49faf014
Parents: c7d5765
Author: Peter Ent <pe...@apache.org>
Authored: Mon Jun 24 15:47:37 2013 -0400
Committer: Peter Ent <pe...@apache.org>
Committed: Mon Jun 24 15:47:37 2013 -0400
----------------------------------------------------------------------
frameworks/as/basic-manifest.xml | 1 +
frameworks/as/defaults.css | 6 +
frameworks/as/src/FlexJSUIClasses.as | 2 +
.../src/org/apache/flex/core/ISpinnerModel.as | 43 +++++++
.../apache/flex/html/staticControls/Spinner.as | 99 +++++++++++++++
.../html/staticControls/beads/ISpinnerBead.as | 30 +++++
.../html/staticControls/beads/SpinnerBead.as | 81 ++++++++++++
.../beads/controllers/SpinnerMouseController.as | 80 ++++++++++++
.../staticControls/beads/models/SpinnerModel.as | 125 +++++++++++++++++++
9 files changed, 467 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b48c8d48/frameworks/as/basic-manifest.xml
----------------------------------------------------------------------
diff --git a/frameworks/as/basic-manifest.xml b/frameworks/as/basic-manifest.xml
index 6bed8a7..92238a7 100644
--- a/frameworks/as/basic-manifest.xml
+++ b/frameworks/as/basic-manifest.xml
@@ -54,5 +54,6 @@
<component id="PanelBead" class="org.apache.flex.html.staticControls.beads.PanelBead"/>
<component id="SimpleAlert" class="org.apache.flex.html.staticControls.SimpleAlert"/>
<component id="Alert" class="org.apache.flex.html.staticControls.Alert"/>
+ <component id="Spinner" class="org.apache.flex.html.staticControls.Spinner"/>
</componentPackage>
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b48c8d48/frameworks/as/defaults.css
----------------------------------------------------------------------
diff --git a/frameworks/as/defaults.css b/frameworks/as/defaults.css
index adaa202..e5fd96a 100644
--- a/frameworks/as/defaults.css
+++ b/frameworks/as/defaults.css
@@ -173,6 +173,12 @@ Alert
border-thickness: 1;
}
+Spinner
+{
+ iSpinnerModel: ClassReference("org.apache.flex.html.staticControls.beads.models.SpinnerModel");
+ iSpinnerBead: ClassReference("org.apache.flex.html.staticControls.beads.SpinnerBead");
+}
+
/* HTML5 */
h5|TextButton
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b48c8d48/frameworks/as/src/FlexJSUIClasses.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/FlexJSUIClasses.as b/frameworks/as/src/FlexJSUIClasses.as
index f91ab96..93101a7 100644
--- a/frameworks/as/src/FlexJSUIClasses.as
+++ b/frameworks/as/src/FlexJSUIClasses.as
@@ -45,6 +45,7 @@ internal class FlexJSUIClasses
import org.apache.flex.html.staticControls.beads.TextButtonMeasurementBead; TextButtonMeasurementBead;
import org.apache.flex.html.staticControls.beads.TitleBarMeasurementBead; TitleBarMeasurementBead;
import org.apache.flex.html.staticControls.beads.ControlBarMeasurementBead; ControlBarMeasurementBead;
+ import org.apache.flex.html.staticControls.beads.SpinnerBead; SpinnerBead;
import org.apache.flex.html.staticControls.beads.models.TextModel; TextModel;
import org.apache.flex.html.staticControls.beads.models.ComboBoxModel; ComboBoxModel;
import org.apache.flex.html.staticControls.beads.models.ToggleButtonModel; ToggleButtonModel;
@@ -53,6 +54,7 @@ internal class FlexJSUIClasses
import org.apache.flex.html.staticControls.beads.models.TitleBarModel; TitleBarModel;
import org.apache.flex.html.staticControls.beads.models.PanelModel; PanelModel;
import org.apache.flex.html.staticControls.beads.models.AlertModel; AlertModel;
+ import org.apache.flex.html.staticControls.beads.models.SpinnerModel; SpinnerModel;
import org.apache.flex.events.CustomEvent; CustomEvent;
import org.apache.flex.events.Event; Event;
import org.apache.flex.utils.Timer; Timer;
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b48c8d48/frameworks/as/src/org/apache/flex/core/ISpinnerModel.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/core/ISpinnerModel.as b/frameworks/as/src/org/apache/flex/core/ISpinnerModel.as
new file mode 100644
index 0000000..0f079da
--- /dev/null
+++ b/frameworks/as/src/org/apache/flex/core/ISpinnerModel.as
@@ -0,0 +1,43 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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;
+
+ public interface ISpinnerModel extends IEventDispatcher, IBeadModel
+ {
+ function get value():Number;
+ function set value(newValue:Number):void;
+
+ function get minimum():Number;
+ function set minimum(value:Number):void;
+
+ function get maximum():Number;
+ function set maximum(value:Number):void;
+
+ function get stepSize():Number;
+ function set stepSize(value:Number):void;
+
+ function get allowValueWrap():Boolean;
+ function set allowValueWrap(value:Boolean):void;
+
+ function get snapInterval():Number;
+ function set snapInterval(value:Number):void;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b48c8d48/frameworks/as/src/org/apache/flex/html/staticControls/Spinner.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/html/staticControls/Spinner.as b/frameworks/as/src/org/apache/flex/html/staticControls/Spinner.as
new file mode 100644
index 0000000..517051e
--- /dev/null
+++ b/frameworks/as/src/org/apache/flex/html/staticControls/Spinner.as
@@ -0,0 +1,99 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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
+{
+ import org.apache.flex.core.IBead;
+ import org.apache.flex.core.IInitModel;
+ import org.apache.flex.core.IInitSkin;
+ import org.apache.flex.core.ISpinnerModel;
+ import org.apache.flex.core.UIBase;
+ import org.apache.flex.core.ValuesManager;
+ import org.apache.flex.html.staticControls.beads.ISpinnerBead;
+
+ [Event(name="valueChanged", type="org.apache.flex.events.Event")]
+
+ public class Spinner extends UIBase implements IInitModel, IInitSkin
+ {
+ public function Spinner()
+ {
+ super();
+
+ className = "Spinner";
+ }
+
+ public function get value():Number
+ {
+ return ISpinnerModel(model).value;
+ }
+ public function set value(newValue:Number):void
+ {
+ ISpinnerModel(model).value = newValue;
+ }
+
+ public function get minimum():Number
+ {
+ return ISpinnerModel(model).minimum;
+ }
+ public function set minimum(value:Number):void
+ {
+ ISpinnerModel(model).minimum = value;
+ }
+
+ public function get maximum():Number
+ {
+ return ISpinnerModel(model).maximum;
+ }
+ public function set maximum(value:Number):void
+ {
+ ISpinnerModel(model).maximum = value;
+ }
+
+ public function get snapInterval():Number
+ {
+ return ISpinnerModel(model).snapInterval;
+ }
+ public function set snapInterval(value:Number):void
+ {
+ ISpinnerModel(model).snapInterval = value;
+ }
+
+ public function get stepSize():Number
+ {
+ return ISpinnerModel(model).stepSize;
+ }
+ public function set stepSize(value:Number):void
+ {
+ ISpinnerModel(model).stepSize = value;
+ }
+
+ override public function initModel():void
+ {
+ if( getBeadByType(ISpinnerModel) == null ) {
+ addBead(new (ValuesManager.valuesImpl.getValue(this, "iSpinnerModel")) as IBead);
+ }
+ }
+
+ public function initSkin():void
+ {
+ if( getBeadByType(ISpinnerBead) == null ) {
+ addBead(new (ValuesManager.valuesImpl.getValue(this, "iSpinnerBead")) as IBead);
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b48c8d48/frameworks/as/src/org/apache/flex/html/staticControls/beads/ISpinnerBead.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/html/staticControls/beads/ISpinnerBead.as b/frameworks/as/src/org/apache/flex/html/staticControls/beads/ISpinnerBead.as
new file mode 100644
index 0000000..9258153
--- /dev/null
+++ b/frameworks/as/src/org/apache/flex/html/staticControls/beads/ISpinnerBead.as
@@ -0,0 +1,30 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.DisplayObject;
+
+ import org.apache.flex.core.IBead;
+
+ public interface ISpinnerBead extends IBead
+ {
+ function get increment():DisplayObject;
+ function get decrement():DisplayObject;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b48c8d48/frameworks/as/src/org/apache/flex/html/staticControls/beads/SpinnerBead.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/html/staticControls/beads/SpinnerBead.as b/frameworks/as/src/org/apache/flex/html/staticControls/beads/SpinnerBead.as
new file mode 100644
index 0000000..40cb382
--- /dev/null
+++ b/frameworks/as/src/org/apache/flex/html/staticControls/beads/SpinnerBead.as
@@ -0,0 +1,81 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.DisplayObject;
+
+ import org.apache.flex.core.ISpinnerModel;
+ import org.apache.flex.core.IStrand;
+ import org.apache.flex.core.UIBase;
+ import org.apache.flex.html.staticControls.Button;
+ import org.apache.flex.html.staticControls.beads.controllers.ButtonAutoRepeatController;
+ import org.apache.flex.html.staticControls.beads.controllers.SpinnerMouseController;
+
+ public class SpinnerBead implements ISpinnerBead
+ {
+ public function SpinnerBead()
+ {
+ }
+
+ private var spinnerModel:ISpinnerModel;
+
+ private var _strand:IStrand;
+ public function set strand(value:IStrand):void
+ {
+ _strand = value;
+ initSkin();
+ }
+
+ public function initSkin():void
+ {
+ _increment = new Button();
+ Button(_increment).addBead(new UpArrowButtonBead());
+ Button(_increment).addBead(new ButtonAutoRepeatController());
+ Button(_increment).initSkin();
+ _decrement = new Button();
+ Button(_decrement).addBead(new DownArrowButtonBead());
+ Button(_decrement).addBead(new ButtonAutoRepeatController());
+ Button(_decrement).initSkin();
+
+ var mouseController:SpinnerMouseController = new SpinnerMouseController();
+ _strand.addBead(mouseController);
+
+ Button(_increment).x = 0;
+ Button(_increment).y = 0;
+ Button(_decrement).x = 0;
+ Button(_decrement).y = Button(_increment).height;
+
+ UIBase(_strand).addChild(_decrement);
+ UIBase(_strand).addChild(_increment);
+ spinnerModel = _strand.getBeadByType(ISpinnerModel) as ISpinnerModel;
+ }
+
+ private var _decrement:DisplayObject;
+ private var _increment:DisplayObject;
+
+ public function get decrement():DisplayObject
+ {
+ return _decrement;
+ }
+ public function get increment():DisplayObject
+ {
+ return _increment;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b48c8d48/frameworks/as/src/org/apache/flex/html/staticControls/beads/controllers/SpinnerMouseController.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/html/staticControls/beads/controllers/SpinnerMouseController.as b/frameworks/as/src/org/apache/flex/html/staticControls/beads/controllers/SpinnerMouseController.as
new file mode 100644
index 0000000..5ab06dc
--- /dev/null
+++ b/frameworks/as/src/org/apache/flex/html/staticControls/beads/controllers/SpinnerMouseController.as
@@ -0,0 +1,80 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.controllers
+{
+ import flash.events.MouseEvent;
+
+ import org.apache.flex.core.IBead;
+ import org.apache.flex.core.ISpinnerModel;
+ import org.apache.flex.core.IStrand;
+ import org.apache.flex.events.Event;
+ import org.apache.flex.events.IEventDispatcher;
+ import org.apache.flex.html.staticControls.beads.ISpinnerBead;
+
+ public class SpinnerMouseController implements IBead
+ {
+ public function SpinnerMouseController()
+ {
+ }
+
+ private var spinnerModel:ISpinnerModel;
+
+ private var _strand:IStrand;
+ public function set strand(value:IStrand):void
+ {
+ _strand = value;
+
+ spinnerModel = value.getBeadByType(ISpinnerModel) as ISpinnerModel;
+
+ var spinnerBead:ISpinnerBead = value.getBeadByType(ISpinnerBead) as ISpinnerBead;
+ spinnerBead.decrement.addEventListener(MouseEvent.CLICK, decrementClickHandler);
+ spinnerBead.decrement.addEventListener("buttonRepeat", decrementClickHandler);
+ spinnerBead.increment.addEventListener(MouseEvent.CLICK, incrementClickHandler);
+ spinnerBead.increment.addEventListener("buttonRepeat", incrementClickHandler);
+ }
+
+ protected function snap(value:Number):Number
+ {
+ var si:Number = spinnerModel.snapInterval;
+ var n:Number = Math.round((value - spinnerModel.minimum) / si) * si + spinnerModel.minimum;
+ if (value > 0)
+ {
+ if (value - n < n + si - value)
+ return n;
+ return n + si;
+
+ }
+ if (value - n > n + si - value)
+ return n + si;
+ return n;
+ }
+
+ private function decrementClickHandler( event:Event ) : void
+ {
+ spinnerModel.value = snap(Math.max(spinnerModel.minimum, spinnerModel.value - spinnerModel.stepSize));
+ IEventDispatcher(_strand).dispatchEvent(new Event("valueChanged"));
+ }
+
+ private function incrementClickHandler( event:Event ) : void
+ {
+ spinnerModel.value = snap(Math.min(spinnerModel.maximum, spinnerModel.value + spinnerModel.stepSize));
+ IEventDispatcher(_strand).dispatchEvent(new Event("valueChanged"));
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/b48c8d48/frameworks/as/src/org/apache/flex/html/staticControls/beads/models/SpinnerModel.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/html/staticControls/beads/models/SpinnerModel.as b/frameworks/as/src/org/apache/flex/html/staticControls/beads/models/SpinnerModel.as
new file mode 100644
index 0000000..81488a5
--- /dev/null
+++ b/frameworks/as/src/org/apache/flex/html/staticControls/beads/models/SpinnerModel.as
@@ -0,0 +1,125 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.models
+{
+ import org.apache.flex.core.IBead;
+ import org.apache.flex.core.ISpinnerModel;
+ import org.apache.flex.core.IStrand;
+ import org.apache.flex.events.Event;
+ import org.apache.flex.events.EventDispatcher;
+
+ public class SpinnerModel extends EventDispatcher implements ISpinnerModel, IBead
+ {
+ public function SpinnerModel()
+ {
+ super();
+ }
+
+ private var _value:Number = 0;
+ public function get value():Number
+ {
+ return _value;
+ }
+
+ public function set value(newValue:Number):void
+ {
+ if( newValue != _value ) {
+ _value = newValue;
+ dispatchEvent( new Event("valueChanged") );
+ trace("Spinner value is " + newValue);
+ }
+ }
+
+ private var _minimum:Number = 0
+ public function get minimum():Number
+ {
+ return _minimum;
+ }
+
+ public function set minimum(value:Number):void
+ {
+ if( value != _minimum ) {
+ _minimum = value;
+ dispatchEvent( new Event("minimumChanged") );
+ }
+ }
+
+ private var _maximum:Number = 10;
+ public function get maximum():Number
+ {
+ return 100;
+ }
+
+ public function set maximum(value:Number):void
+ {
+ if( value != _maximum ) {
+ _maximum = value;
+ dispatchEvent( new Event("maximumChanged") );
+ }
+ }
+
+ private var _stepSize:Number = 1;
+ public function get stepSize():Number
+ {
+ return _stepSize;
+ }
+
+ public function set stepSize(value:Number):void
+ {
+ if( value != _stepSize ) {
+ _stepSize = value;
+ dispatchEvent( new Event("stepSizeChanged") );
+ }
+ }
+
+ private var _allowValueWrap:Boolean = false;
+ public function get allowValueWrap():Boolean
+ {
+ return _allowValueWrap;
+ }
+
+ public function set allowValueWrap(value:Boolean):void
+ {
+ if( value != _allowValueWrap ) {
+ _allowValueWrap = value;
+ dispatchEvent( new Event("valueWrapChanged") );
+ }
+ }
+
+ private var _snapInterval:Number = 1;
+ public function get snapInterval():Number
+ {
+ return _snapInterval;
+ }
+
+ public function set snapInterval(value:Number):void
+ {
+ if( value != _snapInterval ) {
+ _snapInterval = value;
+ dispatchEvent( new Event("snapIntervalChanged") );
+ }
+ }
+
+ private var _strand:IStrand;
+ public function set strand(value:IStrand):void
+ {
+ _strand = value;
+ }
+ }
+}
\ No newline at end of file