decodes.syncgui.TreePanel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opendcs Show documentation
Show all versions of opendcs Show documentation
A collection of software for aggregatting and processing environmental data such as from NOAA GOES satellites.
The newest version!
package decodes.syncgui;
import java.awt.*;
import javax.swing.*;
import javax.swing.tree.*;
import java.util.Date;
import java.util.Iterator;
import javax.swing.event.*;
import java.net.URL;
import java.net.MalformedURLException;
import java.io.InputStream;
import java.io.IOException;
import ilex.util.Logger;
/**
The TreePanel shows on the left side of the GUI. It shows a 3-level tree:
- 1 District Names
- 2 Archived Databases from each district
- 3 Directories within the database
*/
public class TreePanel extends JPanel
implements TreeSelectionListener
{
BorderLayout borderLayout1 = new BorderLayout();
DefaultMutableTreeNode top =
new DefaultMutableTreeNode(SyncConfig.instance().getHubName(), true);
DefaultTreeModel treeModel = new DefaultTreeModel(top);
JTree tree = new JTree(treeModel);
public TreePanel()
{
try {
jbInit();
}
catch(Exception ex) {
ex.printStackTrace();
}
fillDistricts();
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.addTreeSelectionListener(this);
}
public void expandFirstRow()
{
//System.out.println("Tree has " + tree.getRowCount() + " rows.");
//TreePath tp = tree.getPathForRow(0);
//System.out.println("Row 0 path: '" + tp + "'");
//tree.expandPath(tp);
tree.expandRow(0);
}
/**
* Test method to fill tree with demo data.
*/
public void fillDistricts()
{
int i = 0;
for(Iterator it = SyncConfig.instance().iterator(); it.hasNext(); )
{
District dist = (District)it.next();
DefaultMutableTreeNode districtNode =
new DefaultMutableTreeNode(dist, true);
treeModel.insertNodeInto(districtNode, top, i++);
// Put a dummy node under each one so user will be able to expand.
DefaultMutableTreeNode dummy = new DefaultMutableTreeNode("",true);
treeModel.insertNodeInto(dummy, districtNode, 0);
}
}
void jbInit() throws Exception {
this.setLayout(borderLayout1);
tree.addTreeWillExpandListener(new TreePanel_tree_treeWillExpandAdapter(this));
this.add(tree, BorderLayout.CENTER);
}
public void valueChanged(TreeSelectionEvent e)
{
DefaultMutableTreeNode node = (DefaultMutableTreeNode)
tree.getLastSelectedPathComponent();
if (node == null)
return;
Object nodeObj = node.getUserObject();
SyncGuiFrame sgf = SyncGuiFrame.instance();
if (nodeObj instanceof String)
{
// this is the top node
sgf.showTopPanel();
}
else if (nodeObj instanceof District)
{
// show district info in the view panel.
sgf.showDistrictPanel((District)nodeObj);
}
else if (nodeObj instanceof DistrictDBSnap)
{
// show this particular archive db info in the view panel.
sgf.showSnapshotPanel((DistrictDBSnap)nodeObj);
}
else if (nodeObj instanceof PlatList)
{
// show the platform list in the view panel.
sgf.showPlatListPanel((PlatList)nodeObj);
}
else if (nodeObj instanceof FileList)
{
// Show the list of files in the view panel.
sgf.showFileListPanel((FileList)nodeObj);
}
}
/**
* Called when a tree is about to expand. May need to read additional
* info in order to do the expansion.
* @param e TreeExpansionEvent
* @throws ExpandVetoException
*/
void tree_treeWillExpand(TreeExpansionEvent e)
throws ExpandVetoException
{
SyncGuiFrame sgf = SyncGuiFrame.instance();
TreePath tp = e.getPath();
//System.out.println("Will expand '" + tp + "'");
Object []path = tp.getPath();
// for(int i=0; i