PageRenderTime 10ms CodeModel.GetById 5ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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