/// <summary>
		/// Manejo del evento provocado cuando se hace click en un nodo de la 
		/// vista de árbol.
		/// </summary>
		/// <param name="sender">El objeto que provoco el evento.</param>
		/// <param name="arg">Los argumentos del evento.</param>
		private void OnTreeviewSelectionChanged(object sender, EventArgs arg)
		{
		    // Si hemos acabado el proceso y hemos seleccionado algo.
			if(treeview.Selection.CountSelectedRows() > 0)
			{
				SegmentedNode node=
					(SegmentedNode)(treeview.NodeSelection.SelectedNode);
				
				imageAreaNode.Image=node.MathTextBitmap.Pixbuf;

				// Vaciamos el notebook
				while(processedImageNB.NPages > 0)
					processedImageNB.RemovePage(0);
				
				if(recognizementFinished)
				{
					// Añadimos las imagenes procesasdas al notebook

					// Solo mostramos los tabs si hay mas de una imagen procesada
					processedImageNB.ShowTabs = 
						node.MathTextBitmap.ProcessedImages.Count>1;
					
					// Si hemos terminado podemos hacer esto sin peligro.
					foreach(Pixbuf p in node.MathTextBitmap.ProcessedPixbufs)
					{
						ImageArea imageAreaProcessed = new ImageArea();
						imageAreaProcessed.Image=p;
						imageAreaProcessed.ImageMode=ImageAreaMode.Zoom;
						
					
						processedImageNB.AppendPage(imageAreaProcessed,
						                            new Label(String.Format("BD {0}",
						                                                    processedImageNB.NPages+1)));
					}
				}
				
				MarkImage(node.MathTextBitmap);				
			}
		}
		protected void InitializeWidgets()
		{
			store = new NodeStore(typeof(SegmentedNode));
			
			// Creamos el NodeView, podría hacerse en el fichero de Glade,
			// aunque alguna razón habría por la que se hizo así.
			treeview=new NodeView(store);
			treeview.RulesHint = true;
			
			treeview.ShowExpanders = true;
			treeview.AppendColumn ("Imagen", 
			                       new CellRendererText (), 
			                       "text", 0);
			
			CellRendererText cellRenderer = new CellRendererText();
			cellRenderer.Xalign = 0.5f;
			treeview.AppendColumn ("Etiqueta", cellRenderer, "text", 1);
			treeview.AppendColumn ("Posición", 
			                       new CellRendererText (), 
			                       "text", 2);
			
			scrolledtree.Add(treeview);
			
			foreach (TreeViewColumn col in treeview) 
			{
				col.Sizing = TreeViewColumnSizing.Autosize;
			}
			
			
			
			// Asignamos el evento para cuando se produzca la selección de un
			// nodo en el árbol.
			treeview.NodeSelection.Changed += OnTreeviewSelectionChanged;
						
			treeview.ButtonPressEvent += 
				new ButtonPressEventHandler(OnTreeviewButtonPress);
			
			imageAreaOriginal = new ImageArea();
			imageAreaOriginal.ImageMode = ImageAreaMode.Zoom;
				
			frameOriginal.Add(imageAreaOriginal);
			
			
			imageAreaNode=new ImageArea();
			imageAreaNode.ImageMode=ImageAreaMode.Zoom;			
			frameNodeActual.Add(imageAreaNode);
			
			learnImageItem.Image = ImageResources.LoadImage("database16");
		}
		/// <summary>
		/// Manejo del evento que provocado por el controlador cuando comienza 
		/// a tratar una nueva imagen.
		/// </summary>
		/// <param name="sender">El objeto que provoca el evento.</param>
		/// <param name="arg">El argumento del evento.</param>
		private void OnControllerBitmapProcessedByDatabase(object sender, 
		                                         BitmapProcessedArgs arg)
		{
			Gtk.Application.Invoke(sender, arg,
			                       delegate(object resender, EventArgs a)
			{
				if(treeview.NodeSelection.SelectedNodes.Length>0)
				{
					// Si hay un simbolo seleccionado, 
					// nos traemos sus imagenes procesadas.
					SegmentedNode node = 
						(SegmentedNode)(treeview.NodeSelection.SelectedNode);
				
					
					ImageArea imageAreaProcessed = new ImageArea();
					imageAreaProcessed.Image=
						node.MathTextBitmap.LastProcessedImage.CreatePixbuf();
					imageAreaProcessed.ImageMode=ImageAreaMode.Zoom;
					
				
					processedImageNB.AppendPage(imageAreaProcessed,
					                            new Label(String.Format("BD {0}",
					                                                    processedImageNB.NPages+1)));
					
					processedImageNB.Page=processedImageNB.NPages-1;
					
					// Solo mostramos los tabs si hay mas de una imagen procesada
					processedImageNB.ShowTabs = 
						node.MathTextBitmap.ProcessedImages.Count>1;
				}
			});
		}
		/// <summary>
		/// Initializes the child widgets of the widget.
		/// </summary>
		private void InitializeWidgets()
		{
			syntacticalCoverModel = 
				new NodeStore(typeof(SyntacticalCoverNode));
			
			syntacticalCoverTree = new NodeView(syntacticalCoverModel);
			syntacticalCoverTree.RulesHint = true;
			
			syntacticalCoverTree.AppendColumn("Elemento de análisis",
			                                  new CellRendererText(),
			                                  "markup" ,0);
			
			syntacticalCoverTree.RowActivated+= 
				new RowActivatedHandler(OnSyntacticalCoverTreeRowActivated);
			
			syntacticalCoverTree.Selection.Changed +=
				new EventHandler(OnSyntacticalCoverTreeSelectionChanged);
			
			//syntacticalCoverTree.ShowExpanders = false;
			
			syntacticalTreePlaceholder.Add(syntacticalCoverTree);
			
			
			remainingItemsStore = new ListStore(typeof(Gdk.Pixbuf),
			                                    typeof(string),
			                                    typeof(Token));
			remainingItemsIconView.Model = remainingItemsStore;
			
			remainingItemsIconView.PixbufColumn =0;
			remainingItemsIconView.TextColumn = 1;
			
			originalImageArea = new  ImageArea();
			originalImageArea.ImageMode = ImageAreaMode.Zoom;
			
			synImageOriginalPlaceholder.Add(originalImageArea);
			
			originalImageArea.ShowAll();
		}
		/// <summary>
		/// Inicializa los controles del panel del asistente.
		/// </summary>
		/// <param name="imagesStore">
		/// El almacén de imagenes creado en el paso anterior, para que las
		/// imagenes sean seleccionables en la vista de previsualización.
		/// </param>
		private void InitializeWidgets(ListStore imagesStore)
		{
			NodeStore store = new NodeStore(typeof(BitmapProcessNode));
			processesView =  new NodeView(store);			
			
			processesView.ShowExpanders = false;
			
			processesView.RulesHint = true;
			
			processesView.NodeSelection.Changed += OnProcessesSelectionChanged;
			
			processesView.AppendColumn("Algoritmo", 
			                           new CellRendererText(),
			                           "text",0);
			
			processesView.AppendColumn("Parámetros",
			                           new CellRendererText(),
			                           "text",1);		
			
			bitmapsProcessSW.Add(processesView);
			
			originIA = new ImageArea();
			processedIA = new ImageArea();

			originIA.ImageMode = ImageAreaMode.Zoom;
			processedIA.ImageMode = ImageAreaMode.Zoom;
					
			originFrame.Add(originIA);
			processedFrame.Add(processedIA);
			
			imagesTV.Model = imagesStore;
			
			imagesTV.AppendColumn("Imagen",new CellRendererText(),"text",1);
			
			imagesTV.Selection.Changed += OnImagesTVSelectionChanged;
		
			LoadDefaults();
			
		}
		/// <summary>
		/// Initializes the dialog's widgets.
		/// </summary>
		private void InitializeWidgets()
		{	
			textviewOutput.Buffer.Text = output;			
			
			originalImageArea = new ImageArea();
			originalImageArea.ImageMode = ImageAreaMode.Zoom;
			this.outputOriginalPlaceholder.Add(originalImageArea);
			
			if(Config.RecognizerConfig.Instance.ShowOutputConversion)
			{
				this.outputImageArea = new ImageArea();
				this.outputImageArea.ImageMode = ImageAreaMode.Zoom;
				
				this.outputOutputPlaceholder.Add(outputImageArea);
				
				RefreshOutputView();
			}
			else
			{
				this.outputOutputFrame.Visible=false;
			}
		}
		private void InitializeWidgets()
		{
			originalImageArea = new ImageArea();
			originalImageArea.ImageMode = ImageAreaMode.Zoom;
			
			unassistedImagePlaceholder.Add(originalImageArea);
			
			segmentationStore = new NodeStore(typeof(SegmentedNode));
		}
		/// <summary>
		/// Initialize the widget's children widgets.
		/// </summary>
		private void InitializeWidgets()
		{
			this.Add(tokenizingStageWidgetBase);
			
			sequencesModel = new NodeStore(typeof(SequenceNode));
			
			sequencesNV = new NodeView(sequencesModel);
			
			sequencesNV.ShowExpanders = true;
			sequencesNV.RulesHint = true;
			sequencesNVPlaceholder.Add(sequencesNV);
			
			sequencesNV.AppendColumn("Secuencia", 
			                         new CellRendererText(), 
			                         "text",0);
			
			sequencesNV.AppendColumn("Símbolos", 
			                         new CellRendererText(), 
			                         "text",1);
			
			sequencesNV.AppendColumn("Ítem",
			                         new CellRendererText(),
			                         "text",2);
			
			// We tell the treeview's columns to resize automatically.
			foreach (TreeViewColumn column in sequencesNV.Columns) 
			{
				column.Sizing = TreeViewColumnSizing.Autosize;								
			}
			
			// We handle the pressing of the mouse buttons, so we can show
			// the contextual menu.
		
			sequencesNV.Events = Gdk.EventMask.ButtonPressMask;
			sequencesNV.ButtonPressEvent+= 
				new ButtonPressEventHandler(OnSequencesNVButtonPress);
									
			symbolsModel = new ListStore(typeof(Gdk.Pixbuf),
			                             typeof(string),
			                             typeof(Token));
			
			symbolsIV.Model = symbolsModel;
			
			symbolsIV.TextColumn = 1;
			symbolsIV.PixbufColumn =0;
			
			baselineImageArea = new ImageArea();
			baselineImageArea.ImageMode = ImageAreaMode.Zoom;
			currentImageFrm.Add(baselineImageArea);
			
			sequenceMatchingImageArea = new ImageArea();
			sequenceMatchingImageArea.ImageMode = ImageAreaMode.Zoom;
			sequenceImageFrm.Add(sequenceMatchingImageArea);
			
			tokenizingRulesTV.AppendColumn("Item generado", 
			                               new CellRendererText(), 
			                               "text", 0);
			tokenizingRulesTV.AppendColumn("Expresión", 
			                               new CellRendererText(), 
			                               "text", 1);
			
			tokenizingRulesTV.Columns[0].Sizing = TreeViewColumnSizing.Autosize;
			tokenizingRulesTV.Columns[1].Sizing = TreeViewColumnSizing.Autosize;
			
			
				
			
			tokenizingButtonsNB.Page = 0;
			tokenizingStepsNB.Page = 0;
			
			tokenizingStageWidgetBase.ShowAll();
		}
		/// <summary>
		/// Inicializa los controles de la ventana.
		/// </summary>
		private void Initialize()
		{
			mainWindow.Title=title;	
			
			imageAreaOriginal = new ImageArea();
			imageAreaOriginal.ImageMode = ImageAreaMode.Zoom;
			frameOriginal.Add(imageAreaOriginal);
			
			imageAreaProcessed = new ImageArea();
			imageAreaProcessed.ImageMode = ImageAreaMode.Zoom;			
			frameProcessed.Add(imageAreaProcessed);		
				
			logView = new LogView();
			expanderLog.Add(logView);
			
			// La imagen reducida en la primera columna
			imagesIV.PixbufColumn = 0;
			imagesIV.SelectionChanged += 
				new EventHandler(OnImagesIVSelectionChanged);
			
			imagesStore = new ListStore(typeof(Gdk.Pixbuf), 
			                            typeof(Gdk.Pixbuf));
						
			imagesIV.Model = imagesStore;
			
			imagesStore.RowInserted += OnImagesStoreRowInserted;
			imagesStore.RowDeleted += OnImagesStoreRowDeleted;
			
			toolNewDatabase.IconWidget =
				ImageResources.LoadImage("database-new22");
			
			menuDatabase.Image =ImageResources.LoadImage("database-new16");
			
			symbolLabelEditor = new SymbolLabelEditorWidget();
			
			symbolEditorPlaceholder.Add(symbolLabelEditor);
			
			labelTooltips = new Tooltips();
				
			mainWindow.ShowAll();			
		}		
		/// <summary>
		/// Initializes the dialogs' widgets.
		/// </summary>
		/// <param name="node">
		/// A <see cref="SegmentedNode"/>
		/// </param>
		private void InitializeWidgets(SegmentedNode node)
		{			
			imageNameLabel.Text = String.Format(imageNameLabel.Text, node.Name);
			
			labelEditor = new SymbolLabelEditorWidget();
			if(node.Symbols.Count ==0)
			{
				labelEditor.Label = node.Label;
			}
			else
			{
				// If we have various posibilities, we add radio buttons.
				RadioButton group = new RadioButton("group");
				foreach(MathSymbol symbol in node.Symbols)
				{		
					RadioButton rb = new RadioButton(group, symbol.Text);
					Alignment rbAlign = new Alignment(0,0.5f,0,0);
					rbAlign.Add(rb);
					symbolEditorPlaceholder.Add(rbAlign);
					
					rb.Clicked += new EventHandler(OnLabelOptionClicked);
					
					
				}
				
				Alignment rbOtherAlign = new Alignment(0,0.5f,0,0);
				otherLabelRB = new RadioButton(group, "Otra:");
				otherLabelRB.Clicked += new EventHandler(OnLabelOptionClicked);
				
				rbOtherAlign.Add(otherLabelRB);
				symbolEditorPlaceholder.Add(rbOtherAlign);
				labelEditor.Sensitive = false;
			}
			
			symbolEditorPlaceholder.Add(labelEditor);
			
			nodeImage = new ImageArea();
			nodeImage.Image = node.MathTextBitmap.Pixbuf;
			nodeImage.ImageMode = ImageAreaMode.Zoom;
			
			imagePlaceholder.Add(nodeImage);
		}