KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > snow > utils > MemoryUtils


1 package snow.utils;
2
3 import javax.swing.event.TableModelListener JavaDoc;
4 import snow.sortabletable.SortableTableModel;
5 import javax.swing.table.*;
6 import javax.swing.*;
7 import javax.swing.tree.TreeNode JavaDoc;
8 import javax.swing.tree.MutableTreeNode JavaDoc;
9
10
11 /** class MemoryUtils.
12 */

13 public final class MemoryUtils
14 {
15    /** Constructor. */
16    private MemoryUtils()
17    {
18    }
19
20    /** frees the tree one level. If they are MutableTreeNode
21    */

22    public static void freeChilds(MutableTreeNode JavaDoc root)
23    {
24       for(int i=root.getChildCount()-1; i>=0; i--) // reverse
25
{
26          TreeNode JavaDoc tn = root.getChildAt(i);
27          if(tn instanceof MutableTreeNode JavaDoc)
28          {
29             ((MutableTreeNode JavaDoc) tn).removeFromParent();
30          }
31          else
32          {
33             root.remove(i);
34          }
35       }
36    }
37
38    /** frees the table and his model, place a dummy empty model to decouple it.
39    */

40    public static void free(JTable table)
41    {
42       TableModel tm = table.getModel();
43       if(tm!=null)
44       {
45          table.setModel(new EmptyTableModel());
46          if(tm instanceof SortableTableModel)
47          {
48             SortableTableModel stm = (SortableTableModel) tm;
49          }
50       }
51    }
52
53    static class EmptyTableModel implements TableModel
54    {
55      public int getRowCount() { return 0; }
56      public int getColumnCount() { return 0; }
57      public String JavaDoc getColumnName(int columnIndex) { return ""; }
58      public Class JavaDoc<?> getColumnClass(int columnIndex) { return String JavaDoc.class; }
59      public boolean isCellEditable(int rowIndex, int columnIndex) { return false; }
60      public Object JavaDoc getValueAt(int rowIndex, int columnIndex) { return ""; }
61      public void setValueAt(Object JavaDoc aValue, int rowIndex, int columnIndex) {}
62      public void addTableModelListener(TableModelListener JavaDoc l) {}
63      public void removeTableModelListener(TableModelListener JavaDoc l) {}
64    }
65
66 } // MemoryUtils
Popular Tags