1 29 38 39 package org.planetamessenger.mos.ui; 40 41 import javax.swing.*; 42 import javax.swing.event.*; 43 import javax.swing.text.*; 44 import javax.swing.text.html.*; 45 import org.planetamessenger.mos.engine.*; 46 import org.planetamessenger.mos.forms.JMOSSendMessageDlg; 47 import org.planetamessenger.plugin.*; 48 import org.planetamessenger.util.JTextUtil; 49 50 51 public class JTabContent extends java.awt.Container implements ChangeListener { 52 53 JMOSSendMessageDlg parent = null; 54 public JTextPane messageEdit = null; 55 public JScrollPane messagePane = null; 56 public JTextPane historyEdit = null; 57 public JScrollPane historyPane = null; 58 public JContactListItem ownerItem = null; 59 JSplitPane splitPane = null; 60 String strSelfAliasName = ""; 61 62 63 69 JTabContent( JMOSSendMessageDlg parent, JContactListItem ownerItem ) { 70 71 java.awt.GridBagConstraints constraints = new java.awt.GridBagConstraints (); 72 73 74 strSelfAliasName = JSharedObjects.getPluginEngine().get( ownerItem.getPluginId() ).getAliasName(); 75 messageEdit = new JTextPane(); 76 messagePane = new JScrollPane( messageEdit ); 77 historyEdit = new JTextPane(); 78 historyPane = new JScrollPane( historyEdit ); 79 splitPane = new JSplitPane( JSplitPane.VERTICAL_SPLIT, historyPane, messagePane ); 80 this.ownerItem = ownerItem; 81 this.parent = parent; 82 setLayout( new java.awt.GridBagLayout () ); 83 84 constraints.gridx = 0; 86 constraints.gridy = 0; 87 constraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 88 constraints.gridheight = 1; 89 constraints.weightx = 1.0; 90 constraints.weighty = 1.0; 91 constraints.fill = java.awt.GridBagConstraints.BOTH; 92 constraints.insets = new java.awt.Insets ( 1, 1, 1, 1 ); 93 add( splitPane, constraints ); 94 95 splitPane.setOneTouchExpandable( true ); 96 97 historyEdit.setFont( JSystemFonts.FONT ); 98 historyEdit.setEditable( false ); 99 historyEdit.setEditorKit( JEditorPane.createEditorKitForContentType( "text/html" ) ); 100 historyPane.setPreferredSize( new java.awt.Dimension ( 350, 90 ) ); 102 103 messageEdit.setFont( JSystemFonts.FONT ); 105 messageEdit.addKeyListener( new java.awt.event.KeyAdapter () { 106 public void keyReleased( java.awt.event.KeyEvent keyEvt ) { 107 processKey( keyEvt ); 108 } 109 } ); 110 messagePane.setPreferredSize( new java.awt.Dimension ( 350, 75 ) ); 111 } 112 113 118 public void addHistoryText() { 119 120 if( messageEdit.getText().compareTo( "" ) != 0 ) { 121 JButton sendButton = this.parent.getSendButton(); 122 HTMLDocument doc = ( HTMLDocument ) historyEdit.getDocument(); 123 HTMLEditorKit html = ( HTMLEditorKit ) historyEdit.getEditorKit(); 124 125 126 try { 127 html.insertHTML( 128 doc, doc.getLength(), 129 "<b>" + strSelfAliasName + ": </b>" + JTextUtil.encodeHtml( messageEdit.getText() ), 130 0, 0, null 131 ); 132 historyEdit.setCaretPosition( doc.getLength() ); 133 messageEdit.setText( "" ); 134 sendButton.setEnabled( false ); 135 messageEdit.requestFocus(); 136 } catch( BadLocationException e ) { 137 System.err.println( "JTabContent.addHistoryText() - " + e ); 138 } catch( java.io.IOException ioe ) { 139 System.err.println( "JTabContent.addHistoryText() - " + ioe ); 140 } 141 } 142 } 143 144 150 public void addHistoryText( String strText ) { 151 152 if( strText.compareTo( "" ) != 0 ) { 153 JButton sendButton = this.parent.getSendButton(); 154 HTMLDocument doc = ( HTMLDocument ) historyEdit.getDocument(); 155 HTMLEditorKit html = ( HTMLEditorKit ) historyEdit.getEditorKit(); 156 157 try { 158 html.insertHTML( doc, doc.getLength(), strText, 0, 0, null ); 159 historyEdit.setCaretPosition( doc.getLength() ); 160 } catch( BadLocationException e ) { 161 System.err.println( "JTabContent.addHistoryText( String ) - " + e ); 162 } catch( java.io.IOException ioe ) { 163 System.err.println( "JTabContent.addHistoryText( String ) - " + ioe ); 164 } 165 } 166 } 167 168 173 private void processKey( java.awt.event.KeyEvent keyEvt ) { 174 175 JButton sendButton = this.parent.getSendButton(); 176 177 if( messageEdit.getText().length() > 0 ) 178 sendButton.setEnabled( true ); 179 else 180 sendButton.setEnabled( false ); 181 } 182 183 188 public void stateChanged( ChangeEvent changeEvent ) { 189 190 JMessagePane messageTabs = this.parent.getTabbedMessagePane(); 191 192 if( !isShowing() ) 193 processKey( null ); 194 else 195 messageTabs.disableCurrentTabMessageIcon(); 196 } 197 } 198 199 | Popular Tags |