コード例 #1
0
        private void showJTree(JScrollPane view, Point pt)
        {
            JTree     tree = (JTree)view.Viewport.View;
            Point     p    = SwingUtilities.convertPoint(view, pt.x, pt.y, tree);
            int       row  = tree.getClosestRowForLocation(p.x, p.y);
            TreePath  path = tree.getClosestPathForLocation(p.x, p.y);
            Rectangle bds  = tree.getPathBounds(path);

            if (bds == null || !bds.contains(p))
            {
                hide();
                return;
            }
            if (setCompAndRow(tree, row))
            {
                Rectangle   visible = getShowingRect(view);
                Rectangle[] rects   = getRects(bds, visible);
                if (rects.Length > 0)
                {
                    ensureOldPopupsHidden();
                    painter.configure(path.LastPathComponent, view, tree, path, row);
                    showPopups(rects, bds, visible, tree, view);
                }
                else
                {
                    hide();
                }
            }
        }
コード例 #2
0
        private void showJList(JScrollPane view, Point pt)
        {
            JList list = (JList)view.Viewport.View;
            Point p    = SwingUtilities.convertPoint(view, pt.x, pt.y, list);
            int   row  = list.locationToIndex(p);

            if (row == -1)
            {
                hide();
                return;
            }
            Rectangle bds = list.getCellBounds(row, row);
            //GetCellBounds returns a width that is the
            //full component width;  we want only what
            //the renderer really needs.
            ListCellRenderer ren          = list.CellRenderer;
            Dimension        rendererSize = ren.getListCellRendererComponent(list, list.Model.getElementAt(row), row, false, false).PreferredSize;

            // fix for possible npe spotted by SCO
            // http://pspsharp.org/forum/viewtopic.php?p=3387#p3387
            if (bds == null)
            {
                hide();
                return;
            }

            bds.width = rendererSize.width;

            if (!bds.contains(p))
            {
                hide();
                return;
            }

            //bds.width = rendererSize.width;
            //if (bds == null || !bds.contains(p)) {
            //    hide();
            //    return;
            //}
            // end "fix for possible npe spotted by SCO"

            if (setCompAndRow(list, row))
            {
                Rectangle   visible = getShowingRect(view);
                Rectangle[] rects   = getRects(bds, visible);
                if (rects.Length > 0)
                {
                    ensureOldPopupsHidden();
                    painter.configure(list.Model.getElementAt(row), view, list, row);
                    showPopups(rects, bds, visible, list, view);
                }
                else
                {
                    hide();
                }
            }
        }
コード例 #3
0
        public override void mouseMoved(MouseEvent e)
        {
            Point       p    = e.Point;
            JComponent  comp = (JComponent)e.Source;
            JScrollPane jsp  = (JScrollPane)SwingUtilities.getAncestorOfClass(typeof(JScrollPane), comp);

            if (jsp != null)
            {
                p = SwingUtilities.convertPoint(comp, p, jsp);
                show(jsp, p);
            }
        }