home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
inprise
/
JSAMPLES.Z
/
ViewOnlyNavigationBar.java
< prev
next >
Wrap
Text File
|
1998-05-08
|
5KB
|
145 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.beans;
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.*;
/**
* A data-aware button bar bean which allows only navigation through a dataset.
*/
public class ViewOnlyNavigationBar extends BevelPanel implements NavigationListener, AccessListener {
private GridLayout gridLayout1 = new GridLayout();
private ButtonBar buttonBar1 = new ButtonBar();
private DataSet dataSet = null;
public ViewOnlyNavigationBar() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
public void jbInit() throws Exception{
this.setLayout(gridLayout1);
gridLayout1.setRows(1);
gridLayout1.setColumns(4);
buttonBar1.setLayout(gridLayout1);
buttonBar1.setButtonType(ButtonBar.IMAGE_ONLY);
buttonBar1.setLabels(new String[] {"First", "Prior", "Next", "Last"});
buttonBar1.setImageNames(new String[] { this.getClass().getResource("resources/first.gif").toString(),
this.getClass().getResource("resources/prior.gif").toString(),
this.getClass().getResource("resources/next.gif").toString(),
this.getClass().getResource("resources/last.gif").toString(), });
buttonBar1.addActionListener(new ViewOnlyNavigationBar_buttonBar1_actionAdapter(this));
buttonBar1.doLayout();
this.add(buttonBar1, null);
}
public void setDataSet(DataSet dataSet) {
if (dataSet != null) {
dataSet.removeAccessListener(this);
dataSet.removeNavigationListener(this);
}
this.dataSet = dataSet;
dataSet.addAccessListener(this);
dataSet.addNavigationListener(this);
updateButtonEnabledState();
}
public DataSet getDataSet() {
return dataSet;
}
public void accessChange(AccessEvent e) {
updateButtonEnabledState();
}
public void navigated(NavigationEvent e) {
updateButtonEnabledState();
}
void buttonBar1_actionPerformed(java.awt.event.ActionEvent e) {
try {
if (dataSet != null) {
String command = e.getActionCommand();
if (command.equals("First")) {
dataSet.first();
} else if (command.equals("Prior")) {
dataSet.prior();
} else if (command.equals("Next")) {
dataSet.next();
} else if (command.equals("Last")) {
dataSet.last();
}
}
updateButtonEnabledState();
} catch (Exception ex) {
DataSetException.handleException(dataSet, null, ex, true);
}
}
private void updateButtonEnabledState() {
try {
if ((dataSet != null) && (dataSet.isOpen() == true)) {
buttonBar1.setButtonEnabled("First", !dataSet.atFirst());
buttonBar1.setButtonEnabled("Prior", !dataSet.atFirst());
buttonBar1.setButtonEnabled("Last", !dataSet.atLast());
buttonBar1.setButtonEnabled("Next", !dataSet.atLast());
} else {
buttonBar1.setButtonEnabled("First", false);
buttonBar1.setButtonEnabled("Prior", false);
buttonBar1.setButtonEnabled("Last", false);
buttonBar1.setButtonEnabled("Next", false);
}
} catch (DataSetException e) {
DataSetException.handleException(dataSet, null, e, true);
}
}
}
class ViewOnlyNavigationBar_buttonBar1_actionAdapter implements java.awt.event.ActionListener {
ViewOnlyNavigationBar adaptee;
ViewOnlyNavigationBar_buttonBar1_actionAdapter(ViewOnlyNavigationBar adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(java.awt.event.ActionEvent e) {
adaptee.buttonBar1_actionPerformed(e);
}
}