JAL-3725 restrict mapped virtual feature location to mapped region
[jalview.git] / src / jalview / gui / JvSwingUtils.java
index ef96fa6..7a5dde6 100644 (file)
@@ -35,6 +35,7 @@ import java.util.List;
 import java.util.Objects;
 
 import javax.swing.AbstractButton;
+import javax.swing.BorderFactory;
 import javax.swing.JButton;
 import javax.swing.JComboBox;
 import javax.swing.JComponent;
@@ -44,6 +45,8 @@ import javax.swing.JMenuItem;
 import javax.swing.JPanel;
 import javax.swing.JScrollBar;
 import javax.swing.SwingConstants;
+import javax.swing.border.Border;
+import javax.swing.border.TitledBorder;
 
 /**
  * useful functions for building Swing GUIs
@@ -93,7 +96,7 @@ public final class JvSwingUtils
     }
 
     return (enclose ? "<html>" : "")
-            + "<style> p.ttip {width: 350; text-align: justify; word-wrap: break-word;}</style><p class=\"ttip\">"
+            + "<style> p.ttip {width: 350; text-align: left; word-wrap: break-word;}</style><p class=\"ttip\">"
             + ttext + "</p>" + ((enclose ? "</html>" : ""));
 
   }
@@ -316,13 +319,13 @@ public final class JvSwingUtils
    * @param entries
    * @param tooltips
    */
-  public static JComboBox<String> buildComboWithTooltips(
-          List<String> entries, List<String> tooltips)
+  public static JComboBox<Object> buildComboWithTooltips(
+          List<Object> entries, List<String> tooltips)
   {
-    JComboBox<String> combo = new JComboBox<>();
+    JComboBox<Object> combo = new JComboBox<>();
     final ComboBoxTooltipRenderer renderer = new ComboBoxTooltipRenderer();
     combo.setRenderer(renderer);
-    for (String attName : entries)
+    for (Object attName : entries)
     {
       combo.addItem(attName);
     }
@@ -351,4 +354,29 @@ public final class JvSwingUtils
     return combo;
   }
 
+  /**
+   * Adds a titled border to the component in the default font and position (top
+   * left), optionally witht italic text
+   * 
+   * @param comp
+   * @param title
+   * @param italic
+   */
+  public static TitledBorder createTitledBorder(JComponent comp,
+          String title, boolean italic)
+  {
+    Font font = comp.getFont();
+    if (italic)
+    {
+      font = new Font(font.getName(), Font.ITALIC, font.getSize());
+    }
+    Border border = BorderFactory.createTitledBorder("");
+    TitledBorder titledBorder = BorderFactory.createTitledBorder(border,
+            title, TitledBorder.LEADING, TitledBorder.DEFAULT_POSITION,
+            font);
+    comp.setBorder(titledBorder);
+
+    return titledBorder;
+  }
+
 }