From cc152140b86400670d46cba8fe798b30205f6d41 Mon Sep 17 00:00:00 2001 From: Tobias Kellner Date: Fri, 9 Oct 2015 19:32:50 +0200 Subject: (Password)InputDialog added --- .../at/asit/pdfover/gui/controls/InputDialog.java | 153 +++++++++++++++++++++ .../pdfover/gui/controls/PasswordInputDialog.java | 36 +++++ 2 files changed, 189 insertions(+) create mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/InputDialog.java create mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/PasswordInputDialog.java (limited to 'pdf-over-gui') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/InputDialog.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/InputDialog.java new file mode 100644 index 00000000..80c967a6 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/InputDialog.java @@ -0,0 +1,153 @@ +/* + * Copyright 2012 by A-SIT, Secure Information Technology Center Austria + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + */ +package at.asit.pdfover.gui.controls; + +// Imports +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +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 at.asit.pdfover.gui.utils.Messages; + +/** + * + */ +public class InputDialog extends org.eclipse.swt.widgets.Dialog { + /** + * SLF4J Logger instance + **/ +// private static final Logger log = LoggerFactory +// .getLogger(InputDialog.class); + + private String prompt; + String input; + + /** + * SWT flags of the input box + */ + protected static int TEXT_FLAGS = SWT.BORDER; + + /** + * Create a password input dialog + * @param parent parent + * @param title title + * @param prompt prompt message + */ + public InputDialog(Shell parent, String title, String prompt) { + super(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); + setText(title); + setMessage(prompt); + } + + /** + * Get the prompt message + * @return the prompt message + */ + public String getPrompt() { + return this.prompt; + } + + /** + * set the prompt message + * @param message the prompt message + */ + public void setMessage(String message) { + this.prompt = message; + } + + /** + * Get the input + * @return the input + */ + public String getInput() { + return this.input; + } + + /** + * Get the input + * @param input the input + */ + public void setInput(String input) { + this.input = input; + } + + /** + * Open the dialog + * @return the input + */ + public String open() { + Shell shell = new Shell(getParent(), getStyle()); + shell.setText(getText()); + createContents(shell); + shell.pack(); + shell.open(); + Display display = getParent().getDisplay(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + return getInput(); + } + + private void createContents(final Shell shell) { + GridLayout layout = new GridLayout(2, false); + layout.verticalSpacing = 10; + layout.marginLeft = 5; + layout.marginRight = 5; + layout.marginTop = 5; + shell.setLayout(layout); + Label label = new Label(shell, SWT.NONE); + label.setText(this.prompt); + GridData data = new GridData(); + data.horizontalSpan = 2; + label.setLayoutData(data); + final Text text = new Text(shell, TEXT_FLAGS); + data = new GridData(GridData.FILL_HORIZONTAL); + data.horizontalSpan = 2; + text.setLayoutData(data); + Button ok = new Button(shell, SWT.PUSH); + ok.setText(Messages.getString("common.Ok")); //$NON-NLS-1$ + data = new GridData(GridData.FILL_HORIZONTAL); + ok.setLayoutData(data); + ok.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent event) { + InputDialog.this.input = text.getText(); + shell.close(); + } + }); + Button cancel = new Button(shell, SWT.PUSH); + cancel.setText(Messages.getString("common.Cancel")); //$NON-NLS-1$ + data = new GridData(GridData.FILL_HORIZONTAL); + cancel.setLayoutData(data); + cancel.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent event) { + InputDialog.this.input = null; + shell.close(); + } + }); + shell.setDefaultButton(ok); + } +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/PasswordInputDialog.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/PasswordInputDialog.java new file mode 100644 index 00000000..1659b73c --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/PasswordInputDialog.java @@ -0,0 +1,36 @@ +/* + * Copyright 2012 by A-SIT, Secure Information Technology Center Austria + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + */ +package at.asit.pdfover.gui.controls; + +// Imports +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Shell; + +/** + * + */ +public class PasswordInputDialog extends InputDialog { + + /** + * @param parent + * @param title + * @param prompt + */ + public PasswordInputDialog(Shell parent, String title, String prompt) { + super(parent, title, prompt); + TEXT_FLAGS = SWT.BORDER | SWT.PASSWORD; + } +} -- cgit v1.2.3