Refactored to eliminate duplicate spaces between two tokens, handle Business BASIC text exportation the same as RTF

This commit is contained in:
2009-01-03 05:48:26 +00:00
parent 51f442d291
commit 20c92bc931
4 changed files with 59 additions and 48 deletions

View File

@ -53,7 +53,8 @@ public class BusinessBASICFileFilter implements FileFilter {
PrintWriter printWriter = new PrintWriter(byteArray, true);
BusinessBASICTokenizer tokenizer = new BusinessBASICTokenizer(fileEntry);
boolean firstLine = true;
int nest = 0;
boolean firstData = true;
int nestLevels = 0;
while (tokenizer.hasMoreTokens()) {
BusinessBASICToken token = tokenizer.getNextToken();
if (token == null) {
@ -64,22 +65,30 @@ public class BusinessBASICFileFilter implements FileFilter {
} else {
printWriter.println();
}
firstData = true;
printWriter.print(token.getLineNumber());
if (nest > 0) {
for (int i = 1; i < nest; i++)
printWriter.print(" "); //$NON-NLS-1$
if (nestLevels > 0) {
for (int i = 0; i < nestLevels; i++)
printWriter.print(" "); //$NON-NLS-1$
}
/*
if (token.isIndenter())
nest ++;
else if (token.isOutdenter())
nest --;
*/
//printWriter.print(" "); //$NON-NLS-1$
} else if (token.isToken()) {
if (!firstData)
printWriter.print(" "); //$NON-NLS-1$
printWriter.print(token.getTokenString());
firstData = false;
if (token.isIndenter()) {
nestLevels ++; }
else if (token.isOutdenter()) {
nestLevels --; }
} else if (token.isCommandSeparator() || token.isExpressionSeparator()) {
printWriter.print(token.getStringValue());
firstData = true;
} else {
printWriter.print(" "+token.getStringValue());
if (!firstData)
printWriter.print(" "); //$NON-NLS-1$
printWriter.print(token.getStringValue().trim());
firstData = false;
}
}
printWriter.close();

View File

@ -1,7 +1,7 @@
/*
* AppleCommander - An Apple ][ image utility.
* Copyright (C) 2002-2004 by Robert Greene
* robgreene at users.sourceforge.net
* Copyright (C) 2008 by David Schmidt
* david__schmidt at users.sourceforge.net
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@ -33,7 +33,7 @@ import com.webcodepro.applecommander.util.BusinessBASICTokenizer;
/**
* Provides a view of a syntax-colored Apple /// Business BASIC program listing.
*
* @author Rob Greene
* @author David Schmidt
*/
public class BusinessBASICFilterAdapter extends FilterAdapter {
private StyledText styledText;
@ -91,22 +91,24 @@ public class BusinessBASICFilterAdapter extends FilterAdapter {
}
} else if (token.isCommandSeparator() || token.isExpressionSeparator()) {
styledText.append(token.getStringValue());
firstData = false;
firstData = true;
} else if (token.isEndOfCommand()) {
styledText.append("\n"); //$NON-NLS-1$
firstData = false;
} else if (token.isString()) {
if (firstData)
if (!firstData)
styledText.append(" "); //$NON-NLS-1$
int caretOffset = styledText.getCharCount();
styledText.append(token.getStringValue());
styledText.append(token.getStringValue().trim());
StyleRange styleRange = new StyleRange();
styleRange.start = caretOffset;
styleRange.length = token.getStringValue().length();
styleRange.length = token.getStringValue().trim().length();
styleRange.foreground = getGreenColor();
styledText.setStyleRange(styleRange);
firstData = false;
} else if (token.isToken()) {
if (!firstData)
styledText.append(" "); //$NON-NLS-1$
int caretOffset = styledText.getCharCount();
styledText.append(token.getTokenString());
StyleRange styleRange = new StyleRange();