⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 grouptreemodel.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
字号:
// You can redistribute this software and/or modify it under the terms of
// the Ozone Library License version 1 published by ozone-db.org.
//
// The original code and portions created by SMB are
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
//
package org.ozoneDB.adminGui.feature.account.groups;

import java.util.Vector;
import javax.swing.event.TreeModelEvent;
import javax.swing.event.TreeModelListener;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;

import org.ozoneDB.adminGui.feature.account.AccountItem;


//#############################################################################
/**
 * This class is used to manage the group table.
 *
 * @author  <p align=center>Ibsen Ramos-Bonilla
 * <br>Copyright &copy 1997-@year@ by SMB GmbH. All Rights Reserved.</p>
 *
 * @version 1.0
 */
//#############################################################################

public class GroupTreeModel implements TreeModel {

    /** The listeners used on the tree to know was going on. */
    private Vector treeModelListeners = new Vector();
    /** The group root item, holds all other nodes. */
    private AccountItem rootItem = null;


    /**
     * Overloaded constructor begins building the model from the root.
     */
    public GroupTreeModel() {
        this.rootItem = new AccountItem("Accounts", 0);
    }

    /**
     * Adds a listener for the TreeModelEvent posted after the tree changes.
     *
     * @param l - a tree model listener.
     */
    public void addTreeModelListener(TreeModelListener l) {
        this.treeModelListeners.addElement(l);
    }

    /**
     * Removes a listener previously added with addTreeModelListener().
     *
     * @param l - a tree model listener.
     */
    public void removeTreeModelListener(TreeModelListener l) {
        this.treeModelListeners.removeElement(l);
    }

    /**
     * This method returns the root of the tree.
     *
     * @return Object - root item.
     */
    public Object getRoot() {
        return this.rootItem;
    }

    /**
     * This method returns true if node is a leaf.
     *
     * @param node - the selected node.
     * @return boolean - TRUE = node is a leaf.
     *                   FALSE = node is not a leaf.
     */
    public boolean isLeaf(Object node) {
        AccountItem item = (AccountItem) node;
        return item.getChildCount() == 0;
    }

    /**
     * This method returns the number of children of parent.
     *
     * @param parent - the parent of the child count.
     * @return int - the number of children.
     */
    public int getChildCount(Object parent) {
        AccountItem item = (AccountItem) parent;
        return item.getChildCount();
    }

    /**
     * This method returns the index of child in parent.
     *
     * @param parent - the parent to check connection to.
     * @param child - the child to find conenction from.
     * @return int - index of selected child.
     */
    public int getIndexOfChild(Object parent, Object child) {
        AccountItem item = (AccountItem) parent;
        return item.getIndexOfChild((AccountItem) child);
    }

    /**
     * Messaged when the account has altered the value for the item identified by
     * path to newValue.  Not used by this model.
     *
     * @param path - the path to the selected node.
     * @param newValue - the value for the path node changed.
     */
    public void valueForPathChanged(TreePath path, Object newValue) {
        System.out.println("*** valueForPathChanged : " + path + " --> " +
                newValue);
    }

    /**
     * This method returns the child of parent at index index in the parent's
     * child array.
     *
     * @param parent - the parent to search for a child.
     * @param index - the desired children pointed by the parent.
     * @return Object - parent's child.
     */
    public Object getChild(Object parent, int index) {
        AccountItem item = (AccountItem) parent;
        return item.getChildAt(index);
    }

    /**
     * The only event raised by this model is TreeStructureChanged with the
     * root as path, i.e. the whole tree has changed.
     *
     */
    public void fireTreeStructureChanged() {
        int len = this.treeModelListeners.size();
        TreeModelEvent e = new TreeModelEvent(this, new Object[]{rootItem});

        for (int i = 0; i < len; i++) {
            ((TreeModelListener) this.treeModelListeners.elementAt(i)).
                    treeStructureChanged(e);
        }
    }

    /**
     * This method returns a reference to the root item.
     *
     * @return AccountItem - the root item.
     */
    public AccountItem getRootItem() {
        return this.rootItem;
    }

    /**
     * This method clears the tree information.
     */
    public void clearGroups() {
        //get rid of all children
        this.rootItem.setChildren(null);
    }

} //--------------------------------- E O F -----------------------------------


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -