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

📄 receiveimwindow.java

📁 java写的qq代码实现qq的部分功能
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        active = true;
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.swt.events.ShellListener#shellDeactivated(org.eclipse.swt.events.ShellEvent)
     */
    public void shellDeactivated(ShellEvent e) {
        active = false;
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.swt.events.ShellAdapter#shellClosed(org.eclipse.swt.events.ShellEvent)
     */
    public void shellClosed(ShellEvent e) {
		main.getShellRegistry().removeReceiveIMWindow(model);
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.swt.events.ShellListener#shellDeiconified(org.eclipse.swt.events.ShellEvent)
     */
    public void shellDeiconified(ShellEvent e) {
    }

    /* (non-Javadoc)
     * @see org.eclipse.swt.events.ShellListener#shellIconified(org.eclipse.swt.events.ShellEvent)
     */
    public void shellIconified(ShellEvent e) {
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.window.Window#createContents(org.eclipse.swt.widgets.Composite)
     */
    protected Control createContents(Composite parent) {
        parent.setLayout(new FillLayout());
        Composite container = (Composite)super.createContents(parent);
        GridLayout layout = new GridLayout();
        layout.horizontalSpacing = 0;
        container.setLayout(layout);
        container.setBackground(Colors.DIALOG_BACKGOUND);
        
        // 记录区
        Composite chatContainer = new Composite(container, SWT.NONE);
        chatContainer.setLayoutData(new GridData(GridData.FILL_BOTH));
        layout = new GridLayout();        
        layout.marginHeight = layout.marginWidth = 1;
        layout.horizontalSpacing = layout.verticalSpacing = 0;
        chatContainer.setLayout(layout);
        chatContainer.addPaintListener(new PaintListener() {
            public void paintControl(PaintEvent e) {
                Composite c = (Composite)e.getSource();
                Rectangle rect = c.getClientArea();
                rect.width--;
                rect.height--;
                e.gc.setForeground(Colors.WIDGET_BORDER);
                e.gc.drawRectangle(rect);
            }
        });
        
        ViewForm outputForm = new ViewForm(chatContainer, SWT.FLAT);
        outputForm.setLayoutData(new GridData(GridData.FILL_BOTH));
        Composite comp = new Composite(outputForm, SWT.NONE);
        layout = new GridLayout(2, false);
        comp.setLayout(layout);
        comp.setBackground(Colors.VIEWFORM_BANNER_BACKGROUP);
        lblName = new CLabel(comp, SWT.LEFT);
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.horizontalSpan = 2;
        lblName.setLayoutData(gd);
        lblName.setBackground(comp.getBackground());
        setFriendNameLabel();
        lblName.setCursor(handCursor);
        lblName.setForeground(Colors.WHITE);
        lblName.addMouseListener(new MouseAdapter() {
            public void mouseUp(MouseEvent e) {
                main.getShellLauncher().openUserInfoWindow(model, UserInfoWindow.READ_ONLY);
            }
        });
        lblName.addMouseTrackListener(new MouseTrackAdapter() {
            public void mouseEnter(MouseEvent e) {
                lblName.setForeground(Colors.YELLOW);
            }
            
            public void mouseExit(MouseEvent e) {
                lblName.setForeground(Colors.WHITE);
            }
        });
        lblIp = new Label(comp, SWT.LEFT);
        lblIp.setBackground(comp.getBackground());
        lblIp.setLayoutData(new GridData());
        lblIp.setText(ip);
        lblPlace = new Label(comp, SWT.LEFT);
        lblPlace.setBackground(comp.getBackground());
        gd = new GridData();
        gd.horizontalIndent = 10;
        lblPlace.setLayoutData(gd);
        lblPlace.setText(place);
        outputForm.setTopLeft(comp);        
        outputBox = new RichBox(outputForm);
        outputBox.setReadonly(true);
        outputBox.setBackground(Colors.READONLY_BACKGROUND);
        outputForm.setContent(outputBox);    
        
        // 按钮区
        Composite buttonContainer = new Composite(container, SWT.NONE);
        gd = new GridData(GridData.FILL_HORIZONTAL);
        buttonContainer.setLayoutData(gd);
        layout = new GridLayout(5, false);
        layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0;
        buttonContainer.setLayout(layout);
        buttonContainer.setBackground(container.getBackground());

		// 回复消息按钮
		QButton btnReply = new QButton(buttonContainer);
		btnReply.setText(LumaQQ.getString("receive.im.button.reply"));
		btnReply.setLayoutData(new GridData());
		btnReply.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
			    replyAction.run();
			}
		});
		// 快捷回复按钮
		btnQuickReply = new QButton(buttonContainer);
		btnQuickReply.setText(LumaQQ.getString("receive.im.button.quickreply"));
		gd = new GridData();
		gd.horizontalIndent = 3;
		btnQuickReply.setLayoutData(gd);
		btnQuickReply.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				quickReplyAction.run();
			}
		});
		// 快捷回复旁边的下拉箭头按钮
		QButton btnArrow = new QButton(buttonContainer, SWT.ARROW_DOWN);
		btnArrow.setLayoutData(new GridData());
		btnArrow.addMouseListener(new MouseAdapter() {
            public void mouseUp(MouseEvent e) {
				// 设置菜单位置
				Rectangle bound = btnQuickReply.getBounds();
				quickReplyMenu.setLocation(btnQuickReply.getParent().toDisplay(bound.x, bound.y + bound.height));	
				// 显示菜单
				quickReplyMenu.setVisible(true);
            }
		});
        
		// 关闭按钮
        QButton btnClose = new QButton(buttonContainer);
        btnClose.setText(LumaQQ.getString("receive.im.button.close"));
        gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
        gd.grabExcessHorizontalSpace = true;
        btnClose.setLayoutData(gd);
		btnClose.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				closeAction.run();
			}
		});
		
		// 下一条消息按钮
		btnNext = new QButton(buttonContainer);		
		btnNext.setText(LumaQQ.getString("receive.im.button.next"));
		gd = new GridData();
		gd.horizontalIndent = 3;
		btnNext.setLayoutData(gd);
		btnNext.setEnabled(false);
		btnNext.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
			    nextAction.run();
			}
		});
		
		// 初始化菜单
		initQuickReplyMenu();
		
		// 初始化快捷键设置
		initKeyAction();
		
        return container;
    }
    
    /**
     * 初始化快捷键设置
     */
    private void initKeyAction() {
        // mod3 -> alt
        outputBox.setUserKeyAction('C' | SWT.MOD3, closeAction);
        outputBox.setUserKeyAction('R' | SWT.MOD3, replyAction);
        outputBox.setUserKeyAction('S' | SWT.MOD3, quickReplyAction);
        outputBox.setUserKeyAction('N' | SWT.MOD3, nextAction);
        outputBox.setUserKeyAction(SWT.CR, replyAction);
    }

    /* (non-Javadoc)
     * @see org.eclipse.jface.window.Window#getShellStyle()
     */
    protected int getShellStyle() {
        return SWT.SHELL_TRIM;
    }
    
    /**
     * 设置窗口激活
     */
    public void setActive() {
        getShell().setActive();
    }
    
    /**
     * 设置最小化状态
     * 
     * @param b
     */
    public void setMinimized(boolean b) {
        getShell().setMinimized(b);
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.window.Window#open()
     */
    public int open() {
        int ret = super.open();
		outputBox.setFocus();
        return ret;
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.window.Window#constrainShellSize()
     */
    protected void constrainShellSize() {
        getShell().setSize(440, 340);
        
		Point loc = new Point(50, 50);
		int x = model.getLocationX();
		int y = model.getLocationY();
		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)
     */
    protected Point getInitialLocation(Point initialSize) {
		Point loc = new Point(50, 50);
		int x = model.getLocationX();
		int y = model.getLocationY();
		if(x > 0) loc.x = x;
		if(y > 0) loc.y = y;
		return loc;
    }
    
    /**
     * @param c
     * 		群model
     * @param im
     * 		群消息结构
     * @param header
     * @param me
     * 		true表示是我自己
     */
    public void appendMessage(FriendModel f, NormalIM im, NormalIMHeader header) {
        date.setTime(header.sendTime);
		outputBox.appendText('(' + f.getName() + ")  " + df.format(date), myStyle);
		LineStyle style = getLineStyle(im);
		outputBox.appendText(im.message, style);
    }
    
	/**
	 * 设置已经发送的消息,这个方法只用在聊天模式时
	 * @param name 发送消息的人的昵称
	 * @param msg 消息内容
	 * @param date 消息发送时间
     * 		true表示是我自己
	 */
	private void appendMessage(String name, String msg, Date date) {
		outputBox.appendText('(' + name + ")  " + df.format(date), myStyle);		
		outputBox.appendText(msg, getLineStyle(main.getDefaultStyle()));
	}
	
	/**
	 * 在输出框中添加提示信息
	 * 
	 * @param hint
	 * @param style
	 */
	private void appendHint(String hint, LineStyle style) {
	    outputBox.appendText(hint, style);
	}

    /**
     * 刷新群名称标签
     */
    private void setFriendNameLabel() {
        lblName.setImage(HeadFactory.getSmallHeadByStatus(model));
        lblName.setText(model.getName() + " (" + model.getQQ() + ')');
    }

    /**
     * @return
     * 		true表示当前窗口是活动窗口
     */
    public boolean isActive() {
        return active;
    }
	
	/**
	 * 设置好友位置信息
	 * @param place
	 */
	public void setPlace(String place) {
		this.place = place;
	}
	
	/**
	 * 设置下一条按钮的使能状态
	 * 
	 * @param b		
	 */
	public void setNextButtonEnabled(boolean b) {
		btnNext.setEnabled(b);
	}
	
	/**
	 * 设置好友ip信息
	 * @param ip
	 */
	public void setIp(String ip) {
		this.ip = ip;
	}

    /**
     * @param packet
     */
    public void setMessage(ReceiveIMPacket packet) {
        outputBox.clear();
        appendMessage(model, packet.normalIM, packet.normalHeader);
    }
}

⌨️ 快捷键说明

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