« Interface »
Postable
|
+ isPosted() : boolean
+ setPosted(boolean)
|
Part
|
+ isPosted() : boolean
+ setPosted(boolean)
... more
|
|
Labor
|
+ isPosted() : boolean
+ setPosted(boolean)
... more
|
|
The Data List listens for mouse clicks...
DataList
|
+ DataList(DataListModel)
+ addMouseListener(MouseListener)
+ locationToIndex(Point) : int
+ getCellBounds(int, int) : Rectangle
+ repaint()
|
PostClickListener
|
# checkWidth : int
# leftList : JList
|
+ PostClickListener(JList, int)
# repaintList(JList, int)
+ mouseClicked(MouseEvent)
|
|
|
...and toggles the checkbox on and off.
public class PostClickListener extends MouseAdapter {
protected JList leftList;
protected int checkWidth;
public void mouseClicked(MouseEvent e) {
Point loc = e.getPoint();
JList list = (JList) e.getSource();
int index = list.locationToIndex(loc);
Object value = list.getModel().getElementAt(index);
if (value instanceof Postable) {
boolean doubleClick = e.getClickCount() == 2;
boolean inCheckCell = (list == leftList)
&& (loc.x < checkWidth);
if (doubleClick || inCheckCell) {
Postable postable = (Postable) value;
postable.setPosted(!postable.isPosted());
repaintList(list, index);
}
}
}
}
|
|