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

📄 treenode.java

📁 里面是关于jmf编程的例子,希望能给初学者带来一些帮助
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * @(#)TreeNode.java	1.2 00/03/07 * * Copyright (c) 1999 Sun Microsystems, Inc. All Rights Reserved. * * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use, * modify and redistribute this software in source and binary code form, * provided that i) this copyright notice and license appear on all copies of * the software; and ii) Licensee does not utilize the software in a manner * which is disparaging to Sun. * * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. * * This software is not designed or intended for use in on-line control of * aircraft, air traffic, aircraft navigation or aircraft communications; or in * the design, construction, operation or maintenance of any nuclear * facility. Licensee represents and warrants that it will not use or * redistribute the Software for such purposes. */package jmapps.ui;import java.util.*;import java.awt.*;import java.awt.event.*;public class TreeNode extends Vector {    public static final int     MARGIN_HORZ = 6;    public static final int     MARGIN_VERT = 2;    public static final int     BOXSIZE = 8;    public static final String  ACTION_NODE_ADDED = "Node Added";    public static final String  ACTION_NODE_REMOVED = "Node Removed";    public static final String  ACTION_NODE_EXPANDED = "Node Expanded";    public static final String  ACTION_NODE_COLLAPSED = "Node Collapsed";    public static final String  ACTION_NODE_SETCURRENT = "Node Set Current";    public static final String  ACTION_NODE_RESETCURRENT = "Node Reset Current";    public static final Color   colorBg = Color.lightGray;    public static final Color   colorCurBg = new Color ( 0, 0, 128 );    public static final Color   colorFg = Color.black;    public static final Color   colorCurFg = Color.yellow;    public static final Color   colorLines = Color.darkGray;    private Component           componentOwner;    private Vector              vectorActionListeners = new Vector ();    private boolean     boolExpanded = false;    private boolean     boolCurrent = false;    private boolean     boolVisible = true;    private Image       imageTreeElement = null;    private Image       imageTreeElementCur = null;    private int         nWidthImage = 0;    private int         nHeightImage = 0;    private Rectangle   rectElement = null;    private Rectangle   rectElementFull = null;    private String      strName;    private Object      objUserData = null;    private TreeNode    nodeOwner;    public TreeNode ( String stringName, Component clWindowOwner ) {        super ();        this.strName = new String ( stringName );        this.componentOwner = clWindowOwner;        rectElement = new Rectangle ( 0, 0, 0, 0 );        rectElementFull = new Rectangle ( 0, 0, 0, 0 );        setImage ( ImageArea.loadImage ( "treeNode.gif", clWindowOwner, true ) );        setImageCur ( ImageArea.loadImage ( "treeNodeCur.gif", clWindowOwner, true ) );	}    public void addActionListener ( ActionListener listener ) {        if ( listener == null )            return;        vectorActionListeners.addElement ( listener );    }    public void rewmoveActionListener ( ActionListener listener ) {        if ( listener == null )            return;        vectorActionListeners.removeElement ( listener );    }    public String getName () {        return ( strName );    }    public String getFullPathName () {        String  stringName;        if ( nodeOwner != null )            stringName = nodeOwner.getFullPathName ();        else            stringName = new String ();        stringName += "/" + strName;        return ( stringName );    }    public TreeNode getOwner () {        return ( nodeOwner );    }    public TreeNode getRoot () {        TreeNode    nodeRoot;        nodeRoot = this;        while ( nodeRoot.getOwner() != null )            nodeRoot = nodeRoot.getOwner ();        return ( nodeRoot );    }    public Object getUserData () {        return ( objUserData );    }    public TreeNode getSubElement ( int nIndex ) {        int         nSize;        TreeNode    node;        nSize = size ();        if ( nIndex >= nSize  ||  nIndex < 0 )            return ( null );        node = (TreeNode) elementAt ( nIndex );        return ( node );    }    public TreeNode getSubElement ( String stringName ) {        int         i;        int         nSize;        TreeNode    node;        String      stringElementName = null;        nSize = size ();        for ( i = 0;  i < nSize;  i++ ) {            node = (TreeNode) elementAt ( i );            stringElementName = node.getName ();            if ( stringElementName.equals (stringName) )                return ( node );        }        return ( null );    }    public boolean isSubElement ( String stringName ) {        int         i;        int         nSize;        TreeNode    node;        String      stringElementName = null;        nSize = size ();        for ( i = 0;  i < nSize;  i++ ) {            node = (TreeNode) elementAt ( i );            stringElementName = node.getName ();            if ( stringElementName.equals(stringName) )                return ( true );        }        return ( false );    }    public TreeNode findElement ( String stringFullPath ) {        int         i;        int         nSize;        TreeNode    node = null;        if ( stringFullPath.equals("/" + strName) )            return ( this );        if ( !(stringFullPath.startsWith("/"+strName)) )            return ( null );        stringFullPath = stringFullPath.substring ( strName.length() + 1 );        nSize = size ();        for ( i = 0;  i < nSize  &&  node == null;  i++ ) {            node = (TreeNode) elementAt ( i );            node = node.findElement ( stringFullPath );        }        return ( node );    }    public TreeNode addSubElement ( TreeNode node ) {        ActionEvent     event;        if ( node.nodeOwner != null )            node.nodeOwner.removeSubElement ( node );        addElement ( node );        node.nodeOwner = this;        event = new ActionEvent ( this, ActionEvent.ACTION_PERFORMED, ACTION_NODE_ADDED );        fireActionEvent ( event );        return ( node );    }    public TreeNode addSubElement ( String stringName ) {        TreeNode    node;        node = new TreeNode ( stringName, componentOwner );        addSubElement ( node );        return ( node );    }    public TreeNode insertSubElement ( int nIndex, TreeNode node ) {        int     nSize;        if ( node.nodeOwner != null )            node.nodeOwner.removeSubElement ( node );        nSize = size ();        if ( nIndex < 0 )            nIndex = 0;        if ( nIndex > nSize )            nIndex = nSize;        insertElementAt ( node, nIndex );        node.nodeOwner = this;        return ( node );    }    public TreeNode insertSubElement ( int nIndex, String stringName ) {        TreeNode    node;        node = new TreeNode ( stringName, componentOwner );        insertSubElement ( nIndex, node );        return ( node );    }    public void removeSubElement ( TreeNode node ) {        boolean         boolResult;        ActionEvent     event;        boolResult = removeElement ( node );        if ( boolResult == true ) {            node.nodeOwner = null;            event = new ActionEvent ( this, ActionEvent.ACTION_PERFORMED, ACTION_NODE_REMOVED );            fireActionEvent ( event );        }    }    public void destroySubElement ( TreeNode node ) {        node.destroyAllSubElements ();        node.nodeOwner = null;        removeSubElement ( node );    }    public void destroySubElement ( int nIndex ) {        int         nSize;        TreeNode    node;        nSize = size ();        if ( nIndex >= nSize  ||  nIndex < 0 )            return;        node = (TreeNode) elementAt ( nIndex );        destroySubElement ( node );    }    public void destroyAllSubElements () {        int         nSize;        TreeNode    node;        nSize = size ();        while ( nSize > 0 ) {            nSize--;            destroySubElement ( nSize );        }    }    public void sortSubElements () {        int         i, j;        int         nSize;        TreeNode    node1;        TreeNode    node2;        String      stringName1;        String      stringName2;        int         nResult;        nSize = size ();        for ( i = 0;  i < nSize;  i++ ) {            node1 = (TreeNode) elementAt ( i );            stringName1 = node1.getName ();            removeElementAt ( i );            for ( j = 0;  j < i;  j++ ) {                node2 = (TreeNode) elementAt ( j );                stringName2 = node2.getName ();                nResult = stringName1.compareTo ( stringName2 );                if ( nResult < 0 )                    break;            }            insertElementAt ( node1, j );            node1.sortSubElements ();        }    }    public int getImmediateSubElementsCount () {        int	nSize;        nSize = size ();        return ( nSize );    }    public int getRecursiveSubElementsCount () {        int     i;        int     nCount;        int     nSize;        Object  object;        nSize = size ();        nCount = nSize;        for ( i = 0;  i < nSize;  i++ ) {            object = elementAt ( i );            if ( object != null  &&  object instanceof TreeNode )                nCount += ((TreeNode)object).getRecursiveSubElementsCount ();        }        return ( nCount );    }    public int getExpandedSubElementsCount () {        int     i;        int     nCount;        int     nSize;        Object  object;        nSize = size ();        nCount = nSize;        for ( i = 0;  i < nSize;  i++ ) {            object = elementAt ( i );            if ( object != null  &&  object instanceof TreeNode  &&  ((TreeNode)object).isExpanded() )                nCount += ((TreeNode)object).getExpandedSubElementsCount ();        }        return ( nCount );    }    public boolean isRecursiveSubElement ( Object object ) {        boolean     boolResult = false;        int         i;        int         nSize;        Object      objectSub;        if ( object == this )            return ( true );        nSize = size ();        for ( i = 0;  i < nSize  &&  boolResult == false;  i++ ) {            objectSub = elementAt ( i );            if ( object == objectSub )                return ( true );            if ( objectSub != null  &&  objectSub instanceof TreeNode )                boolResult = ((TreeNode)objectSub).isRecursiveSubElement ( object );        }        return ( boolResult );	}    public void setUserData ( Object objectData ) {        this.objUserData = objectData;    }    public boolean isVisible () {        return ( boolVisible );    }    public void setVisible ( boolean boolVisible ) {        if ( this.boolVisible == boolVisible )			return;        this.boolVisible = boolVisible;        if ( boolVisible == false  &&  boolExpanded == false )            switchExpanded ();    }    public boolean isExpanded () {        return ( boolExpanded );    }    public void setExpanded ( boolean boolExpanded ) {        if ( this.boolExpanded != boolExpanded )            switchExpanded ();    }    public boolean switchExpanded () {        ActionEvent     event;        if ( boolExpanded == true ) {            boolExpanded = false;

⌨️ 快捷键说明

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