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

📄 replypage.java

📁 lumaQQ的源文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
* LumaQQ - Java QQ Client
*
* Copyright (C) 2004 luma <stubma@163.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package edu.tsinghua.lumaqq.ui.config.sys;

import static edu.tsinghua.lumaqq.resource.Messages.*;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Text;

import edu.tsinghua.lumaqq.ecore.reply.Replies;
import edu.tsinghua.lumaqq.resource.Colors;
import edu.tsinghua.lumaqq.resource.Resources;
import edu.tsinghua.lumaqq.ui.MainShell;
import edu.tsinghua.lumaqq.ui.config.AbstractPage;
import edu.tsinghua.lumaqq.ui.helper.UITool;
import edu.tsinghua.lumaqq.ui.listener.AroundBorderPaintListener;
import edu.tsinghua.lumaqq.ui.provider.ListContentProvider;

/**
 * 回复设置页
 * 
 * @author luma
 */
public class ReplyPage extends AbstractPage {    
    /**
     * 为table viewer提供label
     * 
     * @author luma
     */
    private class ReplyContentProvider extends LabelProvider implements
            ITableLabelProvider {
        /* (non-Javadoc)
         * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
         */
        public Image getColumnImage(Object element, int columnIndex) {
            return null;
        }

        /* (non-Javadoc)
         * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
         */
        public String getColumnText(Object element, int columnIndex) {
            return (String)element;
        }
    }
    
    private static final int AUTO_REPLY = 1;
    private static final int QUICK_REPLY = 2;
    
    private List<String> autoReplies;
    private List<String> quickReplies;
    private ILabelProvider labelProvider;
    private PaintListener paintListener;
    private TableItem currentAutoReply, currentQuickReply;
    
    private Button btnDeleteAuto, btnDeleteQuick;
    private Text textEdit;
    private Button btnAddAuto, btnAddQuick;
    private TableViewer autoViewer, quickViewer;
    private MainShell main;
    
    /**
     * @param parent
     */
    public ReplyPage(Composite parent, MainShell main) {
        super(parent);
        this.main = main;
    }
    
    /* (non-Javadoc)
     * @see edu.tsinghua.lumaqq.shells.AbstractPage#initialVariable()
     */
	@Override
    protected void initialVariable() {
        autoReplies = new ArrayList<String>();
        quickReplies = new ArrayList<String>();
        labelProvider = new ReplyContentProvider();
        paintListener = new AroundBorderPaintListener(new Class[] { Table.class, Text.class }, Colors.PAGE_CONTROL_BORDER);
    }

    /* (non-Javadoc)
     * @see edu.tsinghua.lumaqq.ui.config.AbstractPage#createContent(org.eclipse.swt.widgets.Composite)
     */
	@Override
    protected Control createContent(Composite parent) {
        Composite container = new Composite(parent, SWT.NONE);
        container.setBackground(Colors.PAGE_BACKGROUND);
        GridLayout layout = new GridLayout(2, true);
        layout.marginHeight = layout.marginWidth = 15;
        layout.verticalSpacing = 15;
        container.setLayout(layout);
        
        // 设置使用缺省背景色
        UITool.setDefaultBackground(null);
        
        // 自动回复组
        layout = new GridLayout();
        layout.marginHeight = layout.marginWidth = 8;
        GridData gd = new GridData(GridData.FILL_BOTH);
        Group autoGroup = UITool.createGroup(container, sys_opt_group_auto_reply, gd, layout);
        autoGroup.addPaintListener(paintListener);
        
        // 删除自动回复按钮
        btnDeleteAuto = UITool.createButton(autoGroup, button_delete);
        btnDeleteAuto.setEnabled(false);
        btnDeleteAuto.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
				btnDeleteAuto.setEnabled(false);
				
                Table t = autoViewer.getTable();
				TableItem ti = t.getItem(t.getSelectionIndex());
				boolean checked = ti.getChecked();
				if(checked)
				    ti.setChecked(false);
				autoReplies.remove(t.getSelectionIndex());
				autoViewer.refresh();
				
				if(checked) {
					if(autoReplies.size() > 0) {
					    currentAutoReply = t.getItem(0);
						currentAutoReply.setChecked(true);						
					} else
					    currentAutoReply = null;
				}				
				
                makeDirty(AUTO_REPLY);
            }
        });
        
        // 自动回复的table viewer
        autoViewer = new TableViewer(autoGroup, SWT.SINGLE | SWT.CHECK | SWT.V_SCROLL | SWT.FULL_SELECTION);
        autoViewer.setContentProvider(new ListContentProvider<String>(autoReplies));
        autoViewer.setLabelProvider(labelProvider);
        new TableColumn(autoViewer.getTable(), SWT.LEFT);
        autoViewer.getTable().setHeaderVisible(false);
        autoViewer.getTable().setLinesVisible(false);
        autoViewer.getTable().setBackground(Colors.PAGE_BACKGROUND);
        gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL);
        gd.widthHint = 150;
        autoViewer.getTable().setLayoutData(gd);
        autoViewer.getTable().addControlListener(new ControlAdapter() {
            public void controlResized(ControlEvent e) {
                Table t = (Table)e.getSource();
                t.getColumn(0).setWidth(t.getClientArea().width);
            }
        });
        autoViewer.getTable().addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
                Table t = (Table)e.getSource();
                
                if(e.detail == SWT.CHECK) {
					TableItem ti = (TableItem)e.item;
					if(ti.getChecked()) {				
					    if(currentAutoReply != null)
					        currentAutoReply.setChecked(false);
						currentAutoReply = ti;
						
						makeDirty(AUTO_REPLY);
					} else
						ti.setChecked(true);
                } else {
					if(t.getSelectionIndex() != -1) {
						btnDeleteAuto.setEnabled(true);
						textEdit.setText(t.getSelection()[0].getText());
					} else {
						btnDeleteAuto.setEnabled(false);
					}                    
                }                
            }
        });

⌨️ 快捷键说明

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