Java 类javax.swing.JToolTip 实例源码

项目:powertext    文件:FoldIndicator.java   
/**
 * Positions tool tips to be aligned in the text component, so that the
 * displayed content is shown (almost) exactly where it would be in the
 * editor.
 *
 * @param e The mouse location.
 */
@Override
public Point getToolTipLocation(MouseEvent e) {

    // ToolTipManager requires both location and text to be null to hide
    // a currently-visible tool tip window.  If text is null but location
    // has some value, it will show a tool tip with empty content, the size
    // of its border (!).
    String text = getToolTipText(e);
    if (text==null) {
        return null;
    }

    // Try to overlap the tip's text directly over the code
    Point p = e.getPoint();
    p.y = (p.y/textArea.getLineHeight()) * textArea.getLineHeight();
    p.x = getWidth() + textArea.getMargin().left;
    Gutter gutter = getGutter();
    int gutterMargin = gutter.getInsets().right;
    p.x += gutterMargin;
    JToolTip tempTip = createToolTip();
    p.x -= tempTip.getInsets().left;
    p.y += 16;
    return p;
}
项目:incubator-netbeans    文件:Outline.java   
@Override
public JToolTip createToolTip() {
    JToolTip t = toolTip;
    toolTip = null;
    if (t != null) {
        t.addMouseMotionListener(new MouseMotionAdapter() { // #233642

            boolean initialized = false;

            @Override
            public void mouseMoved(MouseEvent e) {
                if (!initialized) {
                    initialized = true; // ignore the first event
                } else {
                    // hide the tooltip if mouse moves over it
                    ToolTipManager.sharedInstance().mousePressed(e);
                }
            }
        });
        return t;
    } else {
        return super.createToolTip();
    }
}
项目:powertext    文件:FoldIndicator.java   
/**
 * Overridden to use the editor's background if it's detected that the
 * user isn't using white as the editor bg, but the system's tool tip
 * background is yellow-ish.
 *
 * @return The tool tip.
 */
@Override
public JToolTip createToolTip() {
    JToolTip tip = super.createToolTip();
    Color textAreaBG = textArea.getBackground();
    if (textAreaBG!=null && !Color.white.equals(textAreaBG)) {
        Color bg = TipUtil.getToolTipBackground();
        // If current L&F's tool tip color is close enough to "yellow",
        // and we're not using the default text background of white, use
        // the editor background as the tool tip background.
        if (bg.getRed()>=240 && bg.getGreen()>=240 && bg.getBlue()>=200) {
            tip.setBackground(textAreaBG);
        }
    }
    return tip;
}
项目:hearthstone    文件:DeckBack.java   
private void showToolTip(boolean flag) {
    try {
        if (flag) {
            int qtd = heroi.getDeck().size();
            String txt = (qtd == 0 ? "Nenhum card" : qtd == 1
                    ? "1 card" : qtd + " cards");
            Point p = getLocationOnScreen();
            JToolTip tip = createToolTip();
            tip.setTipText(txt);
            PopupFactory popupFactory = PopupFactory.getSharedInstance();
            tooltip = popupFactory.getPopup(this, tip, p.x + 10, p.y + 10);
            tooltip.show();
        } else {
            tooltip.hide();
        }
    } catch (Exception ex) {
        //ignorar
    }
}
项目:hearthstone    文件:MaoBack.java   
private void showToolTip(boolean flag) {
    try {
        if (flag) {
            int qtd = heroi.getMao().size();
            String txt = (qtd == 0 ? "Nenhum card" : qtd == 1
                    ? "1 card" : qtd + " cards");
            Point p = getLocationOnScreen();
            JToolTip tip = createToolTip();
            tip.setTipText(txt);
            PopupFactory popupFactory = PopupFactory.getSharedInstance();
            tooltip = popupFactory.getPopup(this, tip, p.x + 10, p.y + 10);
            tooltip.show();
        } else {
            tooltip.hide();
        }
    } catch (Exception ex) {
        //ignorar
    }
}
项目:openjdk-jdk10    文件:JComponentOperator.java   
public JToolTipWindowFinder() {
    ppFinder = new ComponentChooser() {
        @Override
        public boolean checkComponent(Component comp) {
            return (comp.isShowing()
                    && comp.isVisible()
                    && comp instanceof JToolTip);
        }

        @Override
        public String getDescription() {
            return "A tool tip";
        }

        @Override
        public String toString() {
            return "JComponentOperator.JToolTipWindowFinder.ComponentChooser{description = " + getDescription() + '}';
        }
    };
}
项目:FreeCol    文件:FreeColToolTipUI.java   
@Override
public Dimension getPreferredSize(JComponent c) {
    String tipText = ((JToolTip)c).getTipText();
    if (tipText == null || tipText.isEmpty()) {
        return new Dimension(0, 0);
    }

    float x = 0f;
    float y = 0f;
    for (String line : lineBreak.split(tipText)) {
        if (line.isEmpty()) {
            y += LEADING;
            continue;
        }
        AttributedCharacterIterator styledText
            = new AttributedString(line).getIterator();
        LineBreakMeasurer measurer = new LineBreakMeasurer(styledText, frc);

        while (measurer.getPosition() < styledText.getEndIndex()) {

            TextLayout layout = measurer.nextLayout(maximumWidth);

            x = Math.max(x, layout.getVisibleAdvance());
            y += layout.getAscent() + layout.getDescent() + layout.getLeading();

        }
    }
    return new Dimension((int) (x + 2 * margin),
                         (int) (y + 2 * margin));

}
项目:oxygen-git-plugin    文件:CommitPanel.java   
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected,
        boolean cellHasFocus) {
    JLabel comp = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    if (value != null) {
      JToolTip createToolTip = comp.createToolTip();
      Font font = createToolTip.getFont();
      FontMetrics fontMetrics = getFontMetrics(font);
      int length = fontMetrics.stringWidth((String) value);
      if (length < MAX_TOOLTIP_WIDTH) {
        comp.setToolTipText("<html><p width=\"" + length + "\">" + value + "</p></html>");
      } else {
        comp.setToolTipText("<html><p width=\"" + MAX_TOOLTIP_WIDTH + "\">" + value + "</p></html>");
      }
    }
    return comp;
}
项目:openjdk9    文件:JComponentOperator.java   
public JToolTipWindowFinder() {
    ppFinder = new ComponentChooser() {
        @Override
        public boolean checkComponent(Component comp) {
            return (comp.isShowing()
                    && comp.isVisible()
                    && comp instanceof JToolTip);
        }

        @Override
        public String getDescription() {
            return "A tool tip";
        }

        @Override
        public String toString() {
            return "JComponentOperator.JToolTipWindowFinder.ComponentChooser{description = " + getDescription() + '}';
        }
    };
}
项目:ftc    文件:FoldIndicator.java   
/**
 * Overridden to use the editor's background if it's detected that the
 * user isn't using white as the editor bg, but the system's tool tip
 * background is yellow-ish.
 *
 * @return The tool tip.
 */
@Override
public JToolTip createToolTip() {
    JToolTip tip = super.createToolTip();
    Color textAreaBG = textArea.getBackground();
    if (textAreaBG!=null && !Color.white.equals(textAreaBG)) {
        Color bg = TipUtil.getToolTipBackground();
        // If current L&F's tool tip color is close enough to "yellow",
        // and we're not using the default text background of white, use
        // the editor background as the tool tip background.
        if (bg.getRed()>=240 && bg.getGreen()>=240 && bg.getBlue()>=200) {
            tip.setBackground(textAreaBG);
        }
    }
    return tip;
}
项目:ftc    文件:FoldIndicator.java   
/**
 * Positions tool tips to be aligned in the text component, so that the
 * displayed content is shown (almost) exactly where it would be in the
 * editor.
 *
 * @param e The mouse location.
 */
@Override
public Point getToolTipLocation(MouseEvent e) {

    // ToolTipManager requires both location and text to be null to hide
    // a currently-visible tool tip window.  If text is null but location
    // has some value, it will show a tool tip with empty content, the size
    // of its border (!).
    String text = getToolTipText(e);
    if (text==null) {
        return null;
    }

    // Try to overlap the tip's text directly over the code
    Point p = e.getPoint();
    p.y = (p.y/textArea.getLineHeight()) * textArea.getLineHeight();
    p.x = getWidth() + textArea.getMargin().left;
    Gutter gutter = getGutter();
    int gutterMargin = gutter.getInsets().right;
    p.x += gutterMargin;
    JToolTip tempTip = createToolTip();
    p.x -= tempTip.getInsets().left;
    p.y += 16;
    return p;
}
项目:SweetHome3D    文件:SwingTools.java   
private static boolean isToolTipShowing(Container container)
{
    if (container instanceof Window)
    {
        for (Window window : ((Window) container).getOwnedWindows())
        {
            if (isToolTipShowing(window))
            {
                return true;
            }
        }
    }
    for (int i = 0; i < container.getComponentCount(); i++)
    {
        Component child = container.getComponent(i);
        if (child instanceof JToolTip && child.isShowing()
                || child instanceof Container && isToolTipShowing((Container) child))
        {
            return true;
        }
    }
    return false;
}
项目:javify    文件:BasicToolTipUI.java   
/**
 * This method returns the preferred size of the given JComponent.
 *
 * @param c The JComponent to find a preferred size for.
 *
 * @return The preferred size.
 */
public Dimension getPreferredSize(JComponent c)
{
  JToolTip tip = (JToolTip) c;
  String str = tip.getTipText();
  FontMetrics fm = c.getFontMetrics(c.getFont());
  Insets i = c.getInsets();
  Dimension d = new Dimension(i.left + i.right, i.top + i.bottom);
  if (str != null && ! str.equals(""))
    {
      View view = (View) c.getClientProperty(BasicHTML.propertyKey);
      if (view != null)
        {
          d.width += (int) view.getPreferredSpan(View.X_AXIS);
          d.height += (int) view.getPreferredSpan(View.Y_AXIS);
        }
      else
        {
          d.width += fm.stringWidth(str) + 6;
          d.height += fm.getHeight();
        }
    }
  return d;
}
项目:SBOLDesigner    文件:AddressBar.java   
private JButton createButton(final ComponentDefinition comp) {
    JButton button = new JButton(comp.getDisplayId(), ICON) {
        public JToolTip createToolTip() {
            Image image = (Image) getClientProperty("overview");
            JToolTipWithIcon tip = new JToolTipWithIcon(new ImageIcon(image));
            tip.setComponent(this);
            return tip;
        }
    };
    button.putClientProperty("comp", comp);
    // TODO this is broken
    // button.addActionListener(new ActionListener() {
    // @Override
    // public void actionPerformed(ActionEvent event) {
    // try {
    // design.focusOut(comp);
    // } catch (SBOLValidationException e) {
    // JOptionPane.showMessageDialog(null, "There was an error: " +
    // e.getMessage());
    // e.printStackTrace();
    // }
    // }
    // });
    Buttons.setStyle(button);
    return button;
}
项目:mars-sim    文件:ToolButton.java   
/**
 * Constructs a ToolButton object.
 * @param toolName the name of the tool
 * @param imageName the name of the tool button image
 */
public ToolButton(String toolName, String imageName) {

    // Use JButton constructor
    super(ImageLoader.getIcon(imageName));

    // Initialize toolName
    this.toolName = toolName;

    // Initialize tool tip for button
    toolButtonTip = new JToolTip();
    toolButtonTip.setBackground(Color.white);
    toolButtonTip.setBorder(new LineBorder(Color.yellow));
    setToolTipText(toolName);

    // Prepare default tool button values
    setAlignmentX(.5F);
    setAlignmentY(.5F);

}
项目:jvm-stm    文件:BasicToolTipUI.java   
/**
 * This method returns the preferred size of the given JComponent.
 *
 * @param c The JComponent to find a preferred size for.
 *
 * @return The preferred size.
 */
public Dimension getPreferredSize(JComponent c)
{
  JToolTip tip = (JToolTip) c;
  String str = tip.getTipText();
  FontMetrics fm = c.getFontMetrics(c.getFont());
  Insets i = c.getInsets();
  Dimension d = new Dimension(i.left + i.right, i.top + i.bottom);
  if (str != null && ! str.equals(""))
    {
      View view = (View) c.getClientProperty(BasicHTML.propertyKey);
      if (view != null)
        {
          d.width += (int) view.getPreferredSpan(View.X_AXIS);
          d.height += (int) view.getPreferredSpan(View.Y_AXIS);
        }
      else
        {
          d.width += fm.stringWidth(str) + 6;
          d.height += fm.getHeight();
        }
    }
  return d;
}
项目:WorldGrower    文件:CustomPopupFactory.java   
public static void setPopupFactory() {
    PopupFactory.setSharedInstance(new PopupFactory() {

        @Override
        public Popup getPopup(Component owner, Component contents, int x, int y) throws IllegalArgumentException {
            if (contents instanceof JToolTip) {
                JToolTip toolTip = (JToolTip)contents;
                int width = (int) toolTip.getPreferredSize().getWidth();

                GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
                int screenWidth = gd.getDisplayMode().getWidth();

                // if there is enough room, move tooltip to the right to have enough room
                // for large tooltips.
                // this way they don't hinder mouse movement and make it possible to easily
                // view multiple tooltips of items.
                if (x + width + TOOLTIP_X_OFFSET < screenWidth) {
                    x += TOOLTIP_X_OFFSET;
                }
            }
            return super.getPopup(owner, contents, x, y);
        }
    });
}
项目:mzmine2    文件:MultiLineToolTipUI.java   
public Dimension getPreferredSize(JComponent c) {
Font font = c.getFont();
String tipText = ((JToolTip) c).getTipText();
JToolTip mtt = (JToolTip) c;
FontMetrics fontMetrics = mtt.getFontMetrics(font);
int fontHeight = fontMetrics.getHeight();

if (tipText == null)
    return new Dimension(0, 0);

String lines[] = tipText.split("\n");
int num_lines = lines.length;

int width, height, onewidth;
height = num_lines * fontHeight;
width = 0;
for (int i = 0; i < num_lines; i++) {
    onewidth = fontMetrics.stringWidth(lines[i]);
    width = Math.max(width, onewidth);
}
return new Dimension(width + inset * 2, height + inset * 2);
   }
项目:mzmine2    文件:MultiLineToolTipUI.java   
public void paint(Graphics g, JComponent c) {
Font font = c.getFont();
JToolTip mtt = (JToolTip) c;
FontMetrics fontMetrics = mtt.getFontMetrics(font);
Dimension dimension = c.getSize();
int fontHeight = fontMetrics.getHeight();
int fontAscent = fontMetrics.getAscent();
String tipText = ((JToolTip) c).getTipText();
if (tipText == null)
    return;
String lines[] = tipText.split("\n");
int num_lines = lines.length;
int height;
int i;

g.setColor(c.getBackground());
g.fillRect(0, 0, dimension.width, dimension.height);
g.setColor(c.getForeground());
for (i = 0, height = 2 + fontAscent; i < num_lines; i++, height += fontHeight) {
    g.drawString(lines[i], inset, height);
}
   }
项目:ESPlorer    文件:FoldIndicator.java   
/**
 * Overridden to use the editor's background if it's detected that the
 * user isn't using white as the editor bg, but the system's tool tip
 * background is yellow-ish.
 *
 * @return The tool tip.
 */
@Override
public JToolTip createToolTip() {
    JToolTip tip = super.createToolTip();
    Color textAreaBG = textArea.getBackground();
    if (textAreaBG!=null && !Color.white.equals(textAreaBG)) {
        Color bg = TipUtil.getToolTipBackground();
        // If current L&F's tool tip color is close enough to "yellow",
        // and we're not using the default text background of white, use
        // the editor background as the tool tip background.
        if (bg.getRed()>=240 && bg.getGreen()>=240 && bg.getBlue()>=200) {
            tip.setBackground(textAreaBG);
        }
    }
    return tip;
}
项目:ESPlorer    文件:FoldIndicator.java   
/**
 * Positions tool tips to be aligned in the text component, so that the
 * displayed content is shown (almost) exactly where it would be in the
 * editor.
 *
 * @param e The mouse location.
 */
@Override
public Point getToolTipLocation(MouseEvent e) {

    // ToolTipManager requires both location and text to be null to hide
    // a currently-visible tool tip window.  If text is null but location
    // has some value, it will show a tool tip with empty content, the size
    // of its border (!).
    String text = getToolTipText(e);
    if (text==null) {
        return null;
    }

    // Try to overlap the tip's text directly over the code
    Point p = e.getPoint();
    p.y = (p.y/textArea.getLineHeight()) * textArea.getLineHeight();
    p.x = getWidth() + textArea.getMargin().left;
    Gutter gutter = getGutter();
    int gutterMargin = gutter.getInsets().right;
    p.x += gutterMargin;
    JToolTip tempTip = createToolTip();
    p.x -= tempTip.getInsets().left;
    p.y += 16;
    return p;
}
项目:openwonderland    文件:HUDWindow.java   
private HUDComponent showPopup(Component component, int x, int y) {
    // sometimes we are given a tooltip with no text that doesn't close.
    // just ignore it
    if (component instanceof JToolTip &&
            (((JToolTip) component).getTipText() == null ||
            ((JToolTip) component).getTipText().isEmpty()))
    {
        return null;
    }

    HUDComponent hc = new HUDPopup2D((JComponent) component, this, x, y);
    hc.setDecoratable(false);

    hud.addComponent(hc);
    hc.setVisible(true);

    return hc;
}
项目:JBroTable    文件:JBroTableHeaderUI.java   
/**
 * A hack to prepare HTML-based Swing components: size initialization is called inside paint method.
 * @param g a non-null Graphics object
 * @param component an HTML-based component that needs to be initialized
 * @param cellRect a space where the component should be painted
 */
public static void htmlHack( Graphics g, Component component, Rectangle cellRect ) {
  String text;
  if ( component instanceof JLabel )
    text = ( ( JLabel )component ).getText();
  else if ( component instanceof AbstractButton )
    text = ( ( AbstractButton )component ).getText();
  else if ( component instanceof JToolTip )
    text = ( ( JToolTip )component ).getTipText();
  else
    text = null;
  if ( !BasicHTML.isHTMLString( text ) )
    return;
  component.setBounds( cellRect );
  Graphics gg = g.create( -cellRect.width, -cellRect.height, cellRect.width, cellRect.height );
  try {
    component.paint( gg );
  } catch ( NullPointerException e ) {
    // Thrown on applet reinitialization.
  } finally {
    gg.dispose();
  }
}
项目:javamelody    文件:CounterRequestTable.java   
@Override
public void paint(Graphics g, JComponent c) {
    try {
        final String tipText = ((JToolTip) c).getTipText();
        final BufferedImage image = getRequestChartByRequestName(tipText);
        // on affiche que l'image et pas le text dans le tooltip
        //          FontMetrics metrics = c.getFontMetrics(g.getFont());
        //          g.setColor(c.getForeground());
        //          g.drawString(tipText, 1, 1);
        if (image != null) {
            g.drawImage(image, 0, 0, c);
        } else {
            super.paint(g, c);
        }
    } catch (final IOException e) {
        // s'il y a une erreur dans la récupération de l'image tant pis
        super.paint(g, c);
    }
}
项目:seaglass    文件:SeaGlassToolTipUI.java   
/**
 * Paints the specified component.
 *
 * @param context
 *            context for the component being painted
 * @param g
 *            the {@code Graphics} object used for painting
 * @see #update(Graphics,JComponent)
 */
protected void paint(SynthContext context, Graphics g) {
    JToolTip tip = (JToolTip) context.getComponent();

    Insets insets = tip.getInsets();
    View v = (View) tip.getClientProperty(BasicHTML.propertyKey);
    if (v != null) {
        Rectangle paintTextR = new Rectangle(insets.left, insets.top, tip.getWidth() - (insets.left + insets.right), tip.getHeight()
                - (insets.top + insets.bottom));
        v.paint(g, paintTextR);
    } else {
        g.setColor(context.getStyle().getColor(context, ColorType.TEXT_FOREGROUND));
        g.setFont(style.getFont(context));
        context.getStyle().getGraphicsUtils(context).paintText(context, g, tip.getTipText(), insets.left, insets.top, -1);
    }
}
项目:seaglass    文件:SeaGlassToolTipUI.java   
/**
 * @inheritDoc
 */
@Override
public Dimension getPreferredSize(JComponent c) {
    SeaGlassContext context = getContext(c);
    Insets insets = c.getInsets();
    Dimension prefSize = new Dimension(insets.left + insets.right, insets.top + insets.bottom);
    String text = ((JToolTip) c).getTipText();

    if (text != null) {
        View v = (c != null) ? (View) c.getClientProperty("html") : null;
        if (v != null) {
            prefSize.width += (int) v.getPreferredSpan(View.X_AXIS);
            prefSize.height += (int) v.getPreferredSpan(View.Y_AXIS);
        } else {
            Font font = context.getStyle().getFont(context);
            FontMetrics fm = c.getFontMetrics(font);
            prefSize.width += context.getStyle().getGraphicsUtils(context).computeStringWidth(context, font, fm, text);
            prefSize.height += fm.getHeight();
        }
    }
    context.dispose();
    return prefSize;
}
项目:seaglass    文件:SeaGlassToolTipUI.java   
/**
 * @inheritDoc
 */
@Override
public void propertyChange(PropertyChangeEvent e) {
    if (SeaGlassLookAndFeel.shouldUpdateStyle(e)) {
        updateStyle((JToolTip) e.getSource());
    }
    String name = e.getPropertyName();
    if (name.equals("tiptext") || "font".equals(name) || "foreground".equals(name)) {
        // remove the old html view client property if one
        // existed, and install a new one if the text installed
        // into the JLabel is html source.
        JToolTip tip = ((JToolTip) e.getSource());
        String text = tip.getTipText();
        BasicHTML.updateRenderer(tip, text);
    }
}
项目:DataCleaner    文件:HelpIcon.java   
@Override
public JToolTip createToolTip() {
    final DCPanel panel = new DCPanel();
    panel.setOpaque(true);
    panel.setBackground(WidgetUtils.BG_COLOR_DARK);

    panel.setLayout(new BorderLayout());
    panel.add(new JLabel(_tooltipIcon), BorderLayout.WEST);

    final DCLabel descriptionLabel = DCLabel.brightMultiLine(_helpMessage);
    panel.add(descriptionLabel, BorderLayout.CENTER);

    final Border border = new CompoundBorder(WidgetUtils.BORDER_THIN, WidgetUtils.BORDER_EMPTY);
    panel.setBorder(border);

    panel.setPreferredSize(300, 130);

    return new DCToolTip(this, panel);
}
项目:ESPlorer    文件:FoldIndicator.java   
/**
 * Overridden to use the editor's background if it's detected that the
 * user isn't using white as the editor bg, but the system's tool tip
 * background is yellow-ish.
 *
 * @return The tool tip.
 */
@Override
public JToolTip createToolTip() {
    JToolTip tip = super.createToolTip();
    Color textAreaBG = textArea.getBackground();
    if (textAreaBG!=null && !Color.white.equals(textAreaBG)) {
        Color bg = TipUtil.getToolTipBackground();
        // If current L&F's tool tip color is close enough to "yellow",
        // and we're not using the default text background of white, use
        // the editor background as the tool tip background.
        if (bg.getRed()>=240 && bg.getGreen()>=240 && bg.getBlue()>=200) {
            tip.setBackground(textAreaBG);
        }
    }
    return tip;
}
项目:ESPlorer    文件:FoldIndicator.java   
/**
 * Positions tool tips to be aligned in the text component, so that the
 * displayed content is shown (almost) exactly where it would be in the
 * editor.
 *
 * @param e The mouse location.
 */
@Override
public Point getToolTipLocation(MouseEvent e) {

    // ToolTipManager requires both location and text to be null to hide
    // a currently-visible tool tip window.  If text is null but location
    // has some value, it will show a tool tip with empty content, the size
    // of its border (!).
    String text = getToolTipText(e);
    if (text==null) {
        return null;
    }

    // Try to overlap the tip's text directly over the code
    Point p = e.getPoint();
    p.y = (p.y/textArea.getLineHeight()) * textArea.getLineHeight();
    p.x = getWidth() + textArea.getMargin().left;
    Gutter gutter = getGutter();
    int gutterMargin = gutter.getInsets().right;
    p.x += gutterMargin;
    JToolTip tempTip = createToolTip();
    p.x -= tempTip.getInsets().left;
    p.y += 16;
    return p;
}
项目:JamVM-PH    文件:BasicToolTipUI.java   
/**
 * This method returns the preferred size of the given JComponent.
 *
 * @param c The JComponent to find a preferred size for.
 *
 * @return The preferred size.
 */
public Dimension getPreferredSize(JComponent c)
{
  JToolTip tip = (JToolTip) c;
  String str = tip.getTipText();
  FontMetrics fm = c.getFontMetrics(c.getFont());
  Insets i = c.getInsets();
  Dimension d = new Dimension(i.left + i.right, i.top + i.bottom);
  if (str != null && ! str.equals(""))
    {
      View view = (View) c.getClientProperty(BasicHTML.propertyKey);
      if (view != null)
        {
          d.width += (int) view.getPreferredSpan(View.X_AXIS);
          d.height += (int) view.getPreferredSpan(View.Y_AXIS);
        }
      else
        {
          d.width += fm.stringWidth(str) + 6;
          d.height += fm.getHeight();
        }
    }
  return d;
}
项目:classpath    文件:BasicToolTipUI.java   
/**
 * This method returns the preferred size of the given JComponent.
 *
 * @param c The JComponent to find a preferred size for.
 *
 * @return The preferred size.
 */
public Dimension getPreferredSize(JComponent c)
{
  JToolTip tip = (JToolTip) c;
  String str = tip.getTipText();
  FontMetrics fm = c.getFontMetrics(c.getFont());
  Insets i = c.getInsets();
  Dimension d = new Dimension(i.left + i.right, i.top + i.bottom);
  if (str != null && ! str.equals(""))
    {
      View view = (View) c.getClientProperty(BasicHTML.propertyKey);
      if (view != null)
        {
          d.width += (int) view.getPreferredSpan(View.X_AXIS);
          d.height += (int) view.getPreferredSpan(View.Y_AXIS);
        }
      else
        {
          d.width += fm.stringWidth(str) + 6;
          d.height += fm.getHeight();
        }
    }
  return d;
}
项目:SOEN6471-FreeCol    文件:FreeColToolTipUI.java   
public Dimension getPreferredSize(JComponent c) {
    String tipText = ((JToolTip)c).getTipText();
    if (tipText == null) {
        return new Dimension(0, 0);
    }

    float x = 0f;
    float y = 0f;
    for (String line : lineBreak.split(((JToolTip) c).getTipText())) {
        AttributedCharacterIterator styledText
            = new AttributedString(line).getIterator();
        LineBreakMeasurer measurer = new LineBreakMeasurer(styledText, frc);

        while (measurer.getPosition() < styledText.getEndIndex()) {

            TextLayout layout = measurer.nextLayout(maximumWidth);

            x = Math.max(x, layout.getVisibleAdvance());
            y += layout.getAscent() + layout.getDescent() + layout.getLeading();

        }
    }
    return new Dimension((int) (x + 2 * margin),
                         (int) (y + 2 * margin));

}
项目:RSyntaxTextArea    文件:FoldIndicator.java   
/**
 * Positions tool tips to be aligned in the text component, so that the
 * displayed content is shown (almost) exactly where it would be in the
 * editor.
 *
 * @param e The mouse location.
 */
public Point getToolTipLocation(MouseEvent e) {

    // ToolTipManager requires both location and text to be null to hide
    // a currently-visible tool tip window.  If text is null but location
    // has some value, it will show a tool tip with empty content, the size
    // of its border (!).
    String text = getToolTipText(e);
    if (text==null) {
        return null;
    }

    // Try to overlap the tip's text directly over the code
    Point p = e.getPoint();
    p.y = (p.y/textArea.getLineHeight()) * textArea.getLineHeight();
    p.x = getWidth() + textArea.getMargin().left;
    Gutter gutter = getGutter();
    int gutterMargin = gutter.getInsets().right;
    p.x += gutterMargin;
    JToolTip tempTip = createToolTip();
    p.x -= tempTip.getInsets().left;
    p.y += 16;
    return p;
}
项目:JRLib    文件:SubstanceToolTipUI.java   
@Override
public Dimension getPreferredSize(JComponent c) {
    Font font = c.getFont();
    Insets insets = c.getInsets();

    Dimension prefSize = new Dimension(insets.left + insets.right,
            insets.top + insets.bottom);
    String text = ((JToolTip) c).getTipText();

    if ((text == null) || text.equals("")) {
        text = "";
    } else {
        View v = (c != null) ? (View) c.getClientProperty("html") : null;
        if (v != null) {
            // fix for 302 - add extra pixels for the HTML view as well
            prefSize.width += (int) (v.getPreferredSpan(View.X_AXIS) + 6);
            prefSize.height += (int) (v.getPreferredSpan(View.Y_AXIS) + 2);
        } else {
            FontMetrics fm = c.getFontMetrics(font);
            prefSize.width += fm.stringWidth(text) + 6;
            prefSize.height += fm.getHeight() + 2;
        }
    }
    return prefSize;
}
项目:osp    文件:LibraryTreePanel.java   
/**
 * Creates the tree.
 * 
 * @param root the root node
 */
protected void createTree(LibraryTreeNode root) {
  treeModel = new DefaultTreeModel(root);
  tree = new JTree(treeModel) {
    public JToolTip createToolTip() {
        return new JMultiLineToolTip();
    }
  };
  if (root.createChildNodes()) {
   LibraryTreeNode lastNode = (LibraryTreeNode)root.getLastChild();
    TreePath path = new TreePath(lastNode.getPath());
    tree.scrollPathToVisible(path);
  }
  treeNodeRenderer = new LibraryTreeNodeRenderer();
  tree.setCellRenderer(treeNodeRenderer);
  tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  ToolTipManager.sharedInstance().registerComponent(tree);
  // listen for tree selections and display the contents
  tree.addTreeSelectionListener(treeSelectionListener);
  // listen for mouse events to display node info and inform propertyChangeListeners
  tree.addMouseListener(treeMouseListener);
  // put tree in scroller
  treeScroller.setViewportView(tree);
}
项目:osp    文件:MultiLineToolTipUI.java   
@Override
public Dimension getPreferredSize(JComponent c) {
    String tipText = ((JToolTip)c).getTipText();
    if (tipText==null)
        return new Dimension(0,0);
    textArea = new JTextArea(tipText);
    textArea.setBorder(BorderFactory.createEmptyBorder(0, 2, 2, 2));
  rendererPane.removeAll();
    rendererPane.add(textArea);
    textArea.setWrapStyleWord(true);
    textArea.setLineWrap(false);

    Dimension dim = textArea.getPreferredSize();        
    dim.height += 2;
    dim.width += 2;
    return dim;
}
项目:incubator-netbeans    文件:FlashingIcon.java   
@Override
public Point getToolTipLocation(MouseEvent event) {

    JToolTip tip = createToolTip();
    tip.setTipText(getToolTipText());
    Dimension d = tip.getPreferredSize();


    Point retValue = new Point(getWidth() - d.width, -d.height);
    return retValue;
}
项目:incubator-netbeans    文件:TooltipLabel.java   
@Override
public JToolTip createToolTip() {
    JToolTip tooltp = new JToolTip();
    tooltp.setBackground(SystemColor.control);
    tooltp.setFont(getFont());
    tooltp.setOpaque(true);
    tooltp.setComponent(this);
    tooltp.setBorder(null);
    return tooltp;
}
项目:incubator-netbeans    文件:OutlineView.java   
@Override
public JToolTip createToolTip() {
    if (component instanceof JComponent) {
        return ((JComponent) component).createToolTip();
    } else {
        return super.createToolTip();
    }
}