1 <?xml version="1.0" encoding="utf-8"?>
3 xmlns:fx="http://ns.adobe.com/mxml/2009"
4 xmlns:mx="library://ns.adobe.com/flex/mx"
5 xmlns:halcyon="net.systemeD.halcyon.*"
6 backgroundColor="white" borderStyle="inset">
8 <mx:HBox horizontalGap="0">
9 <mx:ToggleButtonBar height="100%" dataProvider="{categoryStack}" direction="vertical" styleName="catToggleButtonBar"/>
10 <mx:ViewStack id="categoryStack" width="100%" height="100%"
11 change="_formerIndex=event.newIndex;"
12 creationComplete="setSelectedFeature(_selectedType);">
13 <mx:Repeater id="catRep" dataProvider="{MapFeatures.getInstance().getCategoriesForType(limit)}">
14 <mx:VBox label="{catRep.currentItem.name}">
15 <mx:TileList dataProvider="{catRep.currentItem.getFeaturesForType(limit)}"
16 width="420" height="100%" change="itemSelected(event);" styleName="catToggleTiles"
17 creationComplete="ensureSelection();">
20 <mx:VBox width="100" height="75"
21 horizontalScrollPolicy="off" verticalScrollPolicy="off"
22 horizontalAlign="center" verticalGap="0" toolTip="{data.description}">
23 <mx:Image source="{data.image}" height="100%" verticalAlign="middle"/>
24 <mx:Text text="{data.name}"/>
34 <!-- mx:Label id="hoverInfo" text="Hover Info goes here"/>-->
38 import net.systemeD.halcyon.connection.*;
39 import net.systemeD.potlatch2.mapfeatures.*;
42 import mx.containers.*;
43 import mx.events.IndexChangedEvent;
45 /** Set briefly by ensureSelection() (presumably to avoid an event race condition). */
46 private var settingSelection:Boolean = false;
47 private var _selectedType:Feature;
48 private var _limit:String;
49 private var _formerIndex:int=0;
51 public var allowControllerKeyboardEvents:Boolean = true;
53 [Bindable(event="selectedType")]
54 /** The Feature type (eg, "residential road") currently selected. */
55 public function get selectedType():Feature {
59 [Bindable(event="limitChanged")]
60 /** The type of features currently shown ("area", "node"...) */
61 public function get limit():String {
65 /** Determine which feature was clicked on, and set that as the currently selected type. */
66 private function itemSelected(event:Event):void {
67 _selectedType = Feature(TileList(event.currentTarget).selectedItem);
68 if ( !settingSelection )
69 dispatchEvent(new Event("selectedType"));
72 /** Set the current type of Features that will be shown ("area", "node"... )*/
73 public function setLimitTypes(type:String):void {
75 dispatchEvent(new Event("limitChanged"));
79 * Set the selected feature displayed in the selector.
81 * The tab is switched to the first category the feature
84 * @param feature The feature to make selected.
86 public function setSelectedFeature(feature:Feature):void {
87 _selectedType = feature;
89 // check whether stack built yet, if not we get called again when it's made
90 if ( categoryStack == null )
93 // set the tab to the selected item's category
94 // (we have to manually fire the IndexChangedEvent because Flex's ViewStack.as isn't competent
95 // enough to do it reliably. This is basically a direct crib from dispatchChangeEvent)
97 if ( feature != null ) {
98 var primaryCategory:Category = feature.findFirstCategory();
99 index = MapFeatures.getInstance().getCategoriesForType(limit).indexOf(primaryCategory);
100 if (index==-1) { index=0; } // not found, so just show the default for now
102 var event:IndexChangedEvent = new IndexChangedEvent(IndexChangedEvent.CHANGE);
103 event.oldIndex = _formerIndex;
104 event.newIndex = index;
105 event.relatedObject = categoryStack.getChildAt(index);
106 categoryStack.selectedIndex = index;
107 categoryStack.dispatchEvent(event);
110 // finalise the item selection
113 public function setNoSelectedFeature():void {
114 /*_selectedType=null;*/
115 setSelectedFeature(null);
119 * Sets the selected feature on each category page to the current
120 * value of _selectedType. If there is no selected feature then all
121 * panels selection will be blanked.
123 * This function does not change the selected category tab.
125 * Called both from setSelectedFeature, and category tab completion
126 * (so that newly created tabs work as expected)
128 private function ensureSelection():void {
129 settingSelection = true;
130 for (var i:Number = 0; i < categoryStack.numChildren; i++) {
131 var box:Box = Box(categoryStack.getChildAt(i));
132 if ( box == null || box.numChildren == 0 )
134 var tileList:TileList = TileList(box.getChildAt(0));
135 var category:Category = Category(tileList.getRepeaterItem());
136 var selected:Boolean = false;
137 for each( var catFeature:Feature in category.features ) {
138 if ( catFeature == _selectedType ) {
139 tileList.selectedItem = _selectedType;
144 tileList.selectedItem = null;
146 settingSelection = false;