IPAddressList.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.
*/
/**
* A panel which allows the user to edit a list of IP addresses. Consists of
* a text field for entering new data, paired with a list which allows the
* addresses entered to be ordered or deleted.
*/
public class IPAddressList extends JPanel {
/**
* Construct the address list.
*/
public IPAddressList() {
super();
GridBagConstraints c = new GridBagConstraints();
c.gridheight = 1;
c.gridwidth = 1;
// Field to type in addresses
address = new IPAddressField();
// Button for Add operation
++c.gridx;
c.weightx = 0.5;
// List for addresses
serverListModel = new IPAddressListModel();
// Make sure it's wide enough for our purposes
// Don't allow horizontal scrolling here
c.gridx = 0;
++c.gridy;
c.weightx = 1.0;
// Buttons to manipulate the list contents
moveDown = new DownButton();
++c.gridx;
c.weightx = 0.5;
// Disable all buttons to start; selection changes adjust button state
add.setEnabled(false);
delete.setEnabled(false);
moveUp.setEnabled(false);
moveDown.setEnabled(false);
// Create listener for button presses, take action as needed
ActionListener l = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (a != null) {
}
/*
* Need to sort the indices so that the delete's
* don't interfere with each other
*/
int k = indices[i];
indices[j] = k;
}
}
}
}
// Now delete from high index to low
}
// Clear selection if multiple deleted
/*
* We don't get a selection event for some reason
* so make it work for now
*/
delete.setEnabled(false);
} else {
// Make sure to select something in the list
/*
* List is empty, nothing to select so disable
* delete
*/
delete.setEnabled(false);
// Select last one if we're off the end
} else {
// Select next one in list
}
}
int i = serverList.getSelectedIndex();
// Keep item selected so repeated moveUp's affect same item
int i = serverList.getSelectedIndex();
// Keep item selected so repeated moveDowns affect same item
}
}
};
add.addActionListener(l);
// Put a selection listener on the list to enable buttons appropriately
public void valueChanged(ListSelectionEvent e) {
case 0:
// Nothing selected; disable them all
delete.setEnabled(false);
moveUp.setEnabled(false);
moveDown.setEnabled(false);
break;
case 1:
delete.setEnabled(true);
// Can't move first one up
moveUp.setEnabled(false);
} else {
moveUp.setEnabled(true);
}
// Can't move last one down
moveDown.setEnabled(false);
} else {
moveDown.setEnabled(true);
}
break;
default:
// More than one; only delete is allowed
delete.setEnabled(true);
moveUp.setEnabled(false);
moveDown.setEnabled(false);
}
}
});
// Enable Add when address is not empty.
public void insertUpdate(DocumentEvent e) {
}
public void changedUpdate(DocumentEvent e) {
insertUpdate(e);
}
public void removeUpdate(DocumentEvent e) {
insertUpdate(e);
}
});
}
/**
* Initialize the data in the list
*/
}
/**
* Set the addresses from a comma-delimited string
*/
public void setAddressList(String s) {
}
/**
* Retrieve the data in the list
*/
public Vector getAddressList() {
return serverListModel.getDataVector();
}
/**
* Retrieve the list converted to a comma-delimited string
*/
public String getAddressListString() {
return serverListModel.getDataString();
}
/**
* Return the size of the list
*/
public int getListSize() {
}
class IPAddressListModel extends AbstractListModel {
public IPAddressListModel() {
super();
}
public int getSize() {
}
}
}
}
while (st.hasMoreTokens()) {
try {
} catch (ValidationException e) {
// Ignore it, didn't parse for some reason
}
}
}
}
public void removeElementAt(int index) {
}
}
}
public Vector getDataVector() {
}
public String getDataString() {
StringBuffer b = new StringBuffer();
while (en.hasMoreElements()) {
if (b.length() != 0) {
b.append(',');
}
}
return b.toString();
}
}
}