Package org.boco.seamwebappgen.gui

Source Code of org.boco.seamwebappgen.gui.DocumentationViewer

/***************************************************************************
*  Copyright (c) 2004 - 2008  Fabrizio Boco fabboco@users.sourceforge.net *
*                                                                         *
*                                                                         *
*   This is free software; you can redistribute it and/or                 *
*   modify it under the terms of the GNU Library General Public           *
*   License (version 2.1) as published by the Free Software Foundation    *
*                                                                         *
*   This library  is distributed in the hope that it will be useful,      *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU Library General Public License for more details.                  *
*                                                                         *
*   You should have received a copy of the GNU Library General Public     *
*   License along with this library; see the file COPYING.LIB. If not,    *
*   write to the Free Software Foundation, Inc., 59 Temple Place,         *
*   Suite 330, Boston, MA  02111-1307, USA                                *
*                                                                         *
***************************************************************************/
/**
- $Header: /usr/local/cvslocalrepository/SeamWebAppGenerator/src/org/boco/seamwebappgen/gui/Attic/DocumentationViewer.java,v 1.1.2.3 2008/04/22 05:37:57 fab Exp $
- $Author: fab $
- $Revision: 1.1.2.3 $
- $Date: 2008/04/22 05:37:57 $
- $Log: DocumentationViewer.java,v $
- Revision 1.1.2.3  2008/04/22 05:37:57  fab
- Aggiornamento indirizzo di posta
-
- Revision 1.1.2.2  2008/04/19 13:28:43  fab
- Modifiche varie per rafactoring
-
- Revision 1.1.2.1  2008/04/19 13:12:49  fab
- Modifiche varie per rafactoring
-
- Revision 1.1.2.1  2008/04/19 11:18:32  fab
- Refactoring
-
- Revision 1.1.2.4  2008/04/19 10:07:02  fab
- Aggiornamento riferimenti licenza
-
-
**/
package org.boco.seamwebappgen.gui;

import java.awt.Font;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.HeadlessException;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JScrollPane;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.plaf.FontUIResource;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLFrameHyperlinkEvent;

public class DocumentationViewer extends JDialog implements HyperlinkListener,
      ActionListener
{

  private static final long  serialVersionUID  = 1L;
  private JButton          bOk;
  private JScrollPane       jScrollPane1;
  private JEditorPane       jEditorPane1;

  public DocumentationViewer(Frame owner) throws HeadlessException
  {
    super(owner, true);

    initGUI();

    try
    {
      /**
       *
       * Se il generatore viene lanciato dall'ambiente di sviluppo
       *
       * **/     
      URL helpURL = new URL("file://"+System.getProperty ("user.dir")+"/javadoc/org/boco/seamwebappgen/annotations/package-summary.html");

      URL jarURL = getClass().getResource("");
      String jarName = jarURL.toExternalForm();

//      System.out.println("Jar Name " + jarName);

      int jarIdx = jarName.indexOf("!/org/boco/seamwebappgen/gui/");
     
      if (jarIdx != -1)
      {
        /**
         * L'applicazione è stata lanciata dal jar 
         *
         */
        String jarFileName = jarName.substring(0, jarIdx);

//        System.out.println("Jar Name " + jarFileName);

        helpURL = new URL(jarFileName + "!/javadoc/org/boco/seamwebappgen/annotations/package-summary.html");
      }
     
      jEditorPane1.setPage(helpURL);
      jEditorPane1.addHyperlinkListener(this);
           
      //Font font1 = new Font("Arial",Font.PLAIN,6);
      Font font1 = new Font("Serif", Font.ITALIC, 6);     
      jEditorPane1.setFont(font1);
     
    }
    catch (MalformedURLException e)
    {
      e.printStackTrace();
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }

  }

  private void initGUI()
  {
    try
    {
      GridBagLayout thisLayout = new GridBagLayout();
      this.setTitle("Help - Annotations Javadoc");
      thisLayout.rowWeights = new double[] {0.1, 0.1, 0.1, 0.0, 0.1};
      thisLayout.rowHeights = new int[] {7, 7, 7, 304, 7};
      thisLayout.columnWeights = new double[] {0.1, 0.1, 0.1};
      thisLayout.columnWidths = new int[] {7, 7, 7};
      getContentPane().setLayout(thisLayout);
      this.setPreferredSize(new java.awt.Dimension(800, 600));
      getContentPane().add(getBOk(), new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
      getContentPane().add(getJScrollPane1(), new GridBagConstraints(0, 0, 3, 4, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
      this.setSize(507, 349);
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }

  private JButton getBOk()
  {
    if (bOk == null)
    {
      bOk = new JButton();
      bOk.setText("Ok");
      bOk.addActionListener(this);
    }
    return bOk;
  }

  private JScrollPane getJScrollPane1()
  {
    if (jScrollPane1 == null)
    {
      jScrollPane1 = new JScrollPane();
      jScrollPane1.setViewportView(getJEditorPane1());
    }
    return jScrollPane1;
  }

  private JEditorPane getJEditorPane1()
  {
    if (jEditorPane1 == null)
    {
      jEditorPane1 = new JEditorPane();
      jEditorPane1.setText("jEditorPane1");
      jEditorPane1.setEditable(false);
    }
    return jEditorPane1;
  }

  public void actionPerformed(ActionEvent event)
  {
    if (event.getSource().equals(bOk))
    {
      this.dispose();
    }
  }

  public void hyperlinkUpdate(HyperlinkEvent e)
  {
    if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
    {
      JEditorPane pane = (JEditorPane) e.getSource();
      if (e instanceof HTMLFrameHyperlinkEvent)
      {
        HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) e;
        HTMLDocument doc = (HTMLDocument) pane.getDocument();
        doc.processHTMLFrameHyperlinkEvent(evt);
      }
      else
      {
        try
        {
          pane.setPage(e.getURL());
        }
        catch (Throwable t)
        {
          t.printStackTrace();
        }
      }
    }
  }

}
TOP

Related Classes of org.boco.seamwebappgen.gui.DocumentationViewer

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.