final TreePath editPath = path;  if (startEditTimer != null) startEditTimer.stop();  startEditTimer = new Timer(WAIT_TILL_EDITING, new ActionListener() { public void actionPerformed(ActionEvent e) { startEditing(editPath, EDIT); } }); startEditTimer.setRepeats(false); startEditTimer.start(); } else { if (e.getClickCount() == 2 && ! isLeaf(row)) toggleExpandState(path); else
if (! startEditing(path, e))
    public void mousePressed(MouseEvent e)    {      // Any mouse click cancels the previous waiting edit action, initiated      // by the single click on the selected node.      if (startEditTimer != null)        {          startEditTimer.stop();          startEditTimer = null;        }            Point click = e.getPoint();      TreePath path = getClosestPathForLocation(tree, click.x, click.y);      if (path != null)        {          Rectangle bounds = getPathBounds(tree, path);          int row = getRowForPath(tree, path);                    // Cancel the editing session if clicked on the different row.          if (tree.isEditing() && row != editingRow)            cancelEditing(tree);                    boolean cntlClick = isLocationInExpandControl(path, click.x, click.y);          boolean isLeaf = isLeaf(row);                    TreeCellRenderer tcr = getCellRenderer();          Icon icon;          if (isLeaf)            icon = UIManager.getIcon("Tree.leafIcon");          else if (tree.isExpanded(path))            icon = UIManager.getIcon("Tree.openIcon");          else            icon = UIManager.getIcon("Tree.closedIcon");                    if (tcr instanceof DefaultTreeCellRenderer)            {             Icon tmp = ((DefaultTreeCellRenderer) tcr).getIcon();             if (tmp != null)               icon = tmp;            }                    // add gap*2 for the space before and after the text          if (icon != null)            bounds.width += icon.getIconWidth() + gap * 2;          boolean inBounds = bounds.contains(click.x, click.y);          if ((inBounds || cntlClick) && tree.isVisible(path))            {              if (inBounds)                {                  TreePath currentLead = tree.getLeadSelectionPath();                  if (currentLead != null && currentLead.equals(path)                      && e.getClickCount() == 1 && tree.isEditable())                    {                      // Schedule the editing session.                      final TreePath editPath = path;                                            if (startEditTimer != null)                        startEditTimer.stop();                                              startEditTimer = new Timer(WAIT_TILL_EDITING,                         new ActionListener()                           {                            public void actionPerformed(ActionEvent e)                            {                                startEditing(editPath, EDIT);                            }                          });                       startEditTimer.setRepeats(false);                       startEditTimer.start();                    }                  else                    {                      if (e.getClickCount() == 2 && ! isLeaf(row))                  toggleExpandState(path);                      else                        selectPathForEvent(path, e);                }                }                            if (cntlClick)                {                  handleExpandControlClick(path, click.x, click.y);                  if (cellEditor != null)                    cellEditor.cancelCellEditing();                  tree.scrollPathToVisible(path);                }              else if (tree.isEditable())                startEditing(path, e);            }        }    }