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

📄 sendimwindow.java

📁 lumaQQ的源文件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:

		// 初始化菜单
		initEnterMenu();
		initFileMenu();

		// 初始化快捷键设置
		initKeyAction();

		setTalkMode(model.talkMode);

		return container;
	}

	/**
	 * 初始化快捷键设置
	 */
	private void initKeyAction() {
		// mod3 -> alt
		inputBox.setUserKeyAction('C' | SWT.MOD3, closeAction);
		inputBox.setUserKeyAction('S' | SWT.MOD3, sendAction);
		inputBox.setUserKeyAction('H' | SWT.MOD3, showRecordAction);
		inputBox.setUserKeyAction('T' | SWT.MOD3, modeAction);

		// 发送消息的快捷键
		reinstallSendKey(model.talkMode ? main.getOptionHelper().isUseEnterInTalkMode() : main.getOptionHelper().isUseEnterInMessageMode());
	}

	/**
	 * 刷新发送快捷键设置
	 * 
	 * @param useEnter
	 */
	private void reinstallSendKey(boolean useEnter) {
		if (useEnter) {
			inputBox.removeUserKeyAction(SWT.MOD1 | SWT.CR);
			inputBox.setUserKeyAction(SWT.CR, sendAction);
			inputBox.setKeyBinding(SWT.MOD1 | SWT.CR, RichBox.NEW_LINE);
		} else {
			inputBox.removeUserKeyAction(SWT.CR);
			inputBox.setUserKeyAction(SWT.MOD1 | SWT.CR, sendAction);
			inputBox.setKeyBinding(SWT.CR, RichBox.NEW_LINE);
		}
	}

	/**
	 * 刷新群名称标签
	 */
	private void setFriendNameLabel() {
		FaceRegistry reg = FaceRegistry.getInstance();
		if (model.hasCustomHead && reg.hasFace(reg.getMd5ById(model.customHeadId)))
			lblName.setImage(res.getSmallCustomHead(model.customHeadId, false));
		else
			lblName.setImage(HeadFactory.getSmallHeadByStatus(model));
		lblName.setText(model.displayName + " (" + model.qq + ')');
	}

	/**
	 * 停止闪烁图标
	 */
	protected void stopBlinkImage() {
		blinkRunnable.setStop(true);
	}

	/**
	 * 开始闪烁图标
	 */
	public void startBlinkImage() {
		if (!blinkRunnable.isStop())
			return;
		blinkRunnable.setStop(false);
		main.getDisplay().timerExec(0, blinkRunnable);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.window.Window#getShellStyle()
	 */
	@Override
	protected int getShellStyle() {
		int onTop = main.getOptionHelper().isIMOnTop() ? SWT.ON_TOP : SWT.NONE;
		if (LumaQQ.IS_GTK)
			return SWT.NO_TRIM | SWT.NO_BACKGROUND | onTop;
		else
			return SWT.SHELL_TRIM | onTop;
	}

	/**
	 * 设置窗口激活
	 */
	public void setActive() {
		getShell().setActive();
	}

	/**
	 * 设置最小化状态
	 * 
	 * @param b
	 */
	public void setMinimized(boolean b) {
		getShell().setMinimized(b);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.window.Window#open()
	 */
	@Override
	public int open() {
		int ret = super.open();
		// 设置输入框获得焦点,设置输入框的字体和颜色
		inputBox.setFocus();
		if (main.getDefaultStyle() != null)
			inputBox.setDefaultStyle(main.getDefaultStyle());
		return ret;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.window.Window#constrainShellSize()
	 */
	@Override
	protected void constrainShellSize() {
		if (model.talkMode)
			getShell().setSize(470, 430);
		else
			getShell().setSize(440, 340);

		Point loc = new Point(50, 50);
		int x = model.windowX;
		int y = model.windowY;
		if (x > 0)
			loc.x = x;
		if (y > 0)
			loc.y = y;
		getShell().setLocation(loc);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.window.Window#getInitialLocation(org.eclipse.swt.graphics.Point)
	 */
	@Override
	protected Point getInitialLocation(Point initialSize) {
		Point loc = new Point(50, 50);
		int x = model.windowX;
		int y = model.windowY;
		if (x > 0)
			loc.x = x;
		if (y > 0)
			loc.y = y;
		return loc;
	}

	/**
	 * 追加消息到输出框
	 * 
	 * @param f
	 * @param im
	 * @param header
	 */
	public void appendMessage(User f, NormalIM im, NormalIMHeader header) {
		outputBox.appendText('(' + DefaultFace.escapeFaces(f.displayName) + ")  " + DateTool.format(header.sendTime), otherStyle);
		LineStyle style = getLineStyle(im.fontStyle);
		outputBox.appendText(im.message, style);
	}

	/**
	 * 往输出框追加消息
	 * 
	 * @param entry
	 *            RecordEntry
	 */
	private void appendMessage(RecordEntry entry) {
		outputBox.appendText('(' + DefaultFace.escapeFaces(main.getMyModel().displayName) + ")  " + DateTool.format(entry.time), myStyle);
		outputBox.appendText(entry.message, getLineStyle(main.getDefaultStyle()));
	}

	/**
	 * 在输出框中添加提示信息
	 * 
	 * @param hint
	 * @param style
	 */
	@SuppressWarnings("unused")
	public void appendHint(String hint, LineStyle style) {
		outputBox.appendText(hint, style);
	}

	/**
	 * @return true表示当前窗口是活动窗口
	 */
	public boolean isActive() {
		return active;
	}

	/**
	 * 发送群消息
	 * 
	 * @param string
	 */
	protected void sendMessage(String s) {
		// 检查消息是否为空
		if (s.length() == 0) {
			MessageDialog.openWarning(getShell(), message_box_common_warning_title, message_box_cannot_send_empty_message);
			return;
		}
		// 判断用户是否登录
		if (main.getClient().getUser().isLoggedIn()) {
			message = s;
			// 保存到聊天记录中
			RecordEntry key = new RecordEntry();
			key.owner = model.qq;
			key.sender = main.getMyModel().qq;
			key.senderParent = 0;
			key.receiver = model.qq;
			key.time = System.currentTimeMillis();
			key.type = IKeyConstants.NORMAL;
			key.message = message;
			main.getRecordManager().addRecord(key);

			// 把发送的消息显示到输出框中
			if (model.talkMode)
				appendMessage(key);

			if (model.talkMode)
				inputBox.clear();
			else {
				/*
				 * 如果是消息模式
				 */
				// 设置输入框不可写
				inputBox.setReadonly(true);
				inputBox.setBackground(Colors.READONLY_BACKGROUND);
				// 窗口最小化
				getShell().setMinimized(true);
			}

			// TODO 检查是否包含自定义表情,转换发送消息到QQ格式,启动自定义表情发送任务

			// 启动普通消息发送任务
			main.getIMJobQueue().addJob(new SendNormalIMJob(message, model));
		} else {
			MessageDialog.openWarning(getShell(), message_box_common_warning_title, message_box_please_login_first);
		}
	}

	/**
	 * 显示记录控件
	 */
	private void showRecord() {
		GridData gd = (GridData) viewer.getLayoutData();
		Shell shell = getShell();
		if (gd.exclude) {
			gd.exclude = false;
			viewer.refreshRecord();
		} else {
			gd.exclude = true;
		}
		if (!shell.getMaximized()) {
			Point p = shell.getSize();
			shell.setSize(p.x, p.y + (gd.exclude ? -205 : 205));
		}
		viewer.setVisible(!gd.exclude);
		viewer.getParent().layout();
		shell.layout();
	}

	/**
	 * 关闭窗口
	 */
	public void closeWindow() {
		getShell().close();
	}

	/**
	 * 设置消息发送窗口为聊天模式或者消息模式
	 * 
	 * @param b
	 *            true表示为聊天模式
	 */
	public void setTalkMode(boolean b) {
		if (b) {
			model.talkMode = true;
			btnMode.setText(im_button_mode_message);
			if (main.getOptionHelper().isUseEnterInMessageMode() != main.getOptionHelper().isUseEnterInTalkMode())
				reinstallSendKey(main.getOptionHelper().isUseEnterInTalkMode());
			sash.setVisible(true);
			outputForm.setLayoutData(new GridData(GridData.FILL_BOTH));
			GridData gd = new GridData(GridData.FILL_HORIZONTAL);
			gd.heightHint = 100;
			inputForm.setLayoutData(gd);
			gd = (GridData) sash.getLayoutData();
			gd.heightHint = SWT.DEFAULT;
			if (model.talkMode)
				getShell().setSize(470, viewer.isVisible() ? 630 : 430);
			else
				getShell().setSize(440, viewer.isVisible() ? 540 : 340);
			inputForm.getParent().layout();
		} else {
			outputBox.clear();
			model.talkMode = false;
			btnMode.setText(im_button_mode_talk);
			if (main.getOptionHelper().isUseEnterInMessageMode() != main.getOptionHelper().isUseEnterInTalkMode())
				reinstallSendKey(main.getOptionHelper().isUseEnterInMessageMode());
			sash.setVisible(false);
			GridData gd = new GridData(GridData.FILL_HORIZONTAL);
			gd.heightHint = outputForm.getTopLeft().getSize().y + 2;
			outputForm.setLayoutData(gd);
			inputForm.setLayoutData(new GridData(GridData.FILL_BOTH));
			gd = (GridData) sash.getLayoutData();
			gd.heightHint = 0;
			if (model.talkMode)
				getShell().setSize(470, viewer.isVisible() ? 630 : 430);
			else
				getShell().setSize(440, viewer.isVisible() ? 540 : 340);
			inputForm.getParent().layout();
		}
	}

	/**
	 * 初始化当前文件传输任务菜单
	 */
	private void initFileMenu() {
		fileMenu = new Menu(getShell(), SWT.POP_UP);
		// 缺省,无任务进行中
		MenuItem mi = new MenuItem(fileMenu, SWT.PUSH);
		mi.setText(menu_file_none);
	}

	/**
	 * 设置焦点
	 */
	public void setFocus() {
		getShell().setFocus();
	}

	/**
	 * @return true表示聊天模式
	 */
	public boolean isTalkMode() {
		return model.talkMode;
	}

	/**
	 * 打开表情选择窗口
	 */
	private void openImageSelectionShell(Point loc) {
		if (fss != null && !fss.isDisposed())
			fss.getShell().close();

		fss = new ImageSelector(getShell(), new FaceImageAdvisor(main));
		fss.setListener(this);
		fss.setLocation(loc);
		fss.open();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see edu.tsinghua.lumaqq.events.IFaceSelectionListener#faceSelected(edu.tsinghua.lumaqq.ui.IImageProvider, int, int)
	 */
	public void faceSelected(IImageSelectorAdvisor provider, int group, int sequence) {
		if (group == 0) {
			int index = res.getFaceCode(sequence);
			if (index != -1)
				inputBox.insertImage(IRichContent.DEFAULT_FACE_TAG, index);
		} else {
			MessageDialog.openInformation(getShell(), message_box_common_info_title, message_box_face_to_user);
			/*
			 * 暂时还不支持向单个用户发送自定义表情,注释掉这些代码
			 */
			// FaceUtil util = FaceUtil.getInstance();
			// Face face = util.getFace(group - 1, sequence);
			// if(face == null)
			// return;
			// int id = Util.getInt(face.getId(), -1);
			// if(id == -1)
			// return;
			// inputBox.insertImage(IRichContent.CUSTOM_FACE_TAG, id);
		}
	}

	/**
	 * @return the otherStyle
	 */
	public static LineStyle getOtherStyle() {
		return otherStyle;
	}

	/**
	 * @return the inputBox
	 */
	public RichBox getInputBox() {
		return inputBox;
	}
}

⌨️ 快捷键说明

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