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

📄 jxtatreemodel.java

📁 jxta官方例程
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* *  Copyright (c) 2001 Sun Microsystems, Inc.  All rights *  reserved. * *  Redistribution and use in source and binary forms, with or without *  modification, are permitted provided that the following conditions *  are met: * *  1. Redistributions of source code must retain the above copyright *  notice, this list of conditions and the following disclaimer. * *  2. Redistributions in binary form must reproduce the above copyright *  notice, this list of conditions and the following disclaimer in *  the documentation and/or other materials provided with the *  distribution. * *  3. The end-user documentation included with the redistribution, *  if any, must include the following acknowledgment: *  "This product includes software developed by the *  Sun Microsystems, Inc. for Project JXTA." *  Alternately, this acknowledgment may appear in the software itself, *  if and wherever such third-party acknowledgments normally appear. * *  4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA" *  must not be used to endorse or promote products derived from this *  software without prior written permission. For written *  permission, please contact Project JXTA at http://www.jxta.org. * *  5. Products derived from this software may not be called "JXTA", *  nor may "JXTA" appear in their name, without prior written *  permission of Sun. * *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES *  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *  DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR *  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF *  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT *  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF *  SUCH DAMAGE. *  ==================================================================== * *  This software consists of voluntary contributions made by many *  individuals on behalf of Project JXTA.  For more *  information on Project JXTA, please see *  <http://www.jxta.org/>. * *  This license is based on the BSD license adopted by the Apache Foundation. * *  $Id: JxtaTreeModel.java,v 1.8 2006/05/17 23:23:05 nano Exp $ */package net.jxta.myjxta.ui.model;import org.jdesktop.swingx.treetable.DefaultTreeTableModel;import org.jdesktop.swingx.treetable.TreeTableModel;import net.jxta.myjxta.util.Constants;import net.jxta.myjxta.util.GroupNode;import net.jxta.myjxta.util.Group;import net.jxta.myjxta.util.JxtaNode;import net.jxta.myjxta.util.PeerNode;import net.jxta.myjxta.util.Resources;import net.jxta.myjxta.util.ShareNode;import java.util.ArrayList;import java.util.Collections;import java.util.Iterator;import java.util.List;import java.util.ResourceBundle;/** * The data model for the nodes displayed in the TreeTable * * @version $Id: JxtaTreeModel.java,v 1.8 2006/05/17 23:23:05 nano Exp $ * * @author james todd [gonzo at jxta dot org] */public class JxtaTreeModelextends DefaultTreeTableModel {        /** The list of columns we display */    private static String[] columnNames;        /**     *  The column types for ths columns defined in     *  {@link #columnNames columnNames}.     * DAW: should the first column type not be JxtaNode since that is     * what is returned by  getValueAt     */    private static Class[] columnTypes = {        TreeTableModel.class, String.class    };    private List<JxtaTreeModelListener> listeners = null;        static {        ResourceBundle strings = Resources.getStrings();                columnNames = new String[2];                columnNames[0] = strings.getString("label.network.jxta");        columnNames[1] = strings.getString("label.network.jxta.description");    }        /**     * Create a new JxtaModel, which has a root JXtaNode with     * a label of "JXTA"     */    public JxtaTreeModel() {        super(new JxtaNode(null, Constants.ROOT_NODE));    }    /**     * We dont want to add a PeerNode to the tree, but we want to be sure that the group     * the node lies in is visible.     * @param node      */    public void ensurePeerNodeHasVisibleParent(PeerNode node){        Group g = ((GroupNode)node.getParent()).getGroup();        getParentNode(g); //this call to getParentNode ensures that there is a parent node                          //and creates it otherwise    }    /**     * Add a new JxtaNode to be displayed in the tree     *     * @param node the node to add     * @return true if the node was added, false if the node already     *         existed in the tree     */        public boolean add(JxtaNode node) {        boolean isAdded = false;                if (node instanceof GroupNode) {            Group g = ((GroupNode)node).getGroup();            JxtaNode pn = getParentNode(g.getParentGroup());                        if (pn != null) {                isAdded = addTreeNode(pn, node);            }        } else if (node instanceof PeerNode) {            Group g = ((GroupNode)node.getParent()).getGroup();            JxtaNode pn = getParentNode(g);            int i = pn != null ? pn.getIndexOf(node) : -1;            if (pn != null &&                i == -1) {                isAdded = addTreeNode(pn, node);            }        } else if (node instanceof ShareNode) {            Group g = ((GroupNode)node.getParent()).getGroup();            JxtaNode pn = getParentNode(g);            int i = pn != null ? pn.getIndexOf(node) : -1;                        if (pn != null &&                i == -1) {                isAdded = addTreeNode(pn, node);            }        }                if (isAdded) {            for (Iterator l = getListeners(); l.hasNext(); ) {                ((JxtaTreeModelListener)l.next()).nodeAdded(node);            }        }                return isAdded;    }            /**     * Remove the indicated node     *     * @param node the JxtaNode to remove     */    public void remove(JxtaNode node) {        JxtaNode parent = (JxtaNode)node.getParent();                if (parent != null) {            int changedIndex[] = new int[1];            JxtaNode changedNodes[] = new JxtaNode[1];            changedNodes[0] = node;            changedIndex[0] = parent.getIndexOf(node);                        parent.remove(node);                        fireTreeNodesRemoved(this, parent.getPath(), changedIndex,                changedNodes);                        for (Iterator l = getListeners(); l.hasNext(); ) {                ((JxtaTreeModelListener)l.next()).nodeRemoved(node);            }        }    }               /**     * The indicated Tree node has changed     */    public void nodeChanged(JxtaNode node) {        int changedIndex[] = new int[1];        JxtaNode changedNodes[] = new JxtaNode[1];        JxtaNode parent = (JxtaNode)node.getParent();                if (parent != null) {            changedNodes[0] = node;            changedIndex[0] = parent.getIndexOf(node);                        fireTreeNodesChanged(this,parent.getPath(), changedIndex,                changedNodes);                        for (Iterator l = getListeners(); l.hasNext(); ) {                ((JxtaTreeModelListener)l.next()).nodeUpdated(node);            }        }    }        public void setValueAt(Object v, Object n, int c) {    }        /**     * Get the number of children of the indicated node     *     * @param node the object for which to get the number of children     */    public int getChildCount(Object node) {        return ((JxtaNode)node).getChildrenCount();    }        /**     * Get the child of the indicated node at the indicated index     *     * @param node the  node from which to get the child     * @param index the index of the desired child     *     * @return the child at the indicated index at the indicated node     */    public Object getChild(Object node, int index) {        return node != null ? ((JxtaNode)node).getChildAt(index) : null;    }        /**     * Check whether the indicated node is a leaf node     *     * @param node the node for which to check the status     *     * @return true if node is a lead node, false otherwise     */    public boolean isLeaf(Object node) {        return ((JxtaNode)node).isLeaf();    }        /**     * Get the number of columns to be displayed int     * the TreeTable     *     * @return the desired number of columns     */    public int getColumnCount() {        return columnNames.length;    }        /**     * Get the name of the indicated column     *     * @param column the index of the column     *     * @return the name for the indicated column     */    public String getColumnName(int column) {

⌨️ 快捷键说明

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