Added GUI support for color-coding. Added support for color-coding
and choosing the warning level to TibetanConverter. Better error checking in the GUI converter.
This commit is contained in:
parent
1308f14807
commit
0d6d6ed611
8 changed files with 141 additions and 74 deletions
|
@ -37,6 +37,9 @@ class ConvertDialog extends JDialog
|
||||||
{
|
{
|
||||||
private static final boolean debug = false;
|
private static final boolean debug = false;
|
||||||
|
|
||||||
|
private JCheckBox colors;
|
||||||
|
private static final String colorDesc = "Color-coding (ACIP to RTF only)";
|
||||||
|
|
||||||
// Attributes
|
// Attributes
|
||||||
private FontConversion controller;
|
private FontConversion controller;
|
||||||
|
|
||||||
|
@ -95,6 +98,11 @@ class ConvertDialog extends JDialog
|
||||||
updateWarningLevels();
|
updateWarningLevels();
|
||||||
|
|
||||||
temp.add(warningLevels);
|
temp.add(warningLevels);
|
||||||
|
this.colors = new JCheckBox(colorDesc, false);
|
||||||
|
this.colors.addActionListener(tal);
|
||||||
|
updateWarningLevels();
|
||||||
|
|
||||||
|
temp.add(colors);
|
||||||
content.add(temp);
|
content.add(temp);
|
||||||
|
|
||||||
temp = new JPanel(new FlowLayout(FlowLayout.CENTER,5,5));
|
temp = new JPanel(new FlowLayout(FlowLayout.CENTER,5,5));
|
||||||
|
@ -151,7 +159,7 @@ class ConvertDialog extends JDialog
|
||||||
content.add(buttonBox);
|
content.add(buttonBox);
|
||||||
setContentPane(content);
|
setContentPane(content);
|
||||||
pack();
|
pack();
|
||||||
setSize(new Dimension(620,200));
|
setSize(new Dimension(640,235));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setChoices(String[] choices)
|
private void setChoices(String[] choices)
|
||||||
|
@ -226,6 +234,13 @@ class ConvertDialog extends JDialog
|
||||||
JOptionPane.ERROR_MESSAGE);
|
JOptionPane.ERROR_MESSAGE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if ("".equals(newTextField.getText())) {
|
||||||
|
JOptionPane.showMessageDialog(this,
|
||||||
|
"Choose a target file.",
|
||||||
|
"No target chosen",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
File convertedFile = new File(newTextField.getText());
|
File convertedFile = new File(newTextField.getText());
|
||||||
if(null == convertedFile) {
|
if(null == convertedFile) {
|
||||||
JOptionPane.showMessageDialog(this,
|
JOptionPane.showMessageDialog(this,
|
||||||
|
@ -274,7 +289,8 @@ class ConvertDialog extends JDialog
|
||||||
origFile,
|
origFile,
|
||||||
convertedFile,
|
convertedFile,
|
||||||
(String)choices.getSelectedItem(),
|
(String)choices.getSelectedItem(),
|
||||||
(String)warningLevels.getSelectedItem());
|
(String)warningLevels.getSelectedItem(),
|
||||||
|
colors.isSelected());
|
||||||
} catch (OutOfMemoryError e) {
|
} catch (OutOfMemoryError e) {
|
||||||
JOptionPane.showMessageDialog(this,
|
JOptionPane.showMessageDialog(this,
|
||||||
"The converter ran out of memory. Please give the\nJVM more memory by using java -XmxYYYm where YYY\nis the amount of memory your system has, or\nsomething close to it. E.g., try\n'java -Xmx512m -jar Jskad.jar'.",
|
"The converter ran out of memory. Please give the\nJVM more memory by using java -XmxYYYm where YYY\nis the amount of memory your system has, or\nsomething close to it. E.g., try\n'java -Xmx512m -jar Jskad.jar'.",
|
||||||
|
|
|
@ -48,15 +48,23 @@ public class ConverterGUI implements FontConversion, FontConverterConstants {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean doConversion(ConvertDialog cd, File oldFile, File newFile,
|
public boolean doConversion(ConvertDialog cd, File oldFile, File newFile,
|
||||||
String whichConversion, String warningLevel) {
|
String whichConversion, String warningLevel,
|
||||||
|
boolean colors) {
|
||||||
PrintStream ps;
|
PrintStream ps;
|
||||||
try {
|
try {
|
||||||
|
if (whichConversion == ACIP_TO_UNI_TEXT) {
|
||||||
|
JOptionPane.showMessageDialog(cd,
|
||||||
|
"This conversion will lose information about relative font sizes.\n{KA (KHA) GA} will be treated like {KA KHA GA}, that is.",
|
||||||
|
"Loss of information may result",
|
||||||
|
JOptionPane.WARNING_MESSAGE);
|
||||||
|
}
|
||||||
returnCode
|
returnCode
|
||||||
= TibetanConverter.reallyConvert(new FileInputStream(oldFile),
|
= TibetanConverter.reallyConvert(new FileInputStream(oldFile),
|
||||||
ps = new PrintStream(new FileOutputStream(newFile),
|
ps = new PrintStream(new FileOutputStream(newFile),
|
||||||
false),
|
false),
|
||||||
whichConversion,
|
whichConversion,
|
||||||
warningLevel);
|
warningLevel,
|
||||||
|
colors);
|
||||||
ps.close();
|
ps.close();
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
returnCode = 39;
|
returnCode = 39;
|
||||||
|
|
|
@ -35,8 +35,10 @@ interface FontConversion
|
||||||
displaying the results if you want happy users. The
|
displaying the results if you want happy users. The
|
||||||
conversion performed is specified by the interned String
|
conversion performed is specified by the interned String
|
||||||
whichConversion, which must be one of the known conversions.
|
whichConversion, which must be one of the known conversions.
|
||||||
|
If you want colors to be used in the output (which is only
|
||||||
|
supported by a few conversions), then colors must be true.
|
||||||
@return true on success, false otherwise */
|
@return true on success, false otherwise */
|
||||||
boolean doConversion(ConvertDialog cd, File oldFile,
|
boolean doConversion(ConvertDialog cd, File oldFile,
|
||||||
File newFile, String whichConversion,
|
File newFile, String whichConversion,
|
||||||
String warningLevel);
|
String warningLevel, boolean colors);
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,6 +99,10 @@ public class TMW_RTF_TO_THDL_WYLIETest extends TestCase {
|
||||||
|
|
||||||
private void helper(String mode, String extension, int erc) {
|
private void helper(String mode, String extension, int erc) {
|
||||||
String[] args = new String[] {
|
String[] args = new String[] {
|
||||||
|
"--colors",
|
||||||
|
"no",
|
||||||
|
"--warning-level",
|
||||||
|
"All",
|
||||||
mode,
|
mode,
|
||||||
getTestFileName("Test1")
|
getTestFileName("Test1")
|
||||||
};
|
};
|
||||||
|
|
|
@ -78,40 +78,51 @@ public class TibetanConverter implements FontConverterConstants {
|
||||||
boolean findAllNonTMWMode = false;
|
boolean findAllNonTMWMode = false;
|
||||||
boolean findSomeNonTMMode = false;
|
boolean findSomeNonTMMode = false;
|
||||||
boolean findAllNonTMMode = false;
|
boolean findAllNonTMMode = false;
|
||||||
|
|
||||||
|
boolean colors = false;
|
||||||
|
|
||||||
// Process arguments:
|
// Process arguments:
|
||||||
if ((args.length != 1 && args.length != 2)
|
final int numArgs = 6;
|
||||||
|
if ((args.length != 1 && args.length != numArgs)
|
||||||
|| (args.length == 1
|
|| (args.length == 1
|
||||||
&& !(args[0].equals("-v")
|
&& !(args[0].equals("-v")
|
||||||
|| args[0].equals("--version")))
|
|| args[0].equals("--version")))
|
||||||
|| (args.length == 2
|
|| (args.length == numArgs
|
||||||
&& !((findAllNonTMWMode
|
&& (!(args[numArgs - 6].equals("--colors"))
|
||||||
= args[0].equals("--find-all-non-tmw"))
|
|| !((colors = args[numArgs - 5].equals("yes"))
|
||||||
|| (convertToTMMode
|
|| args[numArgs - 5].equals("no"))
|
||||||
= args[0].equals("--to-tibetan-machine"))
|
|| !(args[numArgs - 4].equals("--warning-level"))
|
||||||
|| (convertToTMWMode
|
|| !(args[numArgs - 3].equals("Most")
|
||||||
= args[0].equals("--to-tibetan-machine-web"))
|
|| args[numArgs - 3].equals("Some")
|
||||||
|| (convertACIPToUniMode
|
|| args[numArgs - 3].equals("All")
|
||||||
= args[0].equals("--acip-to-unicode"))
|
|| args[numArgs - 3].equals("None"))
|
||||||
|| (convertACIPToTMWMode
|
|| !((findAllNonTMWMode
|
||||||
= args[0].equals("--acip-to-tmw"))
|
= args[numArgs - 2].equals("--find-all-non-tmw"))
|
||||||
|| (convertToUnicodeMode
|
|| (convertToTMMode
|
||||||
= args[0].equals("--to-unicode"))
|
= args[numArgs - 2].equals("--to-tibetan-machine"))
|
||||||
|| (convertToWylieRTFMode
|
|| (convertToTMWMode
|
||||||
= args[0].equals("--to-wylie"))
|
= args[numArgs - 2].equals("--to-tibetan-machine-web"))
|
||||||
|| (convertToWylieTextMode
|
|| (convertACIPToUniMode
|
||||||
= args[0].equals("--to-wylie-text"))
|
= args[numArgs - 2].equals("--acip-to-unicode"))
|
||||||
|| (convertToACIPRTFMode
|
|| (convertACIPToTMWMode
|
||||||
= args[0].equals("--to-acip"))
|
= args[numArgs - 2].equals("--acip-to-tmw"))
|
||||||
|| (convertToACIPTextMode
|
|| (convertToUnicodeMode
|
||||||
= args[0].equals("--to-acip-text"))
|
= args[numArgs - 2].equals("--to-unicode"))
|
||||||
|| (findSomeNonTMWMode
|
|| (convertToWylieRTFMode
|
||||||
= args[0].equals("--find-some-non-tmw"))
|
= args[numArgs - 2].equals("--to-wylie"))
|
||||||
|| (findSomeNonTMMode
|
|| (convertToWylieTextMode
|
||||||
= args[0].equals("--find-some-non-tm"))
|
= args[numArgs - 2].equals("--to-wylie-text"))
|
||||||
|| (findAllNonTMMode
|
|| (convertToACIPRTFMode
|
||||||
= args[0].equals("--find-all-non-tm"))
|
= args[numArgs - 2].equals("--to-acip"))
|
||||||
))) {
|
|| (convertToACIPTextMode
|
||||||
|
= args[numArgs - 2].equals("--to-acip-text"))
|
||||||
|
|| (findSomeNonTMWMode
|
||||||
|
= args[numArgs - 2].equals("--find-some-non-tmw"))
|
||||||
|
|| (findSomeNonTMMode
|
||||||
|
= args[numArgs - 2].equals("--find-some-non-tm"))
|
||||||
|
|| (findAllNonTMMode
|
||||||
|
= args[numArgs - 2].equals("--find-all-non-tm"))
|
||||||
|
)))) {
|
||||||
out.println("TibetanConverter --find-all-non-tmw | --find-some-non-tmw");
|
out.println("TibetanConverter --find-all-non-tmw | --find-some-non-tmw");
|
||||||
out.println(" | --to-tibetan-machine | --to-tibetan-machine-web");
|
out.println(" | --to-tibetan-machine | --to-tibetan-machine-web");
|
||||||
out.println(" | --to-unicode | --to-wylie | --to-acip");
|
out.println(" | --to-unicode | --to-wylie | --to-acip");
|
||||||
|
@ -224,8 +235,7 @@ public class TibetanConverter implements FontConverterConstants {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return reallyConvert(in, out, conversionTag,
|
return reallyConvert(in, out, conversionTag,
|
||||||
"Most" // DLC make me configurable
|
args[numArgs - 3].intern(), colors);
|
||||||
);
|
|
||||||
} catch (ThdlLazyException e) {
|
} catch (ThdlLazyException e) {
|
||||||
out.println("TibetanConverter has a BUG:");
|
out.println("TibetanConverter has a BUG:");
|
||||||
e.getRealException().printStackTrace(out);
|
e.getRealException().printStackTrace(out);
|
||||||
|
@ -243,11 +253,12 @@ public class TibetanConverter implements FontConverterConstants {
|
||||||
return code so that TibetanConverter's usage message is
|
return code so that TibetanConverter's usage message is
|
||||||
honored. */
|
honored. */
|
||||||
static int reallyConvert(InputStream in, PrintStream out, String ct,
|
static int reallyConvert(InputStream in, PrintStream out, String ct,
|
||||||
String warningLevel) {
|
String warningLevel, boolean colors) {
|
||||||
if (ACIP_TO_UNI_TEXT == ct || ACIP_TO_TMW == ct) {
|
if (ACIP_TO_UNI_TEXT == ct || ACIP_TO_TMW == ct) {
|
||||||
try {
|
try {
|
||||||
ArrayList al = ACIPTshegBarScanner.scanStream(in, null,
|
ArrayList al = ACIPTshegBarScanner.scanStream(in, null,
|
||||||
250 - 1 // DLC FIXME: make me configurable
|
ThdlOptions.getIntegerOption("thdl.most.errors.a.tibetan.acip.document.can.have",
|
||||||
|
250 - 1)
|
||||||
);
|
);
|
||||||
if (null == al)
|
if (null == al)
|
||||||
return 47;
|
return 47;
|
||||||
|
@ -259,9 +270,10 @@ public class TibetanConverter implements FontConverterConstants {
|
||||||
warningLevel))
|
warningLevel))
|
||||||
return 46;
|
return 46;
|
||||||
} else {
|
} else {
|
||||||
|
if (ct != ACIP_TO_TMW) throw new Error("badness");
|
||||||
if (!ACIPConverter.convertToTMW(al, out, null, warnings,
|
if (!ACIPConverter.convertToTMW(al, out, null, warnings,
|
||||||
embeddedWarnings,
|
embeddedWarnings,
|
||||||
warningLevel))
|
warningLevel, colors))
|
||||||
return 46;
|
return 46;
|
||||||
}
|
}
|
||||||
if (embeddedWarnings && warnings.length() > 0)
|
if (embeddedWarnings && warnings.length() > 0)
|
||||||
|
@ -295,7 +307,6 @@ public class TibetanConverter implements FontConverterConstants {
|
||||||
+ rtfErrorMessage);
|
+ rtfErrorMessage);
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
in.close();
|
in.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
|
@ -145,9 +145,14 @@ public class TibetanDocument extends DefaultStyledDocument {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean allowColors = true; // DLC FIXME: make me configurable
|
private static boolean allowColors = false;
|
||||||
|
/** Enables the use of colors. */
|
||||||
public static void enableColors() { allowColors = true; }
|
public static void enableColors() { allowColors = true; }
|
||||||
|
/** Disables the use of colors. */
|
||||||
public static void disableColors() { allowColors = false; }
|
public static void disableColors() { allowColors = false; }
|
||||||
|
/** Returns true if and only if the use of colors is currently
|
||||||
|
* enabled. */
|
||||||
|
public static boolean colorsEnabled() { return allowColors; }
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -167,6 +172,8 @@ public class TibetanDocument extends DefaultStyledDocument {
|
||||||
* automatically, according to the current Roman font size.
|
* automatically, according to the current Roman font size.
|
||||||
* @param offset the position at which you want to insert text
|
* @param offset the position at which you want to insert text
|
||||||
* @param s the string you want to insert
|
* @param s the string you want to insert
|
||||||
|
* @param color the color in which to insert, which is used if and only
|
||||||
|
* if {@link #colorsEnabled() colors are enabled}
|
||||||
* @see #setRomanAttributeSet(AttributeSet)
|
* @see #setRomanAttributeSet(AttributeSet)
|
||||||
*/
|
*/
|
||||||
public void appendRoman(int offset, String s, Color color) throws BadLocationException {
|
public void appendRoman(int offset, String s, Color color) throws BadLocationException {
|
||||||
|
@ -180,6 +187,8 @@ public class TibetanDocument extends DefaultStyledDocument {
|
||||||
* Inserts Latin text at the end of the document. The font size is
|
* Inserts Latin text at the end of the document. The font size is
|
||||||
* applied automatically, according to the current Roman font size.
|
* applied automatically, according to the current Roman font size.
|
||||||
* @param s the string you want to insert
|
* @param s the string you want to insert
|
||||||
|
* @param color the color in which to insert, which is used if and only
|
||||||
|
* if {@link #colorsEnabled() colors are enabled}
|
||||||
* @see #setRomanAttributeSet(AttributeSet)
|
* @see #setRomanAttributeSet(AttributeSet)
|
||||||
*/
|
*/
|
||||||
public void appendRoman(String s, Color color) {
|
public void appendRoman(String s, Color color) {
|
||||||
|
@ -203,8 +212,10 @@ public class TibetanDocument extends DefaultStyledDocument {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts a stretch of TibetanMachineWeb data into the document.
|
* Inserts a stretch of TibetanMachineWeb data into the document.
|
||||||
* @param glyphs the array of Tibetan data you want to insert
|
|
||||||
* @param pos the position at which you want to insert text
|
* @param pos the position at which you want to insert text
|
||||||
|
* @param glyphs the array of Tibetan data you want to insert
|
||||||
|
* @param color the color in which to insert, which is used if and only
|
||||||
|
* if {@link #colorsEnabled() colors are enabled}
|
||||||
*/
|
*/
|
||||||
public int insertDuff(int pos, DuffData[] glyphs, Color color) {
|
public int insertDuff(int pos, DuffData[] glyphs, Color color) {
|
||||||
return insertDuff(tibetanFontSize, pos, glyphs, true, color);
|
return insertDuff(tibetanFontSize, pos, glyphs, true, color);
|
||||||
|
@ -216,6 +227,9 @@ public class TibetanDocument extends DefaultStyledDocument {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Appends all DuffCodes in glyphs to the end of this document.
|
* Appends all DuffCodes in glyphs to the end of this document.
|
||||||
|
* @param glyphs the array of Tibetan data you want to insert
|
||||||
|
* @param color the color in which to insert, which is used if and only
|
||||||
|
* if {@link #colorsEnabled() colors are enabled}
|
||||||
*/
|
*/
|
||||||
public void appendDuffCodes(DuffCode[] glyphs, Color color) {
|
public void appendDuffCodes(DuffCode[] glyphs, Color color) {
|
||||||
// PERFORMANCE FIXME: this isn't so speedy, but it reuses
|
// PERFORMANCE FIXME: this isn't so speedy, but it reuses
|
||||||
|
|
|
@ -38,6 +38,14 @@ import org.thdl.tib.text.DuffCode;
|
||||||
public class ACIPConverter {
|
public class ACIPConverter {
|
||||||
// DLC NOW: (KA)'s info is lost when you convert to Unicode text instead of Unicode RTF. Give an ERROR.
|
// DLC NOW: (KA)'s info is lost when you convert to Unicode text instead of Unicode RTF. Give an ERROR.
|
||||||
|
|
||||||
|
// DLC NOW: IMPLEMENT (KA) font shrinking
|
||||||
|
|
||||||
|
// DLC NOW: BAo isn't converting.
|
||||||
|
|
||||||
|
// DLC NOW: tRAStA is not converter correctly to Unicode, and no
|
||||||
|
// warning is given when converting to TMW (Wait! isn't the "a
|
||||||
|
// stack occurs w/o a vowel" warning given?)
|
||||||
|
|
||||||
/** Command-line converter. Gives error messages on standard
|
/** Command-line converter. Gives error messages on standard
|
||||||
* output about why we can't convert the document perfectly and
|
* output about why we can't convert the document perfectly and
|
||||||
* exits with non-zero return code, or is silent otherwise and
|
* exits with non-zero return code, or is silent otherwise and
|
||||||
|
@ -51,8 +59,6 @@ public class ACIPConverter {
|
||||||
ThdlOptions.setUserPreference("thdl.rely.on.system.tm.fonts", true);
|
ThdlOptions.setUserPreference("thdl.rely.on.system.tm.fonts", true);
|
||||||
ThdlOptions.setUserPreference("thdl.debug", true);
|
ThdlOptions.setUserPreference("thdl.debug", true);
|
||||||
|
|
||||||
TibetanDocument.enableColors();
|
|
||||||
|
|
||||||
boolean verbose = true;
|
boolean verbose = true;
|
||||||
if (args.length != 1) {
|
if (args.length != 1) {
|
||||||
System.out.println("Bad args! Need just the name of the ACIP text file.");
|
System.out.println("Bad args! Need just the name of the ACIP text file.");
|
||||||
|
@ -74,7 +80,6 @@ public class ACIPConverter {
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
final boolean abortUponScanningError = false;
|
final boolean abortUponScanningError = false;
|
||||||
// DLC NOW: BAo isn't converting.
|
|
||||||
if (errors.length() > 0) {
|
if (errors.length() > 0) {
|
||||||
System.err.println("Errors scanning ACIP input file: ");
|
System.err.println("Errors scanning ACIP input file: ");
|
||||||
System.err.println(errors);
|
System.err.println(errors);
|
||||||
|
@ -84,7 +89,8 @@ public class ACIPConverter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String warningLevel = "Most"; // DLC make me configurable.
|
String warningLevel = "Most";
|
||||||
|
boolean colors = true;
|
||||||
StringBuffer warnings = null;
|
StringBuffer warnings = null;
|
||||||
boolean putWarningsInOutput = false;
|
boolean putWarningsInOutput = false;
|
||||||
if ("None" != warningLevel) {
|
if ("None" != warningLevel) {
|
||||||
|
@ -92,7 +98,7 @@ public class ACIPConverter {
|
||||||
putWarningsInOutput = true;
|
putWarningsInOutput = true;
|
||||||
}
|
}
|
||||||
convertToTMW(al, System.out, errors, warnings,
|
convertToTMW(al, System.out, errors, warnings,
|
||||||
putWarningsInOutput, warningLevel);
|
putWarningsInOutput, warningLevel, colors);
|
||||||
int retCode = 0;
|
int retCode = 0;
|
||||||
if (errors.length() > 0) {
|
if (errors.length() > 0) {
|
||||||
System.err.println("Errors converting ACIP input file: ");
|
System.err.println("Errors converting ACIP input file: ");
|
||||||
|
@ -112,8 +118,6 @@ public class ACIPConverter {
|
||||||
if (verbose) System.err.println("Converted " + args[0] + " perfectly.");
|
if (verbose) System.err.println("Converted " + args[0] + " perfectly.");
|
||||||
}
|
}
|
||||||
System.exit(retCode);
|
System.exit(retCode);
|
||||||
// DLC NOW: tRAStA is not converter correctly to Unicode, and
|
|
||||||
// no warning is given when converting to TMW.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Writes TMW/Latin to out. If errors occur in converting a
|
/** Writes TMW/Latin to out. If errors occur in converting a
|
||||||
|
@ -124,6 +128,9 @@ public class ACIPConverter {
|
||||||
* warnings if warnings is non-null. Returns true upon perfect
|
* warnings if warnings is non-null. Returns true upon perfect
|
||||||
* success or if there were merely warnings, false if errors
|
* success or if there were merely warnings, false if errors
|
||||||
* occurred.
|
* occurred.
|
||||||
|
* @param colors true if and only if you want Sanskrit in one
|
||||||
|
* color, errors/warnings in another, and tsheg-bars affected by
|
||||||
|
* prefix rules in another
|
||||||
* @throws IOException if we cannot write to out
|
* @throws IOException if we cannot write to out
|
||||||
*/
|
*/
|
||||||
public static boolean convertToTMW(ArrayList scan,
|
public static boolean convertToTMW(ArrayList scan,
|
||||||
|
@ -131,7 +138,8 @@ public class ACIPConverter {
|
||||||
StringBuffer errors,
|
StringBuffer errors,
|
||||||
StringBuffer warnings,
|
StringBuffer warnings,
|
||||||
boolean writeWarningsToResult,
|
boolean writeWarningsToResult,
|
||||||
String warningLevel)
|
String warningLevel,
|
||||||
|
boolean colors)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
TibetanDocument tdoc = new TibetanDocument();
|
TibetanDocument tdoc = new TibetanDocument();
|
||||||
|
@ -141,7 +149,7 @@ public class ACIPConverter {
|
||||||
20));
|
20));
|
||||||
boolean rv
|
boolean rv
|
||||||
= convertToTMW(scan, tdoc, errors, warnings,
|
= convertToTMW(scan, tdoc, errors, warnings,
|
||||||
writeWarningsToResult, warningLevel);
|
writeWarningsToResult, warningLevel, colors);
|
||||||
tdoc.writeRTFOutputStream(out);
|
tdoc.writeRTFOutputStream(out);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
@ -151,17 +159,14 @@ public class ACIPConverter {
|
||||||
StringBuffer errors,
|
StringBuffer errors,
|
||||||
StringBuffer warnings,
|
StringBuffer warnings,
|
||||||
boolean writeWarningsToResult,
|
boolean writeWarningsToResult,
|
||||||
String warningLevel)
|
String warningLevel,
|
||||||
|
boolean colors)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
return convertTo(false, scan, null, tdoc, errors, warnings,
|
return convertTo(false, scan, null, tdoc, errors, warnings,
|
||||||
writeWarningsToResult, warningLevel);
|
writeWarningsToResult, warningLevel, colors);
|
||||||
}
|
}
|
||||||
|
|
||||||
// DLC FIXME: sometimes { } is \u0F0B, and sometimes it is a
|
|
||||||
// space. Treat it as a tsheg only when it appears after a
|
|
||||||
// syllable or another tsheg.
|
|
||||||
|
|
||||||
/** Returns UTF-8 encoded Unicode. A bit indirect, so use this
|
/** Returns UTF-8 encoded Unicode. A bit indirect, so use this
|
||||||
* for testing only if performance is a concern. If errors occur
|
* for testing only if performance is a concern. If errors occur
|
||||||
* in scanning the ACIP or in converting a tsheg bar, then they
|
* in scanning the ACIP or in converting a tsheg bar, then they
|
||||||
|
@ -194,16 +199,20 @@ public class ACIPConverter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Writes Unicode to out. If errors occur in converting a tsheg
|
/** Writes Unicode text (not RTF) to out. <em>NOTE WELL: This
|
||||||
* bar, then they are appended to errors if errors is non-null.
|
* inherently cannot describe the ACIP {(KA) KHA} properly, as
|
||||||
* Furthermore, errors are written to out. If writeWarningsToOut
|
* that requires showing KA in a smaller font than KHA, which is
|
||||||
* is true, then warnings also will be written to out.
|
* not possible in plain text.</em> If errors occur in converting
|
||||||
|
* a tsheg bar, then they are appended to errors if errors is
|
||||||
|
* non-null. Furthermore, errors are written to out. If
|
||||||
|
* writeWarningsToOut is true, then warnings also will be written
|
||||||
|
* to out.
|
||||||
* @return true upon perfect success, false if errors occurred.
|
* @return true upon perfect success, false if errors occurred.
|
||||||
* @param scan result of ACIPTshegBarScanner.scan(..)
|
* @param scan result of ACIPTshegBarScanner.scan(..)
|
||||||
* @param out stream to which to write converted text
|
* @param out stream to which to write converted text
|
||||||
* @param errors if non-null, all error messages are appended
|
* @param errors if non-null, all error messages are appended
|
||||||
* @param warnings if non-null, all warning messages are appended
|
* @param warnings if non-null, all warning messages appropriate
|
||||||
* to this
|
* to warningLevel are appended
|
||||||
* @param writeWarningsToOut if true, then all warning messages
|
* @param writeWarningsToOut if true, then all warning messages
|
||||||
* are written to out in the appropriate places
|
* are written to out in the appropriate places
|
||||||
* @throws IOException if we cannot write to out
|
* @throws IOException if we cannot write to out
|
||||||
|
@ -217,7 +226,7 @@ public class ACIPConverter {
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
return convertTo(true, scan, out, null, errors, warnings,
|
return convertTo(true, scan, out, null, errors, warnings,
|
||||||
writeWarningsToOut, warningLevel);
|
writeWarningsToOut, warningLevel, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean peekaheadFindsSpacesAndComma(ArrayList /* of ACIPString */ scan,
|
private static boolean peekaheadFindsSpacesAndComma(ArrayList /* of ACIPString */ scan,
|
||||||
|
@ -245,9 +254,14 @@ public class ACIPConverter {
|
||||||
StringBuffer errors,
|
StringBuffer errors,
|
||||||
StringBuffer warnings,
|
StringBuffer warnings,
|
||||||
boolean writeWarningsToOut,
|
boolean writeWarningsToOut,
|
||||||
String warningLevel)
|
String warningLevel,
|
||||||
|
boolean colors)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
|
if (colors)
|
||||||
|
tdoc.enableColors();
|
||||||
|
else
|
||||||
|
tdoc.disableColors();
|
||||||
int sz = scan.size();
|
int sz = scan.size();
|
||||||
boolean hasErrors = false;
|
boolean hasErrors = false;
|
||||||
BufferedWriter writer = null;
|
BufferedWriter writer = null;
|
||||||
|
@ -276,7 +290,6 @@ public class ACIPConverter {
|
||||||
if (null != writer) writer.write(text);
|
if (null != writer) writer.write(text);
|
||||||
if (null != tdoc) tdoc.appendRoman(text, Color.RED);
|
if (null != tdoc) tdoc.appendRoman(text, Color.RED);
|
||||||
}
|
}
|
||||||
// DLC NOW: Warning: We're going with {'}{R}{DA}, but only because our knowledge of prefix rules says that {'}{R+DA} is not a legal Tibetan tsheg bar ("syllable")
|
|
||||||
|
|
||||||
if (null != warnings) {
|
if (null != warnings) {
|
||||||
warnings.append("Warning: Lexical warning: ");
|
warnings.append("Warning: Lexical warning: ");
|
||||||
|
@ -357,6 +370,8 @@ public class ACIPConverter {
|
||||||
color = Color.BLACK;
|
color = Color.BLACK;
|
||||||
} else {
|
} else {
|
||||||
// Sanskrit
|
// Sanskrit
|
||||||
|
|
||||||
|
// DLC FIXME: a funny vowel, the presence of a sanskrit-only stack, and a funny mark like ACIP ':' should cause green too.
|
||||||
color = Color.GREEN;
|
color = Color.GREEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,7 +468,6 @@ public class ACIPConverter {
|
||||||
if (null != tdoc) {
|
if (null != tdoc) {
|
||||||
if (null != duff && 0 != duff.length) {
|
if (null != duff && 0 != duff.length) {
|
||||||
tdoc.appendDuffCodes(duff, color);
|
tdoc.appendDuffCodes(duff, color);
|
||||||
// DLC NOW FIXME: use TibTextUtils.getVowel logic to make the output beautiful.
|
|
||||||
} else {
|
} else {
|
||||||
// this happens when you have an
|
// this happens when you have an
|
||||||
// [#ERROR]-producing tsheg bar.
|
// [#ERROR]-producing tsheg bar.
|
||||||
|
@ -471,6 +485,3 @@ public class ACIPConverter {
|
||||||
return !hasErrors;
|
return !hasErrors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// DLC FIXME: putting Tibetan in black, Sanskrit in green, and Latin
|
|
||||||
// in yellow would help you quickly decide if ZHIGN maybe should've
|
|
||||||
// been ZHING.
|
|
||||||
|
|
|
@ -276,6 +276,7 @@ class TParseTree {
|
||||||
|
|
||||||
TStackListList up = getUniqueParse(false);
|
TStackListList up = getUniqueParse(false);
|
||||||
if (null == up || up.size() != 1) {
|
if (null == up || up.size() != 1) {
|
||||||
|
// DLC FIXME: code duplication
|
||||||
boolean isLastStack[] = new boolean[1];
|
boolean isLastStack[] = new boolean[1];
|
||||||
TStackListList nip = getNonIllegalParses();
|
TStackListList nip = getNonIllegalParses();
|
||||||
if (nip.size() != 1) {
|
if (nip.size() != 1) {
|
||||||
|
@ -285,9 +286,9 @@ class TParseTree {
|
||||||
if (getBestParse().hasStackWithoutVowel(pl, isLastStack)) {
|
if (getBestParse().hasStackWithoutVowel(pl, isLastStack)) {
|
||||||
if (isLastStack[0]) {
|
if (isLastStack[0]) {
|
||||||
if (warningLevel == "All" || warningLevel == "Most")
|
if (warningLevel == "All" || warningLevel == "Most")
|
||||||
return "Warning: The last stack does not have a vowel in the ACIP {" + ((null != originalACIP) ? originalACIP : recoverACIP()) + "}";
|
return "Warning: The last stack does not have a vowel in the ACIP {" + ((null != originalACIP) ? originalACIP : recoverACIP()) + "}; this may indicate a typo, because Sanskrit, which this is (because it's not legal Tibetan), should have a vowel after each stack.";
|
||||||
} else {
|
} else {
|
||||||
return "Warning: There is a stack, before the last stack, without a vowel in the ACIP {" + ((null != originalACIP) ? originalACIP : recoverACIP()) + "}";
|
return "Warning: There is a stack, before the last stack, without a vowel in the ACIP {" + ((null != originalACIP) ? originalACIP : recoverACIP()) + "}; this may indicate a typo, because Sanskrit, which this is (because it's not legal Tibetan), should have a vowel after each stack.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ("All" == warningLevel) {
|
if ("All" == warningLevel) {
|
||||||
|
@ -298,9 +299,9 @@ class TParseTree {
|
||||||
if (nip.get(0).hasStackWithoutVowel(pl, isLastStack)) {
|
if (nip.get(0).hasStackWithoutVowel(pl, isLastStack)) {
|
||||||
if (isLastStack[0]) {
|
if (isLastStack[0]) {
|
||||||
if (warningLevel == "All" || warningLevel == "Most")
|
if (warningLevel == "All" || warningLevel == "Most")
|
||||||
return "Warning: The last stack does not have a vowel in the ACIP {" + ((null != originalACIP) ? originalACIP : recoverACIP()) + "}";
|
return "Warning: The last stack does not have a vowel in the ACIP {" + ((null != originalACIP) ? originalACIP : recoverACIP()) + "}; this may indicate a typo, because Sanskrit, which this is (because it's not legal Tibetan), should have a vowel after each stack.";
|
||||||
} else {
|
} else {
|
||||||
return "Warning: There is a stack, before the last stack, without a vowel in the ACIP {" + ((null != originalACIP) ? originalACIP : recoverACIP()) + "}";
|
return "Warning: There is a stack, before the last stack, without a vowel in the ACIP {" + ((null != originalACIP) ? originalACIP : recoverACIP()) + "}; this may indicate a typo, because Sanskrit, which this is (because it's not legal Tibetan), should have a vowel after each stack.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue