9a9c2f556106d7c3befdbd9f8417f391549481c9
[jalview.git] / src / jalview / gui / JvSwingUtils.java
1 package jalview.gui;
2
3 import java.awt.Color;
4 import java.awt.Font;
5 import java.awt.event.ActionListener;
6
7 import javax.swing.JButton;
8 import javax.swing.SwingConstants;
9
10 /**
11  * useful functions for building Swing GUIs
12  * @author JimP
13  *
14  */
15 public final class JvSwingUtils
16 {
17   /**
18    * wrap a bare html safe string to around 60 characters per line using a <table width=350><tr><td></td> field 
19    * @param ttext
20    * @return
21    */
22   public static String wrapTooltip(String ttext)
23   {
24     if (ttext.length()<60)
25     {
26       return ttext;
27     } else {
28       return "<table width=350 border=0><tr><td>"+ttext+"</td></tr></table>";
29     }
30   }
31   public static JButton makeButton(String label, String tooltip,
32           ActionListener action)
33   {
34     JButton button = new JButton();
35     button.setText(label);
36     // TODO: get the base font metrics for the Jalview gui from somewhere
37     button.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
38     button.setForeground(Color.black);
39     button.setHorizontalAlignment(SwingConstants.CENTER);
40     button.setToolTipText(tooltip);
41     button.addActionListener(action);
42     return button;
43   }
44
45 }