/src/org/ishafoundation/archives/transcript/components/studio/text/GeneralNodePropertiesPane.mxml

http://transcriptstudio4isha.googlecode.com/ · Macromedia eXtensible Markup Language · 259 lines · 235 code · 24 blank · 0 comment · 0 complexity · 5f3e9f4ae58064a73ea2783eeffa11c3 MD5 · raw file

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!--
  3. Transcript Studio for Isha Foundation: An XML based application that allows users to define
  4. and store contextual metadata for contiguous sections within a text document.
  5. Copyright 2008 Mark Carter, Swami Kevala
  6. This file is part of Transcript Studio for Isha Foundation.
  7. Transcript Studio for Isha Foundation is free software: you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the Free Software
  9. Foundation, either version 3 of the License, or (at your option) any later version.
  10. Transcript Studio for Isha Foundation is distributed in the hope that it will be useful, but
  11. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License along with
  14. Transcript Studio for Isha Foundation. If not, see http://www.gnu.org/licenses/.
  15. -->
  16. <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" horizontalAlign="left" backgroundColor="#FFFFFF" enabled="{this.generalProps != null}" creationComplete="init()" minWidth="400" minHeight="200" paddingTop="5" paddingBottom="5" paddingLeft="5" paddingRight="5">
  17. <mx:Script>
  18. <![CDATA[
  19. import name.carter.mark.flex.project.mdoc.MSuperSegment;
  20. import mx.binding.utils.ChangeWatcher;
  21. import name.carter.mark.flex.project.mdoc.MSegmentSubset;
  22. import name.carter.mark.flex.project.mdoc.MSegmentRange;
  23. import mx.controls.Alert;
  24. import name.carter.mark.flex.project.mdoc.MSegment;
  25. import org.ishafoundation.archives.transcript.model.TranscriptTextSelection;
  26. import name.carter.mark.flex.util.Utils;
  27. import mx.collections.ArrayCollection;
  28. import org.ishafoundation.archives.transcript.model.Transcript;
  29. import mx.utils.StringUtil;
  30. import org.ishafoundation.archives.transcript.model.GeneralNodeProperties;
  31. [Bindable]
  32. public var generalProps:GeneralNodeProperties;
  33. [Bindable]
  34. private var _ttSelection:TranscriptTextSelection;
  35. [Bindable]
  36. public var allowTextEdit:Boolean = true;
  37. [Bindable]
  38. public var speakers:Array;
  39. [Bindable]
  40. public var spokenLanguages:Array = ["english", "tamil", "other"];
  41. [Bindable]
  42. public var sourceIds:Array;
  43. public function init():void {
  44. }
  45. public function set ttSelection(newValue:TranscriptTextSelection):void {
  46. this._ttSelection = newValue;
  47. if (this._ttSelection == null || this._ttSelection.selectedObj is MSuperSegment) {
  48. this.generalProps = null;
  49. }
  50. else {
  51. this.generalProps = GeneralNodeProperties.createInstance(this._ttSelection);
  52. }
  53. }
  54. private static function allowMultipleSegments(ttSelection:TranscriptTextSelection):Boolean {
  55. var allowMultipleSegments:Boolean = ttSelection.toSegmentRange() != null;
  56. if (ttSelection.toSegment() != null) {
  57. // check if the segment is also an inline
  58. var segment:MSegment = ttSelection.toSegment();
  59. if (segment.toContentRange().toSuperContent() != null) {
  60. // don't allow the contents of an inline to go multi-segment
  61. allowMultipleSegments = false;
  62. }
  63. }
  64. return allowMultipleSegments;
  65. }
  66. private function somethingChanged(affectedObj:Object = null):void {
  67. if (affectedObj == null) {
  68. // this panel always changes something (so don't pass null to the event)
  69. affectedObj = _ttSelection.selectedObj;
  70. }
  71. var ttSelection:TranscriptTextSelection = new TranscriptTextSelection(affectedObj);
  72. var event:Event = new TranscriptTextEvent(TranscriptTextEvent.DATA_CHANGE, ttSelection);
  73. dispatchEvent(event);
  74. }
  75. private function confidentialChanged():void {
  76. var newValue:Boolean = new Boolean(confidentialRadioButtonGroup.selectedValue);
  77. trace("Confidential changed: " + newValue);
  78. generalProps.confidential = newValue;
  79. somethingChanged();
  80. }
  81. private function speakerChanged():void {
  82. if (speakerComboBox.selectedItem == null) {
  83. // user is entering some text
  84. return;
  85. }
  86. var newValue:String = speakerComboBox.selectedItem.toString();
  87. trace("Speaker changed: " + newValue);
  88. generalProps.speaker = newValue;
  89. somethingChanged();
  90. }
  91. private function speakerHandler():void {
  92. if (speakerComboBox.selectedItem == null) {
  93. // user edited a new speaker?
  94. var newValue:String = Utils.normalizeSpace(speakerComboBox.text).toLowerCase();
  95. if (newValue.length > 0) {
  96. if (speakers.indexOf(newValue) < 0) {
  97. trace("New speaker set: " + newValue);
  98. speakers.push(newValue);
  99. }
  100. generalProps.speaker = newValue;
  101. somethingChanged();
  102. }
  103. }
  104. }
  105. private function spokenLanguageChanged():void {
  106. var newValue:String = languageComboBox.selectedItem.toString();
  107. trace("SpokenLanguage changed: " + newValue);
  108. generalProps.spokenLanguage = newValue;
  109. somethingChanged();
  110. }
  111. private function emphasisChanged():void {
  112. var newValue:Boolean = new Boolean(emphasisRadioButtonGroup.selectedValue);
  113. trace("Emphasis changed: " + newValue);
  114. generalProps.emphasis = newValue;
  115. somethingChanged();
  116. }
  117. private function textChanged(newTextArray:Array):void {
  118. if (newTextArray.length == 0) {
  119. Alert.show("Cannot remove all text. Try deleting the text instead.\n\nRestoring original text.");
  120. textStack.executeBindings(true);
  121. return;
  122. }
  123. var affectedObj:Object = _ttSelection.editText(newTextArray);
  124. if (affectedObj == null) {
  125. return;
  126. }
  127. somethingChanged(affectedObj);
  128. }
  129. private function segmentTextChanged():void {
  130. if (!textTextArea.editable) {
  131. // obviously it didnt change really
  132. return;
  133. }
  134. var newTextArray:Array = new Array();
  135. var newSegmentTexts:Array = textTextArea.text.split("\r");
  136. for each (var newSegmentText:String in newSegmentTexts) {
  137. newSegmentText = Utils.normalizeSpace(newSegmentText);
  138. if (newSegmentText.length > 0) {
  139. newTextArray.push(newSegmentText);
  140. }
  141. }
  142. textChanged(newTextArray);
  143. }
  144. private function subSegmentTextChanged():void {
  145. textTextInput.text = Utils.normalizeSpace(textTextInput.text);
  146. if (textTextInput.text.length == 0) {
  147. textChanged([]);
  148. }
  149. else {
  150. textChanged([textTextInput.text]);
  151. }
  152. }
  153. private static function getTextAreaText(ttSelection:TranscriptTextSelection):String {
  154. var range:MSegmentRange = ttSelection.toSegmentRange();
  155. if (range == null) {
  156. // this would be called when the text area is hidden
  157. return "";
  158. }
  159. return range.getTextCondensed();
  160. }
  161. private static function getTextInputText(ttSelection:TranscriptTextSelection):String {
  162. if (ttSelection.toSegmentSubset() == null) {
  163. // cannot show on one line - must be a range - so show nothing
  164. // note - if we don't do this and the user selects the whole doc - then very slow
  165. return "";
  166. }
  167. else {
  168. return ttSelection.getText();
  169. }
  170. }
  171. ]]>
  172. </mx:Script>
  173. <mx:HBox width="100%" horizontalGap="30">
  174. <mx:VBox width="100%" height="100%">
  175. <mx:ViewStack id="textStack" width="100%" height="100%" selectedIndex="{allowMultipleSegments(_ttSelection) ? 0 : 1}">
  176. <mx:HBox width="100%" height="100%">
  177. <mx:TextArea id="textTextArea" width="100%" height="100%" minHeight="60" editable="{allowTextEdit &amp;&amp; _ttSelection.allowEditText()}" text="{getTextAreaText(_ttSelection)}" focusOut="segmentTextChanged()"/>
  178. </mx:HBox>
  179. <mx:HBox width="100%">
  180. <mx:TextInput id="textTextInput" width="100%" editable="{allowTextEdit}" text="{getTextInputText(_ttSelection)}" enter="subSegmentTextChanged()" focusOut="subSegmentTextChanged()"/>
  181. </mx:HBox>
  182. </mx:ViewStack>
  183. </mx:VBox>
  184. <mx:Grid horizontalAlign="center">
  185. <mx:GridRow height="100%" id="speakerGridRow" enabled="{generalProps != null &amp;&amp; generalProps.speakerEnabled}">
  186. <mx:GridItem width="100%" height="100%" verticalAlign="middle">
  187. <mx:Label width="100%" textAlign="right" text="Speaker" paddingBottom="2" paddingTop="2"/>
  188. </mx:GridItem>
  189. <mx:GridItem width="100%" height="100%">
  190. <mx:ComboBox id="speakerComboBox" width="100%" enabled="{allowTextEdit}" dataProvider="{speakers}" editable="true" selectedIndex="{generalProps.speaker == null ? -1 : speakers.indexOf(generalProps.speaker)}" prompt="Select..." change="speakerChanged()" enter="speakerHandler()" focusOut="speakerHandler()"/>
  191. </mx:GridItem>
  192. <mx:GridItem height="100%">
  193. <mx:RadioButton label="mixed" enabled="false" id="speakerMixedRadioButton" selected="{generalProps.speaker == null}"/>
  194. </mx:GridItem>
  195. </mx:GridRow>
  196. <mx:GridRow height="100%">
  197. <mx:GridItem width="100%" height="100%" verticalAlign="middle">
  198. <mx:Label width="100%" textAlign="right" text="Spoken Language" paddingBottom="2" paddingTop="2"/>
  199. </mx:GridItem>
  200. <mx:GridItem width="100%" height="100%">
  201. <mx:ComboBox id="languageComboBox" width="100%" enabled="{allowTextEdit}" dataProvider="{spokenLanguages}" prompt="Select..." editable="false" selectedIndex="{generalProps.spokenLanguage == null ? -1 : spokenLanguages.indexOf(generalProps.spokenLanguage)}" change="spokenLanguageChanged()"/>
  202. </mx:GridItem>
  203. <mx:GridItem height="100%">
  204. <mx:RadioButton label="mixed" id="spokenLanguageMixedRadioButton" enabled="false" selected="{generalProps.spokenLanguage == null}"/>
  205. </mx:GridItem>
  206. </mx:GridRow>
  207. <mx:GridRow height="100%" enabled="{generalProps != null &amp;&amp; generalProps.emphasisEnabled}">
  208. <mx:GridItem width="100%" height="100%" verticalAlign="middle">
  209. <mx:Label width="100%" textAlign="right" text="Emphasized" paddingBottom="2" paddingTop="2"/>
  210. </mx:GridItem>
  211. <mx:GridItem width="100%" height="100%">
  212. <mx:RadioButtonGroup id="emphasisRadioButtonGroup" enabled="{allowTextEdit}" selectedValue="{generalProps.emphasis == null ? 'mixed' : generalProps.emphasis.toString()}" change="emphasisChanged()"/>
  213. <mx:RadioButton label="true" groupName="emphasisRadioButtonGroup" id="emphasisTrueRadioButton" value="{true}"/>
  214. <mx:RadioButton label="false" groupName="emphasisRadioButtonGroup" id="emphasisFalseRadioButton" value="{false}"/>
  215. </mx:GridItem>
  216. <mx:GridItem height="100%">
  217. <mx:RadioButton label="mixed" groupName="emphasisRadioButtonGroup" enabled="false" id="emphasisMixedRadioButton"/>
  218. </mx:GridItem>
  219. </mx:GridRow>
  220. <mx:GridRow height="100%" id="confidentialGridRow" enabled="{generalProps != null &amp;&amp; generalProps.confidentialEnabled}">
  221. <mx:GridItem width="100%" height="100%" verticalAlign="middle">
  222. <mx:Label width="100%" textAlign="right" text="Confidential"/>
  223. </mx:GridItem>
  224. <mx:GridItem width="100%" height="100%">
  225. <mx:RadioButtonGroup id="confidentialRadioButtonGroup" enabled="{allowTextEdit}" selectedValue="{generalProps.confidential == null ? 'mixed' : generalProps.confidential.toString()}" change="confidentialChanged()"/>
  226. <mx:RadioButton label="true" groupName="confidentialRadioButtonGroup" id="confidentialTrueRadioButton" value="{true}"/>
  227. <mx:RadioButton label="false" groupName="confidentialRadioButtonGroup" id="confidentialFalseRadioButton" value="{false}"/>
  228. </mx:GridItem>
  229. <mx:GridItem height="100%">
  230. <mx:RadioButton label="mixed" groupName="confidentialRadioButtonGroup" enabled="false" id="confidentialMixedRadioButton"/>
  231. </mx:GridItem>
  232. </mx:GridRow>
  233. </mx:Grid>
  234. </mx:HBox>
  235. </mx:VBox>