Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Problem replacing DefaultStyledDocument with HTMLDocument in an Application

Posted on 2003-12-04
8
465 Views
Last Modified: 2008-02-01
Hi experts,

I'm trying to modify an application that uses JTextPane and DefaultStyledDocuments to implement an Editor.

I need to change the Documenttype from javax.swing.text.DefaultStyledDocument to
javax.swing.text.html.HTMLDocument in order to enhance the editor functionality.

As the documents that we want to edit are not being stored in files on a filesystem, but rather as a set of records in a database, we had to create a new kind of Document which now extends from the DefaultStyledDocument. so far so good ... everything works fine.

when i type a character the method "insertString(int offset, String str, AttributeSet a)" is being called, which we overload with our own database version, that calls the "super.insertString(...)" as well.

now when i change the DefaultStyledDocument to a HTMLDocument everything still works (more or less) .... then when i change the EditorKit to a HTMLEditorKit, the insertString(int offset, String str, AttributeSet a)"-Method is not being called anymore.

Typed text is still being inserted into the text area.... but our database-methods are no longer being called, as they are in the "insertString(...)"-Method that is never called anymore.

now my question : which method IS being called when i type a letter?? which method do i need to rewrite in order to hook my database calls in again everytime a letter is typed?

thanx for your help.

dominik

PS if this turn's out to be real tough one, i'm willing to increase points too.
0
Comment
Question by:dom_bus
8 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 9874312
Are you sure the HTMLDocument you created is being used and not one got from the kit?
0
 
LVL 3

Expert Comment

by:savalou
ID: 9874369
Maybe you should derive from HTMLEditorKit to override the createDefaultDocument() method (if that's how you are creating your document, but also to test whether it's being called).  You could also then override insertHTML() to see what's going on.  Trace the calls in a debugger.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9874420
Make sure the same relationships are preserved as in the following:

   JEditorPane ep = new JEditorPane();
   ep.setContentType("text/html");
   getContentPane().add(ep);
   MyDoc myDoc = new MyDoc();
   ep.setDocument(myDoc);
   EditorKit kit = ep.getEditorKit();
   try {
         kit.read(new StringReader("<HTML><BODY>Type in some text<BR></BODY></HTML>"), myDoc, 0);
   }
   catch(Exception e) {
         e.printStackTrace();
   }


................


class MyDoc extends HTMLDocument {
      public void insertString(int offset, String str, AttributeSet a) throws BadLocationException {
            System.out.println("Called insertStr!");
                super.insertString(offset, str, a);
        }
}

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 9874477
(i.e. the relationship between doc, kit and pane). The above works fine for me.
0
 
LVL 92

Expert Comment

by:objects
ID: 9876991
can you post the relevant parts of your code and we'll help sort out what your problems are.
0
 

Author Comment

by:dom_bus
ID: 11662557
sorry for not accepting this answer (together with the above post of CEHJ) earlier.

lost track of it as soon i finally had this and some other problems solved.

best regards & thanx again.

dom_bus
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11665365
8-)
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question