private static Rectangle TableIndexToRectangle(TableIndex index, float iconWidth, float iconHeight)
        {
            var location = new Point((int) (index.Column * iconWidth), (int) (index.Row * iconHeight));
            var size = new Point((int) iconWidth, (int) iconHeight);

            return new Rectangle(location, size);
        }
Beispiel #2
0
        public void ResizeHandler_AutoResizeTableViewResize_EndIndexIsAdjusted(int rows, int columns, 
            int newRows, int newColumns, int endRow, int endColumn)
        {
            var endIndex = new TableIndex(endRow, endColumn);
            var view = new TableViewMock();
            CreateTableWidget(view, rows, columns);
            
            view.Rows = newRows;
            view.Columns = newColumns;
            view.RaiseTableResizeEvent(newRows, newColumns);

            AssertIndex(endIndex, view.EndIndex.Value);
        }
Beispiel #3
0
        public void Draw_SetStartIndex_DrawnComponentsLimitedByIndex()
        {
            var startIndex = new TableIndex(2, 2);
            var grid = CreateDefaultGrid();
            var components = FillGrid(grid);

            grid.StartIndex = startIndex;
            grid.Draw();

            Assert.IsTrue(grid.StartIndex.HasValue);
            Assert.IsTrue(grid.EndIndex.HasValue);

            ValidateComponentsDrawn(components, grid.StartIndex.Value, grid.EndIndex.Value);
        }
Beispiel #4
0
        public void SetEndIndex_ResizeModelBeforeSetup_GetReturnsEndIndex()
        {
            var modelStub = new Mock<ITableModel<Object>>();
            var table = CreateTable(modelStub);
            int rows = 10;
            int columns = 20;
            var expectedEndIndex = new TableIndex(rows, columns);

            SetDimension(modelStub, rows, columns);
            modelStub.Raise(o => o.SizeChanged += null, new TableResizeEventArgs(rows, columns));

            table.EndIndex = expectedEndIndex;

            AssertIndexesAreEqual(expectedEndIndex, table.EndIndex);
        }
Beispiel #5
0
        public void Resizehandler_RestrictedVisibleArea_EndIndexIsAdjusted(int rows, int columns, 
            int visibleRows, int visibleColumns,
            int selectedRow, int selectedColumn,
            int newRows, int newColumns, int endRow, int endColumn)
        {
            var endIndex = new TableIndex(endRow, endColumn);
            var view = new TableViewMock();
            var table = CreateTableWidget(view, rows, columns, visibleRows, visibleColumns);

            table.SelectCell(selectedRow, selectedColumn);

            view.Rows = newRows;
            view.Columns = newColumns;
            view.RaiseTableResizeEvent(newRows, newColumns);

            AssertIndex(endIndex, view.EndIndex.Value);
        }
        private IDictionary<string, TableIndex> ReadTableMapping()
        {
            var tmpList = new List<string>();
            using (var stream = new StreamReader(fileName))
            {
                string line;
                while ((line = stream.ReadLine()) != null)
                    tmpList.Add(line);
            }

            var table = new Dictionary<string, TableIndex>();
            foreach (var line in tmpList)
            {
                var splitted = line.Split(';');
                var key = splitted[KeyIndex];
                var value = new TableIndex(int.Parse(splitted[RowIndex]), int.Parse(splitted[ColumnIndex]));
                table.Add(key, value);
            }

            return table;
        }
Beispiel #7
0
 private void AssertIndicesAreEqual(TableIndex expectedIndex, TableIndex tableIndex)
 {
     Assert.AreEqual(expectedIndex.Row, tableIndex.Row);
     Assert.AreEqual(expectedIndex.Column, tableIndex.Column);
 }
Beispiel #8
0
 public void SetIndexes_InvalidData_ThrowsException(TableIndex? startIndex, TableIndex? endIndex)
 {
     var grid = CreateDefaultGrid();
     Assert.Throws<ArgumentOutOfRangeException>(() =>
     {
         grid.StartIndex = startIndex;
         grid.EndIndex = endIndex;
     });
 }
Beispiel #9
0
        public void EndIndex_Default_0_0()
        {
            TableIndex defaultEndIndex = new TableIndex(0, 0);
            var grid = new TableGrid(ROWS, COLUMNS);

            Assert.IsTrue(grid.EndIndex.HasValue);
            AssertIndicesAreEqual(defaultEndIndex, grid.EndIndex.Value);
        }
Beispiel #10
0
        public void EndIndexIndex_RowColumnResize_ShrinksIfNeeded(TableIndex endIndex, int newRows, int newColumns, TableIndex expectedEndIndex)
        {
            var grid = CreateDefaultGrid();
            grid.EndIndex = endIndex;

            grid.Rows = newRows;
            grid.Columns = newColumns;

            Assert.IsTrue(grid.EndIndex.HasValue);
            AssertIndicesAreEqual(expectedEndIndex, grid.EndIndex.Value);
        }
Beispiel #11
0
 private void CheckStartRange(TableIndex index)
 {
     if (index.Row == 0 && index.Column == 0)
         return;
     CheckRange(index.Row, index.Column);
 }
Beispiel #12
0
 private void AssertIndexesAreEqual(TableIndex expectedStartIndex, TableIndex? testIndex)
 {
     Assert.NotNull(testIndex);
     Assert.AreEqual(expectedStartIndex.Column, testIndex.Value.Column);
     Assert.AreEqual(expectedStartIndex.Row, testIndex.Value.Row);
 }
Beispiel #13
0
        public void CreateTable_WithVisibleColumnsAndRows_EndIndexHasExpectedValue(int rows, int column, int visibleRows, int visibleColumns, int endRow, int endColumn)
        {
            var view = new TableViewMock();
            CreateTableWidget(view, rows, column, visibleRows, visibleColumns);
            var endIndex = new TableIndex(endRow, endColumn);

            Assert.True(view.EndIndex.HasValue);
            AssertIndex(endIndex, view.EndIndex.Value);

        }
Beispiel #14
0
 private static void AssertIndex(TableIndex idx, int row, int column)
 {
     Assert.AreEqual(column, idx.Column);
     Assert.AreEqual(row, idx.Row);
 }
Beispiel #15
0
 private static void AssertIndex(TableIndex idx, TableIndex idx2)
 {
     AssertIndex(idx2, idx.Row, idx.Column);
 }
Beispiel #16
0
        public void HandleInput_WithVisibleRowsColumnsSet_StartIndexAdjusts(int rows, int columns, int visibleRows, int visibleColumns,
            int selectedRow, int selectedColumn,
            CommandKeys key,
            int startRow, int startColumn)
        {
            var tableViewMock = new TableViewMock();
            var table = CreateTableWidget(tableViewMock, rows, columns, visibleRows, visibleColumns);
            var startIndex = new TableIndex(startRow, startColumn);

            table.SelectCell(selectedRow, selectedColumn);
            table.HandleInput(key);

            AssertIndex(startIndex, tableViewMock.StartIndex.Value);

        }
Beispiel #17
0
        private void CheckEndRange(TableIndex index)
        {
            var row = index.Row;
            var column = index.Column;

            if (row > Rows || row < 0)
                throw new ArgumentOutOfRangeException("index");
            if (column > Columns || column < 0)
                throw new ArgumentOutOfRangeException("index");
        }
Beispiel #18
0
        public void Draw_SetStartIndex_IndexIsHandedToTableGrid()
        {
            var grid = new Mock<ITableGrid>();
            var table = CreateTable(10, 20, grid.Object);
            var startIndex = new TableIndex(5, 10);
            table.StartIndex = startIndex;
            table.Setup();

            table.Draw();

            grid.VerifySet(o => o.StartIndex = startIndex, Times.AtLeastOnce);
        }
Beispiel #19
0
        private void CheckOrder(TableIndex? start, TableIndex? end)
        {
            if (start == null || end == null)
                return;

            var startValue = start.Value;
            var endValue = end.Value;

            if (startValue.Row > endValue.Row || startValue.Column > endValue.Column)
            {
                throw new ArgumentOutOfRangeException("", "StartIndex needs to be less than EndIndex");
            }
        }
Beispiel #20
0
        public void SetStartIndex_OnEmptyTable_DoesNotThrowAnException()
        {
            var grid = CreateGrid(0, 0);
            var startIndex = new TableIndex(0, 0);

            grid.StartIndex = startIndex;
        }
Beispiel #21
0
 private void ValidateComponentsDrawn(Table<SelectableGraphicComponentMock> components, TableIndex startIndex, TableIndex endIndex)
 {
     var drawnArea = components.CreateSubtable(startIndex, endIndex);
     foreach (var c in components)
         Assert.AreEqual(drawnArea.Contains(c), c.WasDrawn);
 }
Beispiel #22
0
        public void SetSelection_CalledTwiceWithDifferentIndexes_EndIndexAdjusts(int rows, int columns, int visibleRows, int visibleColumns,
            int selectedRow, int selectedColumn, int selectedRow2, int selectedColumn2, 
            int endRow, int endColumn)
        {
            var tableViewMock = new TableViewMock();
            var table = CreateTableWidget(tableViewMock, rows, columns, visibleRows, visibleColumns);
            var endIndex = new TableIndex(endRow, endColumn);

            table.SelectCell(selectedRow, selectedColumn);
            table.SelectCell(selectedRow2, selectedColumn2);

            AssertIndex(endIndex, tableViewMock.EndIndex.Value);

        }