home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 15
/
BUGCD1998_06.ISO
/
aplic
/
jbuilder
/
jsamples.z
/
CustomerLookupDialog.java
< prev
next >
Wrap
Text File
|
1997-07-30
|
8KB
|
230 lines
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.*;
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");
private int captionMargin = 10;
MessageFormat formattedMessage;
Object [] messageArgs;
String messageString;
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(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);
}
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();
}
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();
}
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);
}
}