001 package com.croftsoft.core.gui;
002
003 import java.awt.*;
004 import java.awt.event.*;
005 import java.io.*;
006 import java.net.*;
007 import javax.swing.*;
008 import javax.swing.event.*;
009 import javax.swing.border.*;
010
011 import com.croftsoft.core.lang.NullArgumentException;
012
013 /*********************************************************************
014 * Creates pre-configured GUI widgets.
015 *
016 * <p>
017 * Useful for instantiating GUI widgets without creating a subclass.
018 * </p>
019 *
020 * @version
021 * 2001-09-21
022 * @since
023 * 2001-07-29
024 * @author
025 * <a href="https://www.croftsoft.com/">David Wallace Croft</a>
026 *********************************************************************/
027
028 public final class GuiCreator
029 //////////////////////////////////////////////////////////////////////
030 //////////////////////////////////////////////////////////////////////
031 {
032
033 /*********************************************************************
034 * Creates a JEditorPane for displaying HTML text.
035 *
036 * <p>
037 * The pane in non-editable and the caret position is set to zero.
038 * </p>
039 *
040 * <p>
041 * <b>Reference:</b><br />
042 * Kim Topley,
043 * <a target="_blank" href=
044 * "http://www.amazon.com/exec/obidos/ASIN/0130832928/croftsoft-20">
045 * Core Swing: Advanced Programming</a>,
046 * 2000,
047 * Chapter 4 "JEditorPane and the Swing HTML Package",
048 * Section "Hypertext Links",
049 * p476.
050 * </p>
051 *
052 * @param hyperlinkListener
053 *
054 * May be null.
055 *
056 *********************************************************************/
057 public static JEditorPane createHtmlPane (
058 String html,
059 HyperlinkListener hyperlinkListener )
060 //////////////////////////////////////////////////////////////////////
061 {
062 JEditorPane jEditorPane = new JEditorPane ( "text/html", html );
063
064 jEditorPane.setEditable ( false );
065
066 jEditorPane.setCaretPosition ( 0 );
067
068 if ( hyperlinkListener != null )
069 {
070 jEditorPane.addHyperlinkListener ( hyperlinkListener );
071 }
072
073 return jEditorPane;
074 }
075
076 /*********************************************************************
077 * Creates a JEditorPane for displaying HTML text.
078 *
079 * <p>
080 * The pane in non-editable and the caret position is set to zero.
081 * </p>
082 *
083 * <p>
084 * <b>Reference:</b><br />
085 * Kim Topley,
086 * <a target="_blank" href=
087 * "http://www.amazon.com/exec/obidos/ASIN/0130832928/croftsoft-20">
088 * Core Swing: Advanced Programming</a>,
089 * 2000,
090 * Chapter 4 "JEditorPane and the Swing HTML Package",
091 * Section "Hypertext Links",
092 * p476.
093 * </p>
094 *
095 * @param hyperlinkListener
096 *
097 * May be null.
098 *
099 * @throws IOException
100 *
101 * If URL is null or cannot be accessed.
102 *********************************************************************/
103 public static JEditorPane createHtmlPane (
104 URL initialPage,
105 HyperlinkListener hyperlinkListener )
106 throws IOException
107 //////////////////////////////////////////////////////////////////////
108 {
109 JEditorPane jEditorPane = new JEditorPane ( initialPage );
110
111 jEditorPane.setEditable ( false );
112
113 jEditorPane.setCaretPosition ( 0 );
114
115 if ( hyperlinkListener != null )
116 {
117 jEditorPane.addHyperlinkListener ( hyperlinkListener );
118 }
119
120 return jEditorPane;
121 }
122
123 //////////////////////////////////////////////////////////////////////
124 //////////////////////////////////////////////////////////////////////
125
126 private GuiCreator ( ) { }
127
128 //////////////////////////////////////////////////////////////////////
129 //////////////////////////////////////////////////////////////////////
130 }