*/
package jalview.gui;
-import jalview.io.IntKeyStringValueEntry;
-import jalview.util.MessageManager;
-
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
+import jalview.util.MessageManager;
+
/**
* useful functions for building Swing GUIs
*
{
Objects.requireNonNull(ttext,
"Tootip text to format must not be null!");
- ttext = ttext.trim();
+ if (enclose)
+ {
+ ttext = ttext.trim();
+ }
boolean maxLengthExceeded = false;
- if (ttext.contains("<br>"))
+ boolean hasBr = false;
+ for (String br : new String[] { "<br>", "<br/>" })
{
- String[] htmllines = ttext.split("<br>");
- for (String line : htmllines)
+ if (ttext.contains(br))
{
- maxLengthExceeded = line.length() > 60;
- if (maxLengthExceeded)
+ hasBr = true;
+ String[] htmllines = ttext.split(br);
+ StringBuilder sb = new StringBuilder();
+ for (String line : htmllines)
{
- break;
+ if (enclose)
+ {
+ line = line.replaceAll("\\s+", " ");
+ line = line.trim();
+ }
+ if (line.length() == 0 || line.equals(" "))
+ {
+ continue;
+ }
+ String linetext = line.replaceAll("<[^>]+>", "");
+ maxLengthExceeded = linetext.length() > 60;
+ if (sb.length() > 0)
+ {
+ sb.append(br);
+ }
+ sb.append(line);
}
+ ttext = sb.toString();
}
}
- else
+ if (enclose)
+ {
+ ttext = ttext.replaceAll("\\s+", " ");
+ ttext = ttext.trim();
+ }
+ if (!hasBr)
{
maxLengthExceeded = ttext.length() > 60;
}
}
return (enclose ? "<html>" : "")
- + "<style> p.ttip {width: 350; text-align: justify; word-wrap: break-word;}</style><p class=\"ttip\">"
- + ttext + "</p>" + ((enclose ? "</html>" : ""));
-
+ // BH 2018
+ + "<style> div.ttip {width:350px;white-space:pre-wrap;padding:2px;overflow-wrap:break-word;}</style><div class=\"ttip\">"
+ // + "<style> p.ttip {width:350px;margin:-14px 0px -14px
+ // 0px;padding:2px;overflow-wrap:break-word;}"
+ // + "</style><p class=\"ttip\">"
+ + ttext + "</div>"
+ // + "</p>"
+ + ((enclose ? "</html>" : ""));
}
public static JButton makeButton(String label, String tooltip,
* @param entries
* @param tooltips
*/
- public static JComboBox<String> buildComboWithTooltips(
- List<String> entries, List<String> tooltips)
- {
- JComboBox<String> combo = new JComboBox<>();
- final ComboBoxTooltipRenderer renderer = new ComboBoxTooltipRenderer();
- combo.setRenderer(renderer);
- for (String attName : entries)
- {
- combo.addItem(attName);
- }
- renderer.setTooltips(tooltips);
- final MouseAdapter mouseListener = new MouseAdapter()
- {
- @Override
- public void mouseEntered(MouseEvent e)
- {
- int j = combo.getSelectedIndex();
- if (j > -1)
- {
- combo.setToolTipText(tooltips.get(j));
- }
- }
- @Override
- public void mouseExited(MouseEvent e)
- {
- combo.setToolTipText(null);
- }
- };
- for (Component c : combo.getComponents())
- {
- c.addMouseListener(mouseListener);
- }
- return combo;
- }
-
- /**
- * A helper method to build a drop-down choice of values, with tooltips for the
- * entries
- *
- * @param entries
- * @param tooltips
- */
- public static JComboBox<IntKeyStringValueEntry> buildIntKeyStringValueComboWithTooltips(
- List<IntKeyStringValueEntry> entries, List<String> tooltips)
+ public static JComboBox<Object> buildComboWithTooltips(
+ List<Object> entries, List<String> tooltips)
{
- JComboBox<IntKeyStringValueEntry> combo = new JComboBox<>();
+ JComboBox<Object> combo = new JComboBox<>();
final ComboBoxTooltipRenderer renderer = new ComboBoxTooltipRenderer();
combo.setRenderer(renderer);
- for (IntKeyStringValueEntry attName : entries)
+ for (Object attName : entries)
{
combo.addItem(attName);
}