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

📄 chatview.java

📁 mywork是rcp开发的很好的例子
💻 JAVA
字号:
package net.sf.p2pim;import java.text.SimpleDateFormat;import net.jxta.myjxta.MyJXTA;import net.jxta.myjxta.ViewFactory;import net.jxta.myjxta.dialog.Dialog;import net.jxta.myjxta.dialog.DialogListener;import net.jxta.myjxta.dialog.DialogMessage;import net.jxta.myjxta.plugin.PluginView;import net.jxta.pipe.PipeService;import net.sf.component.config.ConfigHelper;import net.sf.component.simplenote.SimpleNote;import net.sf.util.StringUtil;import org.eclipse.jface.layout.GridDataFactory;import org.eclipse.jface.resource.ImageDescriptor;import org.eclipse.jface.resource.JFaceResources;import org.eclipse.swt.SWT;import org.eclipse.swt.events.SelectionAdapter;import org.eclipse.swt.events.SelectionEvent;import org.eclipse.swt.layout.GridLayout;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Display;import org.eclipse.ui.part.ViewPart;public class ChatView extends ViewPart implements DialogListener,PluginView{	public static final String ID = "MyWork_p2pim.view";	private ImageDescriptor img_unread;	private ImageDescriptor img_default;	private SimpleNote note; //对话信息	private ChatNote chat; //对话录入框	private Dialog dialog; //myjxta的对话机制		public void createPartControl(Composite parent) {		img_unread=P2PActivator.getImageDescriptor("icons/unread.gif");		img_default=P2PActivator.getImageDescriptor("icons/messages.gif");		Composite top = new Composite(parent, SWT.NONE);		GridLayout layout = new GridLayout();		layout.marginHeight = 0;		layout.marginWidth = 0;		layout.verticalSpacing=0;		top.setLayout(layout);			note = new SimpleNote(top,SWT.READ_ONLY|SWT.WRAP | SWT.V_SCROLL);		note.setBasePath(ConfigHelper.getDataHome());		GridDataFactory.fillDefaults().grab(true, true).applyTo(note);		chat=new ChatNote(top,SWT.NULL);		GridDataFactory.fillDefaults().hint(100, 120).grab(true, false).applyTo(chat);		chat.addSendListender(new SelectionAdapter(){			public void widgetSelected(SelectionEvent e) {				if(StringUtil.isNotNull(chat.getSimpleNote().getText())){					dialog.dispatch(chat.getSimpleNote().getText());					chat.getSimpleNote().setText("");				}			}		});	}	public void setFocus() {		this.setTitleImage(img_default.createImage(this.getViewSite().getShell().getDisplay()));	}	public void receive(final DialogMessage msg) {		Display.getDefault().asyncExec(new Runnable(){			public void run() {		        if( !StringUtil.isNull(msg.getHtmlMessage())) {		        	note.appendHtml(convertMessage(msg));		        }		        if (!dialog.getPipeAdvertisement().getType().equals(PipeService.PropagateType)) {		            //1:1 chat goodbye		            if (Dialog.GOODBYE_CMD.equals(msg.getCommand())) {		            	chat.setChatEnabled(false);		            }		        }		        //如果不是当前对话,则进行提醒				if(ChatView.this != ChatView.this.getViewSite().getWorkbenchWindow().getActivePage().getActivePart()){					ChatView.this.setTitleImage(img_unread.createImage(ChatView.this.getViewSite().getShell().getDisplay()));				}			}		});        ViewFactory.getView(MyJXTA.getTheInstance()).updatePluginPanel(this, msg.getLabel());	}	private String convertMessage(final DialogMessage msg) {		StringBuffer sb=new StringBuffer();		sb.append("[");		sb.append(msg.getOriginator());		sb.append("@");		sb.append(new SimpleDateFormat("HH:mm:ss").format(msg.getTimeStamp()));		sb.append("]");		//20071123 部分兼容myjxta的消息,对myjxta,只取plaintext		String htmlMessage = msg.getHtmlMessage();		if(htmlMessage.indexOf("<html") != -1)			htmlMessage=msg.getPlainTextMessage();		sb.append(htmlMessage);  //TODO:myjxta传递过来的中文		sb.append("\n");		return sb.toString();	}	public Dialog getDialog() {		return dialog;	}	public void setDialog(Dialog dialog) {		this.dialog = dialog;	}	@Override	public void setPartName(String partName) {		super.setPartName(partName);	}	public void dismiss() {		dialog.close();	}	@Override	public void dispose() {		this.dismiss();		JFaceResources.getResources().destroyImage(img_unread);		JFaceResources.getResources().destroyImage(img_default);		super.dispose();	}	}

⌨️ 快捷键说明

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