01: package snow.utils;
02:
03: import javax.swing.event.TableModelListener;
04: import snow.sortabletable.SortableTableModel;
05: import javax.swing.table.*;
06: import javax.swing.*;
07: import javax.swing.tree.TreeNode;
08: import javax.swing.tree.MutableTreeNode;
09:
10: public final class MemoryUtils {
11: private MemoryUtils() {
12: }
13:
14: /** Frees the tree one level. If they are MutableTreeNode
15: */
16: public static void freeChilds(MutableTreeNode root) {
17: for (int i = root.getChildCount() - 1; i >= 0; i--) // reverse
18: {
19: TreeNode tn = root.getChildAt(i);
20: if (tn instanceof MutableTreeNode) {
21: ((MutableTreeNode) tn).removeFromParent();
22: } else {
23: root.remove(i);
24: }
25: }
26: }
27:
28: /** Frees the table and his model, place a dummy empty model to decouple it.
29: */
30: public static void free(JTable table) {
31: TableModel tm = table.getModel();
32: if (tm != null) {
33: table.setModel(new EmptyTableModel());
34: if (tm instanceof SortableTableModel) {
35: SortableTableModel stm = (SortableTableModel) tm;
36: }
37: }
38: }
39:
40: static class EmptyTableModel implements TableModel {
41: public int getRowCount() {
42: return 0;
43: }
44:
45: public int getColumnCount() {
46: return 0;
47: }
48:
49: public String getColumnName(int columnIndex) {
50: return "";
51: }
52:
53: public Class<?> getColumnClass(int columnIndex) {
54: return String.class;
55: }
56:
57: public boolean isCellEditable(int rowIndex, int columnIndex) {
58: return false;
59: }
60:
61: public Object getValueAt(int rowIndex, int columnIndex) {
62: return "";
63: }
64:
65: public void setValueAt(Object aValue, int rowIndex,
66: int columnIndex) {
67: }
68:
69: public void addTableModelListener(TableModelListener l) {
70: }
71:
72: public void removeTableModelListener(TableModelListener l) {
73: }
74: }
75:
76: }
|