All Downloads are FREE. Search and download functionalities are using the official Maven repository.

editor.HtmlViewer Maven / Gradle / Ivy

There is a newer version: 1.18.1
Show newest version
package editor;

import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import java.net.URL;


/**
 * Extends the Java swing class JEditorPane to produce an HTML viewer.  The editor loads the Gosu class
 * as a stream.  This file also defines the CSS for the Studio Help.
 */
public class HtmlViewer extends JEditorPane
{

  public HtmlViewer()
  {
    super();

    setEditable( false );
    setContentType( "text/html" );
    setBorder( BorderFactory.createEmptyBorder() );

    addHyperlinkListener( new HyperlinkHandler() );
  }

  public void setText( String strText )
  {
    if( strText == null )
    {
      strText = "";
    }
    else if( !strText.startsWith( ""; */
      strText = "\n" +
                "\n" +
                "" +
                strText +
                "";
    }

    super.setText( strText );
  }

  class HyperlinkHandler implements HyperlinkListener
  {
    public void hyperlinkUpdate( HyperlinkEvent e )
    {
      if( e.getEventType() != HyperlinkEvent.EventType.ACTIVATED )
      {
        return;
      }

      URL url = e.getURL();
      if( url == null )
      {
        return;
      }
      String strProtocol = url.getProtocol();
      String strUrl = url.toString();

      if( strProtocol.equals( "gosu" ) )
      {
//        String strCmd = strUrl.substring( strUrl.indexOf( ':' ) + 1 );
//        ICommandShell shell = StudioApplication.instance().getCommandShell();
//        shell.invokeCommand( strCmd, null );
      }
      else
      {
        try
        {
          editor.util.EditorUtilities.browse( strUrl );
        }
        catch( Throwable t )
        {
          editor.util.EditorUtilities.handleUncaughtException( t );
        }
      }
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy