JEditorPane Display Errors

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2005
Posts: 2
Reputation: chetanpandey is an unknown quantity at this point 
Solved Threads: 0
chetanpandey chetanpandey is offline Offline
Newbie Poster

JEditorPane Display Errors

 
0
  #1
Jul 6th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: JEditorPane Display Errors

 
0
  #2
Jul 7th, 2005
How exactly are you converting to unicode? This can cause problems if you accidently mess up in the range of values.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 2
Reputation: chetanpandey is an unknown quantity at this point 
Solved Threads: 0
chetanpandey chetanpandey is offline Offline
Newbie Poster

Re: JEditorPane Display Errors

 
0
  #3
Jul 7th, 2005
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;
}

}
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC