private static final String SELECTION_COLOR_DEFINITION_ID = "org.eclipse.tracecompass.tmf.ui.color.eventraw.selection"; //$NON-NLS-1$
private static final int MAX_LINE_DATA_SIZE = 1000;
private static final int SLIDER_MAX = 1000000;
+ private static final String EMPTY_STRING = ""; //$NON-NLS-1$
+ private static final String LF = "\n"; //$NON-NLS-1$
+ private static final String CR_LF = "\r?\n"; //$NON-NLS-1$
private ITmfTrace fTrace;
private ITmfContext fBottomContext;
this.rank = rank;
this.location = location;
if (string.length() == 0) {
- this.string = " "; // workaround for setLineBackground has no effect on empty line //$NON-NLS-1$
+ /* workaround for setLineBackground has no effect on empty line */
+ this.string = " "; //$NON-NLS-1$
} else {
this.string = string;
}
@Override
public void dispose() {
+ if (fBottomContext != null) {
+ fBottomContext.dispose();
+ }
PlatformUI.getWorkbench().getThemeManager().removePropertyChangeListener(this);
super.dispose();
}
/**
* Initialize the colors.
- * @since 2.0
+ * @since 1.1
*/
protected void initializeColors() {
ColorRegistry colorRegistry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
fStyledText.addMouseMoveListener(this);
fStyledText.addMouseTrackListener(this);
fStyledText.addMouseWheelListener(this);
- fStyledText.addListener(SWT.MouseWheel, new Listener() { // disable mouse scroll of horizontal scroll bar
+ /* disable mouse scroll of horizontal scroll bar */
+ fStyledText.addListener(SWT.MouseWheel, new Listener() {
@Override
- public void handleEvent(Event event) { event.doit = false; }});
+ public void handleEvent(Event event) {
+ event.doit = false;
+ }
+ });
fStyledText.addKeyListener(this);
fTextArea.setBackground(fStyledText.getBackground());
@Override
public void mouseDown(MouseEvent e) {
fTextArea.setFocus();
- }});
+ }
+ });
}
// ------------------------------------------------------------------------
if (fLines.size() == 0) {
setTopRank(0);
} else if (fLines.size() < fNumVisibleLines) {
- fBottomContext = null;
+ if (fBottomContext != null) {
+ fBottomContext.dispose();
+ fBottomContext = null;
+ }
loadLineData();
fillTextArea();
- //fSlider.setSelection((int) (SLIDER_MAX * ((double) fLines.get(fTopLineIndex).rank / fTrace.getNbEvents())));
fSlider.setSelection((int) (SLIDER_MAX * fTrace.getLocationRatio(fLines.get(fTopLineIndex).location)));
}
} else {
- fBottomContext = null;
+ if (fBottomContext != null) {
+ fBottomContext.dispose();
+ fBottomContext = null;
+ }
fillTextArea();
fSlider.setThumb(SLIDER_MAX);
fSlider.setSelection(0);
}
private void setTopRank(long rank) {
+ if (fBottomContext != null) {
+ fBottomContext.dispose();
+ }
fBottomContext = fTrace.seekEvent(rank);
if (fBottomContext == null) {
return;
if (fLines.size() == 0) {
fSlider.setSelection(0);
} else {
- //fSlider.setSelection((int) (SLIDER_MAX * ((double) fLines.get(fTopLineIndex).rank / fTrace.getNbEvents())));
fSlider.setSelection((int) (SLIDER_MAX * fTrace.getLocationRatio(fLines.get(fTopLineIndex).location)));
}
}
private void setTopPosition(double ratio) {
+ if (fBottomContext != null) {
+ fBottomContext.dispose();
+ }
fBottomContext = fTrace.seekEvent(ratio);
if (fBottomContext == null) {
return;
private void loadLineData() {
if (fTopLineIndex < 0) {
- //if (fLines.size() > 0 && fLines.get(0).rank > 0) {
- //long endRank = fLines.get(0).rank;
- //long startRank = Math.max(0, endRank - fNumVisibleLines);
- //TmfContext context = fTrace.seekEvent(startRank);
- //int index = 0;
- //while (context.getRank() < endRank) {
- //long rank = context.getRank();
- //ITmfLocation<?> location = context.getLocation();
- //TmfEvent event = fTrace.getNextEvent(context);
- //String[] lines = event.getRawText().split("\r?\n");
- //for (int i = 0; i < lines.length; i++) {
- //String line = lines[i];
- //LineData lineData = new LineData(rank, location, line);
- //fLines.add(index++, lineData);
- //fTopLineIndex++;
- //fLastTopLineIndex++;
- //}
- //}
- //}
if (fLines.size() > 0 && fTrace.getLocationRatio(fLines.get(0).location) > 0) {
double lastRatio = fTrace.getLocationRatio(fLines.get(fLines.size() - 1).location);
double firstRatio = fTrace.getLocationRatio(fLines.get(0).location);
break;
}
if (event.getContent() != null && event.getContent().getValue() != null) {
- String[] lines = event.getContent().getValue().toString().split("\r?\n"); //$NON-NLS-1$
+ String[] lines = event.getContent().getValue().toString().split(CR_LF);
for (int i = 0; i < lines.length; i++) {
String line = lines[i];
LineData lineData = new LineData(rank, location, line);
fLastTopLineIndex++;
}
} else {
- LineData lineData = new LineData(rank, location, ""); //$NON-NLS-1$
+ LineData lineData = new LineData(rank, location, EMPTY_STRING);
fLines.add(index++, lineData);
fTopLineIndex++;
fLastTopLineIndex++;
}
rank++;
}
+ context.dispose();
long rankOffset = fLines.get(index).rank - rank;
for (int i = 0; i < index; i++) {
fLines.get(i).rank += rankOffset;
if (fLines.size() == 0) {
fBottomContext = fTrace.seekEvent(0);
} else {
- //fBottomContext = fTrace.seekEvent(fLines.get(fLines.size() - 1).rank + 1);
fBottomContext = fTrace.seekEvent(fLines.get(fLines.size() - 1).location);
fTrace.getNext(fBottomContext);
}
break;
}
if (event.getContent() != null && event.getContent().getValue() != null) {
- for (String line : event.getContent().getValue().toString().split("\r?\n")) { //$NON-NLS-1$
+ for (String line : event.getContent().getValue().toString().split(CR_LF)) {
int crPos;
if ((crPos = line.indexOf('\r')) != -1) {
line = line.substring(0, crPos);
fLines.add(lineData);
}
} else {
- LineData lineData = new LineData(rank, location, ""); //$NON-NLS-1$
+ LineData lineData = new LineData(rank, location, EMPTY_STRING);
fLines.add(lineData);
}
}
for (int i = MAX_LINE_DATA_SIZE; i < fLines.size(); i++) {
if (fLines.get(i).rank > rank) {
fLines.subList(i, fLines.size()).clear();
- fBottomContext = null;
+ if (fBottomContext != null) {
+ fBottomContext.dispose();
+ fBottomContext = null;
+ }
break;
}
}
}
private void refreshTextArea() {
- fStyledText.setText(""); //$NON-NLS-1$
+ fStyledText.setText(EMPTY_STRING);
for (int i = 0; i < fLines.size() - fTopLineIndex && i < fNumVisibleLines; i++) {
if (i > 0)
{
- fStyledText.append("\n"); //$NON-NLS-1$
+ fStyledText.append(LF);
}
LineData lineData = fLines.get(fTopLineIndex + i);
fStyledText.append(lineData.string);
for (int i = nextLine; i < fLines.size() - fTopLineIndex && i < fNumVisibleLines; i++) {
if (i > 0)
{
- fStyledText.append("\n"); //$NON-NLS-1$
+ fStyledText.append(LF);
}
LineData lineData = fLines.get(fTopLineIndex + i);
fStyledText.append(lineData.string);
int endOffset = fStyledText.getOffsetAtLine(endLine) - 1;
if (endOffset > fStyledText.getCharCount()) {
fHoldSelection++;
- fStyledText.replaceTextRange(endOffset, fStyledText.getCharCount() - endOffset, ""); //$NON-NLS-1$
+ fStyledText.replaceTextRange(endOffset, fStyledText.getCharCount() - endOffset, EMPTY_STRING);
fHoldSelection--;
}
}
private void updateTextArea() {
if (fTopLineIndex < fLastTopLineIndex) {
- StringBuffer insertedText = new StringBuffer();
+ StringBuilder insertedText = new StringBuilder();
for (int i = fTopLineIndex; i < fLastTopLineIndex; i++) {
- insertedText.append(fLines.get(i).string + "\n"); //$NON-NLS-1$
+ insertedText.append(fLines.get(i).string).append(LF);
}
fStyledText.replaceTextRange(0, 0, insertedText.toString());
for (int i = 0; i < fLastTopLineIndex - fTopLineIndex; i++) {
length += 1;
}
}
- fStyledText.replaceTextRange(0, length, ""); //$NON-NLS-1$
+ fStyledText.replaceTextRange(0, length, EMPTY_STRING);
fLastTopLineIndex = fTopLineIndex;
fillTextArea();
}
if (endLine < fStyledText.getLineCount()) {
int endOffset = fStyledText.getOffsetAtLine(endLine) - 1;
if (endOffset > fStyledText.getCharCount()) {
- fStyledText.replaceTextRange(endOffset, fStyledText.getCharCount() - endOffset, ""); //$NON-NLS-1$
+ fStyledText.replaceTextRange(endOffset, fStyledText.getCharCount() - endOffset, EMPTY_STRING);
}
}
fTextArea.layout();
/*
* The selection event was sent by the viewer, refresh now.
*/
- //long rank = (long) (fTrace.getNbEvents() * ((double) fSlider.getSelection() / SLIDER_MAX));
- //setTopRank(rank);
if (fSlider.getSelection() == 0 || fSlider.getThumb() == SLIDER_MAX) {
fLines.clear();
setTopPosition(0.0);
break;
}
case SWT.ARROW_UP: {
- //if (fLines.size() == 0 || (fTopLineIndex == 0 && fLines.get(0).rank == 0)) {
- if (fLines.size() == 0) {// || (fTopLineIndex == 0 && fLines.get(0).rank == 0)) {
+ if (fLines.size() == 0) {
break;
}
fTopLineIndex--;
break;
}
case SWT.HOME: {
- //selectAndReveal(0);
setTopPosition(0.0);
break;
}
case SWT.END: {
- //if (fTrace.getNbEvents() > 0) {
- //selectAndReveal(fTrace.getNbEvents() - 1);
- //}
double ratio = 1.0;
double delta = Math.pow(10, -15);
fLines.clear();
default:
break;
}
- //fSlider.setSelection((int) (SLIDER_MAX * ((double) fLines.get(fTopLineIndex).rank / fTrace.getNbEvents())));
if (e.detail != SWT.NONE) {
fSlider.setSelection((int) (SLIDER_MAX * fTrace.getLocationRatio(fLines.get(fTopLineIndex).location)));
}
// ------------------------------------------------------------------------
/**
- * @since 2.0
+ * @since 1.1
*/
@Override
public void mouseDown(MouseEvent e) {
}
/**
- * @since 2.0
+ * @since 1.1
*/
@Override
public void mouseUp(MouseEvent e) {
}
/**
- * @since 2.0
+ * @since 1.1
*/
@Override
public void mouseDoubleClick(MouseEvent e) {
if (previousLineAtCaretPosition > 0) {
break;
}
- if (fLines.size() == 0) {// || (fTopLineIndex == 0 && fLines.get(0).rank == 0)) {
+ if (fLines.size() == 0) {
break;
}
fHoldSelection++;
if (previousCaretOffset > 0) {
break;
}
- if (fLines.size() == 0) {// || (fTopLineIndex == 0 && fLines.get(0).rank == 0)) {
+ if (fLines.size() == 0) {
break;
}
long topRank = fLines.get(fTopLineIndex).rank;
if ((e.stateMask & SWT.CTRL) == 0) {
break;
}
- //selectAndReveal(0);
setTopPosition(0.0);
LineData lineData = fLines.get(fTopLineIndex);
if (!lineData.location.equals(fSelectedLocation)) {
if ((e.stateMask & SWT.CTRL) == 0) {
break;
}
- //if (fTrace.getNbEvents() > 0) {
- //selectAndReveal(fTrace.getNbEvents() - 1);
- //}
double ratio = 1.0;
double delta = Math.pow(10, -15);
fLines.clear();
default:
break;
}
- //fSlider.setSelection((int) (SLIDER_MAX * ((double) fLines.get(fTopLineIndex).rank / fTrace.getNbEvents())));
updateHighlightedRank();
fSlider.setSelection((int) (SLIDER_MAX * fTrace.getLocationRatio(fLines.get(fTopLineIndex).location)));
}
loadLineData();
updateTextArea();
fHoldSelection = 0;
- //fSlider.setSelection((int) (SLIDER_MAX * ((double) fLines.get(fTopLineIndex).rank / fTrace.getNbEvents())));
updateHighlightedRank();
fSlider.setSelection((int) (SLIDER_MAX * fTrace.getLocationRatio(fLines.get(fTopLineIndex).location)));
}