Search in sources :

Example 6 with JToolTip

use of javax.swing.JToolTip in project openblocks by mikaelhg.

the class CToolTipUI method getPreferredSize.

public Dimension getPreferredSize(JComponent c) {
    String tipText = ((JToolTip) c).getTipText();
    if (tipText == null) {
        return new Dimension(0, 0);
    }
    textArea.setText(tipText);
    Dimension d = textArea.getPreferredSize();
    d.width = Math.min(d.width, WIDTH);
    d.height++;
    textArea.setSize(d);
    return d;
// return textArea.getPreferredSize();
}
Also used : JToolTip(javax.swing.JToolTip) Dimension(java.awt.Dimension)

Example 7 with JToolTip

use of javax.swing.JToolTip in project vcell by virtualcell.

the class MultiLineToolTipUI method getPreferredSize.

public Dimension getPreferredSize(JComponent c) {
    String tipText = ((JToolTip) c).getTipText();
    if (tipText == null) {
        return new Dimension(0, 0);
    }
    String tipTextSubString = "";
    String[] linesInTipText = getLinesInTipText(tipText);
    boolean bLongLines = linesLongerThanTextArea(linesInTipText);
    int totalLinesCount = linesInTipText.length;
    int displayedLinesCount = 0;
    if (totalLinesCount > 1) {
        // A little bit of twisted logic to limit the lines number of lines displayed in the multilinetooltip,
        if (bLongLines) {
            displayedLinesCount = Math.min(totalLinesCount, 3);
            int i = 0;
            for (i = 0; i < displayedLinesCount - 1; i++) {
                tipTextSubString = tipTextSubString + linesInTipText[i];
            }
            if (totalLinesCount > displayedLinesCount) {
                tipTextSubString = tipTextSubString + linesInTipText[i] + " ...";
            } else {
                tipTextSubString = tipTextSubString + linesInTipText[i];
            }
        } else {
            displayedLinesCount = Math.min(totalLinesCount, 4);
            int i = 0;
            for (i = 0; i < displayedLinesCount - 1; i++) {
                tipTextSubString = tipTextSubString + linesInTipText[i];
            }
            if (totalLinesCount > displayedLinesCount) {
                tipTextSubString = tipTextSubString + linesInTipText[i] + " ...";
            } else {
                tipTextSubString = tipTextSubString + linesInTipText[i];
            }
        }
    } else {
        // if there is only 1 line ...
        if (bLongLines) {
            // else leave text as is.
            if (tipText.length() > 200) {
                tipTextSubString = tipText.substring(0, 199) + " ...";
            } else {
                tipTextSubString = tipText;
            }
        } else {
            // if there is only one line and its not a long line, leave text as is.
            tipTextSubString = tipText;
        }
    }
    textArea = new JTextArea(tipTextSubString);
    rendererPane.removeAll();
    rendererPane.add(textArea);
    textArea.setWrapStyleWord(true);
    int width = ((MultiLineToolTip) c).getFixedWidth();
    int columns = ((MultiLineToolTip) c).getColumns();
    if (columns > 0) {
        textArea.setColumns(columns);
        textArea.setSize(0, 0);
        textArea.setLineWrap(true);
        textArea.setSize(textArea.getPreferredSize());
    } else if (width > 0) {
        textArea.setLineWrap(true);
        Dimension d = textArea.getPreferredSize();
        d.width = width;
        d.height++;
        textArea.setSize(d);
    } else {
        textArea.setLineWrap(false);
    }
    Dimension dim = textArea.getPreferredSize();
    dim.height += 1;
    dim.width += 1;
    dim.width = Math.min(dim.width, 400);
    if ((displayedLinesCount == 3 && bLongLines) || displayedLinesCount == 4 || (totalLinesCount == 1 && bLongLines)) {
        dim.height = 100;
    } else {
        dim.height = Math.min(dim.height, 100);
    }
    // Forcing line wrap for JTextarea. Also, forcng font to be "Panel.font". Else it
    // takes "ToolTip.font" as default which is the monosansserif font, which is different
    // from the other tooltip fonts (Panel.font - dialog).
    textArea.setLineWrap(true);
    textArea.setFont(UIManager.getFont("Panel.font"));
    return dim;
}
Also used : JToolTip(javax.swing.JToolTip) JTextArea(javax.swing.JTextArea) Dimension(java.awt.Dimension)

Example 8 with JToolTip

use of javax.swing.JToolTip in project knime-core by knime.

the class MultiLineToolTipUI method getPreferredSize.

/**
 * {@inheritDoc}
 */
@Override
public Dimension getPreferredSize(final JComponent c) {
    String tipText = ((JToolTip) c).getTipText();
    if (tipText == null) {
        return new Dimension(0, 0);
    }
    textArea = new JTextArea(tipText);
    m_rendererPane.removeAll();
    m_rendererPane.add(textArea);
    textArea.setWrapStyleWord(true);
    int width = ((JMultiLineToolTip) c).getFixedWidth();
    int columns = ((JMultiLineToolTip) c).getColumns();
    if (columns > 0) {
        textArea.setColumns(columns);
        textArea.setSize(0, 0);
        textArea.setLineWrap(true);
        textArea.setSize(textArea.getPreferredSize());
    } else if (width > 0) {
        textArea.setLineWrap(true);
        Dimension d = textArea.getPreferredSize();
        d.width = width;
        d.height++;
        textArea.setSize(d);
    } else {
        textArea.setLineWrap(false);
    }
    Dimension dim = textArea.getPreferredSize();
    dim.height += 1;
    dim.width += 1;
    return dim;
}
Also used : JToolTip(javax.swing.JToolTip) JTextArea(javax.swing.JTextArea) Dimension(java.awt.Dimension)

Example 9 with JToolTip

use of javax.swing.JToolTip in project blue by kunstmusik.

the class BlueToolTipUI method paint.

@Override
public void paint(Graphics g, JComponent c) {
    JToolTip tip = (JToolTip) c;
    super.paint(g, c);
    Font font = c.getFont();
    String keyText = getAcceleratorString(tip);
    String tipText = tip.getTipText();
    if (tipText == null) {
        tipText = "";
    }
    if (!(keyText.equals(""))) {
        // only draw control key if there is one
        g.setFont(smallFont);
        g.setColor(BlueLookAndFeel.getPrimaryControlDarkShadow());
        FontMetrics metrics = g.getFontMetrics();
        g.drawString(keyText, metrics.stringWidth(tipText) + padSpaceBetweenStrings, 2 + metrics.getAscent());
    }
}
Also used : JToolTip(javax.swing.JToolTip) FontMetrics(java.awt.FontMetrics) Font(java.awt.Font)

Example 10 with JToolTip

use of javax.swing.JToolTip in project UniversalMediaServer by UniversalMediaServer.

the class CustomJCheckBox method createToolTip.

public JToolTip createToolTip() {
    JToolTip tip = new HyperLinkToolTip();
    tip.setComponent(this);
    return tip;
}
Also used : JToolTip(javax.swing.JToolTip)

Aggregations

JToolTip (javax.swing.JToolTip)15 Dimension (java.awt.Dimension)3 JToolTipI18n (com.jsql.view.swing.text.JToolTipI18n)2 Point (java.awt.Point)2 MouseAdapter (java.awt.event.MouseAdapter)2 MouseEvent (java.awt.event.MouseEvent)2 JLabel (javax.swing.JLabel)2 JTextArea (javax.swing.JTextArea)2 Unit (games.strategy.engine.data.Unit)1 TripleAUnit (games.strategy.triplea.TripleAUnit)1 TerritoryAttachment (games.strategy.triplea.attachments.TerritoryAttachment)1 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)1 Font (java.awt.Font)1 FontMetrics (java.awt.FontMetrics)1 KeyEvent (java.awt.event.KeyEvent)1 KeyListener (java.awt.event.KeyListener)1 Popup (javax.swing.Popup)1 PopupFactory (javax.swing.PopupFactory)1