FSF GCC merge 02/23/03
[official-gcc.git] / libjava / javax / swing / JList.java
blobb12e3c3d73f173c34f0a769f54ae7c456dc1f8d3
1 /* JList.java --
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)
9 any later version.
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
19 02111-1307 USA.
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
24 combination.
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. */
38 package javax.swing;
40 import javax.swing.event.*;
42 import java.awt.*;
43 import javax.swing.plaf.*;
44 import java.util.*;
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;
56 int visibles = 8;
58 ListModel model;
59 ListSelectionModel sel_model;
61 public JList()
63 init();
66 public JList(Object[] listData)
68 init();
69 setListData(listData);
73 public JList(Vector listData)
75 init();
76 setListData(listData);
80 public JList(ListModel listData)
82 init();
83 setModel(listData);
85 void init()
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);
95 updateUI();
99 public int getVisibleRowCount()
100 { return visibles; }
101 public void setVisibleRowCount(int visibleRowCount)
103 visibles = visibleRowCount;
104 invalidate();
105 repaint();
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();
122 if (index == -1)
123 return null;
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]; }
141 setModel (new AL());
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()
158 { return render; }
159 public void setCellRenderer(ListCellRenderer cellRenderer)
161 render = cellRenderer;
162 invalidate();
163 repaint();
166 public void setModel(ListModel model)
168 ListDataListener l = new ListDataListener()
170 public void intervalAdded(ListDataEvent e) {
171 repaint();
173 public void intervalRemoved(ListDataEvent e) {
174 repaint();
176 public void contentsChanged(ListDataEvent e) {
177 repaint();
181 this.model = model;
182 model.addListDataListener(l);
185 public ListModel getModel()
186 { return model; }
189 public ListUI getUI()
190 { return (ListUI) ui; }
191 public void setUI(ListUI ui)
192 { super.setUI(ui); }
194 public void updateUI()
196 setUI((ListUI)UIManager.getUI(this));
199 public String getUIClassID()
201 return "JList";
205 public AccessibleContext getAccessibleContext()
207 return null;
210 public Dimension getPreferredScrollableViewportSize()
212 return null;
215 public int getScrollableUnitIncrement(Rectangle visibleRect,
216 int orientation,
217 int direction)
219 return 1;
222 public int getScrollableBlockIncrement(Rectangle visibleRect,
223 int orientation,
224 int direction)
226 return 1;
229 public boolean getScrollableTracksViewportWidth()
231 return false;
234 public boolean getScrollableTracksViewportHeight()
236 return false;