944,084 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 3139
  • Java RSS
Jul 6th, 2005
0

JEditorPane Display Errors

Expand Post »
Hi All:

I am new to this List.

I am creating a Swing GUI based Word Processor which takes in English Text and using KeyListeners converts it into Unicode Devanagari - the Script used for writting The Hindi Language of India - which is dispalyed in a JEditorPane set to display RTF text.

My problem is, at times, and not always I start seeing junk in the JEditor Pane and parts of other Hindi characters. Even after I clear the JEditorPane by clicking "Clear: Button, these dots and other small black marks persist and dont seem to go away.

There are three JEditor Panes and this only happens in the Pane for Devanagari Display.

Any suggestions?

All three have JScroll Panes.

Thanks.

Chetan
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
chetanpandey is offline Offline
2 posts
since Jul 2005
Jul 7th, 2005
0

Re: JEditorPane Display Errors

How exactly are you converting to unicode? This can cause problems if you accidently mess up in the range of values.
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
Jul 7th, 2005
0

Re: JEditorPane Display Errors

This is how my conversions are done.

User enters characters through Normal Keyboard and JEditorPane # 1 recieves them.

Say user entered 'himalaya'.

Then this string recieved concurrently through KeyListeners (KeyTyped method ) is converted via my Devanagari-Converter Class for display in JEditorPane # 2.

The Devanagari Converter class has a Hash-table and each char of the string is parsed and search made for in the Hashtable.

Unicode equivalent of 'h' is pulled out. Then that of 'i' and so on, appended and sent to JEditorPane#2.

I have an alogorithm to deal with correct display of vowels as their position can determine their shape. SO I have if and elses to choose the right form of a vowel, but thats about it. I dont miss with their ranges or anything

The following is the code if you are interested.

/* Purpose: Converts Scharfe Encoding to Devanagari
*/

package transliteration;
import sandhi.*;

import java.util.*;
import java.io.*;
import java.text.*;
import java.lang.Integer.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.net.URL;
import java.sql.*;
import sun.jdbc.odbc.*;
import java.nio.charset.Charset;

public class devanagari
{
private String transformed;
private Hashtable<String,String> unicode;
private Hashtable<String,String> matra;

public devanagari()
{
//System.out.println("**** Entered Devanagari:::");
transformed = "";
unicode = new Hashtable<String,String>();
matra = new Hashtable<String,String>();
my_hashtable();
//System.out.println("**** Leaving Devanagari:::");
}

public void my_hashtable( )
//*******************BEGINNING OF FUNCTION********************//public void my_hashtable (String s1)
{

matra.put("halant", "\u094d"); //halanta Sign
matra.put("A", "\u093E");
matra.put("i", "\u093F");
matra.put("I", "\u0940");
matra.put("u", "\u0941");
matra.put("U", "\u0942");
matra.put("f", "\u0943");
matra.put("F", "\u0944");
matra.put("x", "\u0962");
matra.put("X", "\u0963");
matra.put("e", "\u0947");
matra.put("E", "\u0948");
matra.put("o", "\u094b");
matra.put("O", "\u094c");


unicode.put("a", "\u0905");
unicode.put("A", "\u0906");
unicode.put("i", "\u0907");
unicode.put("I", "\u0908");
unicode.put("u", "\u0909");
unicode.put("U", "\u090a");
unicode.put("f", "\u090b");
unicode.put("F", "\u0960");
unicode.put("x", "\u090c");
unicode.put("X", "\u0961");
unicode.put("e", "\u090f");
unicode.put("E", "\u0910");
unicode.put("o", "\u0913");
unicode.put("O", "\u0914");

unicode.put("k", "\u0915");
unicode.put("K", "\u0916");
unicode.put("g", "\u0917");
unicode.put("G", "\u0918");
unicode.put("N", "\u0919");
unicode.put("c", "\u091a");
unicode.put("C", "\u091b");
unicode.put("j", "\u091c");
unicode.put("J", "\u091d");
unicode.put("Y", "\u091e");
unicode.put("w", "\u091f"); // Ta as in Tom
unicode.put("W", "\u0920");
unicode.put("q", "\u0921"); // Da as in David
unicode.put("Q", "\u0922");
unicode.put("R", "\u0923");
unicode.put("t", "\u0924"); // ta as in tamasha
unicode.put("T", "\u0925"); // tha as in thanks
unicode.put("d", "\u0926"); // da as in darvaaza
unicode.put("D", "\u0927"); // dha as in dhanusha
unicode.put("n", "\u0928");
unicode.put("p", "\u092a");
unicode.put("P", "\u092b");
unicode.put("b", "\u092c");
unicode.put("B", "\u092d");
unicode.put("m", "\u092e");
unicode.put("y", "\u092f");
unicode.put("r", "\u0930");
unicode.put("l", "\u0932");

unicode.put("L", "\u0933"); // the Marathi and Vedic 'L'

unicode.put("v", "\u0935");
unicode.put("S", "\u0936");
unicode.put("z", "\u0937");
unicode.put("s", "\u0938");
unicode.put("h", "\u0939");
unicode.put("M", "\u0902"); // anusvara
unicode.put("H", "\u0903"); // visarga
unicode.put("~", "\u0901"); // anunAsika - cchandra bindu, using ~ to represent it\
unicode.put("'", "\u093d"); // avagraha using "'"
unicode.put("3", "\u0969"); // 3 equals to pluta
unicode.put("8", "\u014F");//8 equals to upadhamaniya
// unicode.put("8", "\u0306\u032F");//8 equals to upadhamaniya

}
//*******************END OF FUNCTION********************//


//*******************BEGINNING OF FUNCTION********************//
public String transform(String s1)
{

transformed = "";
//System.out.println(" in devanagari" );

Vowel vowel = new Vowel();

int str_len = s1.length();

Object shabda[];
shabda = new String[str_len*2];
int counter = 0;

for (int i = 0; i < str_len ; i++ )
{
char c = s1.charAt(i);
Character character = new Character(c);
String varna = character.toString();



if (vowel.is_consonant(varna) )
{
shabda[counter++] = unicode.get(varna);
//System.out.println(" shabda [" + (counter - 1) + "] == " + shabda[counter-1]);
shabda[counter++] = "\u094d";//unicode.get("halant");
//System.out.println(" shabda [" + (counter - 1) + "] == " + shabda[counter-1]);
}

else if (vowel.is_Vowel(varna))
{
//System.out.println(" point of error: counter == " + counter);

if ( counter == 0 )
{ shabda[counter++] = unicode.get(varna); }


//System.out.println(" shabda [" + (counter - 1) + "] == " + shabda[counter-1]);
//if( ! shabda[counter - 1].equals(null)){
else if( (shabda[counter - 1].toString()).equals("\u094d") )
{
if( varna.equals("a") )
{ shabda[--counter] = ""; }
else
{
shabda[--counter] = matra.get(varna);
counter++; // or shabda[(--counter)++]
}
}

else
{ shabda[counter++] = unicode.get(varna); }

} // end of else if is-Vowel

else if (unicode.containsKey(varna))
{
shabda[counter++] = unicode.get(varna);
}
else { shabda[counter++] = varna; }
} // end of for

for ( int j = 0; j < counter; j++ )
{
transformed += shabda[j];
}

return transformed; // return transformed;
}

}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
chetanpandey is offline Offline
2 posts
since Jul 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Dont want to display command window
Next Thread in Java Forum Timeline: Html





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC