home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
inprise
/
JSAMPLES.Z
/
PasswordDialog.java
< prev
next >
Wrap
Text File
|
1998-05-08
|
6KB
|
189 lines
/*
* Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
*
* This SOURCE CODE FILE, which has been provided by Borland as part
* of a Borland product for use ONLY by licensed users of the product,
* includes CONFIDENTIAL and PROPRIETARY information of Borland.
*
* USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS
* OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
* THE PRODUCT.
*
* IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
* COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
* OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
* OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
* OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
* OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
* CODE FILE.
*/
package borland.samples.intl.gui;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import borland.jbcl.layout.*;
import borland.jbcl.control.*;
import borland.jbcl.view.*;
import borland.jbcl.model.*;
import borland.jbcl.util.*;
import borland.samples.intl.beans.*;
public class PasswordDialog extends Dialog {
BevelPanel mainDialogPanel = new BevelPanel();
BevelPanel entryPanel = new BevelPanel();
BevelPanel buttonPanel = new BevelPanel();
ButtonControl okButton = new ButtonControl();
ButtonControl cancelButton = new ButtonControl();
LabelControl enterPasswordLabel = new LabelControl();
BorderLayout borderLayout1 = new BorderLayout();
GridLayout gridLayout1 = new GridLayout();
FlowLayout flowLayout1 = new FlowLayout();
MaskableTextItemEditor passwordEntryField = new MaskableTextItemEditor();
private String password = null;
ResourceBundle textRes = java.util.ResourceBundle.getBundle("borland.samples.intl.gui.resources.TextRes",
LocaleChangeManager.getLocale());
public PasswordDialog(Frame frame, String title) {
super(frame, title, true);
try {
jbInit();
passwordEntryField.setEditMask("*aaaaaaaaaaaaaaaaaaaa*", Variant.STRING, Locale.getDefault());
}
catch (Exception e) {
e.printStackTrace();
}
add(mainDialogPanel);
pack();
}
public PasswordDialog(Frame frame) {
this(frame, "");
this.setTitle(textRes.getString("Enter_Password"));
}
public void jbInit() throws Exception {
enterPasswordLabel.setText(textRes.getString("Enter_Password"));
enterPasswordLabel.setAlignment(Label.RIGHT);
passwordEntryField.setColumns(15);
passwordEntryField.addActionListener(new PasswordDialog_passwordEntryField_actionAdapter(this));
entryPanel.setLayout(flowLayout1);
entryPanel.add(enterPasswordLabel, null);
entryPanel.add(passwordEntryField, null);
okButton.setLabel(textRes.getString("OK"));
okButton.addActionListener(new PasswordDialog_okButton_actionAdapter(this));
cancelButton.setLabel(textRes.getString("Cancel"));
cancelButton.addActionListener(new PasswordDialog_cancelButton_actionAdapter(this));
gridLayout1.setRows(1);
gridLayout1.setColumns(2);
gridLayout1.setHgap(10);
buttonPanel.setLayout(gridLayout1);
buttonPanel.setBevelInner(BevelPanel.FLAT);
buttonPanel.setMargins(new Insets(10, 10, 10, 10));
buttonPanel.add(okButton, null);
buttonPanel.add(cancelButton, null);
mainDialogPanel.setLayout(borderLayout1);
mainDialogPanel.add(entryPanel, BorderLayout.CENTER);
mainDialogPanel.add(buttonPanel, BorderLayout.SOUTH);
this.addWindowListener(new PasswordDialog_this_windowAdapter(this));
}
//OK
void okButton_actionPerformed(ActionEvent e) {
try {
if (passwordEntryField.getValue() != null) {
password = passwordEntryField.getValue().toString();
}
} catch (IllegalStateException ex) { // will occur if the entered value fails to satisfy editmask pattern
}
dispose();
}
//Cancel
void cancelButton_actionPerformed(ActionEvent e) {
dispose();
}
void this_windowClosing(WindowEvent e) {
dispose();
}
// In order to center the dialog, we override its addNotify()
// method and set its location immediately after the peer is created.
public void addNotify() {
super.addNotify();
//Center the window
this.pack();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = this.getPreferredSize();
if (frameSize.height > screenSize.height)
frameSize.height = screenSize.height;
if (frameSize.width > screenSize.width)
frameSize.width = screenSize.width;
this.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
}
public String getPassword() {
return password;
}
void passwordEntryField_actionPerformed(ActionEvent e) {
okButton_actionPerformed(e);
}
}
class PasswordDialog_okButton_actionAdapter implements ActionListener{
PasswordDialog adaptee;
PasswordDialog_okButton_actionAdapter(PasswordDialog adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.okButton_actionPerformed(e);
}
}
class PasswordDialog_cancelButton_actionAdapter implements ActionListener{
PasswordDialog adaptee;
PasswordDialog_cancelButton_actionAdapter(PasswordDialog adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.cancelButton_actionPerformed(e);
}
}
class PasswordDialog_this_windowAdapter extends WindowAdapter {
PasswordDialog adaptee;
PasswordDialog_this_windowAdapter(PasswordDialog adaptee) {
this.adaptee = adaptee;
}
public void windowClosing(WindowEvent e) {
adaptee.this_windowClosing(e);
}
}
class PasswordDialog_passwordEntryField_actionAdapter implements java.awt.event.ActionListener {
PasswordDialog adaptee;
PasswordDialog_passwordEntryField_actionAdapter(PasswordDialog adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.passwordEntryField_actionPerformed(e);
}
}