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:
dchandler 2003-09-06 22:56:10 +00:00
parent 1308f14807
commit 0d6d6ed611
8 changed files with 141 additions and 74 deletions

View file

@ -37,6 +37,9 @@ class ConvertDialog extends JDialog
{
private static final boolean debug = false;
private JCheckBox colors;
private static final String colorDesc = "Color-coding (ACIP to RTF only)";
// Attributes
private FontConversion controller;
@ -95,6 +98,11 @@ class ConvertDialog extends JDialog
updateWarningLevels();
temp.add(warningLevels);
this.colors = new JCheckBox(colorDesc, false);
this.colors.addActionListener(tal);
updateWarningLevels();
temp.add(colors);
content.add(temp);
temp = new JPanel(new FlowLayout(FlowLayout.CENTER,5,5));
@ -151,7 +159,7 @@ class ConvertDialog extends JDialog
content.add(buttonBox);
setContentPane(content);
pack();
setSize(new Dimension(620,200));
setSize(new Dimension(640,235));
}
private void setChoices(String[] choices)
@ -226,6 +234,13 @@ class ConvertDialog extends JDialog
JOptionPane.ERROR_MESSAGE);
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());
if(null == convertedFile) {
JOptionPane.showMessageDialog(this,
@ -274,7 +289,8 @@ class ConvertDialog extends JDialog
origFile,
convertedFile,
(String)choices.getSelectedItem(),
(String)warningLevels.getSelectedItem());
(String)warningLevels.getSelectedItem(),
colors.isSelected());
} catch (OutOfMemoryError e) {
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'.",

View file

@ -48,15 +48,23 @@ public class ConverterGUI implements FontConversion, FontConverterConstants {
}
public boolean doConversion(ConvertDialog cd, File oldFile, File newFile,
String whichConversion, String warningLevel) {
String whichConversion, String warningLevel,
boolean colors) {
PrintStream ps;
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
= TibetanConverter.reallyConvert(new FileInputStream(oldFile),
ps = new PrintStream(new FileOutputStream(newFile),
false),
whichConversion,
warningLevel);
warningLevel,
colors);
ps.close();
} catch (FileNotFoundException e) {
returnCode = 39;

View file

@ -35,8 +35,10 @@ interface FontConversion
displaying the results if you want happy users. The
conversion performed is specified by the interned String
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 */
boolean doConversion(ConvertDialog cd, File oldFile,
File newFile, String whichConversion,
String warningLevel);
String warningLevel, boolean colors);
}

View file

@ -99,6 +99,10 @@ public class TMW_RTF_TO_THDL_WYLIETest extends TestCase {
private void helper(String mode, String extension, int erc) {
String[] args = new String[] {
"--colors",
"no",
"--warning-level",
"All",
mode,
getTestFileName("Test1")
};

View file

@ -78,40 +78,51 @@ public class TibetanConverter implements FontConverterConstants {
boolean findAllNonTMWMode = false;
boolean findSomeNonTMMode = false;
boolean findAllNonTMMode = false;
boolean colors = false;
// Process arguments:
if ((args.length != 1 && args.length != 2)
final int numArgs = 6;
if ((args.length != 1 && args.length != numArgs)
|| (args.length == 1
&& !(args[0].equals("-v")
|| args[0].equals("--version")))
|| (args.length == 2
&& !((findAllNonTMWMode
= args[0].equals("--find-all-non-tmw"))
|| (convertToTMMode
= args[0].equals("--to-tibetan-machine"))
|| (convertToTMWMode
= args[0].equals("--to-tibetan-machine-web"))
|| (convertACIPToUniMode
= args[0].equals("--acip-to-unicode"))
|| (convertACIPToTMWMode
= args[0].equals("--acip-to-tmw"))
|| (convertToUnicodeMode
= args[0].equals("--to-unicode"))
|| (convertToWylieRTFMode
= args[0].equals("--to-wylie"))
|| (convertToWylieTextMode
= args[0].equals("--to-wylie-text"))
|| (convertToACIPRTFMode
= args[0].equals("--to-acip"))
|| (convertToACIPTextMode
= args[0].equals("--to-acip-text"))
|| (findSomeNonTMWMode
= args[0].equals("--find-some-non-tmw"))
|| (findSomeNonTMMode
= args[0].equals("--find-some-non-tm"))
|| (findAllNonTMMode
= args[0].equals("--find-all-non-tm"))
))) {
|| (args.length == numArgs
&& (!(args[numArgs - 6].equals("--colors"))
|| !((colors = args[numArgs - 5].equals("yes"))
|| args[numArgs - 5].equals("no"))
|| !(args[numArgs - 4].equals("--warning-level"))
|| !(args[numArgs - 3].equals("Most")
|| args[numArgs - 3].equals("Some")
|| args[numArgs - 3].equals("All")
|| args[numArgs - 3].equals("None"))
|| !((findAllNonTMWMode
= args[numArgs - 2].equals("--find-all-non-tmw"))
|| (convertToTMMode
= args[numArgs - 2].equals("--to-tibetan-machine"))
|| (convertToTMWMode
= args[numArgs - 2].equals("--to-tibetan-machine-web"))
|| (convertACIPToUniMode
= args[numArgs - 2].equals("--acip-to-unicode"))
|| (convertACIPToTMWMode
= args[numArgs - 2].equals("--acip-to-tmw"))
|| (convertToUnicodeMode
= args[numArgs - 2].equals("--to-unicode"))
|| (convertToWylieRTFMode
= args[numArgs - 2].equals("--to-wylie"))
|| (convertToWylieTextMode
= args[numArgs - 2].equals("--to-wylie-text"))
|| (convertToACIPRTFMode
= 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(" | --to-tibetan-machine | --to-tibetan-machine-web");
out.println(" | --to-unicode | --to-wylie | --to-acip");
@ -224,8 +235,7 @@ public class TibetanConverter implements FontConverterConstants {
}
}
return reallyConvert(in, out, conversionTag,
"Most" // DLC make me configurable
);
args[numArgs - 3].intern(), colors);
} catch (ThdlLazyException e) {
out.println("TibetanConverter has a BUG:");
e.getRealException().printStackTrace(out);
@ -243,11 +253,12 @@ public class TibetanConverter implements FontConverterConstants {
return code so that TibetanConverter's usage message is
honored. */
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) {
try {
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)
return 47;
@ -259,9 +270,10 @@ public class TibetanConverter implements FontConverterConstants {
warningLevel))
return 46;
} else {
if (ct != ACIP_TO_TMW) throw new Error("badness");
if (!ACIPConverter.convertToTMW(al, out, null, warnings,
embeddedWarnings,
warningLevel))
warningLevel, colors))
return 46;
}
if (embeddedWarnings && warnings.length() > 0)
@ -295,7 +307,6 @@ public class TibetanConverter implements FontConverterConstants {
+ rtfErrorMessage);
return 3;
}
try {
in.close();
} catch (IOException e) {