KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > swing > List


1 /*
2   Copyright (C) 2001-2003 Renaud Pawlak <renaud@aopsys.com>,
3                           Laurent Martelli <laurent@aopsys.com>
4   
5   This program is free software; you can redistribute it and/or modify
6   it under the terms of the GNU Lesser General Public License as
7   published by the Free Software Foundation; either version 2 of the
8   License, or (at your option) any later version.
9
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   GNU Lesser General Public License for more details.
14
15   You should have received a copy of the GNU Lesser General Public License
16   along with this program; if not, write to the Free Software
17   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

18
19 package org.objectweb.jac.aspects.gui.swing;
20
21 import org.objectweb.jac.aspects.gui.*;
22 import org.objectweb.jac.core.rtti.CollectionItem;
23 import java.awt.Point JavaDoc;
24 import javax.swing.JComponent JavaDoc;
25 import javax.swing.JList JavaDoc;
26 import javax.swing.ListSelectionModel JavaDoc;
27 import javax.swing.event.ListSelectionListener JavaDoc;
28
29 public class List extends AbstractCollection
30     implements ListSelectionListener JavaDoc
31 {
32     // swing table component
33
JList JavaDoc list;
34
35     public List(ViewFactory factory, DisplayContext context,
36                 CollectionItem collection, Object JavaDoc substance, CollectionModel model,
37                 org.objectweb.jac.aspects.gui.CollectionItemView itemView) {
38         super(factory,context,collection,substance,model,itemView);
39     }
40
41     protected JComponent JavaDoc getInnerComponent(Model JavaDoc model) {
42         if (list==null) {
43             list = new JList JavaDoc();
44             list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
45             BetterListSelectionModel selModel = new BetterListSelectionModel(list);
46             list.setSelectionModel(selModel);
47             selModel.addListSelectionListener( this );
48             list.setModel((ListModel)model);
49         }
50         return list;
51     }
52
53     protected void onRemove() {
54         list.clearSelection();
55     }
56
57     /**
58      * Returns an array of the selected objects. The array is empty if
59      * no object is selected, but not null.
60      */

61     protected int[] getSelectedIndices() {
62         return list.getSelectedIndices();
63     }
64
65     protected CollectionUpdate getCollectionUpdate() {
66         return (CollectionUpdate)model;
67     }
68
69     int locationToIndex(Point JavaDoc location) {
70         return list.locationToIndex(location);
71     }
72
73     protected ListSelectionModel JavaDoc getSelectionModel() {
74         return list.getSelectionModel();
75     }
76
77     // CollectionView interface
78

79     public void setSelected(int index) {
80         list.setSelectedIndex(index);
81     }
82
83 }
84
Popular Tags