/** * 添加Text的文本 * * @param msg */ public void appendText(String msg) { if (text.getLineCount() > lineLimit) { text.setText(""); } text.append(msg); }
// Returns the line we clicked on based on mouse coordinates public int getLine(int mouseY) { int topLine = m_Text.getTopIndex(); int lineHeight = m_Text.getLineHeight(); int screenLine = mouseY / lineHeight; int line = topLine + screenLine; if (line > m_Text.getLineCount()) return -1; return line; }
/** Expand/contract all blocks currently on screen */ public void expandPage(boolean state) { // Get all the information about which part of the text window is // visible int topLine = m_Text.getTopIndex(); int lineHeight = m_Text.getLineHeight(); int visibleLines = m_Text.getClientArea().height / lineHeight; int lastLine = Math.min(m_Text.getLineCount(), m_Text.getTopIndex() + visibleLines); boolean atBottom = (lastLine == m_Text.getLineCount()); // Start with the first block that starts at topLine or includes // topLine. Block topBlock = m_FoldingDoc.getBlockByLineNumber(topLine); Block bottomBlock = m_FoldingDoc.getBlockByLineNumber(lastLine); if (topBlock == null) return; // Stop redrawing while we expand/collapse everything then turn it back // on setRedraw(false); // If the lastLine is after the bottom block, use the last block in the // document if (bottomBlock == null) bottomBlock = m_FoldingDoc.getBlock(m_FoldingDoc.getNumberBlocks() - 1); int topIndex = topBlock.getIndex(); int bottomIndex = bottomBlock.getIndex(); for (int i = topIndex; i <= bottomIndex; i++) { Block block = m_FoldingDoc.getBlock(i); m_FoldingDoc.expandBlock(block, state); } // If the selection was set to the bottom before we expanded make sure // it stays there after the expansion. if (state && atBottom) scrollBottom(); // Redraw everything setRedraw(true); }
protected void paintIcons(PaintEvent e) { // Check if we've turned off redraws if (m_DrawingDisabled) return; GC gc = e.gc; Rectangle client = m_IconBar.getClientArea(); // Make sure the text control is properly initialized if (m_Text.getLineHeight() == 0) return; // Get all the information about which part of the text window is // visible int topLine = m_Text.getTopIndex(); int lineHeight = m_Text.getLineHeight(); int visibleLines = m_Text.getClientArea().height / lineHeight; int lastLine = Math.min(m_Text.getLineCount(), m_Text.getTopIndex() + visibleLines); // Start with the first block that starts at topLine or includes // topLine. Block topBlock = m_FoldingDoc.getBlockByLineNumber(topLine); int blockCount = m_FoldingDoc.getNumberBlocks(); if (topBlock == null) return; int blockIndex = topBlock.getIndex(); int outerSize = 9; int innerSize = 6; int offset = (outerSize - innerSize) / 2 + 1; Color gray = m_IconBar.getDisplay().getSystemColor(SWT.COLOR_GRAY); Color black = m_IconBar.getDisplay().getSystemColor(SWT.COLOR_BLACK); // Go through each block in turn until we're off the bottom of the // screen // or at the end of the list of blocks drawing icons while (blockIndex != -1 && blockIndex < blockCount) { Block block = m_FoldingDoc.getBlock(blockIndex); int line = block.getStart(); // Once we drop off the bottom of the screen we're done if (line >= lastLine) break; int pos = line - topLine; int y = pos * lineHeight + (lineHeight / 2) - (outerSize / 2) - 1; int x = 1; boolean expanded = block.isExpanded(); if (block.canExpand()) { gc.drawRectangle(x, y, x + outerSize, x + outerSize); // Start with a - sign int y1 = y + 1 + (outerSize / 2); gc.drawLine(x + offset, y1, x + offset + innerSize, y1); if (!expanded) { // If not expanded turn the - into a + int x1 = x + 1 + (outerSize / 2); gc.drawLine(x1, y + offset, x1, y + offset + innerSize); } else { // If expanded draw a line to show what is in the expanded // area gc.setForeground(gray); int x1 = x + 1 + (outerSize / 2); int yTop = y + outerSize + 2; int yBottom = y + ((block.getSize() - 1) * lineHeight) + (outerSize / 2); gc.drawLine(x1, yTop, x1, yBottom); gc.drawLine(x1, yBottom, client.width - 1, yBottom); gc.setForeground(black); } } blockIndex++; } }