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

📄 tempsessionimwindow.java

📁 lumaQQ的源文件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
			public void menuShown(MenuEvent e) {
			    refreshEnterMenu();
			}
		});
	}
	
	/**
	 * 根据当前选项设置菜单项状态
	 */
	private void refreshEnterMenu() {
		boolean b = model.talkMode ? main.getOptionHelper().isUseEnterInTalkMode() : main.getOptionHelper().isUseEnterInMessageMode();
		enterMenu.getItem(0).setSelection(b);
		enterMenu.getItem(1).setSelection(!b);
	}
    
    /* (non-Javadoc)
     * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
     */
	@Override
    protected void configureShell(Shell newShell) {
        newShell.setText(NLS.bind(im_title, model.displayName));
        newShell.setImage(res.getImage(Resources.icoMessage));
        newShell.addControlListener(new ControlAdapter() {
            public void controlMoved(ControlEvent e) {
        		// 保存自己的位置,以便下次打开窗口时在同样的位置
        		Point loc = ((Shell)e.getSource()).getLocation();
        		model.windowX = loc.x;
        		model.windowY = loc.y;
            }
        });
        newShell.addDisposeListener(new DisposeListener() {
            public void widgetDisposed(DisposeEvent e) {
				for(LineStyle style : styleCache) {
                    if(style.foreground != null)
                        style.foreground.dispose();
                    if(style.background != null)
                        style.background.dispose();
                }
            }
        });
        main.getShell().addShellListener(new ShellAdapter() {
            public void shellClosed(ShellEvent e) {
                inputBox.dispose();
                outputBox.dispose();
            }
        });
        
        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) {
        stopBlinkImage();
        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.getClient().removeQQListener(this);
		main.getShellRegistry().removeTempSessionIMWindow(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);
            }
        });
        
        // output form
        // 设置名称标签
        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);
        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);        
        // 设置ip标签
        lblIp = new CLabel(outputForm, SWT.RIGHT);
        lblIp.setText(getIPText());
        lblIp.setBackground(Colors.VIEWFORM_BANNER_BACKGROUND);
        outputForm.setTopRight(lblIp);
        outputBox = new RichBox(outputForm);
        outputBox.setReadonly(true);
        outputBox.setBackground(Colors.WHITE);
        outputForm.setContent(outputBox);      
        
        sash = new Sash(chatContainer, SWT.HORIZONTAL);
        sash.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        sash.setBackground(Colors.READONLY_BACKGROUND);
        sash.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                GridData data = (GridData)inputForm.getLayoutData();
                data.heightHint = inputForm.getParent().getClientArea().height - e.y;
                inputForm.getParent().layout();
            }
        });
        
        inputForm = new ViewForm(chatContainer, SWT.FLAT);
        GridData gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.heightHint = 100;
        inputForm.setLayoutData(gd);
        ToolBar tb = new ToolBar(inputForm, SWT.FLAT);
        tb.setBackground(Colors.VIEWFORM_BANNER_BACKGROUND);
        // 字体
        ToolItem ti = new ToolItem(tb, SWT.NONE);        
        ti.setImage(res.getImage(Resources.icoFont));
        ti.setToolTipText(tooltip_button_font);
        ti.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				FontDialog dialog = new FontDialog(getShell());
				if(main.getDefaultStyle() != null) 
					dialog.setFontList(main.getDefaultStyle().createFontData());
				if(main.getFontColor() != null)
					dialog.setRGB(main.getFontColor().getRGB());
				dialog.open();
				FontData[] fontList = dialog.getFontList();
				if(fontList == null) return;
				RGB rgb = dialog.getRGB();
				if(main.getFontColor() != null) main.getFontColor().dispose();
				main.getDefaultStyle().fontName = fontList[0].getName();
				main.getDefaultStyle().fontSize = fontList[0].getHeight();
				main.getDefaultStyle().fontStyle = fontList[0].getStyle();
				if(rgb != null) {
					main.setFontColor(new Color(main.getDisplay(), rgb));
					main.getDefaultStyle().foreground = main.getFontColor();
				}
				inputBox.setDefaultStyle(main.getDefaultStyle());
			}
		});
        // 颜色,在有些平台下需要
        if(IS_GTK || IS_MOTIF) {
	        ToolItem tiColor = new ToolItem(tb, SWT.NONE);
	        tiColor.setImage(res.getImage(Resources.icoColor));
	        tiColor.setToolTipText(tooltip_button_color);
	        tiColor.addSelectionListener(new SelectionAdapter() {
	            public void widgetSelected(SelectionEvent e) {
	                ColorDialog dialog = new ColorDialog(getShell());
					if(main.getFontColor() != null)
						dialog.setRGB(main.getFontColor().getRGB());
					dialog.open();
					RGB rgb = dialog.getRGB();
					if(rgb != null) {
						if(main.getFontColor() != null) 
						    main.getFontColor().dispose();
						if(rgb != null) {
							main.setFontColor(new Color(main.getDisplay(), rgb));
							main.getDefaultStyle().foreground = main.getFontColor();
						}
					}
					inputBox.setDefaultStyle(main.getDefaultStyle());
	            }
	        });            
        }
        // 表情
        ti = new ToolItem(tb, SWT.NONE);
        ti.setImage(res.getImage(Resources.icoSmiley));
        ti.setToolTipText(tooltip_button_face);
        ti.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				ToolBar toolbar = ((ToolItem)e.widget).getParent();
				Rectangle bound = toolbar.getBounds();
				openImageSelectionShell(toolbar.getParent().toDisplay(bound.x, bound.y + bound.height));					
			}
		});
        // 动画状态
        ti = new ToolItem(tb, SWT.CHECK);
        ti.setImage(res.getImage(Resources.icoStop));
        ti.setToolTipText(tooltip_button_disable_animation);
        ti.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                ToolItem item = (ToolItem)e.widget;
                outputBox.setForbiddenAnimation(item.getSelection());
                inputBox.setForbiddenAnimation(item.getSelection());                
                item.setToolTipText(item.getSelection() ? tooltip_button_animation : tooltip_button_disable_animation);
            }
        });
		// input form
        inputForm.setTopLeft(tb);
        inputForm.setBackground(Colors.VIEWFORM_BANNER_BACKGROUND);
        inputBox = new RichBox(inputForm);
        inputBox.setBackground(Colors.WHITE);
        inputForm.setContent(inputBox);

        // 按钮区
        Composite buttonContainer = new Composite(container, SWT.NONE);
        gd = new GridData(GridData.FILL_HORIZONTAL);
        buttonContainer.setLayoutData(gd);
        layout = new GridLayout(4, false);
        layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0;
        buttonContainer.setLayout(layout);
        buttonContainer.setBackground(container.getBackground());
        
        Slat btnRecord = new Slat(buttonContainer);
        btnRecord.setText(button_record_accel);
        btnRecord.setLayoutData(new GridData());
        btnRecord.addMouseListener(new MouseAdapter() {
            public void mouseUp(MouseEvent e) {
                showRecord();
            }
        });
        
        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) {
				closeWindow();
			}
		});
        
        final Slat btnSend = new Slat(buttonContainer);
        btnSend.setText(button_send_accel);
        gd = new GridData();
        gd.horizontalIndent = 3;
        btnSend.setLayoutData(gd);
		btnSend.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				sendMessage(inputBox.getText());
			}
		});
        
        Slat btnDropDown = new Slat(buttonContainer);
        btnDropDown.setText("↓");
        gd = new GridData();
        gd.horizontalIndent = 1;
        btnDropDown.setLayoutData(gd);
        btnDropDown.addMouseListener(new MouseAdapter() {
            public void mouseUp(MouseEvent e) {
				// 设置菜单位置
				Rectangle bound = btnSend.getBounds();
				enterMenu.setLocation(btnSend.getParent().toDisplay(bound.x, bound.y + bound.height));
				// 显示菜单
				enterMenu.setVisible(true);
            }
		});
        
		// 聊天记录面板
		viewer = new RecordViewer(container, new FriendRecordProvider(model), main);
		viewer.setFont(res.getDefaultFont());
		viewer.setVisible(false);
		viewer.setRecordManager(main.getRecordManager());
		viewer.setBackground(container.getBackground());
		gd = new GridData(GridData.FILL_HORIZONTAL);
		gd.horizontalSpan = 2;
		gd.heightHint = 200;
		gd.exclude = true;
		viewer.setLayoutData(gd);
		// tableitem双击事件监听器
		viewer.addSelectionListener(
			new SelectionAdapter() {
				public void widgetDefaultSelected(SelectionEvent e) {
					inputBox.appendText(viewer.getSelectedFullText(), main.getDefaultStyle());
				}
			}
		);
		
		// 初始化菜单
		initEnterMenu();
		initFileMenu();
		
		// 初始化快捷键设置
		initKeyAction();
		
		setTalkMode(true);
		
        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);
        
        // 发送消息的快捷键
        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() {
        lblName.setImage(HeadFactory.getSmallHeadByStatus(model));
        lblName.setText(model.displayName + " (" + model.qq + ')');
    }
    
    /**
     * 停止闪烁图标
     */
    protected void stopBlinkImage() {
        blinkRunnable.setStop(true);
    }
    
    /**
     * 开始闪烁图标

⌨️ 快捷键说明

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