home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
inprise
/
JRUNTIME.Z
/
DualListBox.java
< prev
next >
Wrap
Text File
|
1998-05-08
|
5KB
|
195 lines
// This snippet creates a panel containing two list boxes, and buttons to
// copy elements from one list to the other.
// <File=DualListBox.java>
//Title:
//Version:
//Copyright:
//Author:
//Company:
//Description:
//
//<PACKAGE>
import java.awt.*;
import java.awt.event.*;
import borland.jbcl.layout.*;
import borland.jbcl.control.*;
public class DualListBox extends BevelPanel {
XYLayout xYLayout1 = new XYLayout();
Label label1 = new Label();
List source = new List();
Label label2 = new Label();
List destination = new List();
Button addOne = new Button();
Button addAll = new Button();
Button removeOne = new Button();
Button removeAll = new Button();
Button ok = new Button();
Button cancel = new Button();
public DualListBox() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
xYLayout1.setWidth(368);
xYLayout1.setHeight(231);
label1.setText("Source list");
label2.setText("Destination list");
addOne.setLabel(">");
addOne.addActionListener(new DualListBox_addOne_actionAdapter(this));
addAll.setLabel(">>");
addAll.addActionListener(new DualListBox_addAll_actionAdapter(this));
removeOne.setLabel("<");
removeOne.addActionListener(new DualListBox_removeOne_actionAdapter(this));
removeAll.setLabel("<<");
removeAll.addActionListener(new DualListBox_removeAll_actionAdapter(this));
ok.setLabel("OK");
ok.addActionListener(new DualListBox_ok_actionAdapter(this));
cancel.setLabel("Cancel");
cancel.addActionListener(new DualListBox_cancel_actionAdapter(this));
this.setLayout(xYLayout1);
this.add(label1, new XYConstraints(12, 4, 140, 14));
this.add(source, new XYConstraints(12, 20, 140, 176));
this.add(label2, new XYConstraints(214, 4, 140, 14));
this.add(destination, new XYConstraints(214, 20, 140, 176));
this.add(addOne, new XYConstraints(166, 35, 32, 21));
this.add(addAll, new XYConstraints(166, 61, 32, 21));
this.add(removeOne, new XYConstraints(166, 130, 32, 21));
this.add(removeAll, new XYConstraints(166, 160, 32, 21));
this.add(ok, new XYConstraints(198, 205, 72, 21));
this.add(cancel, new XYConstraints(283, 205, 72, 21));
}
void addOne_actionPerformed(ActionEvent e) {
if (source.getSelectedItem() != null) {
destination.addItem(source.getSelectedItem());
source.remove(source.getSelectedIndex());
}
}
void addAll_actionPerformed(ActionEvent e) {
for (int i = 0; i < source.getItemCount(); i++) {
destination.addItem(source.getItem(i));
}
source.removeAll();
}
void removeOne_actionPerformed(ActionEvent e) {
if (destination.getSelectedItem() != null) {
source.addItem(destination.getSelectedItem());
destination.remove(destination.getSelectedIndex());
}
}
void removeAll_actionPerformed(ActionEvent e) {
for (int i = 0; i < destination.getItemCount(); i++) {
source.addItem(destination.getItem(i));
}
destination.removeAll();
}
void ok_actionPerformed(ActionEvent e) {
}
void cancel_actionPerformed(ActionEvent e) {
}
//<Exclude>
// Test case
public static void main(String[] argv) {
DecoratedFrame frame = new DecoratedFrame();
DualListBox dlb=new DualListBox();
dlb.source.addItem("One");
dlb.source.addItem("Two");
dlb.source.addItem("Three");
dlb.source.addItem("Four");
dlb.source.addItem("Five");
frame.add(dlb);
frame.pack();
frame.show();
}
//</Exclude>
}
class DualListBox_addOne_actionAdapter implements ActionListener {
DualListBox adaptee;
DualListBox_addOne_actionAdapter(DualListBox adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.addOne_actionPerformed(e);
}
}
class DualListBox_addAll_actionAdapter implements ActionListener {
DualListBox adaptee;
DualListBox_addAll_actionAdapter(DualListBox adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.addAll_actionPerformed(e);
}
}
class DualListBox_removeOne_actionAdapter implements ActionListener {
DualListBox adaptee;
DualListBox_removeOne_actionAdapter(DualListBox adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.removeOne_actionPerformed(e);
}
}
class DualListBox_removeAll_actionAdapter implements ActionListener {
DualListBox adaptee;
DualListBox_removeAll_actionAdapter(DualListBox adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.removeAll_actionPerformed(e);
}
}
class DualListBox_ok_actionAdapter implements ActionListener {
DualListBox adaptee;
DualListBox_ok_actionAdapter(DualListBox adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.ok_actionPerformed(e);
}
}
class DualListBox_cancel_actionAdapter implements ActionListener {
DualListBox adaptee;
DualListBox_cancel_actionAdapter(DualListBox adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.cancel_actionPerformed(e);
}
}