/** * A class which represents a graphical array of DataCells, numbered and ordered. */ /* ## class DataArray implements IDataSet */ /** * DataArray constructor */ function DataArray(length, width, height, startValue) { var ID_CELL_WIDTH = parseInt(CELL_HEIGHT) - 2 + "px"; var divName = "dataArray" + getNewGUID(); this.frameDiv = document.createElement('DIV'); this.frameDiv.id = divName; this.frameDiv.style.width = width + "px"; this.frameDiv.style.height = height + "px"; /**/ this.frameDiv.style.borderRightWidth = "1px"; this.frameDiv.style.borderRightStyle = "Solid"; this.frameDiv.style.borderRightColor = "#000000"; /**/ this.frameDiv.style.backgroundColor = "#FFFFFF"; //CELL_COLOR; this.frameDiv.style.overflow = "auto"; this.frameDiv.array = this; this.cells = []; this.length = length; this.enabled = true; this.dataSetType = "DataArray"; var t0 = document.createElement("TABLE"); t0.cellSpacing = "0"; t0.cellPadding = "0"; t0.width = "100%"; this.frameDiv.appendChild(t0); rowID = 0; var that = this; for (var i = startValue; i < startValue + this.length; i++) { var cell = new DataCell(false, true, i, 2, (i == startValue)); this.cells.push(cell); cell.onenterpressed = function(id) { if (that.cells[id-startValue+1]) that.cells[id-startValue+1].itemDiv.onmousedown(); } var row = t0.insertRow(rowID++); var idCell = document.createElement("DIV"); idCell.style.width = ID_CELL_WIDTH; idCell.style.height = CELL_HEIGHT; idCell.style.lineHeight = CELL_HEIGHT; //idCell.style.fontWeight = "bolder"; idCell.style.textAlign = "center"; idCell.style.fontSize = "14px"; /* idCell.style.borderBottomWidth = "1px"; idCell.style.borderBottomStyle = "Solid"; idCell.style.borderBottomColor = "#000000"; idCell.style.borderRightWidth = "1px"; idCell.style.borderRightStyle = "Solid"; idCell.style.borderRightColor = "#000000"; */ idCell.style.backgroundColor = "#FFFFFF"; idCell.innerHTML = i < 10 ? "0" + i : i; var c0 = row.insertCell(0); c0.style.width = ID_CELL_WIDTH; c0.appendChild(idCell); row.insertCell(1).appendChild(cell.itemDiv); cell.itemDiv.style.backgroundColor = CELL_COLOR; cell.parent = this; } var cursor = 0; var that = this; /** * Sets the given DataCell to the given index in the array */ this.setCellAt = function(dataCell, index) { index -= startValue; that.getCellAt(index).setValue(dataCell.getValue()); } /** * Returns the DataCell at the specified index */ this.getCellAt = function(index) { index -= startValue; if (index >= 0 && index < that.length) return that.cells[index]; } /** * Returns the current DataCell at cursor's position */ this.getCurrent = function() { return that.getCellAt(cursor); } /** * Increments the cursor to the next cell */ this.goNext = function() { if (cursor < length-1) cursor++; } /** * Decrements the cursor to the previous cell */ this.goBack = function() { if (cursor > 0) cursor--; } /** * Clears a given cell in the list */ this.clearCell = function(dataCell) { dataCell.setValue(0, true); } /** * Returns an array representation of this DataList */ this.toArray = function() { var result = []; for (var i = 0; i < that.cells.length; i++) result[i] = getCellAt(i).getValue(); return result; } this.showValues = function() { for (var i in that.cells) { that.cells[i].showValue(); } } /* //Show "0" as default value for all cells for (var i = startValue; i < this.length + startValue; i++) { this.getCellAt(i).setValue(0); } */ }