Updated comments so that Javadoc 1.4 warnings went away.

This commit is contained in:
dchandler 2002-09-30 03:10:00 +00:00
parent 3ad36a3f8e
commit 10d86fc3b7
3 changed files with 2562 additions and 2500 deletions

View file

@ -25,9 +25,13 @@ import java.awt.font.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import java.lang.*;
import org.thdl.tib.text.*;
import java.io.*;
import javax.swing.text.rtf.*;
/**
* Enables input of Tibetan text
* using Tibetan Computer Company's free cross-platform TibetanMachineWeb fonts.
@ -184,7 +188,7 @@ public class DuffPane extends JTextPane implements KeyListener, FocusListener {
* current entry/edit/deletion position.
*/
private Caret caret;
private StyledEditorKit editorKit;
// private StyledEditorKit editorKit;
private StyleContext styleContext;
private Style rootStyle;
private boolean skipUpdate = false;
@ -194,57 +198,75 @@ public class DuffPane extends JTextPane implements KeyListener, FocusListener {
private int romanFontSize;
private MutableAttributeSet romanAttributeSet;
public Clipboard rtfBoard;
public DataFlavor rtfFlavor;
public RTFEditorKit rtfEd = null;
public DuffPane() {
this(new StyledEditorKit());
setupKeyboard();
setupEditor();
// this(new StyledEditorKit());
}
public DuffPane(TibetanKeyboard keyboard) {
this(new StyledEditorKit(), keyboard);
TibetanMachineWeb.setKeyboard(keyboard);
setupKeyboard();
setupEditor();
// this(new StyledEditorKit(), keyboard);
}
public DuffPane(java.net.URL keyboardURL) {
this(new StyledEditorKit(), keyboardURL);
}
public DuffPane(StyledEditorKit styledEditorKit) {
setupKeyboard();
setupEditor(styledEditorKit);
}
public DuffPane(StyledEditorKit styledEditorKit, TibetanKeyboard keyboard) {
TibetanMachineWeb.setKeyboard(keyboard);
setupKeyboard();
setupEditor(styledEditorKit);
}
public DuffPane(StyledEditorKit styledEditorKit, java.net.URL keyboardURL) {
TibetanMachineWeb.setKeyboard(keyboardURL);
setupKeyboard();
setupEditor();
// this(new StyledEditorKit(), keyboardURL);
}
/*
public DuffPane() {
setupKeyboard();
setupEditor(styledEditorKit);
}
public DuffPane(TibetanKeyboard keyboard) {
TibetanMachineWeb.setKeyboard(keyboard);
setupKeyboard();
setupEditor();
}
public DuffPane(java.net.URL keyboardURL) {
TibetanMachineWeb.setKeyboard(keyboardURL);
setupKeyboard();
setupEditor();
}
*/
/**
* This method sets up the editor, assigns fonts and point sizes,
* sets the document, the caret, and adds key and focus listeners.
*
* @param sek the StyledEditorKit for the editing window
*/
private void setupEditor(StyledEditorKit sek) {
public void setupEditor() {
rtfBoard = getToolkit().getSystemClipboard();
rtfFlavor = new DataFlavor("text/rtf", "Rich Text Format");
rtfEd = new RTFEditorKit();
setEditorKit(rtfEd);
styleContext = new StyleContext();
doc = new TibetanDocument(styleContext);
doc.setTibetanFontSize(36);
setDocument(doc);
Style defaultStyle = styleContext.getStyle(StyleContext.DEFAULT_STYLE);
StyleConstants.setFontFamily(defaultStyle, "TibetanMachineWeb");
StyleConstants.setFontSize(defaultStyle, 36);
romanFontFamily = "Serif";
romanFontSize = 14;
setRomanAttributeSet(romanFontFamily, romanFontSize);
editorKit = sek;
setEditorKit(editorKit);
styleContext = new StyleContext();
Style defaultStyle = styleContext.getStyle(StyleContext.DEFAULT_STYLE);
rootStyle = styleContext.addStyle("RootStyle", defaultStyle);
StyleConstants.setFontFamily(rootStyle, "TibetanMachineWeb");
StyleConstants.setFontSize(rootStyle, 36);
setLogicalStyle(rootStyle);
newDocument();
// newDocument();
caret = getCaret();
addKeyListener(this);
@ -258,7 +280,7 @@ public class DuffPane extends JTextPane implements KeyListener, FocusListener {
* respect to stacking, and concerning the differences between
* Tibetan and Sanskrit; and then it initializes the input method.
*/
private void setupKeyboard() {
public void setupKeyboard() {
if (TibetanMachineWeb.hasTibetanStackingKey()) {
if (TibetanMachineWeb.hasSanskritStackingKey()) {
isDefinitelyTibetan_default = false;
@ -308,12 +330,11 @@ public class DuffPane extends JTextPane implements KeyListener, FocusListener {
}
/**
* Registers a keyboard, and sets it as
* the active keyboard. * Unpredictable behavior will result
* if you set the keyboard in {@link org.thdl.tib.text.TibetanMachineWeb TibetanMachineWeb}
* but don't register it in here.
* @param keyboardURL the URL of the keyboard you want to install
*/
* Registers a keyboard, and sets it as the active keyboard.
* Unpredictable behavior will result if you set the keyboard in {@link
* org.thdl.tib.text.TibetanMachineWeb TibetanMachineWeb} but don't
* register it in here.
* @param keyboardURL the URL of the keyboard you want to install */
public void registerKeyboard(java.net.URL keyboardURL) {
TibetanMachineWeb.setKeyboard(keyboardURL);
setupKeyboard();
@ -336,10 +357,15 @@ public class DuffPane extends JTextPane implements KeyListener, FocusListener {
* Clears the current document.
*/
public void newDocument() {
styleContext = new StyleContext();
doc = new TibetanDocument(styleContext);
doc.setTibetanFontSize(36);
setDocument(doc);
setLogicalStyle(rootStyle);
Style defaultStyle = styleContext.getStyle(StyleContext.DEFAULT_STYLE);
StyleConstants.setFontFamily(defaultStyle, "TibetanMachineWeb");
StyleConstants.setFontSize(defaultStyle, 36);
}
/**
@ -636,7 +662,7 @@ public class DuffPane extends JTextPane implements KeyListener, FocusListener {
/**
* Prints ACHEN together with the vowel v. When using the Wylie
* keyboard, or any other keyboard in which {@link thdl.tibetan.text.TibetanMachineWeb#isAChenRequiredBeforeVowel() isAChenRequiredBeforeVowel()}
* keyboard, or any other keyboard in which {@link org.thdl.tib.text.TibetanMachineWeb#isAChenRequiredBeforeVowel() isAChenRequiredBeforeVowel()}
* is false, this method is called frequently.
*
* @param v the vowel (in Wylie) which you want to print with ACHEN
@ -718,6 +744,57 @@ public class DuffPane extends JTextPane implements KeyListener, FocusListener {
initKeyboard();
}
class RTFSelection implements ClipboardOwner, Transferable {
DataFlavor[] supportedFlavor;
ByteArrayOutputStream rtfOut;
String plainText;
RTFSelection(StyledDocument doc, int offset, int length) {
supportedFlavor = new DataFlavor[2];
supportedFlavor[0] = rtfFlavor;
supportedFlavor[1] = DataFlavor.stringFlavor;
try {
//construct new document that contains only portion of text you want to copy
//this workaround is due to bug 4129911, which will not be fixed (see below after source code)
StyledDocument newDoc = new DefaultStyledDocument();
for (int i=offset; i<offset+length; i++) {
try {
String s = doc.getText(i,1);
AttributeSet as = doc.getCharacterElement(i).getAttributes();
newDoc.insertString(i-offset, s, as);
} catch (BadLocationException ble) {
ble.printStackTrace();
}
}
rtfOut = new ByteArrayOutputStream();
rtfEd.write(rtfOut, newDoc, 0, newDoc.getLength()); //last two parameters ignored, see bug below
plainText = getText(offset, length);
} catch (BadLocationException ble) {
ble.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
public void lostOwnership(Clipboard clipboard, Transferable contents) {
}
public Object getTransferData(DataFlavor flavor) {
if (flavor.equals(rtfFlavor))
return new ByteArrayInputStream(rtfOut.toByteArray());
if (flavor.equals(DataFlavor.stringFlavor))
return plainText;
return null;
}
public DataFlavor[] getTransferDataFlavors() {
return supportedFlavor;
}
public boolean isDataFlavorSupported(DataFlavor flavor) {
for (int i=0; i<supportedFlavor.length; i++)
if (flavor.equals(supportedFlavor[i]))
return true;
return false;
}
}
/**
* Cuts or copies the specified portion of this object's document
* to the system clipboard. What is cut/copied is Wylie text -
@ -731,57 +808,23 @@ public class DuffPane extends JTextPane implements KeyListener, FocusListener {
* false if it is 'copy'
*/
public void copy(int start, int end, boolean remove) {
if (start < end) {
java.util.List dcs = new ArrayList();
int p1 = start;
int p2 = end;
if (p1 != p2) {
RTFSelection rtfSelection = new RTFSelection((StyledDocument)getDocument(), p1, p2-p1);
try {
AttributeSet attr;
String fontName;
int fontNum;
DuffCode dc;
char ch;
int i = start;
while (i < end+1) {
attr = doc.getCharacterElement(i).getAttributes();
fontName = StyleConstants.getFontFamily(attr);
if ((0 == (fontNum = TibetanMachineWeb.getTMWFontNumber(fontName))) || i==end) {
if (i != start) {
DuffCode[] dc_array = new DuffCode[0];
dc_array = (DuffCode[])dcs.toArray(dc_array);
StringSelection data = new StringSelection(TibetanDocument.getWylie(dc_array));
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(data, data);
if (remove) {
doc.remove(start, i-start);
setSelectionEnd(start);
}
else {
setSelectionStart(start);
setSelectionEnd(i);
}
return;
}
else {
setSelectionEnd(start);
return;
rtfBoard.setContents(rtfSelection, rtfSelection);
} catch (IllegalStateException ise) {
ise.printStackTrace();
}
}
else {
ch = doc.getText(i,1).charAt(0);
dc = new DuffCode(fontNum, ch);
dcs.add(dc);
}
i++;
}
}
catch (BadLocationException ble) {
if (remove)
try {
getDocument().remove(p1, p2-p1);
} catch (BadLocationException ble) {
ble.printStackTrace();
}
}
}
/**
* Pastes the contents of the system clipboard into this object's
@ -794,19 +837,37 @@ public class DuffPane extends JTextPane implements KeyListener, FocusListener {
* @param offset the position in the document you want to paste to
*/
public void paste(int offset) {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable data = clipboard.getContents(this);
String s = null;
try {
s = (String)(data.getTransferData(DataFlavor.stringFlavor));
}
catch (Exception e) {
s = data.toString();
}
Transferable contents = rtfBoard.getContents(this);
if (contents.isDataFlavorSupported(rtfFlavor)) {
InputStream in = (InputStream)contents.getTransferData(rtfFlavor);
int p1 = offset;
if (s != null)
toTibetanMachineWeb(s, offset);
//construct new document that contains only portion of text you want to paste
StyledDocument sd = new DefaultStyledDocument();
rtfEd.read(in, sd, 0);
for (int i=0; i<sd.getLength()-1; i++) { //getLength()-1 so that final newline is not included in paste
try {
String s = sd.getText(i,1);
AttributeSet as = sd.getCharacterElement(i).getAttributes();
doc.insertString(p1+i, s, as);
} catch (BadLocationException ble) {
ble.printStackTrace();
}
}
} else if (contents.isDataFlavorSupported(DataFlavor.stringFlavor)) {
String s = (String)contents.getTransferData(DataFlavor.stringFlavor);
replaceSelection(s);
}
} catch (UnsupportedFlavorException ufe) {
ufe.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (IllegalStateException ise) {
ise.printStackTrace();
} catch (BadLocationException ble) {
ble.printStackTrace();
}
}
/**
@ -1298,8 +1359,21 @@ public class DuffPane extends JTextPane implements KeyListener, FocusListener {
*/
public void toTibetanMachineWeb(String wylie, int offset) {
try {
TibetanDocument.DuffData[] dd = TibetanDocument.getTibetanMachineWeb(wylie);
doc.insertDuff(offset, dd);
StringTokenizer sTok = new StringTokenizer(wylie, "\n\t", true);
while (sTok.hasMoreTokens()) {
String next = sTok.nextToken();
if (next.equals("\n") || next.equals("\t")) {
try {
doc.insertString(offset, next, null);
offset++;
} catch (BadLocationException ble) {
ble.printStackTrace();
}
} else {
TibetanDocument.DuffData[] dd = TibetanDocument.getTibetanMachineWeb(next);
offset = doc.insertDuff(offset, dd);
}
}
}
catch (InvalidWylieException iwe) {
JOptionPane.showMessageDialog(this,
@ -1307,7 +1381,6 @@ public class DuffPane extends JTextPane implements KeyListener, FocusListener {
"beginning from:\n " + iwe.getCulpritInContext() + "\n" +
"The culprit is probably the character '"+iwe.getCulprit()+"'.");
}
}
/**
@ -1373,4 +1446,5 @@ public class DuffPane extends JTextPane implements KeyListener, FocusListener {
ble.printStackTrace();
}
}
}

View file

@ -31,8 +31,9 @@ import java.io.Serializable;
/** Used by DictionaryTable to display a Tibetan word or phrase
(in either Roman or Tibetan script) in a single cell.
This THDL version does not include DictionaryTable.
@author Andr&eacute;s Montano Pellegrini
@see DictionaryTable
*/
public class DuffCellRenderer extends DuffPane implements TableCellRenderer, Serializable
{

View file

@ -503,12 +503,18 @@ public static SimpleAttributeSet getAttributeSet(int font) {
* ENTER), false if not
*/
public static boolean isFormatting(char c) {
if (c < 32 || c > 126)
return true;
else
return false;
/*
if ( c == KeyEvent.VK_TAB
|| c == KeyEvent.VK_ENTER)
return true;
else
return false;
*/
}
/**
@ -618,16 +624,13 @@ public static boolean isWylieVowel(String s) {
}
/**
* Is this Wylie valid as a leftmost character
* in a Tibetan syllable? For example, in the
* syllable 'brgyad', 'b' is the leftmost
* character. Valid leftmost characters include
* g, d, b, and m.
* Returns true iff this Wylie is valid as a leftmost character in a
* Tibetan syllable. For example, in the syllable 'brgyad', 'b' is the
* leftmost character. Valid leftmost characters include g, d, b, and
* m.
* @param s the (Wylie) string to be checked
* @return true if s is a possible leftmost
* character in a Tibetan syllable, false
* if not.
*/
* @return true if s is a possible leftmost character in a Tibetan
* syllable, false if not. */
public static boolean isWylieLeft(String s) {
if (keyboard != null)
s = keyboard.getWylieForChar(s);
@ -639,16 +642,13 @@ public static boolean isWylieLeft(String s) {
}
/**
* Is this Wylie valid as a right (post-vowel)
* character in a Tibetan syllable? For example,
* in the syllable 'lags', 'g' is in the right
* character position. Valid right characters
* include g, ng, d, n, b, m, r, l, s, ', and T.
* Returns true iff this Wylie is valid as a right (post-vowel)
* character in a Tibetan syllable. For example, in the syllable
* 'lags', 'g' is in the right character position. Valid right
* characters include g, ng, d, n, b, m, r, l, s, ', and T.
* @param s the (Wylie) string to be checked
* @return true if s is a possible right
* character in a Tibetan syllable, false
* if not.
*/
* @return true if s is a possible right character in a Tibetan
* syllable, false if not. */
public static boolean isWylieRight(String s) {
if (keyboard != null)
s = keyboard.getWylieForChar(s);
@ -660,13 +660,11 @@ public static boolean isWylieRight(String s) {
}
/**
* Is this Wylie valid as a leftmost character
* in a Tibetan syllable?
* Returns true iff this Wylie is valid as a leftmost character in a
* Tibetan syllable.
* @param s the string to be checked
* @return true if s is a possible leftmost
* character in a Tibetan syllable, false
* if not.
*/
* @return true if s is a possible leftmost character in a Tibetan
* syllable, false if not. */
public static boolean isWylieFarRight(String s) {
if (keyboard != null)
s = keyboard.getWylieForChar(s);
@ -1002,11 +1000,10 @@ public static Map getBinduMap() {
}
/**
* Does the keyboard have a disambiguating key?
* @return true if the installed keyboard has a
* disambiguating key, false if not
* @see TibetanKeyboard
*/
* Returns true iff the keyboard has a disambiguating key.
* @return true if the installed keyboard has a disambiguating key,
* false if not
* @see TibetanKeyboard */
public static boolean hasDisambiguatingKey() {
return hasDisambiguatingKey;
}
@ -1022,31 +1019,28 @@ public static char getDisambiguatingKey() {
}
/**
* Does the keyboard have a Sanksrit stacking key?
* @return true if a stacking key is required
* to type Sanskrit stacks, false if not
* @see TibetanKeyboard
*/
* Returns true iff the keyboard has a Sanksrit stacking key.
* @return true if a stacking key is required to type Sanskrit stacks,
* false if not
* @see TibetanKeyboard */
public static boolean hasSanskritStackingKey() {
return hasSanskritStackingKey;
}
/**
* Does the keyboard have a Tibetan stacking key?
* @return true if a stacking key is required to
* type Tibetan stacks, false if not
* @see TibetanKeyboard
*/
* Returns true iff the keyboard has a Tibetan stacking key.
* @return true if a stacking key is required to type Tibetan stacks,
* false if not
* @see TibetanKeyboard */
public static boolean hasTibetanStackingKey() {
return hasTibetanStackingKey;
}
/**
* Is stacking medial?
* @return true if the stacking key is medial,
* false if not, or if there is no stacking key
* @see TibetanKeyboard
*/
* Returns true iff stacking is medial.
* @return true if the stacking key is medial, false if not, or if
* there is no stacking key
* @see TibetanKeyboard */
public static boolean isStackingMedial() {
return isStackingMedial;
}
@ -1062,34 +1056,30 @@ public static char getStackingKey() {
}
/**
* Is achen required before vowels?
* @return true if you have to type achen first
* before you can get a vowel with achen, false
* if you can just type the vowel by itself
* (as in Wylie)
* @see TibetanKeyboard
*/
* Returns true iff achen is required before vowels.
* @return true if you have to type achen first before you can get a
* vowel with achen, false if you can just type the vowel by itself (as
* in Wylie)
* @see TibetanKeyboard */
public static boolean isAChenRequiredBeforeVowel() {
return isAChenRequiredBeforeVowel;
}
/**
* Is achung treated as a consonant?
* @return true if a-chung is considered a consonant
* for the purposes of stacking, false if not
* (as in Wylie)
* @see TibetanKeyboard
*/
* Returns true iff achung is treated as a consonant.
* @return true if a-chung is considered a consonant for the purposes
* of stacking, false if not (as in Wylie)
* @see TibetanKeyboard */
public static boolean isAChungConsonant() {
return isAChungConsonant;
}
/**
* Is there a key for the invisible 'a' vowel in this keyboard?
* @return true if the installed keyboard has a
* dummy a vowel, false if not
* @see TibetanKeyboard
*/
* Returns true iff there is a key for the invisible 'a' vowel in this
* keyboard.
* @return true if the installed keyboard has a dummy a vowel, false if
* not
* @see TibetanKeyboard */
public static boolean hasAVowel() {
return hasAVowel;
}
@ -1105,13 +1095,10 @@ public static String getAVowel() {
}
/**
* Is this glyph a top (superscript) vowel?
* @param a DuffCode representing a TibetanMachineWeb
* glyph
* @return true if the glyph is a top-hanging
* (superscript) vowel (i, u, e, o, ai, or ao)
* and false if not
*/
* Returns true iff this glyph is a top (superscript) vowel.
* @param a DuffCode representing a TibetanMachineWeb glyph
* @return true if the glyph is a top-hanging (superscript) vowel (i,
* u, e, o, ai, or ao) and false if not */
public static boolean isTopVowel(DuffCode dc) {
String wylie = getWylieForGlyph(dc);
if (top_vowels.contains(wylie))