/[classpath]/classpath/javax/swing/ToolTipManager.java
ViewVC logotype

Diff of /classpath/javax/swing/ToolTipManager.java

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

revision 1.19 by langel, Wed Sep 21 21:21:19 2005 UTC revision 1.20 by langel, Thu Sep 22 15:36:38 2005 UTC
# Line 467  public class ToolTipManager extends Mous Line 467  public class ToolTipManager extends Mous
467      Container parent = currentComponent.getParent();      Container parent = currentComponent.getParent();
468      Point p = currentPoint;      Point p = currentPoint;
469      Dimension dims = currentTip.getPreferredSize();      Dimension dims = currentTip.getPreferredSize();
     Rectangle bounds = currentComponent.getBounds();  
     p.x += bounds.width - dims.width;  
     p.y = bounds.height;  
470            
471      if (parent instanceof JPopupMenu)      if (parent instanceof JPopupMenu)
472          setLightWeightPopupEnabled(((JPopupMenu) parent).isLightWeightPopupEnabled());          setLightWeightPopupEnabled(((JPopupMenu) parent).isLightWeightPopupEnabled());
473                    
474      if (isLightWeightPopupEnabled())      if (isLightWeightPopupEnabled())
475        {        {
         if (p.x < parent.getBounds().x)  
           p.x = 0;  
           
476          JLayeredPane pane = ((JRootPane) SwingUtilities.          JLayeredPane pane = ((JRootPane) SwingUtilities.
477              getAncestorOfClass(JRootPane.class, currentComponent)).              getAncestorOfClass(JRootPane.class, currentComponent)).
478              getLayeredPane();              getLayeredPane();
# Line 503  public class ToolTipManager extends Mous Line 497  public class ToolTipManager extends Mous
497            }            }
498    
499          p = SwingUtilities.convertPoint(currentComponent, p, pane);          p = SwingUtilities.convertPoint(currentComponent, p, pane);
500            p = adjustLocation(p, pane, dims);
501            
502          pane.add(containerPanel);          pane.add(containerPanel);
503          containerPanel.setBounds(p.x, p.y, dims.width, dims.height);          containerPanel.setBounds(p.x, p.y, dims.width, dims.height);
504          currentTip.setBounds(0, 0, dims.width, dims.height);          currentTip.setBounds(0, 0, dims.width, dims.height);
505        }        }
506      else if (currentComponent.isShowing())      else if (currentComponent.isShowing())
507        {        {        
         Rectangle b = parent.getBounds();  
         if (p.x + dims.width > b.x + b.width)  
           p.x = b.x - dims.width;  
           
508          SwingUtilities.convertPointToScreen(p, currentComponent);          SwingUtilities.convertPointToScreen(p, currentComponent);
509            p = adjustLocation(p, SwingUtilities.getWindowAncestor(currentComponent),
510                               dims);
511            
512          tooltipWindow = new JDialog();          tooltipWindow = new JDialog();
513          tooltipWindow.setContentPane(currentTip);          tooltipWindow.setContentPane(currentTip);
514          tooltipWindow.setUndecorated(true);          tooltipWindow.setUndecorated(true);
# Line 524  public class ToolTipManager extends Mous Line 519  public class ToolTipManager extends Mous
519          tooltipWindow.show();          tooltipWindow.show();
520        }        }
521      currentTip.setVisible(true);      currentTip.setVisible(true);
     currentTip.revalidate();  
     currentTip.repaint();  
522    }    }
523    
524    /**    /**
525       * Adjusts the point to a new location on the component,
526       * using the currentTip's dimensions.
527       *
528       * @param p - the point to convert.
529       * @param c - the component the point is on.
530       * @param d - the dimensions of the currentTip.
531       */
532      private Point adjustLocation(Point p, Component c, Dimension d)
533      {
534        if (p.x + d.width > c.getWidth())
535          p.x -= d.width;
536        if (p.x < 0)
537          p.x = 0;
538        if (p.y + d.height < c.getHeight())
539          p.y += d.height;
540        else if (p.y + d.height > c.getHeight())
541          p.y -= d.height*2;
542        
543        return p;
544      }
545      
546      /**
547     * This method hides the ToolTip.     * This method hides the ToolTip.
548     * This is package-private to avoid an accessor method.     * This is package-private to avoid an accessor method.
549     */     */

Legend:
Removed from v.1.19  
changed lines
  Added in v.1.20

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