public void actionPerformed(ActionEvent ev)
{
int index = list.getSelectedIndex();
if (index > 0)
{
JCheckListData data = (JCheckListData)m_listModel.get(index);
if ((index == 2 || index == 1) && data.isSeparator())
{
m_listModel.remove(index);
list.setSelectedIndex(index-1);
list.ensureIndexIsVisible(0);
}
else if (index == m_listModel.getSize() - 1)
{
data = new JCheckListData<Integer>();
data.setLabel(separator);
data.setIsSeparator(true);
m_listModel.add(index, data);
list.setSelectedIndex(index);
list.ensureIndexIsVisible(index+1);
}
else if (index > 1)
{
data = (JCheckListData)m_listModel.get(index);
m_listModel.add(index-1, m_listModel.remove(index));
index--;
list.setSelectedIndex(index);
list.ensureIndexIsVisible(index);
}
}
if ((index = list.getSelectedIndex()) >= 0)
{
JCheckListData data = (JCheckListData)m_listModel.get(index);
upButton.setEnabled(index > 1 || data.isSeparator() ? true : false);
}
}
});
panelToolTip.addComponent(upButton, 1, row, GridBagConstraints.SOUTHWEST, new Insets(0, 10, 0, 0), 1, 1, 0, 0.5);
final JButton downButton = new JButton("\u2193");
downButton.setFont(font);
downButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ev)
{
int index = list.getSelectedIndex();
if (index >= 0 && index < m_listModel.getSize() - 1)
{
JCheckListData data = (JCheckListData)m_listModel.get(index);
if ((index == m_listModel.getSize() - 3 || index == m_listModel.getSize() - 2) && data.isSeparator())
{
m_listModel.remove(index);
list.setSelectedIndex(m_listModel.getSize() - 2);
list.ensureIndexIsVisible(m_listModel.getSize() - 1);
}
else if (index == 0)
{
data = new JCheckListData<Integer>();
data.setLabel(separator);
data.setIsSeparator(true);
m_listModel.add(1, data);
list.setSelectedIndex(1);
list.ensureIndexIsVisible(0);
}
else if (index < m_listModel.getSize() - 2)
{
data = (JCheckListData)m_listModel.get(index);
m_listModel.add(index+1, m_listModel.remove(index));
index++;
list.setSelectedIndex(index);
list.ensureIndexIsVisible(index);
}
}
if ((index = list.getSelectedIndex()) >= 0)
{
JCheckListData data = (JCheckListData)m_listModel.get(index);
downButton.setEnabled(index < m_listModel.getSize() - 2 || data.isSeparator() ? true : false);
}
}
});
list.getSelectionModel().addListSelectionListener(new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
{
int index = list.getSelectedIndex();
if (index >= 0)
{
JCheckListData data = (JCheckListData)m_listModel.get(index);
upButton.setEnabled(index == 0 || (index == 1 && !data.isSeparator()) ? false : true);
downButton.setEnabled(index == m_listModel.getSize() - 1 || (index == m_listModel.getSize() - 2 && !data.isSeparator()) ? false : true);
}
}
});
row++;
panelToolTip.addComponent(downButton, 1, row, GridBagConstraints.NORTHWEST, new Insets(3, 10, 0, 0), 1, 1, 0, 0.5);