diff --git a/source/org/thdl/tib/input/ConvertDialog.java b/source/org/thdl/tib/input/ConvertDialog.java index 4bba4cd..7b2038a 100644 --- a/source/org/thdl/tib/input/ConvertDialog.java +++ b/source/org/thdl/tib/input/ConvertDialog.java @@ -69,7 +69,7 @@ class ConvertDialog extends JDialog ConvertDialog.this.theRealActionPerformed(e); }}; private void updateWarningLevels() { - if (choices.getSelectedItem() == ACIP_TO_UNI + if (choices.getSelectedItem() == ACIP_TO_UNI_TEXT || choices.getSelectedItem() == ACIP_TO_TMW) this.warningLevels.enable(); else @@ -79,7 +79,8 @@ class ConvertDialog extends JDialog { jfc = new JFileChooser(controller.getDefaultDirectory()); jfc.setDialogTitle(LOCATE_FILE); - jfc.setFileFilter(new RTFFileFilter()); + jfc.addChoosableFileFilter(new ACIPFileFilter()); + jfc.addChoosableFileFilter(new RTFFileFilter()); content = new JPanel(new GridLayout(0,1)); JPanel temp = new JPanel(new FlowLayout(FlowLayout.CENTER,5,5)); @@ -406,28 +407,50 @@ class ConvertDialog extends JDialog } String ct = (String)choices.getSelectedItem(); - if ("Find all non-TMW" == ct) { - newFileNamePrefix = "FindAllNonTMW__"; + String newFileNameExtension = null; + if (FIND_ALL_NON_TMW == ct) { + newFileNamePrefix = "AllNonTMW__"; + newFileNameExtension = ".TXT"; } else if (FIND_SOME_NON_TMW == ct) { - newFileNamePrefix = "FindSomeNonTMW__"; + newFileNamePrefix = "SomeNonTMW__"; + newFileNameExtension = ".TXT"; } else if (FIND_SOME_NON_TM == ct) { - newFileNamePrefix = "FindSomeNonTM__"; + newFileNamePrefix = "SomeNonTM__"; + newFileNameExtension = ".TXT"; } else if (FIND_ALL_NON_TM == ct) { - newFileNamePrefix = "FindAllNonTM__"; + newFileNamePrefix = "AllNonTM__"; + newFileNameExtension = ".TXT"; } else { // conversion {to Wylie or TM} mode if (TMW_TO_WYLIE == ct) { newFileNamePrefix = suggested_WYLIE_prefix; + } else if (TMW_TO_WYLIE_TEXT == ct) { + newFileNamePrefix = suggested_WYLIE_prefix; + newFileNameExtension = ".TXT"; } else if (TMW_TO_ACIP == ct) { 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; + if (ACIP_TO_UNI_TEXT == ct) + newFileNameExtension = ".TXT"; } else if (TM_TO_TMW == ct || ACIP_TO_TMW == ct) { newFileNamePrefix = suggested_TO_TMW_prefix; + if (ACIP_TO_TMW == ct) + newFileNameExtension = ".RTF"; } else { ThdlDebug.verify(TMW_TO_TM == ct); newFileNamePrefix = suggested_TO_TM_prefix; } } + if (null != newFileNameExtension) { + int li = oldFileNameSansThingy.lastIndexOf('.'); + if (li >= 0) + oldFileNameSansThingy + = (oldFileNameSansThingy.substring(0, li) + + newFileNameExtension); + } newTextField.setText(oldFileDirName + newFileNamePrefix + oldFileNameSansThingy); @@ -437,8 +460,7 @@ class ConvertDialog extends JDialog { public boolean accept(File f) { - if(f.isDirectory() || f.getName().indexOf(".rtf")>-1) { return true; } - return false; + return (f.isDirectory() || f.getName().endsWith(".rtf")); } public String getDescription() @@ -446,5 +468,30 @@ class ConvertDialog extends JDialog 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"; + } + } } diff --git a/source/org/thdl/tib/input/ConverterGUI.java b/source/org/thdl/tib/input/ConverterGUI.java index 352f346..097ad37 100644 --- a/source/org/thdl/tib/input/ConverterGUI.java +++ b/source/org/thdl/tib/input/ConverterGUI.java @@ -56,7 +56,6 @@ public class ConverterGUI implements FontConversion, FontConverterConstants { ps = new PrintStream(new FileOutputStream(newFile), false), whichConversion, - false, // DLC FIXME add a checkbox warningLevel); ps.close(); } catch (FileNotFoundException e) { diff --git a/source/org/thdl/tib/input/FontConverterConstants.java b/source/org/thdl/tib/input/FontConverterConstants.java index 3d695f7..86dc8d0 100644 --- a/source/org/thdl/tib/input/FontConverterConstants.java +++ b/source/org/thdl/tib/input/FontConverterConstants.java @@ -26,26 +26,30 @@ import java.awt.*; @author Nathaniel Garson, Tibetan and Himalayan Digital Library */ interface FontConverterConstants { - final String ACIP_TO_UNI = "ACIP to Unicode"; - final String ACIP_TO_TMW = "ACIP to TMW"; - final String TM_TO_TMW = "TM to TMW"; - final String TMW_TO_UNI = "TMW to Unicode"; - final String TMW_TO_WYLIE = "TMW to Wylie"; - final String TMW_TO_ACIP = "TMW to ACIP"; - final String TMW_TO_TM = "TMW to TM"; - final String FIND_SOME_NON_TMW = "Find some non-TMW"; - final String FIND_SOME_NON_TM = "Find some non-TM"; - final String FIND_ALL_NON_TMW = "Find all non-TMW"; - final String FIND_ALL_NON_TM = "Find all non-TM"; + final String ACIP_TO_UNI_TEXT = "ACIP to Unicode (Text->Text)"; + final String ACIP_TO_TMW = "ACIP to TMW (Text->RTF)"; + final String TMW_TO_ACIP = "TMW to ACIP (RTF->RTF)"; + final String TMW_TO_ACIP_TEXT = "TMW to ACIP (RTF->Text)"; + final String TM_TO_TMW = "TM to TMW (RTF->RTF)"; + final String TMW_TO_TM = "TMW to TM (RTF->RTF)"; + final String TMW_TO_UNI = "TMW to Unicode (RTF->RTF)"; + final String TMW_TO_WYLIE = "TMW to Wylie (RTF->RTF)"; + final String TMW_TO_WYLIE_TEXT = "TMW to Wylie (RTF->Text)"; + final String FIND_SOME_NON_TMW = "Find some non-TMW (in RTF)"; + 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[] { - ACIP_TO_UNI, + ACIP_TO_UNI_TEXT, ACIP_TO_TMW, + TMW_TO_ACIP, + TMW_TO_ACIP_TEXT, TM_TO_TMW, + TMW_TO_TM, TMW_TO_UNI, TMW_TO_WYLIE, - TMW_TO_ACIP, - TMW_TO_TM, + TMW_TO_WYLIE_TEXT, FIND_SOME_NON_TMW, FIND_SOME_NON_TM, FIND_ALL_NON_TMW, diff --git a/source/org/thdl/tib/input/TibetanConverter.java b/source/org/thdl/tib/input/TibetanConverter.java index f3caaf1..5759182 100644 --- a/source/org/thdl/tib/input/TibetanConverter.java +++ b/source/org/thdl/tib/input/TibetanConverter.java @@ -70,15 +70,15 @@ public class TibetanConverter implements FontConverterConstants { boolean convertACIPToUniMode = false; boolean convertACIPToTMWMode = false; boolean convertToTMWMode = false; - boolean convertToWylieMode = false; - boolean convertToACIPMode = false; + boolean convertToWylieRTFMode = false; + boolean convertToWylieTextMode = false; + boolean convertToACIPRTFMode = false; + boolean convertToACIPTextMode = false; boolean findSomeNonTMWMode = false; boolean findAllNonTMWMode = false; boolean findSomeNonTMMode = false; boolean findAllNonTMMode = false; - boolean textOutput = false; - // Process arguments: if ((args.length != 1 && args.length != 2) || (args.length == 1 @@ -97,15 +97,13 @@ public class TibetanConverter implements FontConverterConstants { = args[0].equals("--acip-to-tmw")) || (convertToUnicodeMode = args[0].equals("--to-unicode")) - || (convertToWylieMode + || (convertToWylieRTFMode = args[0].equals("--to-wylie")) - || (convertToWylieMode - = textOutput + || (convertToWylieTextMode = args[0].equals("--to-wylie-text")) - || (convertToACIPMode + || (convertToACIPRTFMode = args[0].equals("--to-acip")) - || (convertToACIPMode - = textOutput + || (convertToACIPTextMode = args[0].equals("--to-acip-text")) || (findSomeNonTMWMode = args[0].equals("--find-some-non-tmw")) @@ -204,16 +202,20 @@ public class TibetanConverter implements FontConverterConstants { } else if (findAllNonTMMode) { conversionTag = FIND_ALL_NON_TM; } else { // conversion {to Wylie or TM} mode - if (convertToWylieMode) { + if (convertToWylieRTFMode) { conversionTag = TMW_TO_WYLIE; - } else if (convertToACIPMode) { + } else if (convertToWylieTextMode) { + conversionTag = TMW_TO_WYLIE_TEXT; + } else if (convertToACIPRTFMode) { conversionTag = TMW_TO_ACIP; + } else if (convertToACIPTextMode) { + conversionTag = TMW_TO_ACIP_TEXT; } else if (convertToUnicodeMode) { conversionTag = TMW_TO_UNI; } else if (convertToTMWMode) { conversionTag = TM_TO_TMW; } else if (convertACIPToUniMode) { - conversionTag = ACIP_TO_UNI; + conversionTag = ACIP_TO_UNI_TEXT; } else if (convertACIPToTMWMode) { conversionTag = ACIP_TO_TMW; } else { @@ -221,7 +223,7 @@ public class TibetanConverter implements FontConverterConstants { conversionTag = TMW_TO_TM; } } - return reallyConvert(in, out, conversionTag, textOutput, + return reallyConvert(in, out, conversionTag, "Most" // DLC make me configurable ); } catch (ThdlLazyException e) { @@ -241,8 +243,8 @@ public class TibetanConverter implements FontConverterConstants { return code so that TibetanConverter's usage message is honored. */ static int reallyConvert(InputStream in, PrintStream out, String ct, - boolean textOutput, String warningLevel) { - if (ACIP_TO_UNI == ct || ACIP_TO_TMW == ct) { + String warningLevel) { + if (ACIP_TO_UNI_TEXT == ct || ACIP_TO_TMW == ct) { try { ArrayList al = ACIPTshegBarScanner.scanStream(in, null, 250 - 1 // DLC FIXME: make me configurable @@ -251,7 +253,7 @@ public class TibetanConverter implements FontConverterConstants { return 47; StringBuffer warnings = new StringBuffer(); boolean embeddedWarnings = (warningLevel != "None"); - if (ACIP_TO_UNI == ct) { + if (ACIP_TO_UNI_TEXT == ct) { if (!ACIPConverter.convertToUnicode(al, out, null, warnings, embeddedWarnings, warningLevel)) @@ -344,7 +346,9 @@ public class TibetanConverter implements FontConverterConstants { + ((TMW_TO_UNI == ct) ? 1 : 0) + ((TM_TO_TMW == 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_TEXT == ct) ? 1 : 0) == 1); long numAttemptedReplacements[] = new long[] { 0 }; if (TMW_TO_WYLIE == ct) { @@ -392,7 +396,7 @@ public class TibetanConverter implements FontConverterConstants { } // Write to standard output the result: - if (textOutput) { + if (TMW_TO_WYLIE_TEXT == ct || TMW_TO_ACIP_TEXT == ct) { try { tdoc.writeTextOutput(new BufferedWriter(new OutputStreamWriter(out))); } catch (IOException e) { diff --git a/source/org/thdl/tib/text/ttt/ACIPRules.java b/source/org/thdl/tib/text/ttt/ACIPRules.java index 92be611..2b0f3b0 100644 --- a/source/org/thdl/tib/text/ttt/ACIPRules.java +++ b/source/org/thdl/tib/text/ttt/ACIPRules.java @@ -443,6 +443,7 @@ class ACIPRules { superACIP2unicode.put(";", "\u0F11"); superACIP2unicode.put("\r", "\r"); superACIP2unicode.put("\t", "\t"); + superACIP2unicode.put("\r\n", "\r\n"); superACIP2unicode.put("\n", "\n"); superACIP2unicode.put("\\", "\u0F84"); // DLC FIXME: make this like a vowel // DLC FIXME: what's the Unicode for caret, ^?