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.tables;
17:
18: import javax.swing.ListSelectionModel;
19: import javax.swing.event.ListSelectionEvent;
20: import javax.swing.event.ListSelectionListener;
21: import org.itsnat.comp.ItsNatTable;
22: import org.itsnat.comp.ui.ItsNatTableUI;
23: import org.w3c.dom.Element;
24:
25: public class TableRowSelectionDecoration implements
26: ListSelectionListener {
27: protected ItsNatTable comp;
28:
29: public TableRowSelectionDecoration(ItsNatTable comp) {
30: this .comp = comp;
31: }
32:
33: public void valueChanged(ListSelectionEvent e) {
34: if (e.getValueIsAdjusting())
35: return;
36:
37: int first = e.getFirstIndex();
38: int last = e.getLastIndex();
39:
40: ListSelectionModel selModel = (ListSelectionModel) e
41: .getSource();
42:
43: for (int i = first; i <= last; i++) {
44: decorateSelection(i, selModel.isSelectedIndex(i));
45: }
46: }
47:
48: public void decorateSelection(int row, boolean selected) {
49: ItsNatTableUI tableUI = comp.getItsNatTableUI();
50: int cols = comp.getTableModel().getColumnCount();
51: for (int i = 0; i < cols; i++) {
52: Element cellElem = tableUI.getCellContentElementAt(row, i);
53: if (cellElem == null)
54: continue;
55: decorateSelection(cellElem, selected);
56: }
57: }
58:
59: public void decorateSelection(Element elem, boolean selected) {
60: if (selected)
61: elem.setAttribute("style",
62: "background:rgb(0,0,255); color:white;");
63: else
64: elem.removeAttribute("style");
65: }
66: }
|