DoubleAddRemovePanel.java revision 7fdb1b8d022ee35baa05f026c08567e86c728607
/*
* 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 legal-notices/CDDLv1_0.txt
* 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 legal-notices/CDDLv1_0.txt.
* 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
*
*
* Copyright 2008-2010 Sun Microsystems, Inc.
*/
/**
* This component displays three list (one available list and two selected
* lists) with some buttons to move the components of one list to the other.
*
* @param <T> the type of the objects in the list.
*/
public class DoubleAddRemovePanel<T> extends JPanel
{
private static final long serialVersionUID = 6881453848780359594L;
private SortableListModel<T> availableListModel;
private SortableListModel<T> selectedListModel1;
private SortableListModel<T> selectedListModel2;
private JLabel selectedLabel1;
private JLabel selectedLabel2;
private JLabel availableLabel;
private JButton removeAll1;
private JButton removeAll2;
private JScrollPane availableScroll;
private JScrollPane selectedScroll1;
private JScrollPane selectedScroll2;
private JList availableList;
private JList selectedList1;
private JList selectedList2;
private boolean ignoreListEvents;
/**
* Mask used as display option. If the provided display options contain
* this mask, the panel will display the remove all button.
*/
public static final int DISPLAY_REMOVE_ALL = 0x001;
/**
* Mask used as display option. If the provided display options contain
* this mask, the panel will display the add all button.
*/
public static final int DISPLAY_ADD_ALL = 0x010;
/**
* Constructor of the default double add remove panel (including 'Add All' and
* 'Remove All' buttons).
* The class is required to avoid warnings in compilation.
* @param theClass the class of the objects in the panel.
*/
{
}
/**
* Constructor of the double add remove panel allowing the user to provide
* some display options.
* The class is required to avoid warnings in compilation.
* @param displayOptions the display options.
* @param theClass the class of the objects in the panel.
*/
{
super(new GridBagLayout());
setOpaque(false);
{
/**
* {@inheritDoc}
*/
{
}
/**
* {@inheritDoc}
*/
{
}
/**
* {@inheritDoc}
*/
{
}
};
{
/**
* {@inheritDoc}
*/
public void mouseClicked(MouseEvent e) {
{
if (e.getSource() == availableList)
{
{
add1Clicked();
}
}
else if (e.getSource() == selectedList1)
{
{
}
}
else if (e.getSource() == selectedList2)
{
{
}
}
}
}
};
availableListModel = new SortableListModel<T>();
availableList = new JList();
selectedListModel1 = new SortableListModel<T>();
selectedList1 = new JList();
selectedListModel2 = new SortableListModel<T>();
selectedList2 = new JList();
if (displayOptions != 0)
{
}
// FIXME how can this be any different than 0? Ditto everywhere else down below
if (displayOptions != 0)
{
}
{
/**
* {@inheritDoc}
*/
{
add1Clicked();
}
});
if (displayOptions != 0)
{
{
{
}
});
}
{
{
}
});
if (displayOptions != 0)
{
removeAll1.setOpaque(false);
{
/**
* {@inheritDoc}
*/
{
}
});
}
{
/**
* {@inheritDoc}
*/
{
add2Clicked();
}
});
if (displayOptions != 0)
{
{
/**
* {@inheritDoc}
*/
{
}
});
}
{
/**
* {@inheritDoc}
*/
{
}
});
if (displayOptions != 0)
{
removeAll2.setOpaque(false);
{
/**
* {@inheritDoc}
*/
{
}
});
}
if (displayOptions != 0)
{
gbc.gridheight ++;
}
if (displayOptions != 0)
{
gbc.gridheight ++;
}
if (displayOptions != 0)
{
gbc.gridheight ++;
}
if (displayOptions != 0)
{
gbc.gridheight ++;
}
{
{
}
};
add1.setEnabled(false);
remove1.setEnabled(false);
add2.setEnabled(false);
remove2.setEnabled(false);
// Set preferred size for the scroll panes.
"The cell that we want to display", 0, true, true);
}
/**
* Enables the state of the components in the panel.
* @param enable whether to enable the components in the panel or not.
*/
public void setEnabled(boolean enable)
{
super.setEnabled(enable);
}
/**
* Returns the available label contained in the panel.
* @return the available label contained in the panel.
*/
public JLabel getAvailableLabel()
{
return availableLabel;
}
/**
* Returns the list of elements in the available list.
* @return the list of elements in the available list.
*/
public SortableListModel<T> getAvailableListModel()
{
return availableListModel;
}
/**
* Returns the first selected label contained in the panel.
* @return the first selected label contained in the panel.
*/
public JLabel getSelectedLabel1()
{
return selectedLabel1;
}
/**
* Returns the list of elements in the first selected list.
* @return the list of elements in the first selected list.
*/
public SortableListModel<T> getSelectedListModel1()
{
return selectedListModel1;
}
/**
* Returns the second selected label contained in the panel.
* @return the second selected label contained in the panel.
*/
public JLabel getSelectedLabel2()
{
return selectedLabel2;
}
/**
* Returns the list of elements in the second selected list.
* @return the list of elements in the second selected list.
*/
public SortableListModel<T> getSelectedListModel2()
{
return selectedListModel2;
}
private void listSelectionChanged()
{
if (ignoreListEvents)
{
return;
}
ignoreListEvents = true;
{
for (T element : unmovableItems)
{
{
{
// This check is necessary since the selection model might not
// be in sync with the list model.
{
indexes[i]);
}
}
}
}
}
ignoreListEvents = false;
{
boolean onlyUnmovable =
}
if (removeAll1 != null)
{
boolean onlyUnmovable =
}
if (removeAll2 != null)
{
boolean onlyUnmovable =
}
}
/**
* Returns the available list.
* @return the available list.
*/
public JList getAvailableList()
{
return availableList;
}
/**
* Returns the first selected list.
* @return the first selected list.
*/
public JList getSelectedList1()
{
return selectedList1;
}
/**
* Returns the second selected list.
* @return the second selected list.
*/
public JList getSelectedList2()
{
return selectedList2;
}
private void add1Clicked()
{
@SuppressWarnings("deprecation")
{
}
}
private void add2Clicked()
{
@SuppressWarnings("deprecation")
{
}
}
private void remove1Clicked()
{
@SuppressWarnings("deprecation")
{
}
}
private void remove2Clicked()
{
@SuppressWarnings("deprecation")
{
}
}
/**
* Sets the list of items that cannot be moved from one list to the others.
* @param unmovableItems the list of items that cannot be moved from one
* list to the others.
*/
{
this.unmovableItems.clear();
}
{
}
}