📄 cipheraction.java
字号:
package net.sf.pim.action;
import net.sf.util.CipherUtil;
import net.sf.util.StringUtil;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
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.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
/**
* @author levin
* 2007-02-19
*/
public class CipherAction extends UiAction {
public CipherAction() {
super();
name = "加密工具...";
gif = "position.gif";
}
public void run() {
super.run();
TitleAreaDialog dialog=new CipherDialog(parent.getTv().getControl().getShell());
dialog.open();
}
class CipherDialog extends TitleAreaDialog {
private Text plain;
private Text cipher;
private CipherDialog(Shell parentShell) {
super(parentShell);
}
@Override
protected Control createContents(Composite parent) {
Control control = super.createContents(parent);
setTitle("加密工具");
setMessage("请输入明文,然后执行加密,再将密文拷贝至配置项的输入框中");
return control;
}
@Override
protected Point getInitialSize() {
return new Point(320,240);
}
@Override
protected Control createDialogArea(Composite parent) {
Composite control=(Composite) super.createDialogArea(parent);
Composite composite=new Composite(control,SWT.NULL);
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.verticalSpacing = 2;
layout.horizontalSpacing = 2;
layout.numColumns=2;
composite.setLayout(layout);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
Label label=new Label(composite,SWT.NULL);
label.setText("明文:");
plain =new Text(composite,SWT.WRAP);
plain.setLayoutData(new GridData(GridData.FILL_BOTH));
label=new Label(composite,SWT.NULL);
label.setText("密文:");
cipher =new Text(composite,SWT.WRAP);
cipher.setLayoutData(new GridData(GridData.FILL_BOTH));
composite.setFont(parent.getFont());
return control;
}
@Override
protected void createButtonsForButtonBar(Composite parent) {
Button cipherButton=createButton(parent, IDialogConstants.CLIENT_ID+1, "加密",true);
cipherButton.addSelectionListener(new SelectionAdapter(){
@Override
public void widgetSelected(SelectionEvent e) {
if(StringUtil.isNull(plain.getText()))return ;
cipher.setText(CipherUtil.PREFIX+CipherUtil.Encrypt(plain.getText())+CipherUtil.SUFIX);
}});
Button copyButton=createButton(parent,IDialogConstants.CLIENT_ID+2,"拷贝",false);
copyButton.addSelectionListener(new SelectionAdapter(){
@Override
public void widgetSelected(SelectionEvent e) {
if(StringUtil.isNull(cipher.getText()))return ;
Object[] data = new Object[] { cipher.getText() };
Transfer[] transferTypes = new Transfer[] { TextTransfer.getInstance() };
new Clipboard(CipherDialog.this.getShell().getDisplay()).setContents(data, transferTypes);
}
});
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,false);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -