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

📄 sendclustermessageshell.java

📁 类似于MSN
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
						FriendModel f = (FriendModel)ti.getData();
						// 设置菜单的使能状态,对于好友,可以发消息,不是好友不能发
						boolean b = main.isFriend(f);
						memberMenu.getItem(0).setEnabled(b);
						memberMenu.getItem(3).setEnabled(!b);
					}
				}
			}
		);
	}

	/**
	 * 初始化使用Enter键的菜单
	 */
	private void initEnterMenu() {
		enterMenu = new Menu(shell, SWT.POP_UP);
		// 使用Enter键菜单
		MenuItem mi = new MenuItem(enterMenu, SWT.RADIO);
		mi.setText(LumaQQ.getResourceString("send.cluster.message.menu.use.enter"));
		mi.addSelectionListener(
			new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {
				    inputBox.setUseEnter(false);
					options.setUseEnterInTalkMode(true);
				}
			}
		);
		// 使用Ctrl + Enter键菜单
		mi = new MenuItem(enterMenu, SWT.RADIO);
		mi.setText(LumaQQ.getResourceString("send.cluster.message.menu.use.ctrl.enter"));
		mi.addSelectionListener(
			new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {
				    inputBox.setUseEnter(true);
					options.setUseEnterInTalkMode(false);
				}
			}
		);
		// 添加菜单显示事件监听器
		enterMenu.addMenuListener(
			new MenuAdapter() {
				public void menuShown(MenuEvent e) {
					// 根据当前选项设置菜单项状态
					boolean b = options.isUseEnterInTalkMode();
					enterMenu.getItem(0).setSelection(b);
					enterMenu.getItem(1).setSelection(!b);
				}
			}
		);
	}
	
	// 初始化其他控件
	private void initLayout() {
		// 好友按钮,就是那个头像,一按就出来好友信息那个
		btnCluster = new ShutterLabel(shell, MySWT.FLAT | MySWT.HOVER | SWT.CENTER, null, null);
		btnCluster.setShowSmallImage(false);
		FormData fd = new FormData();
		fd.left = fd.top = new FormAttachment(0, 5);
		btnCluster.setLayoutData(fd);
		btnCluster.addMouseListener(
			new MouseAdapter() {
				public void mouseUp(MouseEvent e) {
					main.openClusterInfoShell(c);
				}
			}
		);
		// ID标签
		lblId = new Label(shell, SWT.NONE);
		fd = new FormData();
		fd.left = new FormAttachment(btnCluster, 10, SWT.RIGHT);
		fd.top = new FormAttachment(0, 5);
		lblId.setLayoutData(fd);
		// 名称标签
		lblName = new Label(shell, SWT.NONE);
		fd = new FormData();
		fd.left = new FormAttachment(btnCluster, 10, SWT.RIGHT);
		fd.top = new FormAttachment(lblId, 5, SWT.BOTTOM);
		lblName.setLayoutData(fd);
		// 聊天记录面板
		viewer = new RecordViewer(shell, SWT.NONE);
		viewer.setVisible(false);
		fd = new FormData();
		fd.left = new FormAttachment(0, 5);
		fd.right = new FormAttachment(100, -5);
		fd.top = new FormAttachment(100, 0);
		fd.bottom = new FormAttachment(100, -5);
		viewer.setLayoutData(fd);
		// 旁边的成员列表table
		memberTable = new Table(shell, SWT.BORDER | SWT.V_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION);
		fd = new FormData();
		fd.left = new FormAttachment(100, -125);
		fd.right = new FormAttachment(100, -5);
		fd.top = new FormAttachment(btnCluster, 5, SWT.BOTTOM);
		fd.bottom = new FormAttachment(viewer, -8, SWT.TOP);
		memberTable.setLayoutData(fd);
		memberTable.addControlListener(
			new ControlAdapter() {
				public void controlResized(ControlEvent e) {
					memberTable.getColumn(0).setWidth(memberTable.getClientArea().width);
				}
			}
		);
		memberTable.addSelectionListener(
			new SelectionAdapter() {
				/* 双击时和这个成员的聊天窗口 */
				public void widgetDefaultSelected(SelectionEvent e) {
					int index = memberTable.getSelectionIndex();
					if(index != -1) {
						TableItem ti = memberTable.getItem(index);
						FriendModel f = (FriendModel)ti.getData();
						main.openUserInfoShell(f, false);
						main.client.getUserInfo(f.getQQ());
					}
				}
			}
		);
		memberTable.addMouseListener(
			new MouseAdapter() {
				public void mouseDown(MouseEvent e) {
					if(e.button == 3) {
						memberMenu.setLocation(memberTable.toDisplay(e.x, e.y));
						memberMenu.setVisible(true);						
					}
				}
			}
		);
		// 列,只有一列
		TableColumn tc = new TableColumn(memberTable, SWT.LEFT);
		memberTable.setHeaderVisible(false);
		// 输入消息框
		inputBox = new ChatBox(shell, SWT.NONE);
		inputBox.setUseEnter(!options.isUseEnterInTalkMode());
		fd = new FormData();
		fd.left = new FormAttachment(0, 5);
		fd.right = new FormAttachment(memberTable, -5, SWT.LEFT);
		fd.top = new FormAttachment(memberTable, -100, SWT.BOTTOM);
		fd.bottom = new FormAttachment(viewer, -36, SWT.TOP);
		inputBox.setLayoutData(fd);
		inputBox.addAcceleratorListener(this);
		// 工具条
		tb = new ToolBar(shell, SWT.FLAT | SWT.HORIZONTAL);
		tb.setBackground(toolbarBackground);
		fd = new FormData();
		fd.left = new FormAttachment(0, 5);
		fd.right = new FormAttachment(memberTable, -5, SWT.LEFT);
		fd.top = new FormAttachment(inputBox, -22, SWT.TOP);
		fd.bottom = new FormAttachment(inputBox, 0, SWT.TOP);
		tb.setLayoutData(fd);
		tb.setLayout(new FormLayout());
		// 输出消息框
		outputBox = new ChatBox(shell, SWT.NONE);
		outputBox.setEnabled(false);
		fd = new FormData();
		fd.left = new FormAttachment(0, 5);
		fd.right = new FormAttachment(memberTable, -5, SWT.LEFT);
		fd.top = new FormAttachment(btnCluster, 5, SWT.BOTTOM);
		fd.bottom = new FormAttachment(tb, 0, SWT.TOP);
		outputBox.setLayoutData(fd);
		// 选择字体按钮
		ToolItem ti = new ToolItem(tb, SWT.PUSH);
		ti.setImage(icons.getResource(IconHolder.icoFont));
		ti.setToolTipText(LumaQQ.getResourceString("tooltip.button.font"));
		ti.addSelectionListener(
			new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {
					FontDialog dialog = new FontDialog(shell);
					if(main.font != null) 
						dialog.setFontList(main.font.getFontData());
					if(main.fontColor != null)
						dialog.setRGB(main.fontColor.getRGB());
					dialog.open();
					FontData[] fontList = dialog.getFontList();
					if(fontList == null) return;
					RGB rgb = dialog.getRGB();
					if(main.font != null) main.font.dispose();
					if(main.fontColor != null) main.fontColor.dispose();
					main.font = new Font(display, fontList);
					if(rgb != null) {
						main.fontColor = new Color(display, rgb);
						inputBox.setForeground(main.fontColor);						
					}
					inputBox.setFont(main.font);
				}
			}
		);
		// 选择表情按钮
		ti = new ToolItem(tb, SWT.PUSH);
		ti.setImage(icons.getResource(IconHolder.icoSmiley));
		ti.setToolTipText(LumaQQ.getResourceString("tooltip.button.smiley"));
		ti.addSelectionListener(
			new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {
					if(iss == null || iss.isDisposed()) {
						iss = new ImageSelectShell(shell);
						iss.addShellListener(new SmileyPanelListener());
						iss.setImageSize(20, 20);
						iss.setMarginWidth(1);
						iss.setMarginHeight(1);
						iss.setVerticalSpacing(2);
						iss.setHorizontalSpacing(2);
						iss.setDimension(15, 6);
						iss.setContinuous(true);
						iss.addAllSmiley();		
						iss.refresh();
						Rectangle bound = tb.getBounds();
						iss.setLocation(shell.toDisplay(bound.x, bound.y + bound.height));
						iss.open();								
					}
				}
			}
		);
		// 隐藏侧边条按钮
		btnSideBar = new ShutterLabel(tb, MySWT.FLAT | MySWT.HOVER | MySWT.NO_ZOOM | SWT.CENTER, null, icons.getResource(IconHolder.icoRightArrow));
		btnSideBar.setBackground(toolbarBackground);
		btnSideBar.setToolTipText(LumaQQ.getResourceString("tooltip.button.hide"));
		fd = new FormData();
		fd.right = fd.bottom = new FormAttachment(100, -3);
		fd.top = new FormAttachment(0, 1);
		fd.left = new FormAttachment(100, -23);
		btnSideBar.setLayoutData(fd);		
		btnSideBar.addMouseListener(
			new MouseAdapter() {
				public void mouseUp(MouseEvent e) {
					if(memberTable.isVisible()) {
						FormData fd = (FormData)memberTable.getLayoutData();
						fd.left.offset = -5;
						memberTable.setVisible(false);
						btnSideBar.setToolTipText(LumaQQ.getResourceString("tooltip.button.show"));
						btnSideBar.setImage(icons.getResource(IconHolder.icoLeftArrow));
						shell.layout();
					} else {
						FormData fd = (FormData)memberTable.getLayoutData();
						fd.left.offset = -125;
						memberTable.setVisible(true);
						btnSideBar.setToolTipText(LumaQQ.getResourceString("tooltip.button.hide"));
						btnSideBar.setImage(icons.getResource(IconHolder.icoRightArrow));	
						shell.layout();
					}
				}
			}
		);
		// 聊天记录按钮
		ShutterLabel btnRecord = new ShutterLabel(shell, MySWT.HOVER | SWT.CENTER, LumaQQ.getResourceString("send.cluster.message.button.record"), null);
		btnRecord.setBackground(buttonColor);
		fd = new FormData();
		fd.left = new FormAttachment(0, 8);
		fd.top = new FormAttachment(inputBox, 8, SWT.BOTTOM);
		btnRecord.setLayoutData(fd);
		btnRecord.addMouseListener(
			new MouseAdapter() {
				public void mouseUp(MouseEvent e) {
				    showRecord();
				}
			}
		);
		// 发送按钮
		btnSend = new ShutterLabel(shell, MySWT.HOVER | SWT.CENTER, LumaQQ.getResourceString("send.cluster.message.button.send"), null);
		btnSend.setBackground(buttonColor);
		fd = new FormData();
		fd.right = new FormAttachment(memberTable, -18, SWT.LEFT);
		fd.left = new FormAttachment(memberTable, -88, SWT.LEFT);
		fd.top = new FormAttachment(inputBox, 8, SWT.BOTTOM);
		btnSend.setLayoutData(fd);
		btnSend.addMouseListener(
			new MouseAdapter() {
				public void mouseUp(MouseEvent e) {
					sendMessage(inputBox.getMessage());
				}
			}
		);
		// 发送快捷键的下拉按钮
		Button btnUseEnter = new Button(shell, SWT.ARROW | SWT.DOWN);
		fd = new FormData();
		fd.right = new FormAttachment(memberTable, -8, SWT.LEFT);
		fd.left = new FormAttachment(memberTable, -18, SWT.LEFT);
		fd.top = new FormAttachment(inputBox, 8, SWT.BOTTOM);
		fd.bottom = new FormAttachment(btnSend, 0, SWT.BOTTOM);
		btnUseEnter.setLayoutData(fd);
		btnUseEnter.addSelectionListener(
			new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {
					// 设置菜单位置
					Rectangle bound = btnSend.getBounds();
					enterMenu.setLocation(shell.toDisplay(bound.x, bound.y + bound.height));
					// 显示菜单
					enterMenu.setVisible(true);
				}
			}
		);
		// 关闭按钮
		ShutterLabel btnClose = new ShutterLabel(shell, MySWT.HOVER | SWT.CENTER, LumaQQ.getResourceString("send.message.button.close"), null);
		btnClose.setBackground(buttonColor);
		fd = new FormData();
		fd.right = new FormAttachment(btnSend, -3, SWT.LEFT);
		fd.left = new FormAttachment(btnSend, -73, SWT.LEFT);
		fd.top = new FormAttachment(inputBox, 8, SWT.BOTTOM);
		btnClose.setLayoutData(fd);
		btnClose.addMouseListener(
			new MouseAdapter() {
				public void mouseUp(MouseEvent e) {
					close();
				}
			}
		);
		// 设置消息管理器、字符串格式化器,导出器
		viewer.setMessageManager(main.mm);
		// 添加表头
		viewer.setTableColumn(new String[] { LumaQQ.getResourceString("send.cluster.message.table.header.nick"), LumaQQ.getResourceString("send.cluster.message.table.header.time"), LumaQQ.getResourceString("send.cluster.message.table.header.message") });
		viewer.setTableColumnWidth(new String[] { "80", "120", "*" });
		// tableitem双击事件监听器
		viewer.addSelectionListener(
			new SelectionAdapter() {
				public void widgetDefaultSelected(SelectionEvent e) {
					TableItem ti = viewer.getSelectedItem();
					inputBox.setMessage(ti.getText(2));
				}
			}
		);
	}

	/**
     * 显示聊天记录
     */
    protected void showRecord() {
		FormData fd = (FormData)viewer.getLayoutData();
		viewer.setVisible(!viewer.isVisible());
		if(viewer.isVisible()) {
			// 得到记录,显示在table中
			viewer.refreshRecord(false);
			// 设置shell布局和大小
			fd.top.offset = -200;
			if(!shell.getMaximized()) {						    
				Point p = shell.getSize();
				shell.setSize(p.x, p.y + 200);
			}
			// 显示最后一条记录
			viewer.showLast();
		} else {
			fd.top.offset = 0;
			if(!shell.getMaximized()) {
				Point p = shell.getSize();
				shell.setSize(p.x, p.y - 200);						    
			}
		}
		// 专用伺候linux的代码
		shell.layout();		
    }

    /**
	 * 打开与某个成员的聊天窗口
	 * @return 打开的窗口对象,可能为ReceiveMessageShell, 也可能为SendMessageShell
	 */
	protected Object openMemberMessageShell() {
		int index = memberTable.getSelectionIndex();
		if(index != -1) {
			TableItem ti = memberTable.getItem(index);
			FriendModel f = (FriendModel)ti.getData();
			// 在现在的好友中查找这个model
			FriendModel f2 = main.getFriendModel(f.getQQ());
			// 如果找到model为null,说明这个人不是我的好友了,为了界面上的一致
			//     性,把这个人添加到陌生人再打开窗口。否则,这个人肯定已经在model中
			//     ,直接打开窗口
			if(f2 == null) {
				/* 否则这个人还不是我的好友, */
				f2 = f;
				int[] stranger = main.model.findTabIndex(main.strangerMatcher);
				if(stranger != null && stranger.length > 0) {
					main.model.addItem(stranger[0], f);
					main.shutter.refreshTabView(stranger[0]);
				}

⌨️ 快捷键说明

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