<commit_before>/*
Weave (Web-based Analysis and Visualization Environment)
Copyright (C) 2008-2011 University of Massachusetts Lowell

This file is a part of Weave.

Weave is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License, Version 3,
as published by the Free Software Foundation.

Weave is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Weave.  If not, see <http://www.gnu.org/licenses/>.
*/
package weave.ui.CustomDataGrid
{
	import mx.collections.ArrayCollection;
	
	import spark.components.DataGrid;
	import spark.components.gridClasses.GridColumn;
	import spark.events.GridEvent;
	
	import weave.compiler.StandardLib;
	
	public class CustomSparkDataGrid extends DataGrid
	{
		public function CustomSparkDataGrid()
		{
			super();
			showDataTips = true;
			selectionMode = 'multipleCells';
			this.addEventListener(GridEvent.GRID_MOUSE_DOWN,dataGrid_gridMouseDownHandler);
			this.addEventListener(GridEvent.GRID_MOUSE_UP,dataGrid_gridMouseUpHandler);
			
			
		}
		// Single Click Editing support
		// taken From 
		// http://blogs.adobe.com/dloverin/2011/05/single-click-editing-and-more.html
		private var mouseDownRowIndex:int;
		private var mouseDownColumnIndex:int;
		
		protected function dataGrid_gridMouseDownHandler(event:GridEvent):void
		{
			mouseDownRowIndex = event.rowIndex;
			mouseDownColumnIndex = event.columnIndex;
		}
		
		protected function dataGrid_gridMouseUpHandler(event:GridEvent):void
		{
			// Start a grid item editor if:
			// - the rowIndex is valid
			// - mouseUp is on the same cell and mouseDown
			// - shift and ctrl keys are not down
			// - cell is editable
			// - an editor is not already running
			// An editor may already be running if the cell was already
			// selected and the data grid started the editor.
			if (event.rowIndex >= 0 &&
				event.rowIndex == mouseDownRowIndex && 
				event.columnIndex == mouseDownColumnIndex &&
				!(event.shiftKey || event.ctrlKey) &&
				event.column.editable &&
				!event.grid.dataGrid.itemEditorInstance)
			{
				event.grid.dataGrid.startItemEditorSession(event.rowIndex, event.columnIndex);
			}
		}
		
		/**
		 * This function along with getRows() makes it easy to display and edit
		 * a table of data stored as a two-dimensional Array.
		 * @param tableWithHeader An Array of Arrays including a header row.
		 */
		public function setRows(tableWithHeader:Array):void
		{
			// make sure we have at least one row (for the header)
			if (!tableWithHeader || !tableWithHeader.length)
				tableWithHeader = [[]];
			
			// make a copy of the data and find the max row length
			var rowLength:int = 0;
			var rows:Array = tableWithHeader.map(function(row:Array, i:int, a:Array):Array {
				rowLength = Math.max(rowLength, row.length);
				return row.concat();
			});
			// expand rows to match max row length
			rows.forEach(function(row:Array, i:int, a:Array):void {
				row.length = rowLength;
			});
			var header:Array = rows.shift();
			
			var columnArray:Array;
			dataProvider = null;
			var typicalItemArray:Array = new Array();
			var firstRow:Array = rows[0];
			columnArray = header.map(
				function(title:String, index:int, a:Array):GridColumn {
					var dgc:GridColumn = new GridColumn(title);
					dgc.dataField = index;
					// if title is missing, override default headerText which is equal to dataField
					if (!title)
						dgc.headerText = '';
					if(firstRow){
						var headerString:String = header[index];
						// required to add additional characters - column width calcualtion 
						// is based on Header string length due to Bold font,
						headerString += StandardLib.lpad('',Math.ceil(headerString.length/ 20),'0');
						// required to find either header string or first string has maximum length
						// and generate typicalitem object , which decides the column width.
						if(headerString.length > String(firstRow[index]).length)
							typicalItemArray[index] = headerString;
						else
							typicalItemArray[index] = firstRow[index];
					}					
					return dgc;
				}
			);
			columns = new ArrayCollection(columnArray);
			typicalItem = typicalItemArray;
			dataProvider = new ArrayCollection( rows);
		}
		
		/**<commit_msg>fixed null pointer error<commit_after>/*
Weave (Web-based Analysis and Visualization Environment)
Copyright (C) 2008-2011 University of Massachusetts Lowell

This file is a part of Weave.

Weave is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License, Version 3,
as published by the Free Software Foundation.

Weave is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Weave.  If not, see <http://www.gnu.org/licenses/>.
*/
package weave.ui.CustomDataGrid
{
	import mx.collections.ArrayCollection;
	
	import spark.components.DataGrid;
	import spark.components.gridClasses.GridColumn;
	import spark.events.GridEvent;
	
	import weave.compiler.StandardLib;
	
	public class CustomSparkDataGrid extends DataGrid
	{
		public function CustomSparkDataGrid()
		{
			super();
			showDataTips = true;
			selectionMode = 'multipleCells';
			this.addEventListener(GridEvent.GRID_MOUSE_DOWN,dataGrid_gridMouseDownHandler);
			this.addEventListener(GridEvent.GRID_MOUSE_UP,dataGrid_gridMouseUpHandler);
			
			
		}
		// Single Click Editing support
		// taken From 
		// http://blogs.adobe.com/dloverin/2011/05/single-click-editing-and-more.html
		private var mouseDownRowIndex:int;
		private var mouseDownColumnIndex:int;
		
		protected function dataGrid_gridMouseDownHandler(event:GridEvent):void
		{
			mouseDownRowIndex = event.rowIndex;
			mouseDownColumnIndex = event.columnIndex;
		}
		
		protected function dataGrid_gridMouseUpHandler(event:GridEvent):void
		{
			// Start a grid item editor if:
			// - the rowIndex is valid
			// - mouseUp is on the same cell and mouseDown
			// - shift and ctrl keys are not down
			// - cell is editable
			// - an editor is not already running
			// An editor may already be running if the cell was already
			// selected and the data grid started the editor.
			if (event.rowIndex >= 0 &&
				event.rowIndex == mouseDownRowIndex && 
				event.columnIndex == mouseDownColumnIndex &&
				!(event.shiftKey || event.ctrlKey) &&
				event.column.editable &&
				!event.grid.dataGrid.itemEditorInstance)
			{
				event.grid.dataGrid.startItemEditorSession(event.rowIndex, event.columnIndex);
			}
		}
		
		/**
		 * This function along with getRows() makes it easy to display and edit
		 * a table of data stored as a two-dimensional Array.
		 * @param tableWithHeader An Array of Arrays including a header row.
		 */
		public function setRows(tableWithHeader:Array):void
		{
			// make sure we have at least one row (for the header)
			if (!tableWithHeader || !tableWithHeader.length)
				tableWithHeader = [[]];
			
			// make a copy of the data and find the max row length
			var rowLength:int = 0;
			var rows:Array = tableWithHeader.map(function(row:Array, i:int, a:Array):Array {
				rowLength = Math.max(rowLength, row.length);
				return row.concat();
			});
			// expand rows to match max row length
			rows.forEach(function(row:Array, i:int, a:Array):void {
				row.length = rowLength;
			});
			var header:Array = rows.shift();
			
			var columnArray:Array;
			dataProvider = null;
			var typicalItemArray:Array = new Array();
			var firstRow:Array = rows[0];
			columnArray = header.map(
				function(title:String, index:int, a:Array):GridColumn
				{
					var dgc:GridColumn = new GridColumn(title);
					dgc.dataField = index;
					// if title is missing, override default headerText which is equal to dataField
					if (!title)
						dgc.headerText = '';
					if (firstRow)
					{
						var headerString:String = header[index] || '';
						// required to add additional characters - column width calculation 
						// is based on Header string length due to Bold font,
						headerString += StandardLib.lpad('', Math.ceil(headerString.length / 20), '0');
						// required to find either header string or first string has maximum length
						// and generate typicalitem object , which decides the column width.
						if (headerString.length > String(firstRow[index]).length)
							typicalItemArray[index] = headerString;
						else
							typicalItemArray[index] = firstRow[index];
					}
					return dgc;
				}
			);
			columns = new ArrayCollection(columnArray);
			typicalItem = typicalItemArray;
			dataProvider = new ArrayCollection(rows);
		}
		
		/**
{'fraction_non_alphanumeric': 0.09028087382969238, 'fraction_numerical': 0.004681230494872938, 'mean_word_length': 3.4486861675756075, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1459895', 'n_tokens_mistral': 3078, 'n_tokens_neox': 2517, 'n_words': 830}