javascript/examples/grapheditor/www/js/EditorUi.js
function(cells, asText)
	{
		graph.getModel().beginUpdate();
		try
		{
			// Applies only basic text styles
			if (asText)
			{
				var edge = graph.getModel().isEdge(cell);
				var current = (edge) ? graph.currentEdgeStyle : graph.currentVertexStyle;
				var textStyles = ['fontSize', 'fontFamily', 'fontColor'];
				
				for (var j = 0; j < textStyles.length; j++)
				{
					var value = current[textStyles[j]];
					
					if (value != null)
					{
						graph.setCellStyles(textStyles[j], value, cells);
					}
				}
			}
			else
			{
				for (var i = 0; i < cells.length; i++)
				{
					var cell = cells[i];

					// Removes styles defined in the cell style from the styles to be applied
					var cellStyle = graph.getModel().getStyle(cell);
					var tokens = (cellStyle != null) ? cellStyle.split(';') : [];
					var appliedStyles = styles.slice();
					
					for (var j = 0; j < tokens.length; j++)
					{
						var tmp = tokens[j];
				 		var pos = tmp.indexOf('=');
				 					 		
				 		if (pos >= 0)
				 		{
				 			var key = tmp.substring(0, pos);
				 			var index = mxUtils.indexOf(appliedStyles, key);
				 			
				 			if (index >= 0)
				 			{
				 				appliedStyles.splice(index, 1);
				 			}
				 			
				 			// Handles special cases where one defined style ignores other styles
				 			for (var k = 0; k < keyGroups.length; k++)
				 			{
				 				var group = keyGroups[k];
				 				
				 				if (mxUtils.indexOf(group, key) >= 0)
				 				{
				 					for (var l = 0; l < group.length; l++)
				 					{
							 			var index2 = mxUtils.indexOf(appliedStyles, group[l]);
							 			
							 			if (index2 >= 0)
							 			{
							 				appliedStyles.splice(index2, 1);
							 			}
				 					}
				 				}
				 			}
				 		}
					}
	
					// Applies the current style to the cell
					var edge = graph.getModel().isEdge(cell);
					var current = (edge) ? graph.currentEdgeStyle : graph.currentVertexStyle;
					
					for (var j = 0; j < appliedStyles.length; j++)
					{
						var key = appliedStyles[j];
						var styleValue = current[key];
	
						if (styleValue != null && (key != 'shape' || edge))
						{
							// Special case: Connect styles are not applied here but in the connection handler
							if (!edge || mxUtils.indexOf(connectStyles, key) < 0)
							{
								graph.setCellStyles(key, styleValue, [cell]);
							}
						}
					}
				}
			}
		}
		finally
		{
			graph.getModel().endUpdate();
		}
	}
function(cells, asText)
	{
		graph.getModel().beginUpdate();
		try
		{
			// Applies only basic text styles
			if (asText)
			{
				var edge = graph.getModel().isEdge(cell);
				var current = (edge) ? graph.currentEdgeStyle : graph.currentVertexStyle;
				var textStyles = ['fontSize', 'fontFamily', 'fontColor'];
				
				for (var j = 0; j < textStyles.length; j++)
				{
					var value = current[textStyles[j]];
					
					if (value != null)
					{
						graph.setCellStyles(textStyles[j], value, cells);
					}
				}
			}
			else
			{
				for (var i = 0; i < cells.length; i++)
				{
					var cell = cells[i];

					// Removes styles defined in the cell style from the styles to be applied
					var cellStyle = graph.getModel().getStyle(cell);
					var tokens = (cellStyle != null) ? cellStyle.split(';') : [];
					var appliedStyles = styles.slice();
					
					for (var j = 0; j < tokens.length; j++)
					{
						var tmp = tokens[j];
				 		var pos = tmp.indexOf('=');
				 					 		
				 		if (pos >= 0)
				 		{
				 			var key = tmp.substring(0, pos);
				 			var index = mxUtils.indexOf(appliedStyles, key);
				 			
				 			if (index >= 0)
				 			{
				 				appliedStyles.splice(index, 1);
				 			}
				 			
				 			// Handles special cases where one defined style ignores other styles
				 			for (var k = 0; k < keyGroups.length; k++)
				 			{
				 				var group = keyGroups[k];
				 				
				 				if (mxUtils.indexOf(group, key) >= 0)
				 				{
				 					for (var l = 0; l < group.length; l++)
				 					{
							 			var index2 = mxUtils.indexOf(appliedStyles, group[l]);
							 			
							 			if (index2 >= 0)
							 			{
							 				appliedStyles.splice(index2, 1);
							 			}
				 					}
				 				}
				 			}
				 		}
					}
	
					// Applies the current style to the cell
					var edge = graph.getModel().isEdge(cell);
					var current = (edge) ? graph.currentEdgeStyle : graph.currentVertexStyle;
					
					for (var j = 0; j < appliedStyles.length; j++)
					{
						var key = appliedStyles[j];
						var styleValue = current[key];
	
						if (styleValue != null && (key != 'shape' || edge))
						{
							// Special case: Connect styles are not applied here but in the connection handler
							if (!edge || mxUtils.indexOf(connectStyles, key) < 0)
							{
								graph.setCellStyles(key, styleValue, [cell]);
							}
						}
					}
				}
			}
		}
		finally
		{
			graph.getModel().endUpdate();
		}
	}
function ( cells , asText ) { graph . getModel ( ) . beginUpdate ( ) ; try { // Applies only basic text styles if ( asText ) { var edge = graph . getModel ( ) . isEdge ( cell ) ; var current = ( edge ) ? graph . currentEdgeStyle : graph . currentVertexStyle ; var textStyles = [ 'fontSize' , 'fontFamily' , 'fontColor' ] ; for ( var j = 0 ; j < textStyles . length ; j ++ ) { var value = current [ textStyles [ j ] ] ; if ( value != null ) { graph . setCellStyles ( textStyles [ j ] , value , cells ) ; } } } else { for ( var i = 0 ; i < cells . length ; i ++ ) { var cell = cells [ i ] ; // Removes styles defined in the cell style from the styles to be applied var cellStyle = graph . getModel ( ) . getStyle ( cell ) ; var tokens = ( cellStyle != null ) ? cellStyle . split ( ';' ) : [ ] ; var appliedStyles = styles . slice ( ) ; for ( var j = 0 ; j < tokens . length ; j ++ ) { var tmp = tokens [ j ] ; var pos = tmp . indexOf ( '=' ) ; if ( pos >= 0 ) { var key = tmp . substring ( 0 , pos ) ; var index = mxUtils . indexOf ( appliedStyles , key ) ; if ( index >= 0 ) { appliedStyles . splice ( index , 1 ) ; } // Handles special cases where one defined style ignores other styles for ( var k = 0 ; k < keyGroups . length ; k ++ ) { var group = keyGroups [ k ] ; if ( mxUtils . indexOf ( group , key ) >= 0 ) { for ( var l = 0 ; l < group . length ; l ++ ) { var index2 = mxUtils . indexOf ( appliedStyles , group [ l ] ) ; if ( index2 >= 0 ) { appliedStyles . splice ( index2 , 1 ) ; } } } } } } // Applies the current style to the cell var edge = graph . getModel ( ) . isEdge ( cell ) ; var current = ( edge ) ? graph . currentEdgeStyle : graph . currentVertexStyle ; for ( var j = 0 ; j < appliedStyles . length ; j ++ ) { var key = appliedStyles [ j ] ; var styleValue = current [ key ] ; if ( styleValue != null && ( key != 'shape' || edge ) ) { // Special case: Connect styles are not applied here but in the connection handler if ( ! edge || mxUtils . indexOf ( connectStyles , key ) < 0 ) { graph . setCellStyles ( key , styleValue , [ cell ] ) ; } } } } } } finally { graph . getModel ( ) . endUpdate ( ) ; } }
Implements a global current style for edges and vertices that is applied to new cells
Implements a global current style for edges and vertices that is applied to new cells