01: /*
02: * This file is not part of the ItsNat framework.
03: *
04: * Original source code use and closed source derivatives are authorized
05: * to third parties with no restriction or fee.
06: * The original source code is owned by the author.
07: *
08: * This program is distributed AS IS in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11: *
12: * Author: Jose Maria Arranz Santamaria
13: * (C) Innowhere Software Services S.L., Spanish company, year 2007
14: */
15:
16: package org.itsnat.feashow.features.components.lists;
17:
18: import javax.swing.ListSelectionModel;
19: import javax.swing.event.ListSelectionEvent;
20: import javax.swing.event.ListSelectionListener;
21: import org.itsnat.comp.ItsNatListMultSel;
22: import org.w3c.dom.Element;
23:
24: public class ListSelectionDecorator implements ListSelectionListener {
25: protected ItsNatListMultSel comp;
26:
27: public ListSelectionDecorator(ItsNatListMultSel comp) {
28: this .comp = comp;
29: }
30:
31: public void valueChanged(ListSelectionEvent e) {
32: if (e.getValueIsAdjusting())
33: return;
34:
35: int first = e.getFirstIndex();
36: int last = e.getLastIndex();
37:
38: ListSelectionModel selModel = (ListSelectionModel) e
39: .getSource();
40:
41: for (int i = first; i <= last; i++) {
42: decorateSelection(i, selModel.isSelectedIndex(i));
43: }
44: }
45:
46: public void decorateSelection(int index, boolean selected) {
47: Element elem = comp.getItsNatListUI()
48: .getContentElementAt(index);
49: if (elem == null)
50: return;
51:
52: if (selected)
53: elem.setAttribute("style",
54: "background:rgb(0,0,255); color:white;");
55: else
56: elem.removeAttribute("style");
57: }
58:
59: }
|