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

📄 receiveimwindow.java

📁 lumaQQ的源文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        });
        
        if(LumaQQ.IS_GTK) {
        	BorderStyler styler = new BorderStyler(main);
        	styler.setShowMaxButton(true);
        	styler.setHideWhenMinimize(false);
        	styler.decorateShell(newShell);        	
        }
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.window.Window#getShellListener()
     */
	@Override
    protected ShellListener getShellListener() {
        return this;
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.swt.events.ShellListener#shellActivated(org.eclipse.swt.events.ShellEvent)
     */
    public void shellActivated(ShellEvent e) {
        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)
     */
	@Override
    protected Control createContents(Composite parent) {
		Composite container = null;
		if(LumaQQ.IS_GTK) {
			container = ((BorderStyler)getShell().getData(BorderStyler.STYLER)).getCenter();
		} else {
			parent.setLayout(new FillLayout());
			container = (Composite)super.createContents(parent);			
		}
        GridLayout layout = new GridLayout();
        layout.horizontalSpacing = 0;
        container.setLayout(layout);
        container.setBackground(Colors.MAINSHELL_BACKGROUND);
        
        // 记录区
        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));
        outputForm.setBackground(Colors.VIEWFORM_BANNER_BACKGROUND);
        lblName = new CLabel(outputForm, SWT.LEFT);
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.horizontalSpan = 2;
        lblName.setLayoutData(gd);
        lblName.setBackground(Colors.VIEWFORM_BANNER_BACKGROUND);
        setFriendNameLabel();
        lblName.setCursor(handCursor);
        lblName.setForeground(Colors.VIEWFORM_BANNER_TEXT);
        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.VIEWFORM_BANNER_TEXT_HOVER);
            }
            
            public void mouseExit(MouseEvent e) {
                lblName.setForeground(Colors.VIEWFORM_BANNER_TEXT);
            }
        });
        outputForm.setTopLeft(lblName);
        lblIp = new CLabel(outputForm, SWT.LEFT);
        lblIp.setBackground(Colors.VIEWFORM_BANNER_BACKGROUND);
        lblIp.setLayoutData(new GridData());
        lblIp.setText(getIPText());
        outputForm.setTopRight(lblIp);        
        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());

		// 回复消息按钮
		Slat btnReply = new Slat(buttonContainer);
		btnReply.setText(receive_im_button_reply);
		btnReply.setLayoutData(new GridData());
		btnReply.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
			    replyAction.run();
			}
		});
		// 快捷回复按钮
		btnQuickReply = new Slat(buttonContainer);
		btnQuickReply.setText(receive_im_button_quickreply);
		gd = new GridData();
		gd.horizontalIndent = 3;
		btnQuickReply.setLayoutData(gd);
		btnQuickReply.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				quickReplyAction.run();
			}
		});
		// 快捷回复旁边的下拉箭头按钮
		Slat btnArrow = new Slat(buttonContainer, SWT.CENTER);
		btnArrow.setText("↓");
		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);
            }
		});
        
		// 关闭按钮
        Slat btnClose = new Slat(buttonContainer);
        btnClose.setText(button_close_accel);
        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 Slat(buttonContainer);		
		btnNext.setText(button_next_accel);
		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()
     */
	@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();
		outputBox.setFocus();
        return ret;
    }
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.window.Window#constrainShellSize()
     */
	@Override
    protected void constrainShellSize() {
        getShell().setSize(440, 340);
        
		Point loc = new Point(150, 150);
		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(150, 150);
		int x = model.windowX;
		int y = model.windowY;
		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(User f, NormalIM im, NormalIMHeader header) {
        date.setTime(header.sendTime);
		outputBox.appendText('(' + DefaultFace.escapeFaces(f.displayName) + ")  " + df.format(date), myStyle);
		LineStyle style = getLineStyle(im);
		outputBox.appendText(im.message, style);
    }

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

    /**
     * @return
     * 		true表示当前窗口是活动窗口
     */
    public boolean isActive() {
        return active;
    }
	
	/**
	 * 设置下一条按钮的使能状态
	 * 
	 * @param b		
	 */
	public void setNextButtonEnabled(boolean b) {
		btnNext.setEnabled(b);
	}
	
	/**
     * @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 + -