first go at specialised tag editors
[potlatch2.git] / net / systemeD / potlatch2 / mapfeatures / editors / ChoiceComboBox.as
1 package net.systemeD.potlatch2.mapfeatures.editors {
2
3     import mx.controls.*;
4     import mx.containers.*;
5     import mx.core.*;
6     import flash.display.*;
7     import flash.events.*;
8     import mx.events.*;
9     import mx.utils.*;
10
11         public class ChoiceComboBox extends ComboBox {
12
13         protected var textInputReplacement:UIComponent;
14
15         override protected function createChildren():void {
16                 super.createChildren();
17
18                 if ( !textInputReplacement ) {
19                         if ( itemRenderer != null ) {
20                                 //remove the default textInput
21                                 removeChild(textInput);
22
23                                 //create a new itemRenderer to use in place of the text input
24                                 textInputReplacement = itemRenderer.newInstance();
25                                 IDataRenderer(textInputReplacement).data = {text: "banana"};
26                                 addChild(textInputReplacement);
27                         }
28                 }
29         }
30
31         override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
32             super.updateDisplayList(unscaledWidth, unscaledHeight);
33
34             if ( textInputReplacement ) {
35                 IDataRenderer(textInputReplacement).data = selectedItem;
36
37                 var arrowWidth:Number = getStyle("arrowButtonWidth");\r
38                 var itemHeight:Number = textInputReplacement.getExplicitOrMeasuredHeight();\r
39                 var itemWidth:Number = textInputReplacement.getExplicitOrMeasuredWidth();\r
40 \r
41                 if (isNaN(arrowWidth))\r
42                     arrowWidth = 0;\r
43
44                 var bm:EdgeMetrics = borderMetrics;
45
46                 textInputReplacement.setActualSize(unscaledWidth - arrowWidth, itemHeight);\r
47                 textInputReplacement.move(bm.left, bm.top);
48             }
49         }
50
51         override protected function measure():void {
52             super.measure();
53
54             if ( textInputReplacement ) {
55                 IDataRenderer(textInputReplacement).data = selectedItem;
56
57                 var arrowWidth:Number = getStyle("arrowButtonWidth");\r
58                 var itemHeight:Number = textInputReplacement.getExplicitOrMeasuredHeight();\r
59                 var itemWidth:Number = textInputReplacement.getExplicitOrMeasuredWidth();\r
60 \r
61                 if (isNaN(arrowWidth))\r
62                     arrowWidth = 0;\r
63
64                 var bm:EdgeMetrics = borderMetrics;
65                 itemHeight += bm.top + bm.bottom;\r
66                 itemWidth += bm.left + bm.right + arrowWidth;\r
67
68                 measuredMinHeight = measuredHeight = Math.max(measuredHeight, itemHeight);\r
69                 measuredMinWidth = measuredWidth = Math.max(measuredWidth, itemWidth);\r
70             }
71         }
72
73     }
74 }
75
76