001 package ui.model; 002 003 import ui.recognizer.JSpectra; 004 005 import java.io.IOException; 006 import java.io.File; 007 import java.util.Date; 008 import java.util.Stack; 009 import javax.swing.SwingUtilities; 010 import javax.swing.tree.TreePath; 011 012 /** 013 * A kind of TreeTableModel representing an XML database.<p> 014 * 015 * @version 1.0 2003-06-26 016 * @author John Talbot 017 */ 018 public class DatabaseModel extends AbstractTreeTableModel { 019 020 // Names and Types of the columns. 021 static protected String[] cNames = {"Database", "Resolution", "Spectra"}; 022 static protected Class[] cTypes = { TreeTableModel.class, Double.class, String.class}; 023 024 /** 025 * Creates a DatabaseModel with root <code>rootPath</code>. 026 */ 027 public DatabaseModel(String rootPath) { 028 super(null); 029 root = null; 030 } 031 032 // 033 // The TreeModel interface 034 // 035 /** 036 * Returns the number of children of <code>node</code>. 037 */ 038 public int getChildCount(Object node) { 039 Object[] children = getChildren(node); 040 return (children == null) ? 0 : children.length; 041 } 042 043 /** 044 * Returns the child of <code>node</code> at index <code>i</code>. 045 */ 046 public Object getChild(Object node, int i) { 047 return getChildren(node)[i]; 048 } 049 050 /** 051 * Returns true if the passed in object represents a leaf, false 052 * otherwise. 053 */ 054 public boolean isLeaf(Object node) { 055 return ((Node)node).isLeaf(); 056 } 057 058 // 059 // The TreeTableNode interface. 060 // 061 /** 062 * Returns the number of columns. 063 */ 064 public int getColumnCount() { 065 return cNames.length; 066 } 067 068 /** 069 * Returns the name for a particular column. 070 */ 071 public String getColumnName(int column) { 072 return cNames[column]; 073 } 074 075 /** 076 * Returns the class for the particular column. 077 */ 078 public Class getColumnClass(int column) { 079 return cTypes[column]; 080 } 081 082 /** 083 * Returns the value of the particular column. 084 */ 085 public Object getValueAt(Object node, int column) { 086 Node n = (Node)node; 087 try { 088 switch(column) { 089 case 0: 090 return n.getName(); 091 case 1: 092 if (n.isPlot()) { 093 return new Double(n.getResolution()); 094 } 095 return null; 096 case 2: 097 return n.isLeaf() ? "spectra" : "range"; 098 } 099 } 100 catch (SecurityException se) { } 101 102 return null; 103 } 104 105 protected Object[] getChildren(Object node) { 106 Node n = (Node) node; 107 return n.getChildren(); 108 } 109 110 /** 111 * Represents part of a Java object tree read from an XML file using JAXB 112 */ 113 class Node { 114 protected Node(Object node) { } 115 String getName() { return "name"; } 116 Object[] getChildren() { return null; } 117 double getResolution() { return 1.0; } 118 boolean isLeaf() { return false; } 119 boolean isPlot() { return false; } 120 } 121 }