/* Copyright 2006 Rene Grothmann, modified by Eric Hakenholz This file is part of C.a.R. software. C.a.R. is a free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3 of the License. C.a.R. is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ package rene.lister; import java.awt.Color; import java.awt.event.ActionListener; import java.io.PrintWriter; import javax.swing.JScrollPane; import javax.swing.SwingUtilities; public class Lister extends JScrollPane { /** * */ public ListerPanel L; /** * Initialize the display of vertical scrollbar * */ public Lister() { L=new ListerPanel(this); setViewportView(L); setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); setBorder(javax.swing.BorderFactory.createEmptyBorder()); setWheelScrollingEnabled(true); getVerticalScrollBar().setUnitIncrement(16); } /** * Return the lister for external use. * * @return lister panel */ public ListerPanel getLister() { return L; } public void addActionListener(final ActionListener al) { L.addActionListener(al); } public void updateDisplay() { L.repaint(); SwingUtilities.invokeLater(new Runnable() { public void run() { L.fixsize(); } }); } public void removeActionListener(final ActionListener al) { L.removeActionListener(al); } public void clear() { L.clear(); } public void addElement(final Element el) { L.add(el); } /** * Get the first selected index. * * @return index or -1 */ public int getSelectedIndex() { if (L.Selected.size()>0) { return ((Integer) L.Selected.elementAt(0)).intValue(); } else { return -1; } } public String getSelectedItem() { final int n=getSelectedIndex(); if (n<0) { return null; } return L.getElementAt(n).getElementString(); } /** * Get a vector of all selected indices. * * @return vector of indices */ public int[] getSelectedIndices() { final int k[]=new int[L.Selected.size()]; for (int i=0; i