ListPair.java revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* ident "%Z%%M% %I% %E% SMI"
*
* Copyright 2002 by Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* This class is a hack to get around the fact that clearSelection()
* in DefaultListSelectionModel does not always fire an event to its listeners.
* We rely on such an event to enable & disable the arrow buttons which
* move data items between lists. See bug 4177723.
*/
class FixedSelectionModel extends DefaultListSelectionModel {
public void clearSelection() {
super.clearSelection();
}
}
/*
* We implement our own list model rather than use the default so
* that we can take advantage of some of the more advanced collection
* features not supported by DefaultListModel
*/
class OurListModel implements ListModel {
}
}
public void addListDataListener(ListDataListener l) {
}
public void removeListDataListener(ListDataListener l) {
}
protected void fireContentsChanged() {
ListDataEvent e =
0, getSize());
/*
* Listener array is formatted as pairs of (class, listener); walk
* the array backwards and call each ListDataListener in turn with
* the event. See javax.swing.event.EventListenerList for more info.
*/
if (listeners[i] == ListDataListener.class) {
}
}
}
}
public int getSize() {
}
public void addElement(Object o) {
}
public void removeElement(Object o) {
}
}
}
/*
* Our own layout manager which keeps the left & right lists the same size.
*/
class ListPairLayout implements LayoutManager {
public ListPairLayout() {
}
}
}
// Make left & right components same size, center no smaller than min
// If preferred sizes don't fit, go to minimum.
}
// Left & right each get half of what's left after center allocated
// Now place each component
}
// Compute minimum width as max(leftwidth, rightwidth) * 2 + centerwidth
// Compute minimum height as max(leftheight, rightheight, centerheight)
lrheight);
return retDim;
}
// Preferred width is max(leftwidth, rightwidth) * 2 + centerwidth
// Preferred height is max(leftheight, rightheight, centerheight)
lrheight);
return retDim;
}
// Do nothing
}
}
/**
* A ListPair provides a way to display two lists of objects and to move
* objects from one list to another. It is initialized with the contents
* of each list, and can be queried at any time for the contents of each list
*/
/**
* Construct a ListPair with the specified data and captions for each list
* @param leftCaption Caption for left list
* @param leftData An array of objects to display in the left list
* @param rightCaption Caption for right list
* @param rightData An array of objects to display in the right list
*/
// Use our custom layout manager
setLayout(new ListPairLayout());
// Store data into the list models
// Now create the lists
// Now do the layout
rightButton.setEnabled(false);
leftButton.setEnabled(false);
// Now create and hook up the listeners for selection state
new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
// Ignore if user is dragging selection state
if (e.getValueIsAdjusting()) {
return;
}
// Right enabled only if something is selected in left list
if (!leftSelectionModel.isSelectionEmpty()) {
}
}
});
new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
// Ignore if user is dragging selection state
if (e.getValueIsAdjusting()) {
return;
}
// Left enabled only if something is selected in the right list
if (!rightSelectionModel.isSelectionEmpty()) {
}
}
});
// Now add listeners to buttons to move data between lists
public void actionPerformed(ActionEvent e) {
}
/*
* Clear the selection state; this shouldn't be necessary,
* but the selection and data models are unfortunately not
* hooked up to handle this automatically
*/
}
});
public void actionPerformed(ActionEvent e) {
}
/*
* Clear the selection state; this shouldn't be necessary,
* but the selection and data models are unfortunately not
* hooked up to handle this automatically
*/
}
});
}
/**
* Retrieve the contents of the left list
* @return the contents as an array of Object
*/
}
/**
* Retrieve the contents of the right list
* @return the contents as an array of Object
*/
}
}