📄 setpassworddialog.java
字号:
/* * Copyright 2006 Marcel Schoffelmeer * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.s10r.manager.dialogs;import org.eclipse.jface.dialogs.IDialogConstants;import org.eclipse.jface.dialogs.TitleAreaDialog;import org.eclipse.swt.SWT;import org.eclipse.swt.events.KeyEvent;import org.eclipse.swt.events.KeyListener;import org.eclipse.swt.graphics.RGB;import org.eclipse.swt.layout.GridData;import org.eclipse.swt.layout.GridLayout;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 schoffem */public class SetPasswordDialog extends TitleAreaDialog{ private Text password; private Text confirm; private String msg; private String passwordStr; public SetPasswordDialog(Shell shell, String msg) { super(shell); setShellStyle(SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM); setTitleAreaColor(new RGB(255, 255, 255)); // can't set title here.. setTitle(msg); this.msg = msg; } @Override public void create() { super.create(); this.setTitle(msg); } protected Control createDialogArea(Composite parent) { final Composite area = new Composite(parent, SWT.NULL); final GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2; gridLayout.marginWidth = 15; gridLayout.marginHeight = 10; area.setLayout(gridLayout); GridData data = new GridData(GridData.FILL_BOTH); Label label = new Label(area, SWT.NONE); label.setText("Password:"); data = new GridData(GridData.FILL_BOTH); data.widthHint = 200; password = new Text(area, SWT.BORDER); password.setLayoutData(data); password.setEchoChar('*'); KeyListener keyListener = new KeyListener() { public void keyPressed(KeyEvent arg0) { } public void keyReleased(KeyEvent arg0) { validateEntry(); }}; password.addKeyListener(keyListener); Label label2 = new Label(area, SWT.NONE); label2.setText("Confirm Password:"); data = new GridData(GridData.FILL_BOTH); data.widthHint = 200; confirm = new Text(area, SWT.BORDER); confirm.setLayoutData(data); confirm.setEchoChar('*'); confirm.addKeyListener(keyListener); return area; } @Override protected Control createButtonBar(Composite arg0) { Control c = super.createButtonBar(arg0); enableOK(false); return c; } /** * Enables the OK button if more than 1 character of password * entry has been entered and the confirmation matches the * password. */ private void validateEntry() { if (password.getText().length() > 0 && password.getText().equals(confirm.getText())) { passwordStr = password.getText(); enableOK(true); } else { passwordStr = null; enableOK(false); } } private void enableOK(boolean enable) { getButton(IDialogConstants.OK_ID).setEnabled(enable); } /** * @return the password * @uml.property name="password" */ public String getPassword() { return this.passwordStr; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -