01: package org.swingml.treetablebrowser.ext;
02:
03: import java.awt.*;
04: import java.util.*;
05:
06: import javax.swing.*;
07: import javax.swing.event.*;
08: import javax.swing.table.*;
09:
10: import org.swingml.*;
11:
12: /**
13: * @author NumberSix
14: */
15: public class TreeTableBrowserCellLabelEditor implements TableCellEditor {
16:
17: TableCellEditor originalEditor;
18:
19: public TreeTableBrowserCellLabelEditor(TableCellEditor anEditor) {
20: this .originalEditor = anEditor;
21: }
22:
23: public void addCellEditorListener(CellEditorListener l) {
24: originalEditor.addCellEditorListener(l);
25: }
26:
27: public void cancelCellEditing() {
28: originalEditor.cancelCellEditing();
29: }
30:
31: public Object getCellEditorValue() {
32: return originalEditor.getCellEditorValue();
33: }
34:
35: public Component getTableCellEditorComponent(JTable table,
36: Object value, boolean isSelected, int row, int column) {
37: Component result = originalEditor.getTableCellEditorComponent(
38: table, value, isSelected, row, column);
39:
40: if (result instanceof JTextField) {
41: JTextField editor = (JTextField) result;
42: TreeTableComponent treeTable = (TreeTableComponent) table;
43: TreeTableBrowserModelAdapter model = (TreeTableBrowserModelAdapter) treeTable
44: .getModel();
45: TreeTableBrowserDataModel dataModel = model.getDataModel(
46: row, column);
47:
48: if (dataModel != null) {
49: // Set alignment
50: int alignment = JLabel.LEFT;
51: if (dataModel.getAlignment().equalsIgnoreCase(
52: Constants.RIGHT)) {
53: alignment = JLabel.RIGHT;
54: } else if (dataModel.getAlignment().equalsIgnoreCase(
55: Constants.CENTER)) {
56: alignment = JLabel.CENTER;
57: }
58: editor.setHorizontalAlignment(alignment);
59:
60: // auto-select feature
61: if (dataModel.shouldAutoSelectOnCellEdit()) {
62: editor.selectAll();
63: }
64: }
65: }
66:
67: return result;
68: }
69:
70: public boolean isCellEditable(EventObject anEvent) {
71: return originalEditor.isCellEditable(anEvent);
72: }
73:
74: public void removeCellEditorListener(CellEditorListener l) {
75: originalEditor.removeCellEditorListener(l);
76: }
77:
78: public boolean shouldSelectCell(EventObject anEvent) {
79: return originalEditor.shouldSelectCell(anEvent);
80: }
81:
82: public boolean stopCellEditing() {
83: return originalEditor.stopCellEditing();
84: }
85: }
|