home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-07-30 | 5.0 KB | 165 lines |
- 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.*;
-
- 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");
-
- 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();
- }
-
- public void show() {
- //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);
- super.show();
- }
-
- 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);
- }
- }
-
-