Caractères japonais, applet, JTextPane

nhfan Messages postés 3 Date d'inscription mercredi 28 avril 2004 Statut Membre Dernière intervention 12 mai 2004 - 28 avril 2004 à 12:49
cs_tds Messages postés 351 Date d'inscription mercredi 21 janvier 2004 Statut Membre Dernière intervention 9 décembre 2004 - 13 mai 2004 à 07:32
J'ai créé un Applet-Wysiwyg pour éditer des caractères japonais.
Cependant, le JTextPane m'affiche des carrés à la place.
On m'a conseillé d'associer une police spéciale au JTextPane,
alors j'ai rajouter dans la ma classe EkitCore.java :

import java.awt.*;
.
.
.
Font f = new Font("Arial",Plain,10);
monJTextPane.setFont(f);

et celà ne me résout pas le problème.
J'ai même renommer le fichier font.properties.ja en font.properties, mais hélas!!!!

3 réponses

cs_tds Messages postés 351 Date d'inscription mercredi 21 janvier 2004 Statut Membre Dernière intervention 9 décembre 2004
29 avril 2004 à 13:50
Oui, je vois, tu peux utiliser les caractères unicode...String tmp "\u215" > Affiche Le code unicode 215!
Si ca ne fonctionne pas, renseigne-toi sur sun.com car il y des milliers de japs qui font du java et qui parlent anglais :p

B@ron {EU.BELGIUM}
0
nhfan Messages postés 3 Date d'inscription mercredi 28 avril 2004 Statut Membre Dernière intervention 12 mai 2004
12 mai 2004 à 16:14
Salut tds, merci pour m'avoir répondu.
Mais dans quelle partie dois-je intégrer ce String unicode?
Please, jette un coup d'oeil sur une partie de ma classe qui concerne mon JTexpane :
J'suis complètement perdu dans mon Applet à présent, voici le code de ma classe EkitCore :

public class EkitCore extends JPanel implements ActionListener, DocumentListener
{
/* Components */
private JSplitPane jspltDisplay;
private JTextPane jtpMain;
private ExtendedHTMLEditorKit htmlKit;
private ExtendedHTMLDocument htmlDoc;
private StyleSheet styleSheet;
private JTextPane jtpSource;
private JScrollPane jspSource;

public EkitCore(String sDocument, String sStyleSheet, String sRawDocument,
URL urlStyleSheet, boolean showViewSource, boolean showMenuIcons,
boolean editModeExclusive, String sLanguage, String sCountry,
boolean debugMode, URL urlFilePaths, String sRootName,
String sFilePathDelimiter, String sDefaultTables, String sCustomText)
{
super();
exclusiveEdit = editModeExclusive;
frameHandler = new Frame();
// Temporary
String strRootName = sRootName;
String strFilePathDelimiter = sFilePathDelimiter;
/* Localise for language */
Locale baseLocale = (Locale)null;
if(sLanguage != null && sCountry != null)
{
baseLocale = new Locale(sLanguage, sCountry);
}
Translatrix.setLocale(baseLocale);
/* Create the editor kit, document, and stylesheet */
jtpMain = new JTextPane();
htmlKit = new ExtendedHTMLEditorKit();
htmlDoc = (ExtendedHTMLDocument)(htmlKit.createDefaultDocument());
styleSheet = htmlDoc.getStyleSheet();
htmlDoc. setPreservesUnknownTags(false);
htmlKit.setDefaultCursor(new Cursor(Cursor.TEXT_CURSOR))

/* Set up the text pane */
jtpMain.setEditorKit(htmlKit);
jtpMain.setDocument(htmlDoc);
jtpMain.setMargin(new Insets(4, 4, 4, 4));

/* Create the source text area */
jtpSource = new JTextPane();
jtpSource.setBackground(new Color(212, 212, 212));
jtpSource.setSelectionColor(new Color(255, 192, 192));
jtpSource.setText(jtpMain.getText());
jtpSource.getDocument().addDocumentListener(this);
/* Add CaretListener for tracking caret location events */
jtpMain.addCaretListener(new CaretListener()
{
public void caretUpdate(CaretEvent ce)
{
handleCaretPositionChange(ce);
}
});
/* Set up the undo features */
undoMngr = new UndoManager();
undoAction = new UndoAction();
redoAction = new RedoAction();
jtpMain.getDocument().addUndoableEditListener(new CustomUndoableEditListener());
/* Insert raw document, if exists */
if(sRawDocument != null && sRawDocument.length() > 0)
{
jtpMain.setText(sRawDocument);
}
jtpMain.setCaretPosition(0);
jtpMain.getDocument().addDocumentListener(this);
/* Import CSS from reference, if exists */
if(urlStyleSheet != null)
{
try
{
/* Set up the text pane */
jtpMain.setEditorKit(htmlKit);
jtpMain.setDocument(htmlDoc);
String currDocText = jtpMain.getText();
htmlDoc = (ExtendedHTMLDocument)(htmlKit.createDefaultDocument());
styleSheet = htmlDoc.getStyleSheet();
BufferedReader br = new BufferedReader(new InputStreamReader(urlStyleSheet.openStream()));
styleSheet.loadRules(br, urlStyleSheet);
br.close();
htmlDoc = new ExtendedHTMLDocument(styleSheet);
htmlDoc.setPreservesUnknownTags(false);
registerDocument(htmlDoc);
jtpMain.setText(currDocText);
jtpSource.setText(jtpMain.getText());
}
catch(Exception e)
{
e.printStackTrace(System.out);
}
}


/* Create the scroll area for the text pane */
JScrollPane jspViewport = new JScrollPane(jtpMain);
jspViewport.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jspViewport.setPreferredSize(new Dimension(600, 400));
jspViewport.setMinimumSize(new Dimension(32, 32));
/* Create the scroll area for the source viewer */
jspSource = new JScrollPane(jtpSource);
jspSource.setPreferredSize(new Dimension(450, 150));
jspSource.setMinimumSize(new Dimension(450, 150));
jspltDisplay = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
jspltDisplay.setTopComponent(jspViewport);
if(showViewSource)
{
jspltDisplay.setBottomComponent(jspSource);
}
else
{
jspltDisplay.setBottomComponent(null);
}
iSplitPos = jspltDisplay.getDividerLocation();
registerDocumentStyles();
/* Add the components to the app */
this.setLayout(new BorderLayout());
this.add(jspltDisplay, BorderLayout.CENTER);

else {
}
}
}
else if(command.equals("insertorderedlist"))
{
if(this.isInTag(HTML.Tag.P) &&
!this.isInTag(HTML.Tag.LI))
{
insertOrderedList();
}
}
else if(command.equals("insertunorderedlist"))
{
if(this.isInTag(HTML.Tag.P) &&
!this.isInTag(HTML.Tag.LI))
{
insertUnorderedList();
}
}
else if(command.equals("insertorderedlinelist"))
{
if(this.isInTag(HTML.Tag.P) &&
!this.isInTag(HTML.Tag.LI))
{
insertNewLineList(HTML.Tag.OL);
}
}
else if(command.equals("insertunorderedlinelist"))
{
if(this.isInTag(HTML.Tag.P) &&
!this.isInTag(HTML.Tag.LI))
{
insertNewLineList(HTML.Tag.UL);
}
}
else if(command.equals("indentlistitem"))
{
if(this.isInTag(HTML.Tag.OL) || this.isInTag(HTML.Tag.UL))
{
if(this.locateClosestParent(HTML.Tag.OL, HTML.Tag.UL).
getName().equalsIgnoreCase(HTML.Tag.OL.toString()))
{
indentListItem(HTML.Tag.OL);
}
else
{
indentListItem(HTML.Tag.UL);
}
}
}
else if(command.equals("justifylistitem"))
{
if(this.isInTag(HTML.Tag.OL) || this.isInTag(HTML.Tag.UL))
{
Element element = this.locateClosestParent(HTML.Tag.OL, HTML.Tag.UL);
Element elementParent = element.getParentElement();
if( element.getName().equalsIgnoreCase(HTML.Tag.UL.toString()) &&
(elementParent.getName().equalsIgnoreCase(HTML.Tag.OL.toString()) ||
elementParent.getName().equalsIgnoreCase(HTML.Tag.UL.toString())))
{
justifyListItem(HTML.Tag.UL);
}
else if( element.getName().equalsIgnoreCase(HTML.Tag.OL.toString()) &&
(elementParent.getName().equalsIgnoreCase(HTML.Tag.OL.toString()) ||
elementParent.getName().equalsIgnoreCase(HTML.Tag.UL.toString())))
{
justifyListItem(HTML.Tag.OL);
}
}
}
else if(command.equals("insertbreak"))
{
insertBreak();
}
else if(command.equals("insertnbsp"))
{
insertNonbreakingSpace();
}
}
catch(IOException ioe)
{
logException("IOException in actionPerformed method", ioe);
SimpleInfoDialog sidAbout = new SimpleInfoDialog(this.getFrame(), Translatrix.getTranslationString("Error"), true, Translatrix.getTranslationString("ErrorIOException"), SimpleInfoDialog.ERROR);
}
catch(BadLocationException ble)
{
logException("BadLocationException in actionPerformed method", ble);
SimpleInfoDialog sidAbout = new SimpleInfoDialog(this.getFrame(), Translatrix.getTranslationString("Error"), true, Translatrix.getTranslationString("ErrorBadLocationException"), SimpleInfoDialog.ERROR);
}
catch(NumberFormatException nfe)
{
logException("NumberFormatException in actionPerformed method", nfe);
SimpleInfoDialog sidAbout = new SimpleInfoDialog(this.getFrame(), Translatrix.getTranslationString("Error"), true, Translatrix.getTranslationString("ErrorNumberFormatException"), SimpleInfoDialog.ERROR);
}
catch(RuntimeException re)
{
logException("RuntimeException in actionPerformed method", re);
SimpleInfoDialog sidAbout = new SimpleInfoDialog(this.getFrame(), Translatrix.getTranslationString("Error"), true, Translatrix.getTranslationString("ErrorRuntimeException"), SimpleInfoDialog.ERROR);
}
}

int nFirstTag = -1;
int nLastTag = 0;
Element element = htmlDoc.getCharacterElement(cStart);
Element elementParent = element;
while(elementParent != null && !elementParent.getName().equalsIgnoreCase(HTML.Tag.HTML.toString()))
{
if(elementParent.getName().equalsIgnoreCase(HTML.Tag.P.toString()))
{
cStart = elementParent.getStartOffset() + 1;
if (noSelection) {
cEnd = elementParent.getEndOffset();
}
elementParent = elementParent.getParentElement();
for(int i=0; i < elementParent.getElementCount(); i++) {
element = elementParent.getElement(i);
if(cStart < element.getEndOffset() &&
element.getStartOffset() < cEnd)
{
if(nFirstTag < 0) {
nFirstTag = i;
}
nLastTag = i;
}
}
break;
}
else
{
elementParent = elementParent.getParentElement();
}
}
jtpMain.setCaretPosition(cStart);
TagParser tp = new TagParser(this);
tp.setRelativePath();
tp.setPathStringTag(elementParent.getName());
tp.setListItems( HTML.Tag.UL, nFirstTag, nLastTag);
tp.refresh();
jtpMain.setText(tp.toString());
resetCaret(cStart);
purgeUndos();
}
catch (Exception e) {
}
}


/** Convenience method for obtaining the JTextPane
*/
public JTextPane getTextPane()
{
return jtpMain;
}
0
cs_tds Messages postés 351 Date d'inscription mercredi 21 janvier 2004 Statut Membre Dernière intervention 9 décembre 2004
13 mai 2004 à 07:32
Il faudrait que tu subdivises en sous-méthodes, tu verrais + clair.

Je n'ai jamais fait cela et il y a surement + simple mais sinon, si tu sais que tu as stocké du japonais, tu peut parcourir la String et pour chaque caractère, tu prends son numéro Unicode et tu fais qqlc du genre:

for cpt 0 -> LONGUEUR DO
|
| num = code unicode de la lettre CPT de ta String
| Affiche caractère unicode(\u!!!!+code);
|
end for

B@ron {EU.BELGIUM}
0
Rejoignez-nous