home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 77 / IOPROG_77.ISO / tips / Java / Visualizzare un RTF in una pagina Web tramite Java / RTFView.java < prev   
Encoding:
Java Source  |  2003-12-19  |  2.3 KB  |  96 lines

  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.applet.*;
  4. import javax.swing.*;
  5. import javax.swing.text.*;
  6. import javax.swing.text.rtf.*;
  7.  
  8. /**
  9.  * <p>Titolo: RTFView</p>
  10.  * <p>Descrizione: Visualizza RTF in pagine Web</p>
  11.  * @author Gianluca Esposito (giaesp@tiscali.it)
  12.  * @version 0.11.17.03
  13.  */
  14.  
  15. public class RTFView
  16.     extends JApplet {
  17.  
  18.   private boolean isStandalone = false;
  19.   JScrollPane rtfScroller = new JScrollPane();
  20.   JTextPane rtfPane = new JTextPane();
  21.  
  22.   String RTFText;
  23.   int bground;
  24.  
  25.   public String getParameter(String key, String def) {
  26.     return isStandalone ? System.getProperty(key, def) :
  27.         (getParameter(key) != null ? getParameter(key) : def);
  28.   }
  29.  
  30.   public RTFView() {
  31.   }
  32.  
  33.   public void init() {
  34.     try {
  35.       RTFText = this.getParameter("RTF",
  36.                                   "Nessuna informazione da visualizzare.");
  37.     }
  38.     catch (Exception e) {
  39.       e.printStackTrace();
  40.     }
  41.     try {
  42.       bground = Integer.parseInt(this.getParameter("bground", "FFFFFF"), 16);
  43.     }
  44.     catch (Exception e) {
  45.       e.printStackTrace();
  46.     }
  47.     try {
  48.       jbInit();
  49.     }
  50.     catch (Exception e) {
  51.       e.printStackTrace();
  52.     }
  53.   }
  54.  
  55.   private void jbInit() throws Exception {
  56.     // this.setSize(new Dimension(width,height));
  57.     rtfPane.setEditorKit(new RTFEditorKit());
  58.     rtfPane.setEditable(false);
  59.     rtfPane.setCaretPosition(0);
  60.     rtfPane.setText(RTFText); // Inserimento del testo RTF
  61.     this.getContentPane().add(rtfScroller, BorderLayout.CENTER);
  62.     rtfScroller.getViewport().add(rtfPane, null);
  63.     rtfPane.setBackground(new Color(bground));
  64.     rtfScroller.setBackground(new Color(bground));
  65.     this.setVisible(true);
  66.   }
  67.  
  68.   public void start() {
  69.   }
  70.  
  71.   public void stop() {
  72.   }
  73.  
  74.   public void destroy() {
  75.   }
  76.  
  77.   public String getAppletInfo() {
  78.     return "RTFView 0.11.17.03 (Gianluca Esposito - giaesp@tiscali.it)";
  79.   }
  80.  
  81.   public String[][] getParameterInfo() {
  82.     String[][] pinfo = {
  83.         { "RTF", "String", "Corpo dell'RTF"},
  84.         { "bground", "hex int", "Colore di sfondo - Inserire sequenza esadecimale (come nell'HTML, ma senza \"#\")"},
  85.     };
  86.     return pinfo;
  87.   }
  88.  
  89.   static {
  90.     try {
  91.       UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  92.     }
  93.     catch (Exception e) {
  94.     }
  95.   }
  96. }