/[classpath]/classpath/javax/swing/plaf/basic/BasicTreeUI.java
ViewVC logotype

Diff of /classpath/javax/swing/plaf/basic/BasicTreeUI.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.76 by fitzsim, Fri Sep 9 21:34:36 2005 UTC revision 1.77 by langel, Wed Sep 14 19:06:02 2005 UTC
# Line 44  import java.awt.Dimension; Line 44  import java.awt.Dimension;
44  import java.awt.Font;  import java.awt.Font;
45  import java.awt.FontMetrics;  import java.awt.FontMetrics;
46  import java.awt.Graphics;  import java.awt.Graphics;
47    import java.awt.Insets;
48  import java.awt.Point;  import java.awt.Point;
49  import java.awt.Rectangle;  import java.awt.Rectangle;
50  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
# Line 62  import java.awt.event.MouseListener; Line 63  import java.awt.event.MouseListener;
63  import java.awt.event.MouseMotionListener;  import java.awt.event.MouseMotionListener;
64  import java.beans.PropertyChangeEvent;  import java.beans.PropertyChangeEvent;
65  import java.beans.PropertyChangeListener;  import java.beans.PropertyChangeListener;
66    import java.util.Enumeration;
67  import java.util.Hashtable;  import java.util.Hashtable;
68    
69  import javax.swing.AbstractAction;  import javax.swing.AbstractAction;
# Line 96  import javax.swing.text.Caret; Line 98  import javax.swing.text.Caret;
98  import javax.swing.tree.AbstractLayoutCache;  import javax.swing.tree.AbstractLayoutCache;
99  import javax.swing.tree.DefaultTreeCellEditor;  import javax.swing.tree.DefaultTreeCellEditor;
100  import javax.swing.tree.DefaultTreeCellRenderer;  import javax.swing.tree.DefaultTreeCellRenderer;
 import javax.swing.tree.ExpandVetoException;  
101  import javax.swing.tree.FixedHeightLayoutCache;  import javax.swing.tree.FixedHeightLayoutCache;
102  import javax.swing.tree.TreeCellEditor;  import javax.swing.tree.TreeCellEditor;
103  import javax.swing.tree.TreeCellRenderer;  import javax.swing.tree.TreeCellRenderer;
# Line 174  public class BasicTreeUI Line 175  public class BasicTreeUI
175    
176    /** Size needed to completely display all the nodes. */    /** Size needed to completely display all the nodes. */
177    protected Dimension preferredSize;    protected Dimension preferredSize;
178      
179      /** Minimum size needed to completely display all the nodes. */
180      protected Dimension preferredMinSize;
181    
182    /** Is the preferredSize valid? */    /** Is the preferredSize valid? */
183    protected boolean validCachedPreferredSize;    protected boolean validCachedPreferredSize;
# Line 225  public class BasicTreeUI Line 229  public class BasicTreeUI
229    protected boolean editorHasDifferentSize;    protected boolean editorHasDifferentSize;
230    
231    /** The action listener for the editor's Timer. */    /** The action listener for the editor's Timer. */
232    private Timer editorTimer = new EditorUpdateTimer();    Timer editorTimer = new EditorUpdateTimer();
233    
234    /** The new value of the node after editing. */    /** The new value of the node after editing. */
235    private Object newVal;    Object newVal;
236    
237    /** The action bound to KeyStrokes. */    /** The action bound to KeyStrokes. */
238    private TreeAction action;    TreeAction action;
239        
240    /** Boolean to keep track of editing. */    /** Boolean to keep track of editing. */
241    private boolean isEditing;    boolean isEditing;
242      
243      /** The bounds of the current cell. */
244      Rectangle bounds;
245    
246    /** Listeners */    /** Listeners */
247    private PropertyChangeListener propertyChangeListener;    private PropertyChangeListener propertyChangeListener;
   
248    private FocusListener focusListener;    private FocusListener focusListener;
   
249    private TreeSelectionListener treeSelectionListener;    private TreeSelectionListener treeSelectionListener;
   
250    private MouseInputListener mouseInputListener;    private MouseInputListener mouseInputListener;
   
251    private KeyListener keyListener;    private KeyListener keyListener;
   
252    private PropertyChangeListener selectionModelPropertyChangeListener;    private PropertyChangeListener selectionModelPropertyChangeListener;
   
253    private ComponentListener componentListener;    private ComponentListener componentListener;
   
254    private CellEditorListener cellEditorListener;    private CellEditorListener cellEditorListener;
   
255    private TreeExpansionListener treeExpansionListener;    private TreeExpansionListener treeExpansionListener;
   
256    private TreeModelListener treeModelListener;    private TreeModelListener treeModelListener;
257    
258    /**    /**
# Line 456  public class BasicTreeUI Line 454  public class BasicTreeUI
454    protected void setCellRenderer(TreeCellRenderer tcr)    protected void setCellRenderer(TreeCellRenderer tcr)
455    {    {
456      currentCellRenderer = tcr;      currentCellRenderer = tcr;
     tree.setCellRenderer(tcr);  
457      updateRenderer();      updateRenderer();
458    }    }
459    
# Line 625  public class BasicTreeUI Line 622  public class BasicTreeUI
622        {        {
623          Object cell = path.getLastPathComponent();          Object cell = path.getLastPathComponent();
624    
625          TreeModel mod = tree.getModel();          if (treeModel != null)
         if (mod != null)  
626            {            {
627              Object root = mod.getRoot();              Object root = treeModel.getRoot();
628              if (!tree.isRootVisible() && tree.isExpanded(new TreePath(root)))              if (!tree.isRootVisible() && tree.isExpanded(new TreePath(root)))
629                root = getNextNode(root);                root = getNextNode(root);
630    
631              Point loc = getCellLocation(0, 0, tree, mod, cell, root);              Point loc = getCellLocation(0, 0, tree, treeModel, cell, root);
632              return getCellBounds(loc.x, loc.y, cell);              return getCellBounds(loc.x, loc.y, cell);
633            }            }
634        }        }
# Line 650  public class BasicTreeUI Line 646  public class BasicTreeUI
646     */     */
647    public TreePath getPathForRow(JTree tree, int row)    public TreePath getPathForRow(JTree tree, int row)
648    {    {
649      TreeModel mod = tree.getModel();      if (treeModel != null)
     if (mod != null)  
650        {        {
651          Object node = mod.getRoot();          Object node = treeModel.getRoot();
652          if (!tree.isRootVisible()          if (!tree.isRootVisible()
653              && tree.isExpanded(new TreePath(getPathToRoot(node, 0))))              && tree.isExpanded(new TreePath(getPathToRoot(node, 0))))
654            node = getNextNode(node);            node = getNextNode(node);
# Line 705  public class BasicTreeUI Line 700  public class BasicTreeUI
700     */     */
701    public int getRowCount(JTree tree)    public int getRowCount(JTree tree)
702    {    {
     TreeModel mod = tree.getModel();  
703      int count = 0;      int count = 0;
704      if (mod != null)      if (treeModel != null)
705        {        {
706          Object node = mod.getRoot();          Object node = treeModel.getRoot();
707          if (!tree.isRootVisible()          if (!tree.isRootVisible()
708              && tree.isExpanded(new TreePath((getPathToRoot(node, 0)))))              && tree.isExpanded(new TreePath((getPathToRoot(node, 0)))))
709            node = getNextNode(node);            node = getNextNode(node);
# Line 828  public class BasicTreeUI Line 822  public class BasicTreeUI
822     */     */
823    protected void prepareForUIInstall()    protected void prepareForUIInstall()
824    {    {
     // FIXME: not implemented  
825    }    }
826    
827    /**    /**
# Line 837  public class BasicTreeUI Line 830  public class BasicTreeUI
830     */     */
831    protected void completeUIInstall()    protected void completeUIInstall()
832    {    {
     // FIXME: not implemented  
833    }    }
834    
835    /**    /**
# Line 846  public class BasicTreeUI Line 838  public class BasicTreeUI
838     */     */
839    protected void completeUIUninstall()    protected void completeUIUninstall()
840    {    {
     // FIXME: not implemented  
841    }    }
842    
843    /**    /**
# Line 854  public class BasicTreeUI Line 845  public class BasicTreeUI
845     */     */
846    protected void installComponents()    protected void installComponents()
847    {    {
848      // FIXME: not implemented      currentCellRenderer = createDefaultCellRenderer();
849        rendererPane = createCellRendererPane();
850        createdRenderer = true;
851        setCellRenderer(currentCellRenderer);
852    }    }
853    
854    /**    /**
# Line 865  public class BasicTreeUI Line 859  public class BasicTreeUI
859     */     */
860    protected AbstractLayoutCache.NodeDimensions createNodeDimensions()    protected AbstractLayoutCache.NodeDimensions createNodeDimensions()
861    {    {
862      // FIXME: not implemented      return new NodeDimensionsHandler();
     return null;  
863    }    }
864    
865    /**    /**
# Line 1044  public class BasicTreeUI Line 1037  public class BasicTreeUI
1037      TreeCellEditor tce = tree.getCellEditor();      TreeCellEditor tce = tree.getCellEditor();
1038      if (tce != null)      if (tce != null)
1039        tce.removeCellEditorListener(cellEditorListener);        tce.removeCellEditorListener(cellEditorListener);
1040      TreeModel tm = tree.getModel();      if (treeModel != null)
1041      if (tm != null)        treeModel.removeTreeModelListener(treeModelListener);
       tm.removeTreeModelListener(treeModelListener);  
1042    }    }
1043    
1044    /**    /**
# Line 1061  public class BasicTreeUI Line 1053  public class BasicTreeUI
1053     */     */
1054    protected void uninstallComponents()    protected void uninstallComponents()
1055    {    {
1056      // FIXME: not implemented      currentCellRenderer = null;
1057        rendererPane = null;
1058        createdRenderer = false;
1059        setCellRenderer(currentCellRenderer);
1060    }    }
1061    
1062    /**    /**
# Line 1072  public class BasicTreeUI Line 1067  public class BasicTreeUI
1067     */     */
1068    protected int getVerticalLegBuffer()    protected int getVerticalLegBuffer()
1069    {    {
1070      // FIXME: not implemented      return getRowHeight() / 2;
     return 0;  
1071    }    }
1072    
1073    /**    /**
# Line 1085  public class BasicTreeUI Line 1079  public class BasicTreeUI
1079     */     */
1080    protected int getHorizontalLegBuffer()    protected int getHorizontalLegBuffer()
1081    {    {
1082      // FIXME: not implemented      return rightChildIndent / 2;
     return 0;  
1083    }    }
1084    
1085    /**    /**
1086     * Make all the nodes that are expanded in JTree expanded in LayoutCache. This     * Make all the nodes that are expanded in JTree expanded in LayoutCache. This
1087     * invokes update ExpandedDescendants with the root path.     * invokes updateExpandedDescendants with the root path.
1088     */     */
1089    protected void updateLayoutCacheExpandedNodes()    protected void updateLayoutCacheExpandedNodes()
1090    {    {
1091      // FIXME: not implemented      if (treeModel != null)
1092          updateExpandedDescendants(new TreePath(getPathToRoot(treeModel.
1093                                                               getRoot(), 0)));
1094    }    }
1095    
1096    /**    /**
# Line 1108  public class BasicTreeUI Line 1103  public class BasicTreeUI
1103     */     */
1104    protected void updateExpandedDescendants(TreePath path)    protected void updateExpandedDescendants(TreePath path)
1105    {    {
1106      // FIXME: not implemented      Enumeration expanded = tree.getExpandedDescendants(path);
1107        while (expanded.hasMoreElements())
1108          treeState.setExpandedState(((TreePath) expanded.nextElement()), true);
1109    }    }
1110    
1111    /**    /**
# Line 1128  public class BasicTreeUI Line 1125  public class BasicTreeUI
1125     */     */
1126    protected void updateDepthOffset()    protected void updateDepthOffset()
1127    {    {
1128      // FIXME: not implemented      depthOffset += getVerticalLegBuffer();
1129    }    }
1130    
1131    /**    /**
# Line 1148  public class BasicTreeUI Line 1145  public class BasicTreeUI
1145     */     */
1146    protected void updateRenderer()    protected void updateRenderer()
1147    {    {
1148      // FIXME: not implemented      if (tree != null)
1149          tree.setCellRenderer(currentCellRenderer);
1150    }    }
1151    
1152    /**    /**
# Line 1166  public class BasicTreeUI Line 1164  public class BasicTreeUI
1164     */     */
1165    protected void updateSize()    protected void updateSize()
1166    {    {
1167      // FIXME: not implemented      preferredSize = null;
1168        updateCachedPreferredSize();
1169        tree.treeDidChange();
1170    }    }
1171    
1172    /**    /**
# Line 1219  public class BasicTreeUI Line 1219  public class BasicTreeUI
1219      leftChildIndent = defaults.getInt("Tree.leftChildIndent");      leftChildIndent = defaults.getInt("Tree.leftChildIndent");
1220      setRowHeight(defaults.getInt("Tree.rowHeight"));      setRowHeight(defaults.getInt("Tree.rowHeight"));
1221      tree.requestFocusInWindow(false);      tree.requestFocusInWindow(false);
1222        tree.setScrollsOnExpand(defaults.getBoolean("Tree.scrollsOnExpand"));
1223        setExpandedIcon(defaults.getIcon("Tree.expandedIcon"));
1224        setCollapsedIcon(defaults.getIcon("Tree.collapsedIcon"));
1225    }    }
1226    
1227    /**    /**
# Line 1329  public class BasicTreeUI Line 1332  public class BasicTreeUI
1332      tree = (JTree) c;      tree = (JTree) c;
1333      installDefaults();      installDefaults();
1334    
1335      currentCellRenderer = createDefaultCellRenderer();      installComponents();
     rendererPane = createCellRendererPane();  
     createdRenderer = true;  
1336    
1337      setCellEditor(createDefaultCellEditor());      setCellEditor(createDefaultCellEditor());
1338      createdCellEditor = true;      createdCellEditor = true;
# Line 1374  public class BasicTreeUI Line 1375  public class BasicTreeUI
1375      uninstallKeyboardActions();      uninstallKeyboardActions();
1376      uninstallListeners();      uninstallListeners();
1377      tree = null;      tree = null;
1378        uninstallComponents();
1379      completeUIUninstall();      completeUIUninstall();
1380    }    }
1381    
# Line 1394  public class BasicTreeUI Line 1396  public class BasicTreeUI
1396    {    {
1397      JTree tree = (JTree) c;      JTree tree = (JTree) c;
1398    
1399      TreeModel mod = tree.getModel();      if (treeModel != null)
   
     if (mod != null)  
1400        {        {
1401          Object root = mod.getRoot();          Object root = treeModel.getRoot();
1402    
1403          if (!tree.isRootVisible())          if (!tree.isRootVisible())
1404            tree.expandPath(new TreePath(root));            tree.expandPath(new TreePath(root));
1405    
1406          paintRecursive(g, 0, 0, 0, 0, tree, mod, root);          paintRecursive(g, 0, 0, 0, 0, tree, treeModel, root);
1407    
1408          if (hasControlIcons())          if (hasControlIcons())
1409            paintControlIcons(g, 0, 0, 0, 0, tree, mod, root);            paintControlIcons(g, 0, 0, 0, 0, tree, treeModel, root);
1410        }        }
1411    }    }
1412    
# Line 1420  public class BasicTreeUI Line 1420  public class BasicTreeUI
1420     */     */
1421    protected void ensureRowsAreVisible(int beginRow, int endRow)    protected void ensureRowsAreVisible(int beginRow, int endRow)
1422    {    {
1423      // FIXME: not implemented      if (beginRow < endRow)
1424          {
1425            int temp = endRow;
1426            endRow = beginRow;
1427            beginRow = temp;
1428          }
1429        
1430        for (int i = beginRow; i < endRow; i++)
1431          {
1432            TreePath path = getPathForRow(tree, i);
1433            if (!tree.isVisible(path))
1434              tree.makeVisible(path);
1435          }
1436    }    }
1437    
1438    /**    /**
# Line 1473  public class BasicTreeUI Line 1485  public class BasicTreeUI
1485    public Dimension getPreferredSize(JComponent c, boolean checkConsistancy)    public Dimension getPreferredSize(JComponent c, boolean checkConsistancy)
1486    {    {
1487      // FIXME: checkConsistancy not implemented, c not used      // FIXME: checkConsistancy not implemented, c not used
     TreeModel model = tree.getModel();  
1488      int maxWidth = 0;      int maxWidth = 0;
1489      int count = 0;      int count = 0;
1490      if (model != null)      if (treeModel != null)
1491        {        {
1492          Object node = model.getRoot();          Object node = treeModel.getRoot();
1493          if (node != null)          if (node != null)
1494            {            {
1495              maxWidth = (int) (getCellBounds(0, 0, node).getWidth());              maxWidth = (int) (getCellBounds(0, 0, node).getWidth());
# Line 1506  public class BasicTreeUI Line 1517  public class BasicTreeUI
1517     */     */
1518    public Dimension getMinimumSize(JComponent c)    public Dimension getMinimumSize(JComponent c)
1519    {    {
1520      // FIXME: not implemented      Dimension min = getPreferredMinSize();
1521      return getPreferredSize(c);      if (min == null)
1522          return new Dimension();
1523        return min;
1524    }    }
1525    
1526    /**    /**
# Line 1520  public class BasicTreeUI Line 1533  public class BasicTreeUI
1533     */     */
1534    public Dimension getMaximumSize(JComponent c)    public Dimension getMaximumSize(JComponent c)
1535    {    {
1536      // FIXME: not implemented      if (c instanceof JTree)
1537      return getPreferredSize(c);        return ((JTree) c).getPreferredSize();
1538        return new Dimension();
1539    }    }
1540    
1541    /**    /**
# Line 1565  public class BasicTreeUI Line 1579  public class BasicTreeUI
1579        }        }
1580    
1581      if (messageTree)      if (messageTree)
1582        tree.getModel().valueForPathChanged(tree.getLeadSelectionPath(), newVal);        treeModel.valueForPathChanged(tree.getLeadSelectionPath(), newVal);
1583    }    }
1584    
1585    /**    /**
# Line 1634  public class BasicTreeUI Line 1648  public class BasicTreeUI
1648    protected void checkForClickInExpandControl(TreePath path, int mouseX,    protected void checkForClickInExpandControl(TreePath path, int mouseX,
1649                                                int mouseY)                                                int mouseY)
1650    {    {
1651      // FIXME: not implemented      if (isLocationInExpandControl(path, mouseX, mouseY))
1652          toggleExpandState(path);
1653    }    }
1654    
1655    /**    /**
# Line 1655  public class BasicTreeUI Line 1670  public class BasicTreeUI
1670    protected boolean isLocationInExpandControl(TreePath path, int mouseX,    protected boolean isLocationInExpandControl(TreePath path, int mouseX,
1671                                                int mouseY)                                                int mouseY)
1672    {    {
1673      // FIXME: not implemented      boolean cntlClick = false;
1674      return false;      int row = getRowForPath(tree, path);
1675        if (!isLeaf(row))
1676          {
1677            if (bounds == null)
1678              bounds = getPathBounds(tree, path);
1679            if (tree.isExpanded(path) && expandedIcon != null)
1680                bounds.x -= expandedIcon.getIconWidth() - 4;
1681            else if (collapsedIcon != null)
1682                bounds.x -= collapsedIcon.getIconWidth() - 4;
1683    
1684            Icon controlIcon = getCurrentControlIcon(path);
1685            if (controlIcon != null && (mouseX < bounds.x)
1686                && (mouseX > (bounds.x - controlIcon.getIconWidth())))
1687              cntlClick = true;
1688          }
1689        return cntlClick;
1690    }    }
1691    
1692    /**    /**
# Line 1672  public class BasicTreeUI Line 1702  public class BasicTreeUI
1702     */     */
1703    protected void handleExpandControlClick(TreePath path, int mouseX, int mouseY)    protected void handleExpandControlClick(TreePath path, int mouseX, int mouseY)
1704    {    {
1705      // FIXME: not implemented      toggleExpandState(path);
1706    }    }
1707    
1708    /**    /**
# Line 1686  public class BasicTreeUI Line 1716  public class BasicTreeUI
1716     */     */
1717    protected void toggleExpandState(TreePath path)    protected void toggleExpandState(TreePath path)
1718    {    {
1719      // FIXME: not implemented      if (tree.isExpanded(path))
1720          tree.collapsePath(path);
1721        else
1722          tree.expandPath(path);
1723    }    }
1724    
1725    /**    /**
# Line 1700  public class BasicTreeUI Line 1733  public class BasicTreeUI
1733     */     */
1734    protected boolean isToggleSelectionEvent(MouseEvent event)    protected boolean isToggleSelectionEvent(MouseEvent event)
1735    {    {
1736      // FIXME: not implemented      return (tree.getSelectionModel().getSelectionMode() ==
1737      return false;        TreeSelectionModel.SINGLE_TREE_SELECTION);
1738    }    }
1739    
1740    /**    /**
# Line 1715  public class BasicTreeUI Line 1748  public class BasicTreeUI
1748     */     */
1749    protected boolean isMultiSelectEvent(MouseEvent event)    protected boolean isMultiSelectEvent(MouseEvent event)
1750    {    {
1751      // FIXME: not implemented      return (tree.getSelectionModel().getSelectionMode() ==
1752      return false;        TreeSelectionModel.CONTIGUOUS_TREE_SELECTION);
1753    }    }
1754    
1755    /**    /**
# Line 1731  public class BasicTreeUI Line 1764  public class BasicTreeUI
1764     */     */
1765    protected boolean isToggleEvent(MouseEvent event)    protected boolean isToggleEvent(MouseEvent event)
1766    {    {
1767      // FIXME: not implemented      return true;
     return false;  
1768    }    }
1769    
1770    /**    /**
# Line 1749  public class BasicTreeUI Line 1781  public class BasicTreeUI
1781     */     */
1782    protected void selectPathForEvent(TreePath path, MouseEvent event)    protected void selectPathForEvent(TreePath path, MouseEvent event)
1783    {    {
1784      // FIXME: not implemented      if (isToggleSelectionEvent(event))
1785          {
1786            if (tree.isPathSelected(path))
1787              tree.removeSelectionPath(path);
1788            else
1789              {
1790                tree.addSelectionPath(path);
1791                tree.setAnchorSelectionPath(path);
1792              }
1793          }
1794        else if (isMultiSelectEvent(event))
1795          {
1796            TreePath anchor = tree.getAnchorSelectionPath();
1797            if (anchor != null)
1798              {
1799                int aRow = getRowForPath(tree, anchor);
1800                tree.addSelectionInterval(aRow, getRowForPath(tree, path));
1801              }
1802            else
1803              tree.addSelectionPath(path);
1804          }
1805        else
1806          tree.addSelectionPath(path);
1807    }    }
1808    
1809    /**    /**
# Line 1766  public class BasicTreeUI Line 1820  public class BasicTreeUI
1820        return true;        return true;
1821    
1822      Object node = pathForRow.getLastPathComponent();      Object node = pathForRow.getLastPathComponent();
1823      return tree.getModel().isLeaf(node);      return treeModel.isLeaf(node);
1824    }    }
1825    
1826    /**    /**
# Line 1802  public class BasicTreeUI Line 1856  public class BasicTreeUI
1856          {          {
1857            TreePath[] paths = new TreePath[tree.getRowCount()];            TreePath[] paths = new TreePath[tree.getRowCount()];
1858    
1859            Object curr = getNextVisibleNode(tree.getModel().getRoot());            Object curr = getNextVisibleNode(treeModel.getRoot());
1860            int i = 0;            int i = 0;
1861            while (curr != null && i < paths.length)            while (curr != null && i < paths.length)
1862              {              {
# Line 1822  public class BasicTreeUI Line 1876  public class BasicTreeUI
1876              {              {
1877                Object last = lead.getLastPathComponent();                Object last = lead.getLastPathComponent();
1878                TreePath path = new TreePath(getPathToRoot(last, 0));                TreePath path = new TreePath(getPathToRoot(last, 0));
1879                if (!tree.getModel().isLeaf(last))                if (!treeModel.isLeaf(last))
1880                  {                  toggleExpandState(path);
                   if (tree.isExpanded(path))  
                     tree.collapsePath(path);  
                   else  
                     tree.expandPath(path);  
                 }  
1881              }              }
1882          }          }
1883        else if (e.getActionCommand().equals("clearSelection"))        else if (e.getActionCommand().equals("clearSelection"))
# Line 2259  public class BasicTreeUI Line 2308  public class BasicTreeUI
2308    
2309        if (path != null)        if (path != null)
2310          {          {
2311            boolean inBounds = false;            bounds = getPathBounds(tree, path);
2312            boolean cntlClick = false;            boolean cntlClick = isLocationInExpandControl(path, click.x, click.y);
2313            Rectangle bounds = getPathBounds(tree, path);            
2314              if (tree.isExpanded(path) && expandedIcon != null)
2315            bounds.x -= rightChildIndent - 4;              {
2316            bounds.width += rightChildIndent + 4;                bounds.x -= expandedIcon.getIconWidth() - 4;
2317                  bounds.width += expandedIcon.getIconWidth() + 4;
2318            if (bounds.contains(click.x, click.y))              }
2319              inBounds = true;            else if (collapsedIcon != null)
2320            else if (hasControlIcons()              {
2321                     && (click.x < (bounds.x - rightChildIndent + 5) &&                bounds.x -= collapsedIcon.getIconWidth() - 4;
2322                         click.x > (bounds.x - rightChildIndent - 5)))                bounds.width += collapsedIcon.getIconWidth() + 4;
2323              cntlClick = true;              }
2324              
2325              boolean inBounds = bounds.contains(click.x, click.y);
2326            if ((inBounds || cntlClick) && tree.isVisible(path))            if ((inBounds || cntlClick) && tree.isVisible(path))
2327              {              {
2328                selectPath(tree, path);                selectPath(tree, path);
2329                  if (inBounds && e.getClickCount() == 2 && !isLeaf(row))
2330                if ((e.getClickCount() == 2 || cntlClick) && !isLeaf(row))                    toggleExpandState(path);
2331                  {                
2332                    if (tree.isExpanded(path))                if (cntlClick)
2333                      tree.collapsePath(path);                  handleExpandControlClick(path, click.x, click.y);
2334                    else                else if (tree.isEditable())
                     tree.expandPath(path);  
                 }  
   
               if (!cntlClick && tree.isEditable())  
2335                  startEditing(path, e);                  startEditing(path, e);
2336              }              }
2337          }          }
# Line 2464  public class BasicTreeUI Line 2510  public class BasicTreeUI
2510      /**      /**
2511       * Constructor       * Constructor
2512       */       */
2513      public TreeCancelEditingAction()      public TreeCancelEditingAction(String name)
2514      {      {
2515      }      }
2516    
# Line 2890  public class BasicTreeUI Line 2936  public class BasicTreeUI
2936       */       */
2937      public void actionPerformed(ActionEvent e)      public void actionPerformed(ActionEvent e)
2938      {      {
       TreeModel mod = tree.getModel();  
2939        Object last = tree.getLeadSelectionPath().getLastPathComponent();        Object last = tree.getLeadSelectionPath().getLastPathComponent();
2940    
2941        if (e.getActionCommand().equals("selectParent"))        if (e.getActionCommand().equals("selectParent"))
2942          {          {
2943            TreePath path = new TreePath(getPathToRoot(last, 0));            TreePath path = new TreePath(getPathToRoot(last, 0));
2944            Object p = getParent(mod.getRoot(), last);            Object p = getParent(treeModel.getRoot(), last);
2945    
2946            if (!mod.isLeaf(last) && tree.isExpanded(path))            if (!treeModel.isLeaf(last) && tree.isExpanded(path))
2947              tree.collapsePath(path);              tree.collapsePath(path);
2948            else if (p != null)            else if (p != null)
2949              selectPath(tree, new TreePath(getPathToRoot(p, 0)));              selectPath(tree, new TreePath(getPathToRoot(p, 0)));
# Line 2907  public class BasicTreeUI Line 2952  public class BasicTreeUI
2952          {          {
2953            TreePath path = new TreePath(getPathToRoot(last, 0));            TreePath path = new TreePath(getPathToRoot(last, 0));
2954    
2955            if (!mod.isLeaf(last) && tree.isCollapsed(path))            if (!treeModel.isLeaf(last) && tree.isCollapsed(path))
2956              tree.expandPath(path);              tree.expandPath(path);
2957            else            else
2958              {              {
# Line 3120  public class BasicTreeUI Line 3165  public class BasicTreeUI
3165                    {                    {
3166                      g.setColor(getHashColor());                      g.setColor(getHashColor());
3167                      heightOfLine = descent + halfHeight;                      heightOfLine = descent + halfHeight;
3168                      g.drawLine(indentation + halfWidth, heightOfLine,                      paintHorizontalLine(g, (JComponent) tree, heightOfLine,
3169                                 indentation + rightChildIndent, heightOfLine);                        indentation + halfWidth, indentation + rightChildIndent);
3170                    }                    }
3171    
3172                  descent = paintRecursive(g, indent, descent, i, depth + 1,                  descent = paintRecursive(g, indent, descent, i, depth + 1,
# Line 3135  public class BasicTreeUI Line 3180  public class BasicTreeUI
3180            && mod.getChildCount(curr) > 0)            && mod.getChildCount(curr) > 0)
3181          {          {
3182            g.setColor(getHashColor());            g.setColor(getHashColor());
3183            g.drawLine(indentation + halfWidth, y0, indentation + halfWidth,            paintVerticalLine(g, (JComponent) tree, indentation + halfWidth,
3184                       heightOfLine);                              y0, heightOfLine);
3185          }          }
3186    
3187      return descent;      return descent;
# Line 3170  public class BasicTreeUI Line 3215  public class BasicTreeUI
3215    {    {
3216      int h = descent;      int h = descent;
3217      int rowHeight = getRowHeight();      int rowHeight = getRowHeight();
3218      Icon ei = UIManager.getLookAndFeelDefaults().getIcon("Tree.expandedIcon");      TreePath path = new TreePath(getPathToRoot(node, 0));
3219      Icon ci = UIManager.getLookAndFeelDefaults().getIcon("Tree.collapsedIcon");      Icon icon = getCurrentControlIcon(path);
3220        
3221      Rectangle clip = g.getClipBounds();      Rectangle clip = g.getClipBounds();
3222      if (indentation > clip.x + clip.width + rightChildIndent      if (indentation > clip.x + clip.width + rightChildIndent
3223          || descent > clip.y + clip.height + getRowHeight())          || descent > clip.y + clip.height + getRowHeight())
# Line 3187  public class BasicTreeUI Line 3233  public class BasicTreeUI
3233          int max = 0;          int max = 0;
3234          if (!mod.isLeaf(node))          if (!mod.isLeaf(node))
3235            max = mod.getChildCount(node);            max = mod.getChildCount(node);
         if (tree.isExpanded(new TreePath(getPathToRoot(node, 0))))  
           {  
             if (!node.equals(mod.getRoot()))  
               ei.paintIcon(tree, g, indentation - rightChildIndent - 3, h);  
3236    
3237            if (!node.equals(mod.getRoot()))
3238              icon.paintIcon(tree, g, indentation - rightChildIndent - 3, h);
3239            
3240            if (tree.isExpanded(path))
3241              {
3242              for (int i = 0; i < max; i++)              for (int i = 0; i < max; i++)
3243                {                {
3244                  int indent = indentation + rightChildIndent;                  int indent = indentation + rightChildIndent;
# Line 3202  public class BasicTreeUI Line 3249  public class BasicTreeUI
3249                                              tree, mod, mod.getChild(node, i));                                              tree, mod, mod.getChild(node, i));
3250                }                }
3251            }            }
         else if (!node.equals(mod.getRoot()))  
           ci.paintIcon(tree, g, indentation - rightChildIndent - 3,  
                        descent - getRowHeight());  
3252        }        }
3253    
3254      return descent;      return descent;
3255    }    }
3256    
3257    /**    /**
3258     * Returns true if the LookAndFeel implements the control icons Package     * Returns control icon. It is null if the LookAndFeel does not
3259     * private for use in inner classes.     * implements the control icons.
3260       * Package private for use in inner classes.
3261       *
3262       * @return control icon if it exists.
3263       */
3264      Icon getCurrentControlIcon(TreePath path)
3265      {
3266        if (tree.isExpanded(path))
3267          return UIManager.getLookAndFeelDefaults().getIcon("Tree.expandedIcon");
3268        return UIManager.getLookAndFeelDefaults().getIcon("Tree.collapsedIcon");
3269      }
3270      
3271      /**
3272       * Returns true if the LookAndFeel implements the control icons.
3273       * Package private for use in inner classes.
3274     *     *
3275     * @return true if control icons are visible     * @returns true if there are control icons
3276     */     */
3277    boolean hasControlIcons()    boolean hasControlIcons()
3278    {    {
3279      if (UIManager.getLookAndFeelDefaults().getIcon("Tree.expandedIcon") == null      if (UIManager.getLookAndFeelDefaults().getIcon("Tree.expandedIcon") != null
3280          || UIManager.getLookAndFeelDefaults().getIcon("Tree.collapsedIcon") == null)          || UIManager.getLookAndFeelDefaults().getIcon("Tree.collapsedIcon")
3281        return false;          != null)
3282      return true;        return true;
3283        return false;
3284    }    }
3285    
3286    /**    /**
# Line 3253  public class BasicTreeUI Line 3312  public class BasicTreeUI
3312     */     */
3313    private Object findNode(Object root, Object node)    private Object findNode(Object root, Object node)
3314    {    {
     TreeModel mod = tree.getModel();  
3315      int size = 0;      int size = 0;
3316      if (!mod.isLeaf(root))      if (!treeModel.isLeaf(root))
3317        size = mod.getChildCount(root);        size = treeModel.getChildCount(root);
3318      for (int i = 0; i < size; i++)      for (int i = 0; i < size; i++)
3319        {        {
3320          if (mod.getIndexOfChild(root, node) != -1)          if (treeModel.getIndexOfChild(root, node) != -1)
3321            return root;            return root;
3322    
3323          Object n = findNode(mod.getChild(root, i), node);          Object n = findNode(treeModel.getChild(root, i), node);
3324          if (n != null)          if (n != null)
3325            return n;            return n;
3326        }        }
# Line 3346  public class BasicTreeUI Line 3404  public class BasicTreeUI
3404     */     */
3405    Object getNextNode(Object curr)    Object getNextNode(Object curr)
3406    {    {
3407      TreeModel mod = tree.getModel();      if (!treeModel.isLeaf(curr) && treeModel.getChildCount(curr) > 0)
3408      if (!mod.isLeaf(curr) && mod.getChildCount(curr) > 0)        return treeModel.getChild(curr, 0);
       return mod.getChild(curr, 0);  
3409    
3410      Object node = curr;      Object node = curr;
3411      Object sibling = null;      Object sibling = null;
# Line 3356  public class BasicTreeUI Line 3413  public class BasicTreeUI
3413      do      do
3414        {        {
3415          sibling = getNextSibling(node);          sibling = getNextSibling(node);
3416          node = getParent(mod.getRoot(), node);          node = getParent(treeModel.getRoot(), node);
3417        }        }
3418      while (sibling == null && node != null);      while (sibling == null && node != null);
3419    
# Line 3373  public class BasicTreeUI Line 3430  public class BasicTreeUI
3430     */     */
3431    Object getPreviousNode(Object node)    Object getPreviousNode(Object node)
3432    {    {
3433      TreeModel mod = tree.getModel();      Object parent = getParent(treeModel.getRoot(), node);
     Object parent = getParent(mod.getRoot(), node);  
3434      if (parent == null)      if (parent == null)
3435        return null;        return null;
3436    
# Line 3384  public class BasicTreeUI Line 3440  public class BasicTreeUI
3440        return parent;        return parent;
3441    
3442      int size = 0;      int size = 0;
3443      if (!mod.isLeaf(sibling))      if (!treeModel.isLeaf(sibling))
3444        size = mod.getChildCount(sibling);        size = treeModel.getChildCount(sibling);
3445      while (size > 0)      while (size > 0)
3446        {        {
3447          sibling = mod.getChild(sibling, size - 1);          sibling = treeModel.getChild(sibling, size - 1);
3448          if (!mod.isLeaf(sibling))          if (!treeModel.isLeaf(sibling))
3449            size = mod.getChildCount(sibling);            size = treeModel.getChildCount(sibling);
3450          else          else
3451            size = 0;            size = 0;
3452        }        }
# Line 3408  public class BasicTreeUI Line 3464  public class BasicTreeUI
3464     */     */
3465    Object getNextSibling(Object node)    Object getNextSibling(Object node)
3466    {    {
3467      TreeModel mod = tree.getModel();      Object parent = getParent(treeModel.getRoot(), node);
     Object parent = getParent(mod.getRoot(), node);  
3468      if (parent == null)      if (parent == null)
3469        return null;        return null;
3470    
3471      int index = mod.getIndexOfChild(parent, node) + 1;      int index = treeModel.getIndexOfChild(parent, node) + 1;
3472    
3473      int size = 0;      int size = 0;
3474      if (!mod.isLeaf(parent))      if (!treeModel.isLeaf(parent))
3475        size = mod.getChildCount(parent);        size = treeModel.getChildCount(parent);
3476      if (index == 0 || index >= size)      if (index == 0 || index >= size)
3477        return null;        return null;
3478    
3479      return mod.getChild(parent, index);      return treeModel.getChild(parent, index);
3480    }    }
3481    
3482    /**    /**
# Line 3434  public class BasicTreeUI Line 3489  public class BasicTreeUI
3489     */     */
3490    Object getPreviousSibling(Object node)    Object getPreviousSibling(Object node)
3491    {    {
3492      TreeModel mod = tree.getModel();      Object parent = getParent(treeModel.getRoot(), node);
     Object parent = getParent(mod.getRoot(), node);  
3493      if (parent == null)      if (parent == null)
3494        return null;        return null;
3495    
3496      int index = mod.getIndexOfChild(parent, node) - 1;      int index = treeModel.getIndexOfChild(parent, node) - 1;
3497    
3498      int size = 0;      int size = 0;
3499      if (!mod.isLeaf(parent))      if (!treeModel.isLeaf(parent))
3500        size = mod.getChildCount(parent);        size = treeModel.getChildCount(parent);
3501      if (index < 0 || index >= size)      if (index < 0 || index >= size)
3502        return null;        return null;
3503    
3504      return mod.getChild(parent, index);      return treeModel.getChild(parent, index);
3505    }    }
3506    
3507    /**    /**
# Line 3495  public class BasicTreeUI Line 3549  public class BasicTreeUI
3549     */     */
3550    Object[] getPathToRoot(Object node, int depth)    Object[] getPathToRoot(Object node, int depth)
3551    {    {
     TreeModel mod = tree.getModel();  
3552      if (node == null)      if (node == null)
3553        {        {
3554          if (depth == 0)          if (depth == 0)
# Line 3504  public class BasicTreeUI Line 3557  public class BasicTreeUI
3557          return new Object[depth];          return new Object[depth];
3558        }        }
3559    
3560      Object[] path = getPathToRoot(getParent(mod.getRoot(), node), depth + 1);      Object[] path = getPathToRoot(getParent(treeModel.getRoot(), node), depth + 1);
3561      path[path.length - depth - 1] = node;      path[path.length - depth - 1] = node;
3562      return path;      return path;
3563    }    }
# Line 3523  public class BasicTreeUI Line 3576  public class BasicTreeUI
3576    
3577      do      do
3578        {        {
3579          current = getParent(tree.getModel().getRoot(), current);          current = getParent(treeModel.getRoot(), current);
3580          count++;          count++;
3581        }        }
3582      while (current != null);      while (current != null);
# Line 3592  public class BasicTreeUI Line 3645  public class BasicTreeUI
3645      int beginPositionY = y - icon.getIconHeight() / 2;      int beginPositionY = y - icon.getIconHeight() / 2;
3646      icon.paintIcon(c, g, beginPositionX, beginPositionY);      icon.paintIcon(c, g, beginPositionX, beginPositionY);
3647    }    }
3648      
3649      /**
3650       * Draws a dashed horizontal line.
3651       *
3652       * @param g - the graphics configuration.
3653       * @param y - the y location to start drawing at
3654       * @param x1 - the x location to start drawing at
3655       * @param x2 - the x location to finish drawing at
3656       */
3657      protected void drawDashedHorizontalLine(Graphics g, int y, int x1, int x2)
3658      {
3659        for (int i = x1; i < x2; i += 2)
3660          g.drawLine(i, y, i + 1, y);
3661      }
3662      
3663      /**
3664       * Draws a dashed vertical line.
3665       *
3666       * @param g - the graphics configuration.
3667       * @param x - the x location to start drawing at
3668       * @param y1 - the y location to start drawing at
3669       * @param y2 - the y location to finish drawing at
3670       */
3671      protected void drawDashedVerticalLine(Graphics g, int x, int y1, int y2)
3672      {
3673        for (int i = y1; i < y2; i += 2)
3674          g.drawLine(x, i, x, i + 1);
3675      }
3676      
3677      /**
3678       * Paints the expand (toggle) part of a row. The receiver should NOT modify
3679       * clipBounds, or insets.
3680       *
3681       * @param g - the graphics configuration
3682       * @param clipBounds -
3683       * @param insets -
3684       * @param bounds - bounds of expand control
3685       * @param path - path to draw control for
3686       * @param row - row to draw control for
3687       * @param isExpanded - is the row expanded
3688       * @param hasBeenExpanded - has the row already been expanded
3689       * @param isLeaf - is the path a leaf
3690       */
3691      protected void paintExpandControl(Graphics g, Rectangle clipBounds,
3692                                        Insets insets, Rectangle bounds,
3693                                        TreePath path, int row,
3694                                        boolean isExpanded, boolean hasBeenExpanded,
3695                                        boolean isLeaf)
3696      {
3697        if (treeModel != null)
3698          paintControlIcons(g, 0, 0, 0, 0, tree, treeModel, path.getLastPathComponent());
3699      }
3700    
3701      /**
3702       *  Paints the horizontal part of the leg. The receiver should NOT modify
3703       *  clipBounds, or insets.
3704       *  NOTE: parentRow can be -1 if the root is not visible.
3705       *  
3706       * @param g - the graphics configuration
3707       * @param clipBounds -
3708       * @param insets -
3709       * @param bounds - bounds of expand control
3710       * @param path - path to draw control for
3711       * @param row - row to draw control for
3712       * @param isExpanded - is the row expanded
3713       * @param hasBeenExpanded - has the row already been expanded
3714       * @param isLeaf - is the path a leaf
3715       */
3716      protected void paintHorizontalPartOfLeg(Graphics g, Rectangle clipBounds,
3717                                              Insets insets, Rectangle bounds,
3718                                              TreePath path, int row,
3719                                              boolean isExpanded, boolean hasBeenExpanded,
3720                                              boolean isLeaf)
3721      {
3722        // FIXME: not implemented
3723      }
3724      
3725      /**
3726       * Paints the vertical part of the leg. The receiver should NOT modify
3727       * clipBounds, insets.
3728       *
3729       * @param g - the graphics configuration.
3730       * @param clipbounds -
3731       * @param insets -
3732       * @param path - the path to draw the vertical part for.
3733       */
3734      protected void paintVerticalPartOfLeg(Graphics g, Rectangle clipBounds,
3735                                            Insets insets, TreePath path)
3736      {
3737        // FIXME: not implemented
3738      }
3739    
3740      /**
3741       * Paints the renderer part of a row. The receiver should NOT modify clipBounds,
3742       * or insets.
3743       *
3744       * @param g - the graphics configuration
3745       * @param clipBounds -
3746       * @param insets -
3747       * @param bounds - bounds of expand control
3748       * @param path - path to draw control for
3749       * @param row - row to draw control for
3750       * @param isExpanded - is the row expanded
3751       * @param hasBeenExpanded - has the row already been expanded
3752       * @param isLeaf - is the path a leaf
3753       */
3754      protected void paintRow(Graphics g, Rectangle clipBounds,
3755                              Insets insets, Rectangle bounds,
3756                              TreePath path, int row,
3757                              boolean isExpanded, boolean hasBeenExpanded,
3758                              boolean isLeaf)
3759      {
3760        // FIXME: not implemented.
3761      }
3762    
3763      /**
3764       * Prepares for the UI to uninstall.
3765       */
3766      protected void prepareForUIUninstall()
3767      {
3768      }
3769      
3770      /**
3771       * Returns true if the expand (toggle) control should be drawn for the
3772       * specified row.
3773       *
3774       * @param path - current path to check for.
3775       * @param row - current row to check for.
3776       * @param isExpanded - true if the path is expanded
3777       * @param hasBeenExpanded - true if the path has been expanded already
3778       * @param isLeaf - true if the row is a lead
3779       */
3780      protected boolean shouldPaintExpandControl(TreePath path, int row,
3781                                                 boolean isExpanded,
3782                                                 boolean hasBeenExpanded,
3783                                                 boolean isLeaf)
3784      {
3785        // FIXME: not implemented.
3786        return false;
3787      }
3788  } // BasicTreeUI  } // BasicTreeUI

Legend:
Removed from v.1.76  
changed lines
  Added in v.1.77

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26