/* * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6) * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle * * This file is part of Jalview. * * Jalview is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * Jalview is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with Jalview. If not, see . */ package jalview.gui; import java.awt.Color; import java.awt.Font; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.SwingConstants; /** * useful functions for building Swing GUIs * @author JimP * */ public final class JvSwingUtils { /** * wrap a bare html safe string to around 60 characters per line using a field * @param ttext * @return */ public static String wrapTooltip(String ttext) { if (ttext.length()<60) { return ttext; } else { return "
"+ttext+"
"; } } public static JButton makeButton(String label, String tooltip, ActionListener action) { JButton button = new JButton(); button.setText(label); // TODO: get the base font metrics for the Jalview gui from somewhere button.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); button.setForeground(Color.black); button.setHorizontalAlignment(SwingConstants.CENTER); button.setToolTipText(tooltip); button.addActionListener(action); return button; } }