001 package ui.model; 002 003 import java.util.*; 004 import javax.swing.tree.*; 005 import javax.swing.event.*; 006 import astronomy.data.spectra.*; 007 008 public class SpectraTreeModel implements TreeModel { 009 010 protected Spectradatabase _sd; 011 012 private EventListenerList listenerList = new EventListenerList(); 013 014 public SpectraTreeModel(Spectradatabase sd) { 015 _sd = sd; 016 } 017 018 protected java.util.List getChildren(Object aParent) { 019 if (aParent instanceof Spectradatabase) { 020 Spectradatabase sd = (Spectradatabase) aParent; 021 return sd.getType(); 022 023 } else if (aParent instanceof SpectradatabaseType.TypeType) { 024 SpectradatabaseType.TypeType type = (SpectradatabaseType.TypeType) aParent; 025 return type.getSource(); 026 027 } else if (aParent instanceof SpectradatabaseType.TypeType.SourceType) { 028 SpectradatabaseType.TypeType.SourceType source = (SpectradatabaseType.TypeType.SourceType) aParent; 029 return source.getSpectra(); 030 031 } else if (aParent instanceof SpectraType) { 032 SpectraType spectraType = (SpectraType) aParent; 033 List list = new ArrayList(spectraType.getPlot()); 034 list.addAll(spectraType.getAbsorptionline()); 035 list.addAll(spectraType.getEmissionline()); 036 list.addAll(spectraType.getDiscontinuity()); 037 return list; 038 039 } else if (aParent instanceof PlotType) { 040 PlotType plot = (PlotType) aParent; 041 PlotType.PlotdataType data = plot.getPlotdata(); 042 List list = new ArrayList(1); 043 list.add(data); 044 return list; 045 046 } else if (aParent instanceof PlotType.PlotdataType) { 047 PlotType.PlotdataType data = (PlotType.PlotdataType) aParent; 048 List list = new ArrayList(); 049 if (data.getImagefile() != null) list.add(data.getImagefile()); 050 if (data.getPlotfile() != null) list.add(data.getPlotfile()); 051 return list; 052 053 } else if (aParent instanceof LineType) { 054 LineType line = (LineType) aParent; 055 return line.getTransition(); 056 057 } else { 058 return new ArrayList(); 059 } 060 } 061 062 public Object getChild(Object aParent, int anIndex) { 063 return getChildren(aParent).get(anIndex); 064 } 065 066 public int getIndexOfChild(Object aParent, Object aChild) { 067 return getChildren(aParent).indexOf(aChild); 068 } 069 070 public int getChildCount(Object aParent) { 071 return getChildren(aParent).size(); 072 } 073 074 public boolean isLeaf(Object aNode) { 075 return getChildCount(aNode) == 0; 076 } 077 078 public Object getRoot() { 079 return _sd; 080 } 081 082 public void valueForPathChanged(TreePath aPath, Object newValue) { 083 Object _treeObject = aPath.getLastPathComponent(); 084 //if (_treeObject != null && _treeObject instanceof KBObject) 085 } 086 087 public void addTreeModelListener(TreeModelListener l) { 088 listenerList.add(TreeModelListener.class, l); 089 } 090 091 public void removeTreeModelListener(TreeModelListener l) { 092 listenerList.remove(TreeModelListener.class, l); 093 } 094 095 } 096