home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
inprise
/
JSAMPLES.Z
/
VisualEvents_Frame.java
< prev
next >
Wrap
Text File
|
1998-05-08
|
5KB
|
116 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.visualevents;
import java.awt.*;
import java.awt.event.*;
import borland.jbcl.control.*;
import borland.jbcl.layout.*;
import borland.sql.dataset.*;
import borland.jbcl.dataset.*;
import borland.jbcl.util.*;
public class VisualEvents_Frame extends DecoratedFrame {
private BorderLayout borderLayout1 = new BorderLayout();
private BevelPanel bevelPanel1 = new BevelPanel();
Database database1 = new Database();
QueryDataSet queryDataSet1 = new QueryDataSet();
QueryDataSet queryDataSet2 = new QueryDataSet();
GridControl gridControl1 = new GridControl();
GridControl gridControl2 = new GridControl();
StatusBar statusBar1 = new StatusBar();
NavigatorControl navigatorControl1 = new NavigatorControl();
GridBagLayout gridBagLayout1 = new GridBagLayout();
//Construct the frame
public VisualEvents_Frame() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception{
this.setLayout(borderLayout1);
this.setSize(new Dimension(559, 482));
this.setTitle("Share NavigatorControl and StatusBar, Show/Hide Buttons");
bevelPanel1.setLayout(gridBagLayout1);
//add a Database component and set its connection property
database1.setConnection(new borland.sql.dataset.ConnectionDescriptor(
"jdbc:odbc:DataSet Tutorial", "SYSDBA", "masterkey", false, Database.DEFAULT_DRIVERS));
//add a QueryDataSet and set its query property
queryDataSet1.setQuery(new QueryDescriptor(database1,
"select * from department", null));
//add a second QueryDataSet and set its query property
// and its masterDetail property
queryDataSet2.setQuery(new QueryDescriptor(database1,
"select * from employee", null));
queryDataSet2.setMasterLink(new MasterLinkDescriptor(queryDataSet1,
new String[] {"DEPT_NO"}, new String[] {"DEPT_NO"}, false));
//add two gridControls and bind each to a data set
gridControl1.setDataSet(queryDataSet1);
gridControl2.setDataSet(queryDataSet2);
statusBar1.setBevelOuter(0);
//add a NavigatorControl
navigatorControl1.setDataSet(queryDataSet1);
this.add(bevelPanel1, BorderLayout.CENTER);
bevelPanel1.add(gridControl1, new GridBagConstraints2(0, 1, 1, 1, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(7, 11, 0, 11), -496, -290));
bevelPanel1.add(gridControl2, new GridBagConstraints2(0, 2, 1, 1, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 11, 0, 11), -944, 146));
bevelPanel1.add(statusBar1, new GridBagConstraints2(0, 3, 1, 1, 1.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 11, 8, 11), 326, -2));
bevelPanel1.add(navigatorControl1, new GridBagConstraints2(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(8, 0, 0, 0), 0, 0));
//define which navigator buttons to show for each data set
int[] grid1EnabledFlags = { 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
int[] grid2EnabledFlags = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
//instantiate a listener for each data set
FocusListener grid1Focus = new VisualEvents_Focus(this, queryDataSet1,
grid1EnabledFlags);
FocusListener grid2Focus = new VisualEvents_Focus(this, queryDataSet2,
grid2EnabledFlags);
//tie each listener to its grid
gridControl1.addFocusListener(grid1Focus);
gridControl2.addFocusListener(grid2Focus);
}
// set navigator and statusBar properties for the grid that got focus
public void gridFocusGained(QueryDataSet qds, int[] navEnabledFlags) {
navigatorControl1.setDataSet(qds);
for (int i = 0; i < navEnabledFlags.length; ++i)
navigatorControl1.setButtonEnabled(i, navEnabledFlags[i] == 1);
statusBar1.setDataSet(qds);
}
}