Beispiel #1
0
 /**
  * Returns the tooltip text at the specified location. The default implementation returns the
  * value from the child View identified by the passed in location.
  *
  * @since 1.4
  * @see JTextComponent#getToolTipText
  */
 public String getToolTipText(float x, float y, Shape allocation) {
   int viewIndex = getViewIndex(x, y, allocation);
   if (viewIndex >= 0) {
     allocation = getChildAllocation(viewIndex, allocation);
     Rectangle rect =
         (allocation instanceof Rectangle) ? (Rectangle) allocation : allocation.getBounds();
     if (rect.contains(x, y)) {
       return getView(viewIndex).getToolTipText(x, y, allocation);
     }
   }
   return null;
 }
Beispiel #2
0
  /**
   * Returns the child view index representing the given position in the view. This iterates over
   * all the children returning the first with a bounds that contains <code>x</code>, <code>y</code>
   * .
   *
   * @param x the x coordinate
   * @param y the y coordinate
   * @param allocation current allocation of the View.
   * @return index of the view representing the given location, or -1 if no view represents that
   *     position
   * @since 1.4
   */
  public int getViewIndex(float x, float y, Shape allocation) {
    for (int counter = getViewCount() - 1; counter >= 0; counter--) {
      Shape childAllocation = getChildAllocation(counter, allocation);

      if (childAllocation != null) {
        Rectangle rect =
            (childAllocation instanceof Rectangle)
                ? (Rectangle) childAllocation
                : allocation.getBounds();

        if (rect.contains(x, y)) {
          return counter;
        }
      }
    }
    return -1;
  }
 @Override
 public boolean isCellEditable(EventObject e) {
   if (e instanceof MouseEvent && e.getSource() instanceof JTree) {
     MouseEvent me = (MouseEvent) e;
     JTree tree = (JTree) e.getSource();
     TreePath path = tree.getPathForLocation(me.getX(), me.getY());
     Rectangle r = tree.getPathBounds(path);
     if (r == null) {
       return false;
     }
     Dimension d = getPreferredSize();
     r.setSize(new Dimension(d.width, r.height));
     if (r.contains(me.getX(), me.getY())) {
       if (str == null && System.getProperty("java.version").startsWith("1.7.0")) {
         setBounds(new Rectangle(0, 0, d.width, r.height));
       }
       // System.out.println(getBounds());
       return true;
     }
   }
   return false;
 }