protected void drawBottomSpace(GC gc) { Rectangle r = getClientArea(); if (m_Model.getRowCount() > 0) { r.y = m_Model.getFirstRowHeight() + (m_Model.getFixedRowCount() - 1 + m_RowsVisible) * m_Model.getRowHeight() + 1; } gc.setBackground(getBackground()); gc.fillRectangle(r); gc.fillRectangle(getLastColumnRight() + 2, 0, r.width, r.height); if (m_Model.getRowCount() > 0) { if (flatStyleSpecified) // gc.setForeground(this.getBackground()); gc.setForeground(m_Display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); else gc.setForeground(m_Display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW)); // Linke Schattenlinie gc.drawLine(0, 0, 0, r.y - 1); } if (!flatStyleSpecified) gc.setForeground(this.getBackground()); else gc.setForeground(m_Display.getSystemColor(SWT.COLOR_WHITE)); // Untere Abschlusslinie gc.drawLine(0, r.y - 1, getLastColumnRight() + 1, r.y - 1); // Rechte Abschlusslinie gc.drawLine(getLastColumnRight() + 1, 0, getLastColumnRight() + 1, r.y - 1); }
protected void onKeyDown(KeyEvent e) { boolean focusChanged = false; int newFocusRow = m_FocusRow; int newFocusCol = m_FocusCol; if (m_Model == null) return; if ((e.character == ' ') || (e.character == '\r')) { openEditorInFocus(); return; } else if (e.keyCode == SWT.HOME) { newFocusCol = m_Model.getFixedColumnCount(); if (newFocusRow == -1) newFocusRow = m_Model.getFixedRowCount(); focusChanged = true; } else if (e.keyCode == SWT.END) { newFocusCol = m_Model.getColumnCount() - 1; if (newFocusRow == -1) newFocusRow = m_Model.getFixedRowCount(); focusChanged = true; } else if (e.keyCode == SWT.ARROW_LEFT) { if (!m_RowSelectionMode) { if (newFocusCol > m_Model.getFixedColumnCount()) newFocusCol--; } focusChanged = true; } else if (e.keyCode == SWT.ARROW_RIGHT) { if (!m_RowSelectionMode) { if (newFocusCol == -1) { newFocusCol = m_Model.getFixedColumnCount(); newFocusRow = m_Model.getFixedRowCount(); } else if (newFocusCol < m_Model.getColumnCount() - 1) newFocusCol++; } focusChanged = true; } else if (e.keyCode == SWT.ARROW_DOWN) { if (newFocusRow == -1) { newFocusRow = m_Model.getFixedRowCount(); newFocusCol = m_Model.getFixedColumnCount(); } else if (newFocusRow < m_Model.getRowCount() - 1) newFocusRow++; focusChanged = true; } else if (e.keyCode == SWT.ARROW_UP) { if (newFocusRow > m_Model.getFixedRowCount()) newFocusRow--; focusChanged = true; } else if (e.keyCode == SWT.PAGE_DOWN) { newFocusRow += m_RowsVisible - 1; if (newFocusRow >= m_Model.getRowCount()) newFocusRow = m_Model.getRowCount() - 1; if (newFocusCol == -1) newFocusCol = m_Model.getFixedColumnCount(); focusChanged = true; } else if (e.keyCode == SWT.PAGE_UP) { newFocusRow -= m_RowsVisible - 1; if (newFocusRow < m_Model.getFixedRowCount()) newFocusRow = m_Model.getFixedRowCount(); if (newFocusCol == -1) newFocusCol = m_Model.getFixedColumnCount(); focusChanged = true; } if (focusChanged) { focusCell(newFocusCol, newFocusRow, e.stateMask); if (!isCellFullyVisible(m_FocusCol, m_FocusRow)) scrollToFocus(); } }
/** * Returns the number of the row that is present at position y or -1, if out of area. * * @param y * @return int */ public int calcRowNum(int y) { if (m_Model == null) return -1; if (y < m_Model.getFirstRowHeight()) return (m_Model.getFixedRowCount() == 0 ? m_TopRow : 0); y -= m_Model.getFirstRowHeight(); int row = 1 + (y / m_Model.getRowHeight()); if ((row < 0) || (row >= m_Model.getRowCount())) return -1; if (row >= m_Model.getFixedRowCount()) return m_TopRow + row - m_Model.getFixedRowCount(); return row; }
/** * Selects the given cell. If scroll is true, it scrolls to show this cell if neccessary. In Row * Selection Mode, the given row is selected and a scroll to the given column is done. Does * nothing if the cell does not exist. * * @param col * @param row * @param scroll */ public void setSelection(int col, int row, boolean scroll) { if (col < m_Model.getColumnCount() && col >= m_Model.getFixedColumnCount() && row < m_Model.getRowCount() && row >= m_Model.getFixedRowCount()) { focusCell(col, row, 0); if (scroll) { scrollToFocus(); } } }
protected void drawCell(GC gc, int col, int row) { if ((row < 0) || (row >= m_Model.getRowCount())) { return; } Rectangle rect = getCellRect(col, row); m_Model .getCellRenderer(col, row) .drawCell( gc, rect, col, row, m_Model.getContentAt(col, row), showAsSelected(col, row), col < m_Model.getFixedColumnCount() || row < m_Model.getFixedRowCount(), col == m_ClickColumnIndex && row == m_ClickRowIndex); }
protected void doCalculations() { if (m_Model == null) { ScrollBar sb = getHorizontalBar(); if (sb != null) { sb.setMinimum(0); sb.setMaximum(1); sb.setPageIncrement(1); sb.setThumb(1); sb.setSelection(1); } sb = getVerticalBar(); if (sb != null) { sb.setMinimum(0); sb.setMaximum(1); sb.setPageIncrement(1); sb.setThumb(1); sb.setSelection(1); } return; } int m_HeaderHeight = m_Model.getFirstRowHeight(); int m_RowHeight = m_Model.getRowHeight(); Rectangle rect = getClientArea(); if (m_LeftColumn < m_Model.getFixedColumnCount()) { m_LeftColumn = m_Model.getFixedColumnCount(); } if (m_TopRow < m_Model.getFixedRowCount()) { m_TopRow = m_Model.getFixedRowCount(); } int fixedWidth = getFixedWidth(); int fixedHeight = m_HeaderHeight + (m_Model.getFixedRowCount() - 1) * m_Model.getRowHeight(); m_ColumnsVisible = 0; m_ColumnsFullyVisible = 0; if (m_Model.getColumnCount() > m_Model.getFixedColumnCount()) { int runningWidth = getColumnLeft(m_LeftColumn); for (int col = m_LeftColumn; col < m_Model.getColumnCount(); col++) { if (runningWidth < rect.width + rect.x) m_ColumnsVisible++; runningWidth += m_Model.getColumnWidth(col); if (runningWidth < rect.width + rect.x) m_ColumnsFullyVisible++; else break; } } ScrollBar sb = getHorizontalBar(); if (sb != null) { if (m_Model.getColumnCount() <= m_Model.getFixedColumnCount()) { sb.setMinimum(0); sb.setMaximum(1); sb.setPageIncrement(1); sb.setThumb(1); sb.setSelection(1); } else { sb.setMinimum(m_Model.getFixedColumnCount()); sb.setMaximum(m_Model.getColumnCount()); sb.setIncrement(1); sb.setPageIncrement(2); sb.setThumb(m_ColumnsFullyVisible); sb.setSelection(m_LeftColumn); } } m_RowsFullyVisible = Math.max(0, (rect.height - fixedHeight) / m_RowHeight); m_RowsFullyVisible = Math.min(m_RowsFullyVisible, m_Model.getRowCount() - m_Model.getFixedRowCount()); m_RowsFullyVisible = Math.max(0, m_RowsFullyVisible); m_RowsVisible = m_RowsFullyVisible + 1; if (m_TopRow + m_RowsFullyVisible > m_Model.getRowCount()) { m_TopRow = Math.max(m_Model.getFixedRowCount(), m_Model.getRowCount() - m_RowsFullyVisible); } if (m_TopRow + m_RowsFullyVisible >= m_Model.getRowCount()) { m_RowsVisible--; } sb = getVerticalBar(); if (sb != null) { if (m_Model.getRowCount() <= m_Model.getFixedRowCount()) { sb.setMinimum(0); sb.setMaximum(1); sb.setPageIncrement(1); sb.setThumb(1); sb.setSelection(1); } else { sb.setMinimum(m_Model.getFixedRowCount()); sb.setMaximum(m_Model.getRowCount()); sb.setPageIncrement(m_RowsVisible); sb.setIncrement(1); sb.setThumb(m_RowsFullyVisible); sb.setSelection(m_TopRow); } } }