From the converter GUI, you can now choose TMW->ACIP text and

TMW->Wylie text.  All the conversions show you which format they take
as input and which format they give as output.

File filter for ACIP files added.

The GUI converter suggests a file extension wisely.

Fixed newline bug in ACIP->Unicode converter.
This commit is contained in:
dchandler 2003-09-05 02:05:34 +00:00
parent 4abbf6db37
commit 5c240ac072
5 changed files with 98 additions and 43 deletions

View file

@ -69,7 +69,7 @@ class ConvertDialog extends JDialog
ConvertDialog.this.theRealActionPerformed(e); ConvertDialog.this.theRealActionPerformed(e);
}}; }};
private void updateWarningLevels() { private void updateWarningLevels() {
if (choices.getSelectedItem() == ACIP_TO_UNI if (choices.getSelectedItem() == ACIP_TO_UNI_TEXT
|| choices.getSelectedItem() == ACIP_TO_TMW) || choices.getSelectedItem() == ACIP_TO_TMW)
this.warningLevels.enable(); this.warningLevels.enable();
else else
@ -79,7 +79,8 @@ class ConvertDialog extends JDialog
{ {
jfc = new JFileChooser(controller.getDefaultDirectory()); jfc = new JFileChooser(controller.getDefaultDirectory());
jfc.setDialogTitle(LOCATE_FILE); jfc.setDialogTitle(LOCATE_FILE);
jfc.setFileFilter(new RTFFileFilter()); jfc.addChoosableFileFilter(new ACIPFileFilter());
jfc.addChoosableFileFilter(new RTFFileFilter());
content = new JPanel(new GridLayout(0,1)); content = new JPanel(new GridLayout(0,1));
JPanel temp = new JPanel(new FlowLayout(FlowLayout.CENTER,5,5)); JPanel temp = new JPanel(new FlowLayout(FlowLayout.CENTER,5,5));
@ -406,28 +407,50 @@ class ConvertDialog extends JDialog
} }
String ct = (String)choices.getSelectedItem(); String ct = (String)choices.getSelectedItem();
if ("Find all non-TMW" == ct) { String newFileNameExtension = null;
newFileNamePrefix = "FindAllNonTMW__"; if (FIND_ALL_NON_TMW == ct) {
newFileNamePrefix = "AllNonTMW__";
newFileNameExtension = ".TXT";
} else if (FIND_SOME_NON_TMW == ct) { } else if (FIND_SOME_NON_TMW == ct) {
newFileNamePrefix = "FindSomeNonTMW__"; newFileNamePrefix = "SomeNonTMW__";
newFileNameExtension = ".TXT";
} else if (FIND_SOME_NON_TM == ct) { } else if (FIND_SOME_NON_TM == ct) {
newFileNamePrefix = "FindSomeNonTM__"; newFileNamePrefix = "SomeNonTM__";
newFileNameExtension = ".TXT";
} else if (FIND_ALL_NON_TM == ct) { } else if (FIND_ALL_NON_TM == ct) {
newFileNamePrefix = "FindAllNonTM__"; newFileNamePrefix = "AllNonTM__";
newFileNameExtension = ".TXT";
} else { // conversion {to Wylie or TM} mode } else { // conversion {to Wylie or TM} mode
if (TMW_TO_WYLIE == ct) { if (TMW_TO_WYLIE == ct) {
newFileNamePrefix = suggested_WYLIE_prefix; newFileNamePrefix = suggested_WYLIE_prefix;
} else if (TMW_TO_WYLIE_TEXT == ct) {
newFileNamePrefix = suggested_WYLIE_prefix;
newFileNameExtension = ".TXT";
} else if (TMW_TO_ACIP == ct) { } else if (TMW_TO_ACIP == ct) {
newFileNamePrefix = suggested_ACIP_prefix; newFileNamePrefix = suggested_ACIP_prefix;
} else if (TMW_TO_UNI == ct || ACIP_TO_UNI == ct) { } else if (TMW_TO_ACIP_TEXT == ct) {
newFileNamePrefix = suggested_ACIP_prefix;
newFileNameExtension = ".TXT";
} else if (TMW_TO_UNI == ct || ACIP_TO_UNI_TEXT == ct) {
newFileNamePrefix = suggested_TO_UNI_prefix; newFileNamePrefix = suggested_TO_UNI_prefix;
if (ACIP_TO_UNI_TEXT == ct)
newFileNameExtension = ".TXT";
} else if (TM_TO_TMW == ct || ACIP_TO_TMW == ct) { } else if (TM_TO_TMW == ct || ACIP_TO_TMW == ct) {
newFileNamePrefix = suggested_TO_TMW_prefix; newFileNamePrefix = suggested_TO_TMW_prefix;
if (ACIP_TO_TMW == ct)
newFileNameExtension = ".RTF";
} else { } else {
ThdlDebug.verify(TMW_TO_TM == ct); ThdlDebug.verify(TMW_TO_TM == ct);
newFileNamePrefix = suggested_TO_TM_prefix; newFileNamePrefix = suggested_TO_TM_prefix;
} }
} }
if (null != newFileNameExtension) {
int li = oldFileNameSansThingy.lastIndexOf('.');
if (li >= 0)
oldFileNameSansThingy
= (oldFileNameSansThingy.substring(0, li)
+ newFileNameExtension);
}
newTextField.setText(oldFileDirName newTextField.setText(oldFileDirName
+ newFileNamePrefix + newFileNamePrefix
+ oldFileNameSansThingy); + oldFileNameSansThingy);
@ -437,8 +460,7 @@ class ConvertDialog extends JDialog
{ {
public boolean accept(File f) public boolean accept(File f)
{ {
if(f.isDirectory() || f.getName().indexOf(".rtf")>-1) { return true; } return (f.isDirectory() || f.getName().endsWith(".rtf"));
return false;
} }
public String getDescription() public String getDescription()
@ -446,5 +468,30 @@ class ConvertDialog extends JDialog
return "RTF files only"; return "RTF files only";
} }
} }
public class ACIPFileFilter extends javax.swing.filechooser.FileFilter
{
public boolean accept(File f)
{
return (f.isDirectory()
|| f.getName().toUpperCase().endsWith(".ACIP")
|| f.getName().toUpperCase().endsWith(".TXT")
|| f.getName().toUpperCase().endsWith(".ACE")
|| f.getName().toUpperCase().endsWith(".ACM")
|| f.getName().toUpperCase().endsWith(".ACT")
|| f.getName().toUpperCase().endsWith(".AET")
|| f.getName().toUpperCase().endsWith(".ALT")
|| f.getName().toUpperCase().endsWith(".AT1")
|| f.getName().toUpperCase().endsWith(".INC")
|| f.getName().toUpperCase().endsWith(".INE")
|| f.getName().toUpperCase().endsWith(".INL")
|| f.getName().toUpperCase().endsWith(".INM"));
}
public String getDescription()
{
return "ACIP text files only";
}
}
} }

View file

@ -56,7 +56,6 @@ public class ConverterGUI implements FontConversion, FontConverterConstants {
ps = new PrintStream(new FileOutputStream(newFile), ps = new PrintStream(new FileOutputStream(newFile),
false), false),
whichConversion, whichConversion,
false, // DLC FIXME add a checkbox
warningLevel); warningLevel);
ps.close(); ps.close();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {

View file

@ -26,26 +26,30 @@ import java.awt.*;
@author Nathaniel Garson, Tibetan and Himalayan Digital Library */ @author Nathaniel Garson, Tibetan and Himalayan Digital Library */
interface FontConverterConstants interface FontConverterConstants
{ {
final String ACIP_TO_UNI = "ACIP to Unicode"; final String ACIP_TO_UNI_TEXT = "ACIP to Unicode (Text->Text)";
final String ACIP_TO_TMW = "ACIP to TMW"; final String ACIP_TO_TMW = "ACIP to TMW (Text->RTF)";
final String TM_TO_TMW = "TM to TMW"; final String TMW_TO_ACIP = "TMW to ACIP (RTF->RTF)";
final String TMW_TO_UNI = "TMW to Unicode"; final String TMW_TO_ACIP_TEXT = "TMW to ACIP (RTF->Text)";
final String TMW_TO_WYLIE = "TMW to Wylie"; final String TM_TO_TMW = "TM to TMW (RTF->RTF)";
final String TMW_TO_ACIP = "TMW to ACIP"; final String TMW_TO_TM = "TMW to TM (RTF->RTF)";
final String TMW_TO_TM = "TMW to TM"; final String TMW_TO_UNI = "TMW to Unicode (RTF->RTF)";
final String FIND_SOME_NON_TMW = "Find some non-TMW"; final String TMW_TO_WYLIE = "TMW to Wylie (RTF->RTF)";
final String FIND_SOME_NON_TM = "Find some non-TM"; final String TMW_TO_WYLIE_TEXT = "TMW to Wylie (RTF->Text)";
final String FIND_ALL_NON_TMW = "Find all non-TMW"; final String FIND_SOME_NON_TMW = "Find some non-TMW (in RTF)";
final String FIND_ALL_NON_TM = "Find all non-TM"; final String FIND_SOME_NON_TM = "Find some non-TM (in RTF)";
final String FIND_ALL_NON_TMW = "Find all non-TMW (in RTF)";
final String FIND_ALL_NON_TM = "Find all non-TM (in RTF)";
final String[] CHOICES = new String[] { final String[] CHOICES = new String[] {
ACIP_TO_UNI, ACIP_TO_UNI_TEXT,
ACIP_TO_TMW, ACIP_TO_TMW,
TMW_TO_ACIP,
TMW_TO_ACIP_TEXT,
TM_TO_TMW, TM_TO_TMW,
TMW_TO_TM,
TMW_TO_UNI, TMW_TO_UNI,
TMW_TO_WYLIE, TMW_TO_WYLIE,
TMW_TO_ACIP, TMW_TO_WYLIE_TEXT,
TMW_TO_TM,
FIND_SOME_NON_TMW, FIND_SOME_NON_TMW,
FIND_SOME_NON_TM, FIND_SOME_NON_TM,
FIND_ALL_NON_TMW, FIND_ALL_NON_TMW,

View file

@ -70,15 +70,15 @@ public class TibetanConverter implements FontConverterConstants {
boolean convertACIPToUniMode = false; boolean convertACIPToUniMode = false;
boolean convertACIPToTMWMode = false; boolean convertACIPToTMWMode = false;
boolean convertToTMWMode = false; boolean convertToTMWMode = false;
boolean convertToWylieMode = false; boolean convertToWylieRTFMode = false;
boolean convertToACIPMode = false; boolean convertToWylieTextMode = false;
boolean convertToACIPRTFMode = false;
boolean convertToACIPTextMode = false;
boolean findSomeNonTMWMode = false; boolean findSomeNonTMWMode = false;
boolean findAllNonTMWMode = false; boolean findAllNonTMWMode = false;
boolean findSomeNonTMMode = false; boolean findSomeNonTMMode = false;
boolean findAllNonTMMode = false; boolean findAllNonTMMode = false;
boolean textOutput = false;
// Process arguments: // Process arguments:
if ((args.length != 1 && args.length != 2) if ((args.length != 1 && args.length != 2)
|| (args.length == 1 || (args.length == 1
@ -97,15 +97,13 @@ public class TibetanConverter implements FontConverterConstants {
= args[0].equals("--acip-to-tmw")) = args[0].equals("--acip-to-tmw"))
|| (convertToUnicodeMode || (convertToUnicodeMode
= args[0].equals("--to-unicode")) = args[0].equals("--to-unicode"))
|| (convertToWylieMode || (convertToWylieRTFMode
= args[0].equals("--to-wylie")) = args[0].equals("--to-wylie"))
|| (convertToWylieMode || (convertToWylieTextMode
= textOutput
= args[0].equals("--to-wylie-text")) = args[0].equals("--to-wylie-text"))
|| (convertToACIPMode || (convertToACIPRTFMode
= args[0].equals("--to-acip")) = args[0].equals("--to-acip"))
|| (convertToACIPMode || (convertToACIPTextMode
= textOutput
= args[0].equals("--to-acip-text")) = args[0].equals("--to-acip-text"))
|| (findSomeNonTMWMode || (findSomeNonTMWMode
= args[0].equals("--find-some-non-tmw")) = args[0].equals("--find-some-non-tmw"))
@ -204,16 +202,20 @@ public class TibetanConverter implements FontConverterConstants {
} else if (findAllNonTMMode) { } else if (findAllNonTMMode) {
conversionTag = FIND_ALL_NON_TM; conversionTag = FIND_ALL_NON_TM;
} else { // conversion {to Wylie or TM} mode } else { // conversion {to Wylie or TM} mode
if (convertToWylieMode) { if (convertToWylieRTFMode) {
conversionTag = TMW_TO_WYLIE; conversionTag = TMW_TO_WYLIE;
} else if (convertToACIPMode) { } else if (convertToWylieTextMode) {
conversionTag = TMW_TO_WYLIE_TEXT;
} else if (convertToACIPRTFMode) {
conversionTag = TMW_TO_ACIP; conversionTag = TMW_TO_ACIP;
} else if (convertToACIPTextMode) {
conversionTag = TMW_TO_ACIP_TEXT;
} else if (convertToUnicodeMode) { } else if (convertToUnicodeMode) {
conversionTag = TMW_TO_UNI; conversionTag = TMW_TO_UNI;
} else if (convertToTMWMode) { } else if (convertToTMWMode) {
conversionTag = TM_TO_TMW; conversionTag = TM_TO_TMW;
} else if (convertACIPToUniMode) { } else if (convertACIPToUniMode) {
conversionTag = ACIP_TO_UNI; conversionTag = ACIP_TO_UNI_TEXT;
} else if (convertACIPToTMWMode) { } else if (convertACIPToTMWMode) {
conversionTag = ACIP_TO_TMW; conversionTag = ACIP_TO_TMW;
} else { } else {
@ -221,7 +223,7 @@ public class TibetanConverter implements FontConverterConstants {
conversionTag = TMW_TO_TM; conversionTag = TMW_TO_TM;
} }
} }
return reallyConvert(in, out, conversionTag, textOutput, return reallyConvert(in, out, conversionTag,
"Most" // DLC make me configurable "Most" // DLC make me configurable
); );
} catch (ThdlLazyException e) { } catch (ThdlLazyException e) {
@ -241,8 +243,8 @@ 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,
boolean textOutput, String warningLevel) { String warningLevel) {
if (ACIP_TO_UNI == 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 250 - 1 // DLC FIXME: make me configurable
@ -251,7 +253,7 @@ public class TibetanConverter implements FontConverterConstants {
return 47; return 47;
StringBuffer warnings = new StringBuffer(); StringBuffer warnings = new StringBuffer();
boolean embeddedWarnings = (warningLevel != "None"); boolean embeddedWarnings = (warningLevel != "None");
if (ACIP_TO_UNI == ct) { if (ACIP_TO_UNI_TEXT == ct) {
if (!ACIPConverter.convertToUnicode(al, out, null, warnings, if (!ACIPConverter.convertToUnicode(al, out, null, warnings,
embeddedWarnings, embeddedWarnings,
warningLevel)) warningLevel))
@ -344,7 +346,9 @@ public class TibetanConverter implements FontConverterConstants {
+ ((TMW_TO_UNI == ct) ? 1 : 0) + ((TMW_TO_UNI == ct) ? 1 : 0)
+ ((TM_TO_TMW == ct) ? 1 : 0) + ((TM_TO_TMW == ct) ? 1 : 0)
+ ((TMW_TO_ACIP == ct) ? 1 : 0) + ((TMW_TO_ACIP == ct) ? 1 : 0)
+ ((TMW_TO_ACIP_TEXT == ct) ? 1 : 0)
+ ((TMW_TO_WYLIE == ct) ? 1 : 0) + ((TMW_TO_WYLIE == ct) ? 1 : 0)
+ ((TMW_TO_WYLIE_TEXT == ct) ? 1 : 0)
== 1); == 1);
long numAttemptedReplacements[] = new long[] { 0 }; long numAttemptedReplacements[] = new long[] { 0 };
if (TMW_TO_WYLIE == ct) { if (TMW_TO_WYLIE == ct) {
@ -392,7 +396,7 @@ public class TibetanConverter implements FontConverterConstants {
} }
// Write to standard output the result: // Write to standard output the result:
if (textOutput) { if (TMW_TO_WYLIE_TEXT == ct || TMW_TO_ACIP_TEXT == ct) {
try { try {
tdoc.writeTextOutput(new BufferedWriter(new OutputStreamWriter(out))); tdoc.writeTextOutput(new BufferedWriter(new OutputStreamWriter(out)));
} catch (IOException e) { } catch (IOException e) {

View file

@ -443,6 +443,7 @@ class ACIPRules {
superACIP2unicode.put(";", "\u0F11"); superACIP2unicode.put(";", "\u0F11");
superACIP2unicode.put("\r", "\r"); superACIP2unicode.put("\r", "\r");
superACIP2unicode.put("\t", "\t"); superACIP2unicode.put("\t", "\t");
superACIP2unicode.put("\r\n", "\r\n");
superACIP2unicode.put("\n", "\n"); superACIP2unicode.put("\n", "\n");
superACIP2unicode.put("\\", "\u0F84"); // DLC FIXME: make this like a vowel superACIP2unicode.put("\\", "\u0F84"); // DLC FIXME: make this like a vowel
// DLC FIXME: what's the Unicode for caret, ^? // DLC FIXME: what's the Unicode for caret, ^?