Rearranged the Tools menu; made the converter smart about "find some..."

and "find all..." modes.
This commit is contained in:
dchandler 2003-07-05 21:02:46 +00:00
parent 72d2eee503
commit 8c4ab30a52
2 changed files with 142 additions and 108 deletions

View file

@ -89,6 +89,21 @@ public class ConverterGUI implements FontConversion, FontConverterConstants {
"Errors in Conversion", "Errors in Conversion",
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
return false; return false;
} else if (1 == returnCode) {
if (FIND_SOME_NON_TMW == whichConversion
|| FIND_ALL_NON_TMW == whichConversion) {
JOptionPane.showMessageDialog(cd,
"Something besides TibetanMachineWeb was found; see output file.",
"Not entirely TMW",
JOptionPane.PLAIN_MESSAGE);
} else if (FIND_SOME_NON_TM == whichConversion
|| FIND_ALL_NON_TM == whichConversion) {
JOptionPane.showMessageDialog(cd,
"Something besides TibetanMachine was found; see output file.",
"Not entirely TM",
JOptionPane.PLAIN_MESSAGE);
}
return false;
} else if (0 != returnCode) { } else if (0 != returnCode) {
JOptionPane.showMessageDialog(cd, JOptionPane.showMessageDialog(cd,
"The conversion failed with code " + returnCode + "; please e-mail\ndchandler@users.sourceforge.net to learn what that means if\nyou can't find out from the output.", "The conversion failed with code " + returnCode + "; please e-mail\ndchandler@users.sourceforge.net to learn what that means if\nyou can't find out from the output.",
@ -96,11 +111,26 @@ public class ConverterGUI implements FontConversion, FontConverterConstants {
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
return false; return false;
} else { } else {
if (!ThdlOptions.getBooleanOption("thdl.skip.conversion.success.message")) if (!ThdlOptions.getBooleanOption("thdl.skip.conversion.success.message")) {
JOptionPane.showMessageDialog(cd, if (FIND_SOME_NON_TMW == whichConversion
"The conversion went perfectly.", || FIND_ALL_NON_TMW == whichConversion) {
"Conversion succeeded", JOptionPane.showMessageDialog(cd,
JOptionPane.PLAIN_MESSAGE); "Nothing except TibetanMachineWeb was found.",
"All TMW",
JOptionPane.PLAIN_MESSAGE);
} else if (FIND_SOME_NON_TM == whichConversion
|| FIND_ALL_NON_TM == whichConversion) {
JOptionPane.showMessageDialog(cd,
"Nothing except TibetanMachine was found.",
"All TM",
JOptionPane.PLAIN_MESSAGE);
} else {
JOptionPane.showMessageDialog(cd,
"The conversion went perfectly.",
"Conversion succeeded",
JOptionPane.PLAIN_MESSAGE);
}
}
return true; return true;
} }
} }

View file

@ -396,13 +396,15 @@ public class Jskad extends JPanel implements DocumentListener {
JMenu toolsMenu = new JMenu("Tools"); JMenu toolsMenu = new JMenu("Tools");
JMenu convertSelectionMenu = new JMenu("Convert Selection");
JMenuItem TMWWylieItem = new JMenuItem("Convert Tibetan to Wylie"); JMenuItem TMWWylieItem = new JMenuItem("Convert Tibetan to Wylie");
TMWWylieItem.addActionListener(new ThdlActionListener() { TMWWylieItem.addActionListener(new ThdlActionListener() {
public void theRealActionPerformed(ActionEvent e) { public void theRealActionPerformed(ActionEvent e) {
toWylie(); toWylie();
} }
}); });
toolsMenu.add(TMWWylieItem); convertSelectionMenu.add(TMWWylieItem);
toolsMenu.add(convertSelectionMenu);
JMenuItem wylieTMWItem = new JMenuItem("Convert Wylie to Tibetan"); JMenuItem wylieTMWItem = new JMenuItem("Convert Wylie to Tibetan");
wylieTMWItem.addActionListener(new ThdlActionListener() { wylieTMWItem.addActionListener(new ThdlActionListener() {
@ -410,117 +412,104 @@ public class Jskad extends JPanel implements DocumentListener {
toTibetan(); toTibetan();
} }
}); });
toolsMenu.add(wylieTMWItem); convertSelectionMenu.add(wylieTMWItem);
if (parentObject instanceof JFrame || parentObject instanceof JInternalFrame) { JMenu convertAllMenu = new JMenu("Convert All");
JMenuItem openWithItem = new JMenuItem("Open With External Viewer...");
openWithItem.addActionListener(new ThdlActionListener() {
public void theRealActionPerformed(ActionEvent e) {
openWithExternalViewer();
}
});
toolsMenu.addSeparator();
toolsMenu.add(openWithItem);
JMenuItem toTMItem = new JMenuItem("Convert Tibetan to TM"); // DLC FIXME: do it just in the selection?
JMenuItem importItem = new JMenuItem("Import Wylie as Tibetan"); toTMItem.addActionListener(new ThdlActionListener() {
importItem.addActionListener(new ThdlActionListener() { public void theRealActionPerformed(ActionEvent e) {
public void theRealActionPerformed(ActionEvent e) { StringBuffer errors = new StringBuffer();
importWylie(); long numAttemptedReplacements[] = new long[] { 0 };
} boolean errorReturn
}); = ((TibetanDocument)dp.getDocument()).convertToTM(0, -1, errors,
toolsMenu.addSeparator(); numAttemptedReplacements); // entire document
toolsMenu.add(importItem); if (errorReturn) {
JOptionPane.showMessageDialog(Jskad.this,
JMenuItem toTMItem = new JMenuItem("Convert TMW to TM"); // DLC FIXME: do it just in the selection? "At least one error occurred while converting Tibetan Machine Web\nto Tibetan Machine. Your document is mostly converted,\nexcept for the following glyphs, which you should replace manually\nbefore retrying:\n"
toTMItem.addActionListener(new ThdlActionListener() { + errors.toString(),
public void theRealActionPerformed(ActionEvent e) { "Tibetan to TM Errors",
StringBuffer errors = new StringBuffer(); JOptionPane.PLAIN_MESSAGE);
long numAttemptedReplacements[] = new long[] { 0 }; } else {
boolean errorReturn if (numAttemptedReplacements[0] > 0) {
= ((TibetanDocument)dp.getDocument()).convertToTM(0, -1, errors,
numAttemptedReplacements); // entire document
if (errorReturn) {
JOptionPane.showMessageDialog(Jskad.this, JOptionPane.showMessageDialog(Jskad.this,
"At least one error occurred while converting Tibetan Machine Web\nto Tibetan Machine. Your document is mostly converted,\nexcept for the following glyphs, which you should replace manually\nbefore retrying:\n" "Converting Tibetan Machine Web to Tibetan Machine met with perfect success.",
+ errors.toString(), "Success",
"TMW to TM Errors",
JOptionPane.PLAIN_MESSAGE); JOptionPane.PLAIN_MESSAGE);
} else { } else {
if (numAttemptedReplacements[0] > 0) { JOptionPane.showMessageDialog(Jskad.this,
JOptionPane.showMessageDialog(Jskad.this, "No Tibetan Machine Web was found, so nothing was converted.",
"Converting Tibetan Machine Web to Tibetan Machine met with perfect success.", "Nothing to do",
"Success", JOptionPane.ERROR_MESSAGE);
JOptionPane.PLAIN_MESSAGE);
} else {
JOptionPane.showMessageDialog(Jskad.this,
"No Tibetan Machine Web was found, so nothing was converted.",
"Nothing to do",
JOptionPane.ERROR_MESSAGE);
}
} }
} }
}); }
});
JMenuItem toTMWItem = new JMenuItem("Convert TM to TMW"); // DLC FIXME: do it just in the selection? JMenuItem toTMWItem = new JMenuItem("Convert TM to Tibetan"); // DLC FIXME: do it just in the selection?
toTMWItem.addActionListener(new ThdlActionListener() { toTMWItem.addActionListener(new ThdlActionListener() {
public void theRealActionPerformed(ActionEvent e) { public void theRealActionPerformed(ActionEvent e) {
StringBuffer errors = new StringBuffer(); StringBuffer errors = new StringBuffer();
long numAttemptedReplacements[] = new long[] { 0 }; long numAttemptedReplacements[] = new long[] { 0 };
boolean errorReturn boolean errorReturn
= ((TibetanDocument)dp.getDocument()).convertToTMW(0, -1, errors, = ((TibetanDocument)dp.getDocument()).convertToTMW(0, -1, errors,
numAttemptedReplacements); // entire document
if (errorReturn) {
JOptionPane.showMessageDialog(Jskad.this,
"At least one error occurred while converting Tibetan Machine\nto Tibetan Machine Web. Your document is mostly converted,\nexcept for the following glyphs, which you should replace manually\nbefore retrying:\n"
+ errors.toString(),
"TM to Tibetan Errors", JOptionPane.PLAIN_MESSAGE);
} else {
if (numAttemptedReplacements[0] > 0) {
JOptionPane.showMessageDialog(Jskad.this,
"Converting Tibetan Machine to Tibetan Machine Web met with perfect success.",
"Success",
JOptionPane.PLAIN_MESSAGE);
} else {
JOptionPane.showMessageDialog(Jskad.this,
"No Tibetan Machine was found, so nothing was converted.",
"Nothing to do",
JOptionPane.ERROR_MESSAGE);
}
}
}
});
JMenuItem toUnicodeItem = new JMenuItem("Convert Tibetan to Unicode (not perfect yet)"); // DLC FIXME: do it just in the selection?
toUnicodeItem.addActionListener(new ThdlActionListener() {
public void theRealActionPerformed(ActionEvent e) {
StringBuffer errors = new StringBuffer();
long numAttemptedReplacements[] = new long[] { 0 };
boolean errorReturn
= ((TibetanDocument)dp.getDocument()).convertToUnicode(0, -1, errors,
ThdlOptions.getStringOption("thdl.tmw.to.unicode.font").intern(),
numAttemptedReplacements); // entire document numAttemptedReplacements); // entire document
if (errorReturn) { if (errorReturn) {
JOptionPane.showMessageDialog(Jskad.this,
"At least one error occurred while converting Tibetan Machine Web\nto Unicode. Your document is mostly converted,\nexcept for the following glyphs, which you should replace manually\nbefore retrying:\n"
+ errors.toString(),
"Tibetan to Unicode Errors", JOptionPane.PLAIN_MESSAGE);
} else {
if (numAttemptedReplacements[0] > 0) {
JOptionPane.showMessageDialog(Jskad.this, JOptionPane.showMessageDialog(Jskad.this,
"At least one error occurred while converting Tibetan Machine\nto Tibetan Machine Web. Your document is mostly converted,\nexcept for the following glyphs, which you should replace manually\nbefore retrying:\n" "Converting Tibetan Machine Web to Unicode met with perfect success.",
+ errors.toString(), "Success",
"TM to TMW Errors", JOptionPane.PLAIN_MESSAGE); JOptionPane.PLAIN_MESSAGE);
} else { } else {
if (numAttemptedReplacements[0] > 0) { JOptionPane.showMessageDialog(Jskad.this,
JOptionPane.showMessageDialog(Jskad.this, "No Tibetan Machine Web was found, so nothing was converted.",
"Converting Tibetan Machine to Tibetan Machine Web met with perfect success.", "Nothing to do",
"Success", JOptionPane.ERROR_MESSAGE);
JOptionPane.PLAIN_MESSAGE);
} else {
JOptionPane.showMessageDialog(Jskad.this,
"No Tibetan Machine was found, so nothing was converted.",
"Nothing to do",
JOptionPane.ERROR_MESSAGE);
}
} }
} }
}); }
});
JMenuItem toUnicodeItem = new JMenuItem("Convert TMW to Unicode"); // DLC FIXME: do it just in the selection? convertAllMenu.add(toTMItem);
toUnicodeItem.addActionListener(new ThdlActionListener() { convertAllMenu.add(toTMWItem);
public void theRealActionPerformed(ActionEvent e) { convertAllMenu.add(toUnicodeItem);
StringBuffer errors = new StringBuffer(); toolsMenu.add(convertAllMenu);
long numAttemptedReplacements[] = new long[] { 0 };
boolean errorReturn
= ((TibetanDocument)dp.getDocument()).convertToUnicode(0, -1, errors,
ThdlOptions.getStringOption("thdl.tmw.to.unicode.font").intern(),
numAttemptedReplacements); // entire document
if (errorReturn) {
JOptionPane.showMessageDialog(Jskad.this,
"At least one error occurred while converting Tibetan Machine Web\nto Unicode. Your document is mostly converted,\nexcept for the following glyphs, which you should replace manually\nbefore retrying:\n"
+ errors.toString(),
"TMW to Unicode Errors", JOptionPane.PLAIN_MESSAGE);
} else {
if (numAttemptedReplacements[0] > 0) {
JOptionPane.showMessageDialog(Jskad.this,
"Converting Tibetan Machine Web to Unicode met with perfect success.",
"Success",
JOptionPane.PLAIN_MESSAGE);
} else {
JOptionPane.showMessageDialog(Jskad.this,
"No Tibetan Machine Web was found, so nothing was converted.",
"Nothing to do",
JOptionPane.ERROR_MESSAGE);
}
}
}
});
if (parentObject instanceof JFrame || parentObject instanceof JInternalFrame) {
JMenuItem converterItem = new JMenuItem("Launch Converter..."); JMenuItem converterItem = new JMenuItem("Launch Converter...");
converterItem.addActionListener(new ThdlActionListener() { converterItem.addActionListener(new ThdlActionListener() {
public void theRealActionPerformed(ActionEvent e) { public void theRealActionPerformed(ActionEvent e) {
@ -532,12 +521,27 @@ public class Jskad extends JPanel implements DocumentListener {
: null)); : null));
} }
}); });
toolsMenu.addSeparator();
toolsMenu.add(toTMItem);
toolsMenu.add(toTMWItem);
toolsMenu.add(toUnicodeItem);
toolsMenu.addSeparator();
toolsMenu.add(converterItem); toolsMenu.add(converterItem);
JMenuItem importItem = new JMenuItem("Import Wylie as Tibetan...");
importItem.addActionListener(new ThdlActionListener() {
public void theRealActionPerformed(ActionEvent e) {
importWylie();
}
});
toolsMenu.addSeparator();
toolsMenu.add(importItem);
JMenuItem openWithItem = new JMenuItem("Open With External Viewer...");
openWithItem.addActionListener(new ThdlActionListener() {
public void theRealActionPerformed(ActionEvent e) {
openWithExternalViewer();
}
});
toolsMenu.addSeparator();
toolsMenu.add(openWithItem);
} }