e9d4e278d8a2da750a9b4c08d17d8f764bb310b2
[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 = selectedItem;
26                                 textInputReplacement.mouseChildren = false;
27                                 textInputReplacement.mouseEnabled = false;
28                                 addChild(textInputReplacement);
29                         }
30                 }
31         }
32
33         override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
34             super.updateDisplayList(unscaledWidth, unscaledHeight);
35
36             if ( textInputReplacement ) {
37                 IDataRenderer(textInputReplacement).data = selectedItem;
38
39                 var arrowWidth:Number = getStyle("arrowButtonWidth");\r
40                 var itemHeight:Number = textInputReplacement.getExplicitOrMeasuredHeight();\r
41                 var itemWidth:Number = textInputReplacement.getExplicitOrMeasuredWidth();\r
42 \r
43                 if (isNaN(arrowWidth))\r
44                     arrowWidth = 0;\r
45
46                 var bm:EdgeMetrics = borderMetrics;
47
48                 textInputReplacement.setActualSize(unscaledWidth - arrowWidth, itemHeight);\r
49                 textInputReplacement.move(bm.left, bm.top);
50             }
51         }
52
53         override protected function measure():void {
54             super.measure();
55
56             if ( textInputReplacement ) {
57                 IDataRenderer(textInputReplacement).data = selectedItem;
58
59                 var arrowWidth:Number = getStyle("arrowButtonWidth");\r
60                 var itemHeight:Number = textInputReplacement.getExplicitOrMeasuredHeight();\r
61                 var itemWidth:Number = textInputReplacement.getExplicitOrMeasuredWidth();\r
62 \r
63                 if (isNaN(arrowWidth))\r
64                     arrowWidth = 0;\r
65
66                 var bm:EdgeMetrics = borderMetrics;
67                 itemHeight += bm.top + bm.bottom;\r
68                 itemWidth += bm.left + bm.right + arrowWidth;\r
69
70                 measuredMinHeight = measuredHeight = Math.max(measuredHeight, itemHeight);\r
71                 measuredMinWidth = measuredWidth = Math.max(measuredWidth, itemWidth);\r
72             }
73         }
74
75     }
76 }
77
78