/*
 This file is part of the software framework JStatCom, 
 a library for building applications for data based analysis.

 Copyright (C) 2000-2005  Markus Kraetzig

 This library is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as
 published by the Free Software Foundation; either version 2.1 of the
 License, or (at your option) any later version.

 This library is distributed in the hope that it will be useful, but
 WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 USA
 */

package com.jstatcom.model.control;

import javax.swing.JTree;
import javax.swing.border.EmptyBorder;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeSelectionModel;

import com.jstatcom.model.SymbolTable;

/**
 * A Singleton tree that contains all symbol tables as parent nodes with
 * their names and all JSCData elements as leafes.
 * A symbol table is added under the root node, if its parent table
 * is null, otherwise the parent is added first and
 * the table under it. Empty symbol tables are not shown.
 * 

* This component can be used to display all data used in a * model. It should be references by getInstance. * * @author Markus Kraetzig */ public final class SymbolTree extends JTree { private static final SymbolTree symbolTree = new SymbolTree(); /** * Root node of this tree. */ private final DefaultMutableTreeNode ROOT = new DefaultMutableTreeNode("ROOT"); // tree model private final DefaultTreeModel symbolTreeModel = new DefaultTreeModel(ROOT); // tree cell renderer private final SymbolTreeCellRenderer symbolTreeModelCellRenderer = new SymbolTreeCellRenderer(); /** * Not to be invoked. */ private SymbolTree() { super(); initialize(); } /** * Runs init tasks. */ private void initialize() { setBorder(new EmptyBorder(1, 3, 0, 0)); setRowHeight(21); setModel(symbolTreeModel); setCellRenderer(symbolTreeModelCellRenderer); getSelectionModel().setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION); setRootVisible(false); } /** * Gets the singleton instance of this symbol tree. * * @return singleton instance */ public static SymbolTree getInstance() { return symbolTree; } /** * Adds the symbol table to this tree. If the parent is * null, then it is added under the root node, otherwise * the parent is added first and symbolTable * is added under the parent node. * * @param symbolTable the table to add * @throws IllegalArgumentException if (symbolTable == null) */ public void addSymbolTable(SymbolTable symbolTable) { if (symbolTable == null) throw new IllegalArgumentException("Argument was null."); // manages adding/removing itself new SymbolTableTreeNode(symbolTable, symbolTreeModel); } }

Ads help maintain this website.