2 Copyright (C) 2002, 2003 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. */
41 import java
.awt
.Color
;
42 import java
.awt
.Dimension
;
43 import java
.awt
.Rectangle
;
44 import java
.util
.Vector
;
45 import javax
.accessibility
.Accessible
;
46 import javax
.accessibility
.AccessibleContext
;
47 import javax
.swing
.event
.ListDataEvent
;
48 import javax
.swing
.event
.ListDataListener
;
49 import javax
.swing
.event
.ListSelectionListener
;
50 import javax
.swing
.plaf
.ListUI
;
52 public class JList
extends JComponent
implements Accessible
, 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 class AL
extends AbstractListModel
148 public int getSize() { return listData
.size(); }
149 public Object
getElementAt(int i
) { return listData
.elementAt(i
); }
156 public ListCellRenderer
getCellRenderer()
158 public void setCellRenderer(ListCellRenderer cellRenderer
)
160 render
= cellRenderer
;
165 public void setModel(ListModel model
)
167 ListDataListener l
= new ListDataListener()
169 public void intervalAdded(ListDataEvent e
) {
172 public void intervalRemoved(ListDataEvent e
) {
175 public void contentsChanged(ListDataEvent e
) {
181 model
.addListDataListener(l
);
184 public ListModel
getModel()
188 public ListUI
getUI()
189 { return (ListUI
) ui
; }
190 public void setUI(ListUI ui
)
193 public void updateUI()
195 setUI((ListUI
)UIManager
.getUI(this));
198 public String
getUIClassID()
204 public AccessibleContext
getAccessibleContext()
209 public Dimension
getPreferredScrollableViewportSize()
214 public int getScrollableUnitIncrement(Rectangle visibleRect
,
221 public int getScrollableBlockIncrement(Rectangle visibleRect
,
228 public boolean getScrollableTracksViewportWidth()
233 public boolean getScrollableTracksViewportHeight()