< prev index next >

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

Print this page




  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.swing;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 import java.beans.*;
  31 import java.io.*;
  32 import java.util.*;
  33 import javax.swing.event.*;
  34 import javax.swing.plaf.*;
  35 import javax.swing.tree.*;
  36 import javax.swing.text.Position;
  37 import javax.accessibility.*;



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


1545                 Object       lastPath = path.getLastPathComponent();
1546                 Component    rComponent = r.getTreeCellRendererComponent
1547                     (this, lastPath, isRowSelected(selRow),
1548                      isExpanded(selRow), getModel().isLeaf(lastPath), selRow,
1549                      true);
1550 
1551                 if(rComponent instanceof JComponent) {
1552                     MouseEvent      newEvent;
1553                     Rectangle       pathBounds = getPathBounds(path);
1554 
1555                     p.translate(-pathBounds.x, -pathBounds.y);
1556                     newEvent = new MouseEvent(rComponent, event.getID(),
1557                                           event.getWhen(),
1558                                               event.getModifiers(),
1559                                               p.x, p.y,
1560                                               event.getXOnScreen(),
1561                                               event.getYOnScreen(),
1562                                               event.getClickCount(),
1563                                               event.isPopupTrigger(),
1564                                               MouseEvent.NOBUTTON);




1565 
1566                     tip = ((JComponent)rComponent).getToolTipText(newEvent);
1567                 }
1568             }
1569         }
1570         // No tip from the renderer get our own tip
1571         if (tip == null) {
1572             tip = getToolTipText();
1573         }
1574         return tip;
1575     }
1576 
1577     /**
1578      * Called by the renderers to convert the specified value to
1579      * text. This implementation returns <code>value.toString</code>, ignoring
1580      * all other arguments. To control the conversion, subclass this
1581      * method and use any of the arguments you need.
1582      *
1583      * @param value the <code>Object</code> to convert to text
1584      * @param selected true if the node is selected




  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.swing;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 import java.beans.*;
  31 import java.io.*;
  32 import java.util.*;
  33 import javax.swing.event.*;
  34 import javax.swing.plaf.*;
  35 import javax.swing.tree.*;
  36 import javax.swing.text.Position;
  37 import javax.accessibility.*;
  38 
  39 import sun.awt.AWTAccessor;
  40 import sun.awt.AWTAccessor.MouseEventAccessor;
  41 import sun.swing.SwingUtilities2;
  42 import sun.swing.SwingUtilities2.Section;
  43 import static sun.swing.SwingUtilities2.Section.*;
  44 
  45 
  46 /**
  47  * <a name="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="https://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>


1548                 Object       lastPath = path.getLastPathComponent();
1549                 Component    rComponent = r.getTreeCellRendererComponent
1550                     (this, lastPath, isRowSelected(selRow),
1551                      isExpanded(selRow), getModel().isLeaf(lastPath), selRow,
1552                      true);
1553 
1554                 if(rComponent instanceof JComponent) {
1555                     MouseEvent      newEvent;
1556                     Rectangle       pathBounds = getPathBounds(path);
1557 
1558                     p.translate(-pathBounds.x, -pathBounds.y);
1559                     newEvent = new MouseEvent(rComponent, event.getID(),
1560                                           event.getWhen(),
1561                                               event.getModifiers(),
1562                                               p.x, p.y,
1563                                               event.getXOnScreen(),
1564                                               event.getYOnScreen(),
1565                                               event.getClickCount(),
1566                                               event.isPopupTrigger(),
1567                                               MouseEvent.NOBUTTON);
1568                     MouseEventAccessor meAccessor =
1569                         AWTAccessor.getMouseEventAccessor();
1570                     meAccessor.setCausedByTouchEvent(newEvent,
1571                         meAccessor.isCausedByTouchEvent(event));
1572 
1573                     tip = ((JComponent)rComponent).getToolTipText(newEvent);
1574                 }
1575             }
1576         }
1577         // No tip from the renderer get our own tip
1578         if (tip == null) {
1579             tip = getToolTipText();
1580         }
1581         return tip;
1582     }
1583 
1584     /**
1585      * Called by the renderers to convert the specified value to
1586      * text. This implementation returns <code>value.toString</code>, ignoring
1587      * all other arguments. To control the conversion, subclass this
1588      * method and use any of the arguments you need.
1589      *
1590      * @param value the <code>Object</code> to convert to text
1591      * @param selected true if the node is selected


< prev index next >