< prev index next >

src/java.desktop/share/classes/javax/swing/JTree.java

Print this page




  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package javax.swing;
  26 
  27 import java.awt.*;
  28 import java.awt.event.*;
  29 import java.beans.JavaBean;
  30 import java.beans.BeanProperty;
  31 import java.beans.ConstructorProperties;
  32 import java.beans.PropertyChangeEvent;
  33 import java.beans.PropertyChangeListener;
  34 import java.io.*;
  35 import java.util.*;
  36 import javax.swing.event.*;
  37 import javax.swing.plaf.*;
  38 import javax.swing.tree.*;
  39 import javax.swing.text.Position;
  40 import javax.accessibility.*;
  41 


  42 import sun.swing.SwingUtilities2;
  43 import sun.swing.SwingUtilities2.Section;
  44 import static sun.swing.SwingUtilities2.Section.*;
  45 
  46 /**
  47  * <a id="jtree_description"></a>
  48  * A control that displays a set of hierarchical data as an outline.
  49  * You can find task-oriented documentation and examples of using trees in
  50  * <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/tree.html">How to Use Trees</a>,
  51  * a section in <em>The Java Tutorial.</em>
  52  * <p>
  53  * A specific node in a tree can be identified either by a
  54  * <code>TreePath</code> (an object
  55  * that encapsulates a node and all of its ancestors), or by its
  56  * display row, where each row in the display area displays one node.
  57  * An <i>expanded</i> node is a non-leaf node (as identified by
  58  * <code>TreeModel.isLeaf(node)</code> returning false) that will displays
  59  * its children when all its ancestors are <i>expanded</i>.
  60  * A <i>collapsed</i>
  61  * node is one which hides them. A <i>hidden</i> node is one which is


1561                 Component    rComponent = r.getTreeCellRendererComponent
1562                     (this, lastPath, isRowSelected(selRow),
1563                      isExpanded(selRow), getModel().isLeaf(lastPath), selRow,
1564                      true);
1565 
1566                 if(rComponent instanceof JComponent) {
1567                     MouseEvent      newEvent;
1568                     Rectangle       pathBounds = getPathBounds(path);
1569 
1570                     p.translate(-pathBounds.x, -pathBounds.y);
1571                     @SuppressWarnings("deprecation")
1572                     final int modifiers = event.getModifiers();
1573                     newEvent = new MouseEvent(rComponent, event.getID(),
1574                                           event.getWhen(), modifiers,
1575                                               p.x, p.y,
1576                                               event.getXOnScreen(),
1577                                               event.getYOnScreen(),
1578                                               event.getClickCount(),
1579                                               event.isPopupTrigger(),
1580                                               MouseEvent.NOBUTTON);




1581 
1582                     tip = ((JComponent)rComponent).getToolTipText(newEvent);
1583                 }
1584             }
1585         }
1586         // No tip from the renderer get our own tip
1587         if (tip == null) {
1588             tip = getToolTipText();
1589         }
1590         return tip;
1591     }
1592 
1593     /**
1594      * Called by the renderers to convert the specified value to
1595      * text. This implementation returns <code>value.toString</code>, ignoring
1596      * all other arguments. To control the conversion, subclass this
1597      * method and use any of the arguments you need.
1598      *
1599      * @param value the <code>Object</code> to convert to text
1600      * @param selected true if the node is selected




  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package javax.swing;
  26 
  27 import java.awt.*;
  28 import java.awt.event.*;
  29 import java.beans.JavaBean;
  30 import java.beans.BeanProperty;
  31 import java.beans.ConstructorProperties;
  32 import java.beans.PropertyChangeEvent;
  33 import java.beans.PropertyChangeListener;
  34 import java.io.*;
  35 import java.util.*;
  36 import javax.swing.event.*;
  37 import javax.swing.plaf.*;
  38 import javax.swing.tree.*;
  39 import javax.swing.text.Position;
  40 import javax.accessibility.*;
  41 
  42 import sun.awt.AWTAccessor;
  43 import sun.awt.AWTAccessor.MouseEventAccessor;
  44 import sun.swing.SwingUtilities2;
  45 import sun.swing.SwingUtilities2.Section;
  46 import static sun.swing.SwingUtilities2.Section.*;
  47 
  48 /**
  49  * <a id="jtree_description"></a>
  50  * A control that displays a set of hierarchical data as an outline.
  51  * You can find task-oriented documentation and examples of using trees in
  52  * <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/tree.html">How to Use Trees</a>,
  53  * a section in <em>The Java Tutorial.</em>
  54  * <p>
  55  * A specific node in a tree can be identified either by a
  56  * <code>TreePath</code> (an object
  57  * that encapsulates a node and all of its ancestors), or by its
  58  * display row, where each row in the display area displays one node.
  59  * An <i>expanded</i> node is a non-leaf node (as identified by
  60  * <code>TreeModel.isLeaf(node)</code> returning false) that will displays
  61  * its children when all its ancestors are <i>expanded</i>.
  62  * A <i>collapsed</i>
  63  * node is one which hides them. A <i>hidden</i> node is one which is


1563                 Component    rComponent = r.getTreeCellRendererComponent
1564                     (this, lastPath, isRowSelected(selRow),
1565                      isExpanded(selRow), getModel().isLeaf(lastPath), selRow,
1566                      true);
1567 
1568                 if(rComponent instanceof JComponent) {
1569                     MouseEvent      newEvent;
1570                     Rectangle       pathBounds = getPathBounds(path);
1571 
1572                     p.translate(-pathBounds.x, -pathBounds.y);
1573                     @SuppressWarnings("deprecation")
1574                     final int modifiers = event.getModifiers();
1575                     newEvent = new MouseEvent(rComponent, event.getID(),
1576                                           event.getWhen(), modifiers,
1577                                               p.x, p.y,
1578                                               event.getXOnScreen(),
1579                                               event.getYOnScreen(),
1580                                               event.getClickCount(),
1581                                               event.isPopupTrigger(),
1582                                               MouseEvent.NOBUTTON);
1583                     MouseEventAccessor meAccessor =
1584                         AWTAccessor.getMouseEventAccessor();
1585                     meAccessor.setCausedByTouchEvent(newEvent,
1586                         meAccessor.isCausedByTouchEvent(event));
1587 
1588                     tip = ((JComponent)rComponent).getToolTipText(newEvent);
1589                 }
1590             }
1591         }
1592         // No tip from the renderer get our own tip
1593         if (tip == null) {
1594             tip = getToolTipText();
1595         }
1596         return tip;
1597     }
1598 
1599     /**
1600      * Called by the renderers to convert the specified value to
1601      * text. This implementation returns <code>value.toString</code>, ignoring
1602      * all other arguments. To control the conversion, subclass this
1603      * method and use any of the arguments you need.
1604      *
1605      * @param value the <code>Object</code> to convert to text
1606      * @param selected true if the node is selected


< prev index next >