PageRenderTime 75ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/fp10/src/com/furusystems/dconsole2/plugins/inspectorviews/propertyview/fieldtypes/PropertyField.as

http://doomsdayconsole.googlecode.com/
ActionScript | 171 lines | 148 code | 19 blank | 4 comment | 9 complexity | 730d769f3342a3d009576e1139626e88 MD5 | raw file
  1. package com.furusystems.dconsole2.plugins.inspectorviews.propertyview.fieldtypes
  2. {
  3. import com.furusystems.dconsole2.DConsole;
  4. import com.furusystems.dconsole2.IConsole;
  5. import com.furusystems.messaging.pimp.PimpCentral;
  6. import flash.display.Sprite;
  7. import flash.events.Event;
  8. import flash.events.MouseEvent;
  9. import flash.geom.Rectangle;
  10. import flash.text.TextField;
  11. import flash.utils.Dictionary;
  12. import com.furusystems.dconsole2.core.gui.TextFieldFactory;
  13. import com.furusystems.dconsole2.core.Notifications;
  14. import com.furusystems.dconsole2.core.style.Colors;
  15. import com.furusystems.dconsole2.core.style.GUIUnits;
  16. import com.furusystems.dconsole2.plugins.inspectorviews.propertyview.TabContent;
  17. /**
  18. * ...
  19. * @author Andreas Roenning
  20. */
  21. public class PropertyField extends TabContent
  22. {
  23. public var controlField:ControlField;
  24. public var nameField:TextField;
  25. private var _readOnly:Boolean = false;
  26. private var _prevWidth:Number = 0;
  27. private var splitControl:Sprite = new Sprite();
  28. private var _mouseOrigX:Number;
  29. private var _splitRatio:Number = 0.5;
  30. private var _access:String;
  31. private var _objRef:Dictionary = new Dictionary(true);
  32. private var _console:IConsole;
  33. public function PropertyField(console:IConsole, object:Object,property:String,type:String,access:String = "readwrite")
  34. {
  35. super(property);
  36. _console = console;
  37. _access = access;
  38. _objRef[0] = object;
  39. nameField = TextFieldFactory.getLabel(property);
  40. nameField.textColor = Colors.INSPECTOR_PROPERTY_FIELD_NAME_FG;
  41. nameField.background = true;
  42. nameField.backgroundColor = Colors.INSPECTOR_PROPERTY_FIELD_NAME_BG;
  43. addChild(nameField);
  44. controlField = new ControlField(console, property, type, access);
  45. nameField.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver, false, 0, true);
  46. nameField.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut, false, 0, true);
  47. controlField.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver, false, 0, true);
  48. controlField.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut, false, 0, true);
  49. addChild(controlField);
  50. splitControl.buttonMode = true;
  51. splitControl.addEventListener(MouseEvent.MOUSE_DOWN, onSplitBeginDrag, false, 0, true);
  52. splitControl.x = width * _splitRatio;
  53. splitControl.graphics.clear();
  54. splitControl.graphics.beginFill(0, 0.1);
  55. splitControl.graphics.drawRect(0, 0, -5, GUIUnits.SQUARE_UNIT);
  56. addChild(splitControl);
  57. if(object!=null){
  58. if (_access != "writeonly") {
  59. controlField.value = object[property];
  60. }
  61. }
  62. _prevWidth = width;
  63. }
  64. public function splitToName():void {
  65. splitControl.x = nameField.textWidth;
  66. _splitRatio = Math.max(.1, Math.min(.9, (splitControl.x / super.width)));
  67. updateFieldWidths();
  68. }
  69. private function onSplitBeginDrag(e:MouseEvent):void
  70. {
  71. _mouseOrigX = mouseX;
  72. stage.addEventListener(MouseEvent.MOUSE_MOVE, onSplitDrag);
  73. stage.addEventListener(MouseEvent.MOUSE_UP, onSplitRelease);
  74. }
  75. private function onSplitRelease(e:MouseEvent):void
  76. {
  77. stage.removeEventListener(MouseEvent.MOUSE_MOVE, onSplitDrag);
  78. stage.removeEventListener(MouseEvent.MOUSE_UP, onSplitRelease);
  79. }
  80. private function onSplitDrag(e:MouseEvent):void
  81. {
  82. splitRatio = (splitControl.x + mouseX - _mouseOrigX) / _prevWidth;
  83. _mouseOrigX = mouseX;
  84. dispatchEvent(new Event(Event.CHANGE));
  85. }
  86. override public function updateFromSource():void
  87. {
  88. if (!controlField.hasFocus) {
  89. if (_access != "writeonly") {
  90. var t:* = _objRef[0][controlField.targetProperty];
  91. if (t) controlField.value = t;
  92. }
  93. }
  94. }
  95. private function onMouseOut(e:MouseEvent):void
  96. {
  97. _console.messaging.send(Notifications.TOOLTIP_HIDE_REQUEST, null, this);
  98. }
  99. private function onMouseOver(e:MouseEvent):void
  100. {
  101. var t:String = "";
  102. switch(e.currentTarget) {
  103. case controlField:
  104. t = controlField.value;
  105. break;
  106. case nameField:
  107. t = nameField.text;
  108. break;
  109. }
  110. _console.messaging.send(Notifications.TOOLTIP_SHOW_REQUEST, t, this);
  111. }
  112. override public function set width(value:Number):void
  113. {
  114. if (value == _prevWidth) return;
  115. graphics.clear();
  116. graphics.beginFill(Colors.INSPECTOR_PROPERTY_FIELD_BG);
  117. graphics.drawRect(0, 0, value, GUIUnits.SQUARE_UNIT);
  118. graphics.endFill();
  119. _prevWidth = value;
  120. updateFieldWidths();
  121. scrollRect = new Rectangle(0, 0, value, GUIUnits.SQUARE_UNIT);
  122. }
  123. override public function get width():Number {
  124. return _prevWidth;
  125. }
  126. private function updateFieldWidths():void
  127. {
  128. nameField.width = controlField.x = Math.floor(_prevWidth * _splitRatio)
  129. controlField.width = Math.floor(_prevWidth * (1-_splitRatio));
  130. splitControl.x = _prevWidth * _splitRatio;
  131. }
  132. public function get readOnly():Boolean { return _readOnly; }
  133. public function set readOnly(value:Boolean):void
  134. {
  135. controlField.readOnly = _readOnly = value;
  136. }
  137. public function get splitRatio():Number { return _splitRatio; }
  138. public function set splitRatio(value:Number):void
  139. {
  140. _splitRatio = Math.max(.1, Math.min(.9, value));
  141. updateFieldWidths();
  142. }
  143. override public function updateAppearance():void
  144. {
  145. super.updateAppearance();
  146. width = _prevWidth;
  147. nameField.textColor = Colors.INSPECTOR_PROPERTY_FIELD_NAME_FG;
  148. nameField.backgroundColor = Colors.INSPECTOR_PROPERTY_FIELD_NAME_BG;
  149. controlField.updateAppearance();
  150. }
  151. }
  152. }