Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data chooser keyboard support #101

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@
<component id="DateChooser" class="org.apache.royale.html.DateChooser"/>
<component id="DateChooserList" class="org.apache.royale.html.supportClasses.DateChooserList" />
<component id="DateChooserHeader" class="org.apache.royale.html.supportClasses.DateChooserHeader" />
<component id="DateChooserView" class="org.apache.royale.html.beads.DateChooserView" />
<component id="DateChooserMouseController" class="org.apache.royale.html.beads.controllers.DateChooserMouseController" />
<component id="DateChooserKeyboardController" class="org.apache.royale.html.beads.controllers.DateChooserKeyboardController" />
<component id="DateChooserMouseKeyboardController" class="org.apache.royale.html.beads.controllers.DateChooserMouseKeyboardController" />
<component id="DateField" class="org.apache.royale.html.DateField"/>
<component id="VerticalColumnLayout" class="org.apache.royale.html.beads.layouts.VerticalColumnLayout" />

Expand Down
2 changes: 2 additions & 0 deletions frameworks/projects/Basic/src/main/royale/BasicClasses.as
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ internal class BasicClasses
import org.apache.royale.html.beads.models.DateChooserModel; DateChooserModel;
import org.apache.royale.html.beads.models.DataGridPresentationModel; DataGridPresentationModel;
import org.apache.royale.html.beads.controllers.DateChooserMouseController; DateChooserMouseController;
import org.apache.royale.html.beads.controllers.DateChooserKeyboardController; DateChooserKeyboardController;
import org.apache.royale.html.beads.controllers.DateChooserMouseKeyboardController; DateChooserMouseKeyboardController;
import org.apache.royale.html.beads.controllers.DateFieldMouseController; DateFieldMouseController;
import org.apache.royale.html.beads.controllers.RangeStepperMouseController; RangeStepperMouseController;
import org.apache.royale.html.supportClasses.DataGridColumn; DataGridColumn;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
////////////////////////////////////////////////////////////////////////////////
//
// 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.royale.html.beads.controllers
{
import org.apache.royale.html.beads.models.DateChooserModel;

/**
* The CalendarNavigation class adjusts a calendar by a month, week and/or day.
*
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion FlexJS 0.9
*/
public class CalendarNavigation
{
/**
* constructor.
*
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion FlexJS 0.9
*/
public function CalendarNavigation()
{
}

/**
* Move the display model back one month.
*
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion FlexJS 0.9
*/
public function previousMonth(model:DateChooserModel):void
{
var month:Number = model.displayedMonth - 1;
var year:Number = model.displayedYear;
if (month < 0) {
month = 11;
year--;
}
model.displayedMonth = month;
model.displayedYear = year;
}

/**
* Move the display model forward one month.
*
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion FlexJS 0.9
*/
public function nextMonth(model:DateChooserModel):void
{
var month:Number = model.displayedMonth + 1;
var year:Number = model.displayedYear;
if (month >= 12) {
month = 0;
year++;
}
model.displayedMonth = month;
model.displayedYear = year;
}

/**
* Move the date one week into the past, the month and year
* displayed may change.
*
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion FlexJS 0.9
*/
public function previousWeek(model:DateChooserModel):Date
{
return pastDate(model, 7);
}

/**
* Move the date one week into the future, the month and year
* displayed may change.
*
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion FlexJS 0.9
*/
public function nextWeek(model:DateChooserModel):Date
{
return futureDate(model, 7);
}

/**
* Move the date one day into the past, teh month and year
* displayed may change.
*
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion FlexJS 0.9
*/
public function previousDay(model:DateChooserModel):Date
{
return pastDate(model, 1);
}

/**
* Move the date one day into the future, the month and year
* displayed may change.
*
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion FlexJS 0.9
*/
public function nextDay(model:DateChooserModel):Date
{
return futureDate(model, 1);
}

/**
* @private
*/
private function futureDate(model:DateChooserModel, noDays:int):Date
{
var selected:Date = new Date(model.selectedDate.getTime());
var month:Number = selected.getMonth();

selected.setDate(selected.getDate() + noDays);
if (month > selected.getMonth()) {
nextMonth(model);
}
return selected;
}

/**
* @private
*/
private function pastDate(model:DateChooserModel, noDays:int):Date
{
var selected:Date = new Date(model.selectedDate.getTime());
var month:Number = selected.getMonth();

selected.setDate(selected.getDate() - noDays);
if (month < selected.getMonth()) {
previousMonth(model);
}
return selected;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
////////////////////////////////////////////////////////////////////////////////
//
// 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.royale.html.beads.controllers
{
import org.apache.royale.html.beads.DateChooserView;
import org.apache.royale.html.beads.models.DateChooserModel;

import org.apache.royale.core.IBeadController;
import org.apache.royale.core.IBeadModel;
import org.apache.royale.core.IBeadView;
import org.apache.royale.core.IStrand;
import org.apache.royale.events.Event;
import org.apache.royale.events.KeyboardEvent;
import org.apache.royale.events.IEventDispatcher;

/**
* The DateChooserMouseController class is responsible for listening to
* mouse event related to the DateChooser. Events such as selecting a date
* or changing the calendar.
*
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion Royale 0.0
*/
public class DateChooserKeyboardController extends CalendarNavigation implements IBeadController
{
/**
* constructor.
*
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion Royale 0.0
*/
public function DateChooserKeyboardController()
{
}

private var _strand:IStrand;

/**
* @copy org.apache.royale.core.IBead#strand
*
* @langversion 3.0
* @playerversion Flash 10.2
* @playerversion AIR 2.6
* @productversion Royale 0.9
*/
public function set strand(value:IStrand):void
{
_strand = value;
var view:DateChooserView = value.getBeadByType(IBeadView) as DateChooserView;
IEventDispatcher(_strand).addEventListener(KeyboardEvent.KEY_DOWN, keyboardHandler);
}

private function keyboardHandler(event:KeyboardEvent):void
{
var model:DateChooserModel = _strand.getBeadByType(IBeadModel) as DateChooserModel;
var changed:Boolean = false;
var newDate:Date;

switch (event.key) {
case "ArrowUp":
newDate = previousWeek(model);
changed = true;
break;
case "ArrowDown":
newDate = nextWeek(model);
changed = true;
break;
case "ArrowLeft":
newDate = previousDay(model);
changed = true;
break;
case "ArrowRight":
newDate = nextDay(model);
changed = true;
break;
}

if (changed) {
model.selectedDate = newDate;
IEventDispatcher(_strand).dispatchEvent( new Event("change") );
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ package org.apache.royale.html.beads.controllers
* @playerversion AIR 2.6
* @productversion Royale 0.0
*/
public class DateChooserMouseController implements IBeadController
public class DateChooserMouseController extends CalendarNavigation implements IBeadController
{
/**
* constructor.
Expand Down Expand Up @@ -91,14 +91,7 @@ package org.apache.royale.html.beads.controllers
event.preventDefault();

var model:DateChooserModel = _strand.getBeadByType(IBeadModel) as DateChooserModel;
var month:Number = model.displayedMonth - 1;
var year:Number = model.displayedYear;
if (month < 0) {
month = 11;
year--;
}
model.displayedMonth = month;
model.displayedYear = year;
nextMonth(model);
}

/**
Expand All @@ -109,14 +102,7 @@ package org.apache.royale.html.beads.controllers
event.preventDefault();

var model:DateChooserModel = _strand.getBeadByType(IBeadModel) as DateChooserModel;
var month:Number = model.displayedMonth + 1;
var year:Number = model.displayedYear;
if (month >= 12) {
month = 0;
year++;
}
model.displayedMonth = month;
model.displayedYear = year;
previousMonth(model);
}

}
Expand Down
Loading