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();
}
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;
}
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;
}
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());
}
}
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;
}
Aggregations