/** * set text * * @param lines lines * @param widgetLineNumbers number text widget * @param widgetText text widget * @param widgetHorizontalScrollBar horizontal scrollbar widget * @param widgetVerticalScrollBar horizontal scrollbar widget */ private void setText( String[] lines, StyledText widgetLineNumbers, StyledText widgetText, ScrollBar widgetHorizontalScrollBar, ScrollBar widgetVerticalScrollBar) { if (!widgetLineNumbers.isDisposed() && !widgetText.isDisposed() && !widgetVerticalScrollBar.isDisposed() && !widgetHorizontalScrollBar.isDisposed()) { StringBuilder lineNumbers = new StringBuilder(); StringBuilder text = new StringBuilder(); int lineNb = 1; int maxWidth = 0; // get text for (String line : lines) { lineNumbers.append(String.format("%d\n", lineNb)); lineNb++; text.append(line); text.append('\n'); maxWidth = Math.max(maxWidth, line.length()); } // set text widgetLineNumbers.setText(lineNumbers.toString()); widgetText.setText(text.toString()); widgetText.setCaretOffset(0); // set scrollbars widgetHorizontalScrollBar.setMinimum(0); widgetHorizontalScrollBar.setMaximum(maxWidth); widgetVerticalScrollBar.setMinimum(0); widgetVerticalScrollBar.setMaximum(lineNb - 1); // force redraw (Note: for some reason this is necessary to keep texts and scrollbars in sync) widgetLineNumbers.redraw(); widgetText.redraw(); widgetLineNumbers.update(); widgetText.update(); // show top widgetLineNumbers.setTopIndex(0); widgetLineNumbers.setSelection(0); widgetText.setTopIndex(0); widgetText.setCaretOffset(0); widgetVerticalScrollBar.setSelection(0); } }
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); } } }