📄 mobileinputdialog.java
字号:
/*
* 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.dialogs;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Rectangle;
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.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import edu.tsinghua.lumaqq.IconHolder;
import edu.tsinghua.lumaqq.LumaQQ;
/**
* 添加手机好友输入框
*
* @author 马若劼
*/
public class MobileInputDialog extends Dialog {
private IconHolder icons = IconHolder.getInstance();
private Text textName, textNumber;
private String name, number;
/**
* @param parent
*/
public MobileInputDialog(Shell parent) {
super(parent);
}
/**
* @param parent
* @param style
*/
public MobileInputDialog(Shell parent, int style) {
super(parent, style);
}
/**
* 打开对话框
*/
public void open() {
// create dialog
Shell parent = getParent();
Display display = parent.getDisplay();
Shell dialog = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.MIN);
// init child controls
initLayout(dialog);
// set title and image
dialog.setImage(icons.getImage(IconHolder.icoMobileFriend));
dialog.setText(LumaQQ.getString("add.mobile.title"));
// set dialog to center of screen
Rectangle dialogRect = dialog.getBounds();
Rectangle displayRect = display.getBounds();
dialog.setLocation((displayRect.width-dialogRect.width)/2, (displayRect.height-dialogRect.height)/2);
// event loop
dialog.pack();
dialog.open();
while(!dialog.isDisposed())
if(!display.readAndDispatch())
display.sleep();
}
/**
* @param dialog
*/
private void initLayout(final Shell dialog) {
dialog.setLayout(new GridLayout(2, false));
// 手机好友名称
Label lblTemp = new Label(dialog, SWT.LEFT);
lblTemp.setText(LumaQQ.getString("add.mobile.label.name"));
lblTemp.setLayoutData(new GridData());
textName = new Text(dialog, SWT.BORDER | SWT.SINGLE);
textName.setLayoutData(new GridData(150, -1));
// 手机号码
lblTemp = new Label(dialog, SWT.LEFT);
lblTemp.setText(LumaQQ.getString("add.mobile.label.number"));
lblTemp.setLayoutData(new GridData());
textNumber = new Text(dialog, SWT.BORDER | SWT.SINGLE);
textNumber.setLayoutData(new GridData(150, -1));
Composite comp = new Composite(dialog, SWT.NONE);
comp.setLayout(new GridLayout(2, true));
comp.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, false, 2, 1));
// ok button
Button btnOK = new Button(comp, SWT.PUSH);
btnOK.setText(LumaQQ.getString("add.mobile.button.ok"));
btnOK.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
btnOK.addSelectionListener(
new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
name = textName.getText().trim();
number = textNumber.getText().trim();
dialog.close();
}
}
);
// cancel button
Button btnCancel = new Button(comp, SWT.PUSH);
btnCancel.setText(LumaQQ.getString("add.mobile.button.cancel"));
btnCancel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
btnCancel.addSelectionListener(
new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
name = number = null;
dialog.close();
}
}
);
}
public String getName() {
return name;
}
public String getNumber() {
return number;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -