⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 instantmessagepanel.java

📁 100%Java编写及时报信工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package jim;

import java.awt.event.*;
import java.io.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import javax.swing.*;

/* Copyright, 2001 Jason Dominiczak.
 *
 * This file is part of JIM - The Java Instant Messenger.
 * eMailer is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.

 * JIM 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
 * General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with eMailer; see the file COPYING. If not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 * MA 02111-1307, USA.
 */
public class InstantMessagePanel extends JPanel {
	private JEditorPane ivjConversationText = null;
	private JPanel ivjJPanel1 = null;
	private JPanel ivjJPanel2 = null;
	private JPanel ivjJPanel3 = null;
	private JScrollPane ivjJScrollPane1 = null;
	private JScrollPane ivjJScrollPane2 = null;
	private JSplitPane ivjJSplitPane1 = null;
	private JToolBar ivjJToolBar1 = null;
	private JButton ivjSendButton = null;
	private JTextArea ivjSendingText = null;
	private PluginInterface pInterface;
	public java.lang.String fromField;
	public java.lang.String pluginField;
	public InstantMessage IMessage;
	IvjEventHandler ivjEventHandler = new IvjEventHandler();

class IvjEventHandler implements java.awt.event.ActionListener {
		public void actionPerformed(java.awt.event.ActionEvent e) {
			if (e.getSource() == InstantMessagePanel.this.getSendButton()) 
				connEtoC2(e);
		};
	};
/**
 * InstantMessagePanel constructor comment.
 */
public InstantMessagePanel() {
	super();
	initialize();
}
/**
 * InstantMessagePanel constructor comment.
 * @param layout java.awt.LayoutManager
 */
public InstantMessagePanel(java.awt.LayoutManager layout) {
	super(layout);
}
/**
 * InstantMessagePanel constructor comment.
 * @param layout java.awt.LayoutManager
 * @param isDoubleBuffered boolean
 */
public InstantMessagePanel(java.awt.LayoutManager layout, boolean isDoubleBuffered) {
	super(layout, isDoubleBuffered);
}
/**
 * Insert the method's description here.
 * Creation date: (10/15/2001 5:19:08 PM)
 * @param from java.lang.String
 * @param text java.lang.String
 * @param plInterface jim.PluginInterface
 */
public InstantMessagePanel(String from, String text, PluginInterface plInterface, InstantMessage imessage) 
{
	setPInterface(plInterface);
	getConversationText().setText(formatText(from, text));
	setFromField(from);
	if(plInterface!=null)
		setPluginField(plInterface.getTreeName());
	IMessage = imessage;
	initialize();
	}
/**
 * Insert the method's description here.
 * Creation date: (10/15/2001 5:19:08 PM)
 * @param from java.lang.String
 * @param text java.lang.String
 * @param plInterface jim.PluginInterface
 */
public InstantMessagePanel(String from, String text, PluginInterface plInterface, InstantMessage imessage, boolean iSent) 
{
	setPInterface(plInterface);
	if(iSent==false)
	{
		getConversationText().setText(formatText(from, text));
	}else{
		getConversationText().setText(formatText(plInterface.getSN(), text));
	}
	
	
	setFromField(from);
	if(plInterface!=null)
		setPluginField(plInterface.getTreeName());
	IMessage = imessage;
	initialize();
	}
/**
 * InstantMessagePanel constructor comment.
 * @param isDoubleBuffered boolean
 */
public InstantMessagePanel(boolean isDoubleBuffered) {
	super(isDoubleBuffered);
}
/**
 * Insert the method's description here.
 * Creation date: (10/15/2001 6:23:07 PM)
 * @param from java.lang.String
 * @param text java.lang.String
 */
public void addtlMessage(String from, String text) {
	/*
	String FormattedText = formatText(from, text);
	//String FinalText = new String("\n" + getConversationText().getText() + FormattedText);
	//getConversationText().setText(FinalText);
	//getConversationText().append(FormattedText);
	String FinalText = new String(getConversationText().getText() + FormattedText);
	getConversationText().setText(FinalText);
	getConversationText().setCaretPosition(FinalText.length());
	*/
	HTMLEditorKit kit = (HTMLEditorKit)getConversationText().getEditorKit();
		Document doc = getConversationText().getDocument();
		int start = getConversationText().getDocument().getLength();
		int length = text.length();
									
        try 
        {        	        				
			kit.read(new java.io.StringReader(formatText(from, text)), doc, start);
			//kit.read(new java.io.StringReader(new String("<html><body>hi</body></html>")), doc, start);
		}
  		catch( IOException e ) 
  		{ 
        	System.err.println( e.toString() );
        }					
  		catch( BadLocationException bl ) 
  		{ 
        	System.err.println( bl );
      	}
  		getConversationText().getCaret().setDot( getConversationText().getText().length() );
		getJScrollPane1().scrollRectToVisible(getConversationText().getVisibleRect() );
	}	
/**
 * connEtoC2:  (SendButton.action.actionPerformed(java.awt.event.ActionEvent) --> InstantMessagePanel.sendMessage()V)
 * @param arg1 java.awt.event.ActionEvent
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void connEtoC2(java.awt.event.ActionEvent arg1) {
	try {
		// user code begin {1}
		// user code end
		this.sendMessage();
		// user code begin {2}
		// user code end
	} catch (java.lang.Throwable ivjExc) {
		// user code begin {3}
		// user code end
		handleException(ivjExc);
	}
}
/**
 * Insert the method's description here.
 * Creation date: (11/18/2001 12:55:28 PM)
 * @return java.lang.String
 * @param From java.lang.String
 */
public String formatFrom(String From) {
	String Output = new String();
	if(From.equalsIgnoreCase(pInterface.getSN()))
	{
		Output=new String("<font color=\"#FF0000\">" + From + "</font>");
	} else {
		Output=new String("<font color=\"#0000FF\">" + From + "</font>");
	}
	
	return Output;
}
/**
 * Insert the method's description here.
 * Creation date: (10/15/2001 5:22:02 PM)
 * @param From java.lang.String
 * @param Text java.lang.String
 */
public String formatText(String From, String Text) {
    String GoodText = new String();
    if(getPInterface().getSN()!=From)
    {
	    int templen = Text.length() - 13;
	    char[] temparry = new char[templen];
	    Text.getChars(6, (Text.length() - 7), temparry, 0);
	    GoodText= new String(temparry);
    } else{
		GoodText=Text;
    }
    String output = new String("<HTML>" + formatFrom(From) + ": " + GoodText + "</HTML>");
    return output;
}
/**
 * Insert the method's description here.
 * Creation date: (10/15/2001 5:30:09 PM)
 * @return java.lang.String[]
 */
public String[] getConversationInfo() {
	String[] output = new String[2];
	output[0] = getFromField();
	output[1] = getPluginField();
	return output;
}
/**
 * Return the ConversationText property value.
 * @return javax.swing.JEditorPane
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JEditorPane getConversationText() {
	if (ivjConversationText == null) {
		try {
			ivjConversationText = new javax.swing.JEditorPane();
			ivjConversationText.setName("ConversationText");
			ivjConversationText.setPreferredSize(new java.awt.Dimension(300, 90));
			ivjConversationText.setDocument(new javax.swing.text.PlainDocument());
			ivjConversationText.setBounds(0, 0, 6, 18);
			ivjConversationText.setEditable(false);
			ivjConversationText.setMinimumSize(new java.awt.Dimension(334, 100));
			// user code begin {1}
			ivjConversationText.setContentType("text/html");
			// user code end
		} catch (java.lang.Throwable ivjExc) {
			// user code begin {2}
			// user code end
			handleException(ivjExc);
		}
	}
	return ivjConversationText;
}
/**
 * Insert the method's description here.
 * Creation date: (10/15/2001 5:30:31 PM)
 * @return java.lang.String
 */
public java.lang.String getFromField() {
	return fromField;
}
/**
 * Return the JPanel1 property value.
 * @return javax.swing.JPanel
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JPanel getJPanel1() {
	if (ivjJPanel1 == null) {
		try {
			ivjJPanel1 = new javax.swing.JPanel();
			ivjJPanel1.setName("JPanel1");
			ivjJPanel1.setPreferredSize(new java.awt.Dimension(3, 75));
			ivjJPanel1.setLayout(new java.awt.BorderLayout());
			getJPanel1().add(getJScrollPane1(), "Center");
			// user code begin {1}
			// user code end
		} catch (java.lang.Throwable ivjExc) {
			// user code begin {2}
			// user code end
			handleException(ivjExc);
		}
	}
	return ivjJPanel1;
}
/**
 * Return the JPanel2 property value.
 * @return javax.swing.JPanel
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JPanel getJPanel2() {
	if (ivjJPanel2 == null) {
		try {
			ivjJPanel2 = new javax.swing.JPanel();
			ivjJPanel2.setName("JPanel2");
			ivjJPanel2.setLayout(new java.awt.BorderLayout());
			getJPanel2().add(getJPanel3(), "South");
			getJPanel2().add(getJScrollPane2(), "Center");
			// user code begin {1}
			// user code end
		} catch (java.lang.Throwable ivjExc) {
			// user code begin {2}
			// user code end
			handleException(ivjExc);
		}
	}
	return ivjJPanel2;
}
/**
 * Return the JPanel3 property value.
 * @return javax.swing.JPanel
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private javax.swing.JPanel getJPanel3() {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -