001 package com.croftsoft.apps.agoracast.c2p; 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.text.*; 010 import javax.swing.text.html.*; 011 012 import com.croftsoft.core.gui.GuiCreator; 013 import com.croftsoft.core.gui.LogPanel; 014 import com.croftsoft.core.gui.PairsPanel; 015 import com.croftsoft.core.jnlp.JnlpProxy; 016 import com.croftsoft.core.lang.NullArgumentException; 017 import com.croftsoft.core.lang.ObjectLib; 018 import com.croftsoft.core.lang.Pair; 019 import com.croftsoft.core.util.pubsub.Subscriber; 020 021 /********************************************************************* 022 * Main Agoracast GUI panel. 023 * 024 * <p /> 025 * 026 * @version 027 * 2002-02-03 028 * @since 029 * 2001-07-06 030 * @author 031 * <a href="https://www.croftsoft.com/">David Wallace Croft</a> 032 *********************************************************************/ 033 034 public final class AgoracastPanel 035 extends JPanel 036 implements AgoracastConstants, HyperlinkListener 037 ////////////////////////////////////////////////////////////////////// 038 ////////////////////////////////////////////////////////////////////// 039 { 040 041 private final AgoracastMediator agoracastMediator; 042 043 private final PairsPanel configPairsPanel; 044 045 ////////////////////////////////////////////////////////////////////// 046 ////////////////////////////////////////////////////////////////////// 047 048 public AgoracastPanel ( 049 AgoracastMediator agoracastMediator, 050 String documentationText, 051 Frame parentFrame ) 052 ////////////////////////////////////////////////////////////////////// 053 { 054 super ( new BorderLayout ( ), true ); // isDoubleBuffered 055 056 NullArgumentException.check ( 057 this.agoracastMediator = agoracastMediator ); 058 059 AgoracastLib.setColor ( this, agoracastMediator ); 060 061 Color panelBackgroundColor 062 = agoracastMediator.getPanelBackgroundColor ( ); 063 064 Color textFieldBackgroundColor 065 = agoracastMediator.getTextFieldBackgroundColor ( ); 066 067 /* 068 JMenuBar jMenuBar = new JMenuBar ( ); 069 070 jMenuBar.add ( new JMenu ( "About" ) ); 071 072 add ( jMenuBar, BorderLayout.NORTH ); 073 */ 074 075 JTabbedPane jTabbedPane = new JTabbedPane ( ); 076 077 configPairsPanel = new PairsPanel ( 078 createConfigPairs ( ), 079 AgoracastConstants.CONFIG_HELP_TEXT, 080 new ChangeListener ( ) 081 { 082 public void stateChanged ( ChangeEvent changeEvent ) 083 { 084 handleConfigUpdate ( ); 085 } 086 }, 087 true, 088 panelBackgroundColor, 089 textFieldBackgroundColor ); 090 091 final JEditorPane jEditorPane 092 = GuiCreator.createHtmlPane ( documentationText, this ); 093 094 new Thread ( 095 new Runnable ( ) 096 { 097 public void run ( ) 098 { 099 try 100 { 101 URL documentationURL = new URL ( DOCUMENTATION_URL ); 102 103 jEditorPane.setPage ( documentationURL ); 104 } 105 catch ( Exception ex ) 106 { 107 ex.printStackTrace ( ); 108 } 109 } 110 } ).start ( ); 111 112 jTabbedPane.addTab ( 113 "Documentation", new JScrollPane ( jEditorPane ) ); 114 115 jTabbedPane.addTab ( "Configuration", configPairsPanel ); 116 117 jTabbedPane.addTab ( "Browse", 118 new AgoracastBrowsePanel ( agoracastMediator ) ); 119 120 jTabbedPane.addTab ( "Defaults", 121 new AgoracastDefaultsPanel ( agoracastMediator ) ); 122 123 jTabbedPane.addTab ( "Post", 124 new AgoracastPostPanel ( agoracastMediator ) ); 125 126 AgoracastLogPanel agoracastLogPanel = new AgoracastLogPanel ( 127 agoracastMediator, LOG_TEXT_LENGTH_MAX, panelBackgroundColor ); 128 129 jTabbedPane.addTab ( "Log", new JScrollPane ( agoracastLogPanel ) ); 130 131 add ( jTabbedPane, BorderLayout.CENTER ); 132 133 agoracastMediator.setJTabbedPane ( jTabbedPane ); 134 135 agoracastMediator.setTabEnabled ( TAB_INDEX_LOG, false ); 136 137 agoracastMediator.setLog ( agoracastLogPanel ); 138 } 139 140 ////////////////////////////////////////////////////////////////////// 141 ////////////////////////////////////////////////////////////////////// 142 143 public synchronized void hyperlinkUpdate ( HyperlinkEvent e ) 144 ////////////////////////////////////////////////////////////////////// 145 { 146 try 147 { 148 if ( e.getEventType ( ) == HyperlinkEvent.EventType.ACTIVATED ) 149 { 150 JEditorPane jEditorPane = ( JEditorPane ) e.getSource ( ); 151 152 if ( e instanceof HTMLFrameHyperlinkEvent ) 153 { 154 HTMLDocument htmlDocument 155 = ( HTMLDocument ) jEditorPane.getDocument ( ); 156 157 htmlDocument.processHTMLFrameHyperlinkEvent ( 158 ( HTMLFrameHyperlinkEvent ) e ); 159 } 160 else 161 { 162 URL url = e.getURL ( ); 163 164 if ( !JnlpProxy.showDocument ( url ) ) 165 { 166 System.out.println ( url ); 167 } 168 } 169 } 170 } 171 catch ( Exception ex ) 172 { 173 agoracastMediator.getLog ( ).record ( ex ); 174 } 175 } 176 177 ////////////////////////////////////////////////////////////////////// 178 ////////////////////////////////////////////////////////////////////// 179 180 public synchronized void handleConfigUpdate ( ) 181 ////////////////////////////////////////////////////////////////////// 182 { 183 String email = configPairsPanel.getText ( CONFIG_EMAIL ); 184 185 String server = configPairsPanel.getText ( CONFIG_SERVER ); 186 187 String username = configPairsPanel.getText ( CONFIG_USERNAME ); 188 189 String newsgroup = configPairsPanel.getText ( CONFIG_NEWSGROUP ); 190 191 agoracastMediator.setEmail ( email ); 192 193 agoracastMediator.setServer ( server ); 194 195 agoracastMediator.setUsername ( username ); 196 197 agoracastMediator.setNewsgroup ( newsgroup ); 198 199 configPairsPanel.setText ( createConfigPairs ( ) ); 200 } 201 202 ////////////////////////////////////////////////////////////////////// 203 ////////////////////////////////////////////////////////////////////// 204 205 private Pair [ ] createConfigPairs ( ) 206 ////////////////////////////////////////////////////////////////////// 207 { 208 return new Pair [ ] 209 { 210 new Pair ( CONFIG_SERVER , agoracastMediator.getServer ( ) ), 211 new Pair ( CONFIG_EMAIL , agoracastMediator.getEmail ( ) ), 212 new Pair ( CONFIG_USERNAME , agoracastMediator.getUsername ( ) ), 213 new Pair ( CONFIG_NEWSGROUP, agoracastMediator.getNewsgroup ( ) ) 214 }; 215 } 216 217 ////////////////////////////////////////////////////////////////////// 218 ////////////////////////////////////////////////////////////////////// 219 }