home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
inprise
/
JSAMPLES.Z
/
CustomerLookupDialog.java
< prev
next >
Wrap
Text File
|
1998-05-08
|
10KB
|
265 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.text.*;
import java.util.*;
import borland.jbcl.layout.*;
import borland.jbcl.control.*;
import borland.jbcl.dataset.*;
import borland.jbcl.view.*;
import borland.jbcl.model.*;
import borland.samples.intl.application.*;
import borland.samples.intl.beans.*;
import borland.samples.intl.beans.event.*;
public class CustomerLookupDialog extends Dialog {
private AppDataModule appDataModule = AppDataModule.getDataModule();
private boolean validCustomer = false;
ResourceBundle textRes = java.util.ResourceBundle.getBundle("borland.samples.intl.gui.resources.TextRes",
LocaleChangeManager.getLocale());
private int captionMargin = 10;
MessageFormat formattedMessage;
Object [] messageArgs;
String messageString;
Dimension screenSize = null;
BevelPanel mainDialogPanel = new BevelPanel();
LabelControl searchNameLabel = new LabelControl();
GridControl gridControl1 = new GridControl();
LocatorControl locatorControl1 = new LocatorControl();
BevelPanel buttonPanel = new BevelPanel();
ButtonControl okButton = new ButtonControl();
ButtonControl cancelButton = new ButtonControl();
GridLayout gridLayout1 = new GridLayout();
GridBagLayout gridBagLayout1 = new GridBagLayout();
public CustomerLookupDialog() {
this(new Frame(), true);
}
public CustomerLookupDialog(Frame frame, boolean modal) {
super(frame, modal);
try {
jbInit();
formattedMessage = new MessageFormat(textRes.getString("Search_by_fieldName"));
messageArgs = new Object [] { gridControl1.getColumnView(0).getCaption() };
messageString = formattedMessage.format(messageArgs);
searchNameLabel.setText(messageString);
screenSize = Toolkit.getDefaultToolkit().getScreenSize();
}
catch (Exception e) {
borland.jbcl.util.Diagnostic.printStackTrace(e);
}
add(mainDialogPanel);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
mainDialogPanel.setSize(screenSize.width * 2 / 3, screenSize.height / 2);
}
public void jbInit() throws Exception{
mainDialogPanel.setLayout(gridBagLayout1);
searchNameLabel.setAlignment(Label.LEFT);
locatorControl1.setDataSet(appDataModule.getCustomerDataSetView());
gridControl1.setDataSet(appDataModule.getCustomerDataSetView());
gridControl1.setShowPopup(false);
gridControl1.addMouseListener(new CustomerLookupDialog_gridControl1_mouseAdapter(this));
gridControl1.addSubfocusListener(new CustomerLookupDialog_gridControl1_subfocusAdapter(this));
gridControl1.setReadOnly(true);
okButton.setLabel(textRes.getString("OK"));
okButton.addActionListener(new CustomerLookupDialog_okButton_actionAdapter(this));
cancelButton.setLabel(textRes.getString("Cancel"));
cancelButton.addActionListener(new CustomerLookupDialog_cancelButton_actionAdapter(this));
gridLayout1.setRows(1);
gridLayout1.setColumns(2);
gridLayout1.setHgap(10);
buttonPanel.setLayout(gridLayout1);
buttonPanel.setBevelInner(BevelPanel.FLAT);
buttonPanel.add(okButton, null);
buttonPanel.add(cancelButton, null);
this.setTitle(textRes.getString("Find_customer"));
mainDialogPanel.add(searchNameLabel, new GridBagConstraints2(0, 0, 5, 1, 100.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(10, 10, 5, 10), 0, 0));
mainDialogPanel.add(locatorControl1, new GridBagConstraints2(0, 1, 5, 1, 100.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 5, 10), 0, 0));
mainDialogPanel.add(gridControl1, new GridBagConstraints2(0, 2, 5, 4, 100.0, 100.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 10, 5, 10), 0, 0));
mainDialogPanel.add(buttonPanel, new GridBagConstraints2(0, 6, 5, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 10, 10, 10), 0, 0));
this.addWindowListener(new CustomerLookupDialog_this_windowAdapter(this));
}
// if a customer was selected and the password was valid, returns true
// otherwise, returns false
public boolean isValidCustomer() {
return validCustomer;
}
//OK
void okButton_actionPerformed(ActionEvent e) {
try {
Component component = this;
Frame frame = null;
while ((component = component.getParent()) != null) {
if (component instanceof Frame) {
frame = (Frame) component;
break;
}
}
if (frame == null) {
frame = new Frame();
}
PasswordDialog passwordDialog = new PasswordDialog(frame, textRes.getString("Password"));
passwordDialog.show();
String password;
if ((password = passwordDialog.getPassword()) != null) {
if (!appDataModule.isValidCustomerDataViewPassword(password)) {
Message message = new Message();
message.setFrame(frame);
message.setLabels(new String [] { textRes.getString("OK") });
message.setMessage(textRes.getString("Invalid_password"));
message.setVisible(true);
return;
}
validCustomer = true;
} else {
return;
}
} catch (Exception ex) {
borland.jbcl.util.Diagnostic.printStackTrace(ex);
}
dispose();
}
//Cancel
void cancelButton_actionPerformed(ActionEvent 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();
gridControl1.setPreferredSize(new Dimension((gridControl1.getPreferredSize().width >= screenSize.width) ? (screenSize.width / 2) :
gridControl1.getPreferredSize().width,
(gridControl1.getPreferredSize().height >= screenSize.height) ? (screenSize.height / 2) :
gridControl1.getPreferredSize().height));
//Center the window
this.pack();
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);
}
void this_windowClosing(WindowEvent e) {
System.out.println("CustomerLookupDialog() window closing...");
dispose();
}
void gridControl1_subfocusChanged(MatrixSubfocusEvent e) {
// messageArgs = new Object [] { textRes.getString(gridControl1.getColumnView(e.getLocation().column).getName()) };
messageArgs = new Object [] { gridControl1.getColumnView(e.getLocation().column).getCaption() };
messageString = formattedMessage.format(messageArgs);
searchNameLabel.setText(messageString);
}
void gridControl1_mouseClicked(MouseEvent e) {
if (e.getClickCount() >= 2) {
okButton_actionPerformed(new ActionEvent(gridControl1, ActionEvent.ACTION_PERFORMED, ""));
}
}
}
class CustomerLookupDialog_okButton_actionAdapter implements ActionListener{
CustomerLookupDialog adaptee;
CustomerLookupDialog_okButton_actionAdapter(CustomerLookupDialog adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.okButton_actionPerformed(e);
}
}
class CustomerLookupDialog_cancelButton_actionAdapter implements ActionListener{
CustomerLookupDialog adaptee;
CustomerLookupDialog_cancelButton_actionAdapter(CustomerLookupDialog adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.cancelButton_actionPerformed(e);
}
}
class CustomerLookupDialog_this_windowAdapter extends WindowAdapter {
CustomerLookupDialog adaptee;
CustomerLookupDialog_this_windowAdapter(CustomerLookupDialog adaptee) {
this.adaptee = adaptee;
}
public void windowClosing(WindowEvent e) {
adaptee.this_windowClosing(e);
}
}
class CustomerLookupDialog_gridControl1_subfocusAdapter extends borland.jbcl.model.MatrixSubfocusAdapter {
CustomerLookupDialog adaptee;
CustomerLookupDialog_gridControl1_subfocusAdapter(CustomerLookupDialog adaptee) {
this.adaptee = adaptee;
}
public void subfocusChanged(MatrixSubfocusEvent e) {
adaptee.gridControl1_subfocusChanged(e);
}
}
class CustomerLookupDialog_gridControl1_mouseAdapter extends java.awt.event.MouseAdapter {
CustomerLookupDialog adaptee;
CustomerLookupDialog_gridControl1_mouseAdapter(CustomerLookupDialog adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.gridControl1_mouseClicked(e);
}
}