Package memory.chants

Source Code of memory.chants.JDialogTexteInformatif

package memory.chants;
import java.awt.Desktop;
import java.awt.Dimension;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkEvent.EventType;
import javax.swing.event.HyperlinkListener;

/**
* @author patrice
* Le Jdialog pour l'aide
*/
public class JDialogTexteInformatif extends JDialog implements HyperlinkListener
{
  /**
   * constructeur
   * @param fenetre  la fenêtre parent
   * @param titre    le titre du JDialog
   */
  public JDialogTexteInformatif(Fenetre fenetre, GestionDonnees gd, String titre)
  {
    //construction du JDialog modal
    super(fenetre,gd.getTxt("titreAide",0),true);
    //sa dimension
        this.setSize(new Dimension(800,500));
      //centre le JDialog
      this.setLocationRelativeTo(null);
      //l'aide sur le jeu dans un JEditorPane
      JEditorPane jep = new JEditorPane();
     
      jep.setEditable(false);
    jep.setContentType ( "text/html" )
    jep.setText ((titre.equals("titreAide") ? gd.getAide() : gd.getLicences()));
    jep.setCaretPosition(0);
    jep.addHyperlinkListener(this);
    this.add(new JScrollPane(jep));
      //rendre la fenêtre visible
      this.setVisible(true);
  }
 
  /**
   * un autre constructeur sans passage de la gestion de données. Le traitement lié à la langue
   * est effectué avant l'appel et se trouve dans le texte.
   * @param fenetre  la fenêtre parent du JDialog
   * @param titre    le titre de la fenêtre
   * @param texte    le texte affiché
   */
  public JDialogTexteInformatif(Fenetre fenetre, String titre, String texte)
  {
    //construction du JDialog modal
    super(fenetre, titre, true);
        this.setSize(new Dimension(800,500));
      //centre le JDialog
      this.setLocationRelativeTo(null);
      //le texte est affiché dans un JEditorPane
      JEditorPane jep = new JEditorPane();
      //qui n'est pas éditable
      jep.setEditable(false);
      //qui contient du html
    jep.setContentType ( "text/html" );
    //le texte du JeditorPane
    jep.setText (texte);
    //positionné au début
    jep.setCaretPosition(0);
    //il réagit aux liens hypertextes
    jep.addHyperlinkListener(this);
    //le JEditorPane est dans JScrollPane
    this.add(new JScrollPane(jep));
      //rendre la fenêtre visible
      this.setVisible(true);
  }

 
  @Override
  public void hyperlinkUpdate(HyperlinkEvent ev)
  {
    if (ev.getEventType() == EventType.ACTIVATED)
    {
      System.out.println(ev.getURL());
      try
      {
        URI uri = ev.getURL().toURI();
        if(Desktop.isDesktopSupported())
        {
          //Desktop supporté
          if(Desktop.getDesktop().isSupported(java.awt.Desktop.Action.BROWSE))
          {
            java.awt.Desktop.getDesktop().browse(uri);
          }
          else
          {
            JOptionPane.showMessageDialog(this, "Je ne parviens pas à ouvrir votre navigateur Internet.");
         
        }
        else
        {
          JOptionPane.showMessageDialog(this, "Je ne parviens pas à ouvrir votre navigateur Internet.");
        }

      }
      catch (URISyntaxException e)
      {
        e.printStackTrace();
      }
      catch (IOException e)
      {
        e.printStackTrace();
      }
    }
  }
 
  public static void main(String[] args)
  {
    final GestionDonnees gd = new GestionDonnees();
//    final String texte = gd.getInformations();
    final String texte = gd.getLicences();
    System.out.println(texte);

      javax.swing.SwingUtilities.invokeLater(new Runnable()
        {
      public void run()
            {
        new JDialogTexteInformatif(null,"sources",texte);
            }
        });
  }

}
TOP

Related Classes of memory.chants.JDialogTexteInformatif

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.