java-org.hwo.ui/src/org/hwo/ui/InteractiveObjectListView.java

76 lines
1.4 KiB
Java

package org.hwo.ui;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import org.hwo.interactiveobjects.IInteractiveObjectEditor;
import org.hwo.interactiveobjects.InteractiveObjectHelper;
public class InteractiveObjectListView extends JList {
DefaultListModel pModel;
public InteractiveObjectListView()
{
this.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseClicked(MouseEvent arg0) {
if (arg0.getClickCount()==2)
openEditor();
}
});
pModel = new DefaultListModel();
setModel(pModel);
}
private void openEditor()
{
if (getSelectedIndex() != -1)
{
IInteractiveObjectEditor oe = InteractiveObjectHelper.getEditor(getSelectedValue());
if (oe != null)
oe.setVisible(true);
}
}
public void setItems(List items)
{
pModel.clear();
for (Object o:items)
{
pModel.addElement(o);
}
}
}