home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
inprise
/
JSAMPLES.Z
/
dbSampleFrame.java
< prev
next >
Wrap
Text File
|
1998-05-08
|
17KB
|
460 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.tutorial.dataset.dbsample;
import java.awt.*;
import java.awt.event.*;
import borland.jbcl.control.*;
import borland.jbcl.layout.*;
import borland.sql.dataset.*;
import borland.jbcl.dataset.*;
import java.math.*;
public class dbSampleFrame extends DecoratedFrame {
BorderLayout borderLayout1 = new BorderLayout();
BorderLayout borderLayout2 = new BorderLayout();
MenuBar menuBar1 = new MenuBar();
Menu menuFile = new Menu();
MenuItem menuFileExit = new MenuItem();
Menu menuHelp = new Menu();
MenuItem menuHelpAbout = new MenuItem();
StatusBar statusBar = new StatusBar();
Database db = new Database();
QueryDataSet qDataSet = new QueryDataSet();
BevelPanel topPanel = new BevelPanel();
CheckboxPanel checkboxPanel1 = new CheckboxPanel();
BevelPanel middlePanel = new BevelPanel();
BevelPanel functionPanel = new BevelPanel();
Panel locatePanel = new Panel();
LocatorControl locateControl = new LocatorControl();
GridBagLayout gridBagLayout2 = new GridBagLayout();
Label locateLabel = new Label();
NavigatorControl navigatorControl1 = new NavigatorControl();
CardLayout cardLayout1 = new CardLayout();
GridControl gridControl1 = new GridControl();
BorderLayout borderLayout3 = new BorderLayout();
Column column1 = new Column();
Column column2 = new Column();
Column column3 = new Column();
Column column4 = new Column();
Column column5 = new Column();
Column column6 = new Column();
Column column7 = new Column();
Column column8 = new Column();
Column column9 = new Column();
Column column10 = new Column();
Column column11 = new Column();
MenuItem navigateMenuItem = new MenuItem();
Panel calcResultsPanel = new Panel();
Panel bottomPanel = new Panel();
BorderLayout borderLayout5 = new BorderLayout();
XYLayout xYLayout1 = new XYLayout();
Label label4 = new Label();
Label label5 = new Label();
Label label6 = new Label();
MenuItem findMenuItem = new MenuItem();
FieldControl orgTotal = new FieldControl();
FieldControl newTotal = new FieldControl();
FieldControl difference = new FieldControl();
//Construct the frame
public dbSampleFrame() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception{
this.setLayout(borderLayout1);
this.setTitle("dbSample");
menuFile.setLabel("File");
menuFileExit.setLabel("Exit");
menuFileExit.addActionListener(new dbSampleFrame_menuFileExit_ActionAdapter(this));
menuHelp.setLabel("Help");
menuHelpAbout.setLabel("About");
statusBar.setAlignment(Label.CENTER);
statusBar.setDataSet(qDataSet);
statusBar.setForeground(Color.blue);
statusBar.setFont(new Font("Helvetica", 1, 12));
menuHelpAbout.addActionListener(new dbSampleFrame_menuHelpAbout_ActionAdapter(this));
topPanel.setLayout(borderLayout2);
checkboxPanel1.setFont(new Font("Dialog", 1, 12));
checkboxPanel1.setGrouped(true);
checkboxPanel1.setLabels(new String[] {"Navigate", "Find"});
checkboxPanel1.setSelectedIndex(0);
middlePanel.setBevelOuter(BevelPanel.LOWERED);
middlePanel.setLayout(borderLayout3);
checkboxPanel1.addItemListener(new dbSampleFrame_checkboxPanel1_itemAdapter(this));
checkboxPanel1.setOrientation(borland.jbcl.util.Orientation.HORIZONTAL);
functionPanel.setBevelOuter(BevelPanel.LOWERED);
locateControl.setDataSet(qDataSet);
locateLabel.setFont(new Font("Dialog", 1, 12));
locateLabel.setText(" Find");
navigatorControl1.setDataSet(qDataSet);
gridControl1.setDataSet(qDataSet);
// Set column Properties
column1.setColumnName("EMP_NO");
column1.setDataType(borland.jbcl.util.Variant.SHORT);
column1.setWidth(10);
column2.setColumnName("FULL_NAME");
column2.setDataType(borland.jbcl.util.Variant.STRING);
column2.setWidth(20);
// sets the display mask for the date column
column3.setColumnName("HIRE_DATE");
column3.setDisplayMask("MM-dd-yy");
column3.setDataType(borland.jbcl.util.Variant.TIMESTAMP);
// sets the edit mask for the date column
column3.setEditMask("MM-dd-yyyy");
column4.setColumnName("DEPT_NO");
column4.setDataType(borland.jbcl.util.Variant.STRING);
column4.setWidth(10);
column5.setCaption("COUNTRY");
column5.setColumnName("JOB_COUNTRY");
column5.setDataType(borland.jbcl.util.Variant.STRING);
column5.setWidth(15);
column6.setCaption("SALARY");
column6.setColumnName("SALARY");
column6.setDataType(borland.jbcl.util.Variant.BIGDECIMAL);
column6.setScale(2);
column6.setWidth(12);
column7.setCalcType(borland.jbcl.dataset.CalcType.CALC);
column7.setColumnName("NEW_SALARY");
column7.setDataType(borland.jbcl.util.Variant.BIGDECIMAL);
column7.setVisible(borland.jbcl.util.TriState.NO);
// Aggregator on a dataColumn..
column8.setCalcType(borland.jbcl.dataset.CalcType.AGGREGATE);
column8.setAgg(new AggDescriptor(null,"Salary",new SumAggOperator()));
column8.setColumnName("ORG_TOTAL");
column8.setDataType(borland.jbcl.util.Variant.BIGDECIMAL);
column8.setScale(2);
// Aggregator on a calcColumn..
column9.setCalcType(borland.jbcl.dataset.CalcType.AGGREGATE);
column9.setColumnName("NEW_TOTAL");
column9.setAgg(new AggDescriptor(null,"NEW_SALARY",new SumAggOperator()));
column9.setDataType(borland.jbcl.util.Variant.BIGDECIMAL);
column9.setScale(2);
// Calc on Aggregated Column..
column10.setCalcType(borland.jbcl.dataset.CalcType.CALC);
column10.setColumnName("DIFF_SALARY");
column10.setDataType(borland.jbcl.util.Variant.BIGDECIMAL);
column10.setScale(2);
column10.setVisible(borland.jbcl.util.TriState.NO);
// Aggregator on calcColumn..
column11.setCalcType(borland.jbcl.dataset.CalcType.AGGREGATE);
column11.setColumnName("DIFF_TOTAL");
column11.setAgg(new AggDescriptor(null,"DIFF_SALARY",new SumAggOperator()));
column11.setDataType(borland.jbcl.util.Variant.BIGDECIMAL);
column11.setPrecision(2);
navigateMenuItem.setLabel("Navigate");
findMenuItem.setLabel("Find");
orgTotal.setColumnName("ORG_TOTAL");
orgTotal.setDataSet(qDataSet);
newTotal.setColumnName("NEW_TOTAL");
newTotal.setDataSet(qDataSet);
difference.setColumnName("DIFF_TOTAL");
difference.setDataSet(qDataSet);
findMenuItem.addActionListener(new dbSampleFrame_findMenuItem_actionAdapter(this));
calcResultsPanel.setLayout(xYLayout1);
navigateMenuItem.addActionListener(new dbSampleFrame_navigateMenuItem_actionAdapter(this));
functionPanel.setLayout(cardLayout1);
locatePanel.setLayout(gridBagLayout2);
menuFile.add(navigateMenuItem);
menuFile.add(findMenuItem);
menuFile.add(menuFileExit);
menuHelp.add(menuHelpAbout);
menuBar1.add(menuFile);
menuBar1.add(menuHelp);
db.setConnection(new borland.sql.dataset.ConnectionDescriptor("jdbc:odbc:dataset tutorial", "sysdba", "masterkey", false, "sun.jdbc.odbc.JdbcOdbcDriver"));
qDataSet.setQuery(new borland.sql.dataset.QueryDescriptor(db, "select Emp_no,Full_name,Hire_date,Dept_No,Job_Country,Salary from employee", null, true, Load.ALL));
qDataSet.addCalcFieldsListener(new dbSampleFrame_qDataSet_calcFieldsAdapter(this));
label4.setText("Original Total");
label5.setText("New Total");
label6.setText("Difference");
bottomPanel.setLayout(borderLayout5);
this.setMenuBar(menuBar1);
this.setSize(new Dimension(722, 439));
this.add(topPanel, BorderLayout.NORTH);
this.add(middlePanel, BorderLayout.CENTER);
this.add(bottomPanel, BorderLayout.SOUTH);
// Set the top Pannel
functionPanel.add(navigatorControl1, "navigatorControl1");
locatePanel.add(locateControl, new GridBagConstraints2(1, 0, 1, 2, 1.0, 0.0
,GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 214, 0));
locatePanel.add(locateLabel, new GridBagConstraints2(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), -4, 0));
functionPanel.add(locatePanel, "locatePanel");
topPanel.add(functionPanel, BorderLayout.WEST);
topPanel.add(checkboxPanel1, BorderLayout.CENTER);
// Set the middlePannel
middlePanel.add(gridControl1, BorderLayout.CENTER);
// Set the bottomPannel
bottomPanel.add(calcResultsPanel, BorderLayout.NORTH);
calcResultsPanel.add(label4, new XYConstraints(7, 14, -1, -1));
calcResultsPanel.add(label5, new XYConstraints(229, 14, 95, -1));
calcResultsPanel.add(label6, new XYConstraints(459, 14, -1, -1));
calcResultsPanel.add(orgTotal, new XYConstraints(89, 14, -1, -1));
calcResultsPanel.add(newTotal, new XYConstraints(325, 14, -1, -1));
calcResultsPanel.add(difference, new XYConstraints(538, 14, -1, -1));
bottomPanel.add(statusBar, BorderLayout.SOUTH);
qDataSet.setColumns(new Column[] {column1, column2, column3, column4, column5, column6, column7, column8, column9, column10, column11});
}
//File | Exit action performed
public void fileExit_actionPerformed(ActionEvent e) {
System.exit(0);
}
//Help | About action performed
public void helpAbout_actionPerformed(ActionEvent e) {
dbSampleFrame_AboutBox dlg = new dbSampleFrame_AboutBox(this);
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
dlg.setModal(true);
dlg.show();
}
void checkboxPanel1_itemStateChanged(ItemEvent e) {
switch(checkboxPanel1.getSelectedIndex()){
case 0 : cardLayout1.show(functionPanel,"navigatorControl1"); break;
case 1 : cardLayout1.show(functionPanel,"locatePanel");break;
case 2 : break;
default : break;
}
}
void qDataSet_calcFields(ReadRow readRow, DataRow dataRow, boolean boolean1) throws DataSetException{
BigDecimal bDin = readRow.getBigDecimal("Salary");
BigDecimal bDout = bDin.add(new BigDecimal(bDin.doubleValue()*10.0/100));
dataRow.setBigDecimal("NEW_SALARY",bDout);
dataRow.setBigDecimal("DIFF_SALARY",bDout.subtract(bDin));
}
void findMenuItem_actionPerformed(ActionEvent e) {
checkboxPanel1.setSelectedIndex(1);
cardLayout1.show(functionPanel,"locatePanel");
}
void navigateMenuItem_actionPerformed(ActionEvent e) {
checkboxPanel1.setSelectedIndex(0);
cardLayout1.show(functionPanel,"navigatorControl1");
}
}
class dbSampleFrame_menuFileExit_ActionAdapter implements ActionListener{
dbSampleFrame adaptee;
dbSampleFrame_menuFileExit_ActionAdapter(dbSampleFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.fileExit_actionPerformed(e);
}
}
class dbSampleFrame_menuHelpAbout_ActionAdapter implements ActionListener{
dbSampleFrame adaptee;
dbSampleFrame_menuHelpAbout_ActionAdapter(dbSampleFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.helpAbout_actionPerformed(e);
}
}
class dbSampleFrame_AboutBox extends Dialog implements ActionListener {
Panel panel1 = new Panel();
BevelPanel bevelPanel1 = new BevelPanel();
dbSampleFrame_InsetsPanel insetsPanel1 = new dbSampleFrame_InsetsPanel();
dbSampleFrame_InsetsPanel insetsPanel2 = new dbSampleFrame_InsetsPanel();
dbSampleFrame_InsetsPanel insetsPanel3 = new dbSampleFrame_InsetsPanel();
Button button1 = new Button();
ImageControl imageControl1 = new ImageControl();
Label label1 = new Label();
Label label2 = new Label();
Label label3 = new Label();
Label label4 = new Label();
BorderLayout borderLayout1 = new BorderLayout();
BorderLayout borderLayout2 = new BorderLayout();
FlowLayout flowLayout1 = new FlowLayout();
GridLayout gridLayout1 = new GridLayout();
String product = "DataBase Sample";
String version = "";
String copyright = "Copyright (c) 1997";
String comments = "DataBase Sample";
public dbSampleFrame_AboutBox(Frame parent) {
super(parent);
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
pack();
}
void jbInit() throws Exception{
this.setTitle("About");
setResizable(false);
panel1.setLayout(borderLayout1);
bevelPanel1.setLayout(borderLayout2);
insetsPanel2.setLayout(flowLayout1);
insetsPanel2.setInsets(new Insets(10, 10, 10, 10));
gridLayout1.setRows(4);
gridLayout1.setColumns(1);
label1.setText(product);
label2.setText(version);
label3.setText(copyright);
label4.setText(comments);
insetsPanel3.setLayout(gridLayout1);
insetsPanel3.setInsets(new Insets(10, 60, 10, 10));
button1.setLabel("OK");
button1.addActionListener(this);
imageControl1.setImageName("");
insetsPanel2.add(imageControl1, null);
bevelPanel1.add(insetsPanel2, BorderLayout.WEST);
this.add(panel1, null);
insetsPanel3.add(label1, null);
insetsPanel3.add(label2, null);
insetsPanel3.add(label3, null);
insetsPanel3.add(label4, null);
bevelPanel1.add(insetsPanel3, BorderLayout.CENTER);
insetsPanel1.add(button1, null);
panel1.add(insetsPanel1, BorderLayout.SOUTH);
panel1.add(bevelPanel1, BorderLayout.NORTH);
pack();
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button1) {
setVisible(false);
dispose();
}
}
}
class dbSampleFrame_InsetsPanel extends Panel {
protected Insets insets;
public Insets getInsets() {
return insets == null ? super.getInsets() : insets;
}
public void setInsets(Insets insets) {
this.insets = insets;
}
}
class dbSampleFrame_checkboxPanel1_itemAdapter implements java.awt.event.ItemListener{
dbSampleFrame adaptee;
dbSampleFrame_checkboxPanel1_itemAdapter(dbSampleFrame adaptee) {
this.adaptee = adaptee;
}
public void itemStateChanged(ItemEvent e) {
adaptee.checkboxPanel1_itemStateChanged(e);
}
}
class dbSampleFrame_navigateMenuItem_actionAdapter implements java.awt.event.ActionListener{
dbSampleFrame adaptee;
dbSampleFrame_navigateMenuItem_actionAdapter(dbSampleFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.navigateMenuItem_actionPerformed(e);
}
}
class dbSampleFrame_qDataSet_calcFieldsAdapter implements borland.jbcl.dataset.CalcFieldsListener {
dbSampleFrame adaptee;
dbSampleFrame_qDataSet_calcFieldsAdapter(dbSampleFrame adaptee) {
this.adaptee = adaptee;
}
public void calcFields(ReadRow readRow, DataRow dataRow, boolean boolean1) throws DataSetException{
adaptee.qDataSet_calcFields(readRow, dataRow, boolean1);
}
}
class dbSampleFrame_findMenuItem_actionAdapter implements java.awt.event.ActionListener {
dbSampleFrame adaptee;
dbSampleFrame_findMenuItem_actionAdapter(dbSampleFrame adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.findMenuItem_actionPerformed(e);
}
}