2 Copyright (C) 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
40 import javax
.swing
.event
.*;
43 import javax
.swing
.plaf
.*;
47 import javax
.accessibility
.AccessibleContext
;
48 import javax
.accessibility
.AccessibleRole
;
49 import javax
.accessibility
.AccessibleState
;
50 import javax
.accessibility
.AccessibleStateSet
;
52 public class JList
extends JComponent
implements Scrollable
54 Color select_back
, select_fore
;
55 ListCellRenderer render
;
59 ListSelectionModel sel_model
;
66 public JList(Object
[] listData
)
69 setListData(listData
);
73 public JList(Vector listData
)
76 setListData(listData
);
80 public JList(ListModel listData
)
87 render
= new DefaultCellRenderer();
89 sel_model
= new DefaultListSelectionModel();
90 setModel(new DefaultListModel());
92 select_back
= new Color(0,0,255);
93 select_fore
= new Color(255,255,255);
99 public int getVisibleRowCount()
101 public void setVisibleRowCount(int visibleRowCount
)
103 visibles
= visibleRowCount
;
108 void addListSelectionListener(ListSelectionListener listener
)
109 { sel_model
.addListSelectionListener(listener
); }
110 void removeListSelectionListener(ListSelectionListener listener
)
111 { sel_model
.removeListSelectionListener(listener
); }
113 void setSelectionMode(int a
)
114 { sel_model
.setSelectionMode(a
); }
115 void setSelectedIndex(int a
)
116 { sel_model
.setSelectionInterval(a
,a
); }
117 int getSelectedIndex()
118 { return sel_model
.getMinSelectionIndex(); }
119 Object
getSelectedValue()
121 int index
= getSelectedIndex();
124 return getModel().getElementAt(index
);
127 Color
getSelectionBackground()
128 { return select_back
; }
129 Color
getSelectionForeground()
130 { return select_fore
; }
133 public void setListData(final Object
[] listData
)
135 class AL
extends AbstractListModel
137 public int getSize() { return listData
.length
; }
138 public Object
getElementAt(int i
) { return listData
[i
]; }
144 public void setListData(final Vector listData
)
146 // XXX - FIXME Don't also name this AL, workaround for gcj 3.1.
147 class ALData
extends AbstractListModel
149 public int getSize() { return listData
.size(); }
150 public Object
getElementAt(int i
) { return listData
.elementAt(i
); }
153 setModel (new ALData());
157 public ListCellRenderer
getCellRenderer()
159 public void setCellRenderer(ListCellRenderer cellRenderer
)
161 render
= cellRenderer
;
166 public void setModel(ListModel model
)
168 ListDataListener l
= new ListDataListener()
170 public void intervalAdded(ListDataEvent e
) {
173 public void intervalRemoved(ListDataEvent e
) {
176 public void contentsChanged(ListDataEvent e
) {
182 model
.addListDataListener(l
);
185 public ListModel
getModel()
189 public ListUI
getUI()
190 { return (ListUI
) ui
; }
191 public void setUI(ListUI ui
)
194 public void updateUI()
196 setUI((ListUI
)UIManager
.getUI(this));
199 public String
getUIClassID()
205 public AccessibleContext
getAccessibleContext()
210 public Dimension
getPreferredScrollableViewportSize()
215 public int getScrollableUnitIncrement(Rectangle visibleRect
,
222 public int getScrollableBlockIncrement(Rectangle visibleRect
,
229 public boolean getScrollableTracksViewportWidth()
234 public boolean getScrollableTracksViewportHeight()