From c7a377406dbeb5077501dcc1f0647b28c0783ae8 Mon Sep 17 00:00:00 2001 From: Michael Scharf Date: Thu, 11 Oct 2007 15:39:20 +0000 Subject: [PATCH] helper method added to be used in "New Detail Formatter.." in the debugger variables view --- .../terminal/model/TerminalTextData.java | 53 +++++++++++++++---- .../textcanvas/AbstractTextCanvasModel.java | 2 +- .../terminal/textcanvas/GridCanvas.java | 22 ++++++-- 3 files changed, 63 insertions(+), 14 deletions(-) diff --git a/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/model/TerminalTextData.java b/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/model/TerminalTextData.java index 7101f21b04f..341e3b740a5 100644 --- a/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/model/TerminalTextData.java +++ b/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/model/TerminalTextData.java @@ -1,11 +1,11 @@ /******************************************************************************* * Copyright (c) 2007 Wind River Systems, Inc. and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: * Michael Scharf (Wind River) - initial API and implementation *******************************************************************************/ package org.eclipse.tm.internal.terminal.model; @@ -15,6 +15,7 @@ import java.util.Arrays; import java.util.List; import org.eclipse.tm.terminal.model.ITerminalTextData; +import org.eclipse.tm.terminal.model.ITerminalTextDataReadOnly; import org.eclipse.tm.terminal.model.ITerminalTextDataSnapshot; import org.eclipse.tm.terminal.model.LineSegment; import org.eclipse.tm.terminal.model.Style; @@ -31,6 +32,40 @@ public class TerminalTextData implements ITerminalTextData { public TerminalTextDataSnapshot[] fSnapshots=new TerminalTextDataSnapshot[0]; private int fCursorColumn; private int fCursorLine; + /** + * Debug helper method -- use as "New Detail Formatter.." in the + * debugger variables view: + *
TerminalTextData.toMultiLineText(this,0,200))
+ * @param term the terminal + * @param start start line to show + * @param len number of lines to show -- negative numbers means show all + * @return a string representation of the content + */ + static public String toMultiLineText(ITerminalTextDataReadOnly term, int start, int len) { + if(len<0) + len=term.getHeight(); + StringBuffer buff=new StringBuffer(); + int width=term.getWidth(); + int n=Math.min(len,term.getHeight()-start); + for (int line = start; line < n; line++) { + if(line>0) + buff.append("\n"); //$NON-NLS-1$ + for (int column = 0; column < width; column++) { + buff.append(term.getChar(line, column)); + } + } + return buff.toString().replaceAll("\000+", ""); //$NON-NLS-1$//$NON-NLS-2$ + } + + /** + * Show the first 100 lines + * see {@link #toMultiLineText(ITerminalTextDataReadOnly, int, int)} + * @param term + * @return a string representaron of the terminal + */ + static public String toMultiLineText(ITerminalTextDataReadOnly term) { + return toMultiLineText(term, 0, 100); + } public TerminalTextData() { this(new TerminalTextDataFastScroll()); @@ -118,7 +153,7 @@ public class TerminalTextData implements ITerminalTextData { fSnapshots[i].markLinesChanged(line, n); } } - + /** * Notify snapshot that a region was scrolled * @param startLine @@ -163,7 +198,7 @@ public class TerminalTextData implements ITerminalTextData { // was is an append or a scroll? int newHeight=getHeight(); if(newHeight>oldHeight) { - //the line was appended + //the line was appended sendLinesChangedToSnapshot(oldHeight, 1); int width=getWidth(); sendDimensionsChanged(oldHeight, width, newHeight, width); @@ -172,7 +207,7 @@ public class TerminalTextData implements ITerminalTextData { // the line was scrolled sendScrolledToSnapshots(0, oldHeight, -1); } - + } public void copy(ITerminalTextData source) { diff --git a/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/textcanvas/AbstractTextCanvasModel.java b/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/textcanvas/AbstractTextCanvasModel.java index 21ae6f1bcfd..f39516cce26 100644 --- a/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/textcanvas/AbstractTextCanvasModel.java +++ b/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/textcanvas/AbstractTextCanvasModel.java @@ -168,7 +168,7 @@ abstract public class AbstractTextCanvasModel implements ITextCanvasModel { } } public void setVisibleRectangle(int startLine, int startCol, int height, int width) { - fSnapshot.setInterestWindow(Math.max(0,startLine), Math.max(1,Math.min(fSnapshot.getHeight(),height))); + fSnapshot.setInterestWindow(Math.max(0,startLine), Math.max(1,height)); update(); } protected void showCursor(boolean show) { diff --git a/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/textcanvas/GridCanvas.java b/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/textcanvas/GridCanvas.java index 60dd821c621..f920c92df6e 100644 --- a/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/textcanvas/GridCanvas.java +++ b/terminal/org.eclipse.tm.terminal/src/org/eclipse/tm/internal/terminal/textcanvas/GridCanvas.java @@ -45,6 +45,20 @@ abstract public class GridCanvas extends VirtualCanvas { } + public void setBounds(int x, int y, int width, int height) { + // adjust the height so that there are no characters cut + // Maybe it would be better to use a custom Layout... + int shiftH=0; + if(getCellHeight()!=0) + shiftH=height % getCellHeight(); + super.setBounds(x, y+shiftH, width, height-shiftH); + } + + public void setBounds(Rectangle rect) { + // just to be sure our set bounds is called! + setBounds(rect.x,rect.y,rect.width,rect.height); + } + /** template method paint. * iterates over all cells in the clipping rectangle and paints them. */ @@ -159,11 +173,11 @@ abstract public class GridCanvas extends VirtualCanvas { int cellY=virtualYToCell(y); // End coordinates int xE=virtualXToCell(x+fCellWidth+width-1); - if(xE>getCols()) - xE=getCols(); +// if(xE>getCols()) +// xE=getCols(); int yE=virtualYToCell(y+fCellHeight+height-1); - if(yE>getRows()) - yE=getRows(); +// if(yE>getRows()) +// yE=getRows(); visibleCellRectangleChanged(cellX,cellY,xE-cellX,yE-cellY); }