Probleme avec JEditorPane HTML impression

oleronpower Messages postés 20 Date d'inscription lundi 19 septembre 2005 Statut Membre Dernière intervention 29 juin 2009 - 29 mai 2008 à 15:55
oleronpower Messages postés 20 Date d'inscription lundi 19 septembre 2005 Statut Membre Dernière intervention 29 juin 2009 - 5 juin 2008 à 10:30
Bonjour à tous,

J'ai un petit probleme avec JEditorPane, je n'arrive pas a savoir quand la page html est complétement chargée, conséquence les impressions se lancent et les images manquent ou sont coupées au milieux.

Existe t'il une methode (onNavigated ou onCompleted comme pour un twebbrowser en csharp) sur ce composant pour savoir si le chargement de la page est achevé.

Merci d'avance

7 réponses

Ombitious_Developper Messages postés 2333 Date d'inscription samedi 28 février 2004 Statut Membre Dernière intervention 26 juillet 2013 38
29 mai 2008 à 22:27
Salut:

Voici ce que dit la documentation:

This may load either synchronously or asynchronously
depending upon the document returned by the
EditorKit
.
If the
Document
is of type
AbstractDocument
and has a value returned by
AbstractDocument.getAsynchronousLoadPriority

that is greater than or equal to zero, the page will be
loaded on a separate thread using that priority.

If the document is loaded synchronously, it will be
filled in with the stream prior to being installed into
the editor with a call to
setDocument
, which
is bound and will fire a property change event. If an
IOException
is thrown the partially loaded
document will
be discarded and neither the document or page property
change events will be fired. If the document is
successfully loaded and installed, a view will be
built for it by the UI which will then be scrolled if
necessary, and then the page property change event
will be fired.



If the document is loaded asynchronously, the document
will be installed into the editor immediately using a
call to
setDocument
which will fire a
document property change event, then a thread will be
created which will begin doing the actual loading.
In this case, the page property change event will not be
fired by the call to this method directly, but rather will be
fired when the thread doing the loading has finished.
Since the calling thread can not throw an
IOException

in the event of failure on the other thread, the page
property change event will be fired when the other
thread is done whether the load was successful or not.

Si on résume tout ça, tu dois implémenter un PropertyChangeListener comme ceci:

public class Browser extends JFrame implements PropertyChangeListener {

    public Browser() throws IOException {
        super("Browser");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(500, 500);
       
        JEditorPane editor = new JEditorPane();
        editor.setPreferredSize(new Dimension(500, 500));
        editor.setPage("http://www.google.com/");
        editor.addPropertyChangeListener(this);
       
        getContentPane().add(editor);
        pack();
    }
   
    public static void main(String[] args) throws IOException {
        Browser b = new Browser ();
        b.setVisible(true);
    }

    @Override
    public void propertyChange(PropertyChangeEvent evt) {
        String propertyName = evt.getPropertyName();
        if (propertyName.equals("page")) {
            System.out.println("The HTML page is loaded ...");
        }
    }
}

J'ai listé toutes les propriétés qui ont changé pendant le chargement de la page, et j'ai fini par trouvé que c'est la propriété page qui est modifiée lorsque la page est complétement chargée.
0
oleronpower Messages postés 20 Date d'inscription lundi 19 septembre 2005 Statut Membre Dernière intervention 29 juin 2009
2 juin 2008 à 17:34
J'avais mm pas vu que tu avais posté une réponse, le jour de mon anniversaire, j'aurais du y penser....

MErci en tout cas, je teste cela demain, merci bcp
0
Ombitious_Developper Messages postés 2333 Date d'inscription samedi 28 février 2004 Statut Membre Dernière intervention 26 juillet 2013 38
2 juin 2008 à 23:12
Salut:

Joyeux anniversaire.
0
oleronpower Messages postés 20 Date d'inscription lundi 19 septembre 2005 Statut Membre Dernière intervention 29 juin 2009
3 juin 2008 à 15:45
J'ai testé, mais cela ne fonctionne toujours pas...

J4ai toujours le mm probleme, cependant, vu ke je débute en Java, j'ai peut etre tout faux:

j'ai ajouté la method
comme ceci

public class Ready implements PropertyChangeListener{
     public void propertyChange(PropertyChangeEvent evt) {
            String propertyName = evt.getPropertyName();
            if (propertyName.equals("page")) {
                             
               System.out.println("Chargement OK lancement de l'impression");
                //Quand je rentre ici en débugage toute les images ne sont pas chargée
                //Ici je lance l'impression ou j'ai mm essayé de mettre a jour un variable que je testais dams                     //mon main
                }
                catch(Exception E)
                {
                    System.out.println("Erreur de Wait:"+E.getMessage());
                }
                System.out.println("Fin de l'impression");
            }
     }
    }

//Main

private Ready ready=new Ready();

JEditorPane  navigateur;
navigateur = new JEditorPane("http://www.yahoo.com");
navigateur .addPropertyChangeListener(ready);

//ici boucle avec recherche et parcours de toutes mes pages html
    nouvelleURL =xxxxxxx;
    navigateur.setPage(nouvelle_URL);

C'est peut etre une autre propriété que page pour annoncer que la page est complétement chargée? Car en pmettant un systeme de varable a jour j'ai vu que la page etait vu comme carchée et que les image n'etais pas toute chargée, il y a quoi comme autre propriété?

ps: j'espère que c'est clair ce que j'ecris?
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Ombitious_Developper Messages postés 2333 Date d'inscription samedi 28 février 2004 Statut Membre Dernière intervention 26 juillet 2013 38
3 juin 2008 à 20:33
Salut:

Dans mon code, j'ai implémenter le pattern [Observer] dont le plus grand interêt est le fait que les écouteurs d'un éventuel évenement ne sont pas mis à l'écoute active mais ils seront notifiés dès qu'un événement se passe.

try {
        // Début du chargement de la page
        JEditorPanel editorPane = ...;
        System.out.println("Loading page ...");

        // Pourquoi avoir remplacer l'URL de Google par celle de Yahoo
        // Je suis fan des technologies de Google
        editorPane.setPage("http://www.google.com/");
} catch (IOException e) {
        System.out.println("Error when loading the HTML page : " + e.getMessage());
}

@Override
public void propertyChange(PropertyChangeEvent evt) {
        String propertyName = evt.getPropertyName();
        if (propertyName.equals("page")) {
            System.out.println("The HTML page is loaded ...");
        }
}
0
oleronpower Messages postés 20 Date d'inscription lundi 19 septembre 2005 Statut Membre Dernière intervention 29 juin 2009
4 juin 2008 à 10:41
Ok je vais suivre ton conseil et implementer ton pattern observer et non plus ajouter un listener, je te tiens au courant si cela change tout, j'espère...

Un grand merci en tout cas, et désolé pour avoir fait mes test en chargeant une page yahoo...
0
oleronpower Messages postés 20 Date d'inscription lundi 19 septembre 2005 Statut Membre Dernière intervention 29 juin 2009
5 juin 2008 à 10:30
Non ca ne marche toujours pas, je n'ai que des moitiées d'image ou une petite icone (style image non trouvée)
0
Rejoignez-nous