01: /*
02: * Copyright (C) 2005 Jeff Tassin
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package com.jeta.swingbuilder.gui.properties;
20:
21: import java.awt.Component;
22: import java.beans.PropertyEditor;
23:
24: import com.jeta.forms.gui.common.FormUtils;
25:
26: public class PropertyEditorCache {
27: /**
28: * @directed
29: */
30: private PropertyTableModel m_model;
31:
32: /**
33: * The bean we are currently rendering properties for
34: */
35: private Object m_bean;
36:
37: /**
38: * The property editors for each row in the table
39: */
40: private PropertyEditor[] m_editors;
41:
42: /**
43: * ctor
44: */
45: public PropertyEditorCache(PropertyTableModel model) {
46: m_model = model;
47: }
48:
49: public PropertyEditor getPropertyEditor(int row) {
50: if (m_bean != m_model.getBean() || m_editors == null
51: || m_editors.length != m_model.getRowCount()) {
52: m_bean = m_model.getBean();
53: m_editors = new PropertyEditor[m_model.getRowCount()];
54: }
55:
56: PropertyEditor editor = m_editors[row];
57: if (editor == null) {
58: editor = m_model.getPropertyEditor(row);
59: if (editor != null) {
60: try {
61: m_editors[row] = (PropertyEditor) editor.getClass()
62: .newInstance(); // we
63: // need
64: // to
65: // create
66: // a
67: // copy
68: // here
69: editor = m_editors[row];
70: } catch (Exception e) {
71: e.printStackTrace();
72: }
73: }
74: }
75: return editor;
76: }
77:
78: public void updateUI() {
79: if (m_editors != null) {
80: for (int index = 0; index < m_editors.length; index++) {
81: PropertyEditor editor = m_editors[index];
82: if (editor != null) {
83: Component comp = editor.getCustomEditor();
84: FormUtils.updateLookAndFeel(comp);
85: }
86: }
87: }
88:
89: }
90: }
|