From: jprocter Date: Thu, 9 Sep 2010 15:32:45 +0000 (+0000) Subject: wrap tooltips X-Git-Tag: Release_2_6~56 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=286a98d09d3a0848c23a00a4d57f783a1be2e6a9;p=jalview.git wrap tooltips --- diff --git a/src/jalview/gui/JvSwingUtils.java b/src/jalview/gui/JvSwingUtils.java new file mode 100644 index 0000000..9a9c2f5 --- /dev/null +++ b/src/jalview/gui/JvSwingUtils.java @@ -0,0 +1,45 @@ +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; + } + +} diff --git a/src/jalview/gui/WsJobParameters.java b/src/jalview/gui/WsJobParameters.java index 5c12187..2da6106 100644 --- a/src/jalview/gui/WsJobParameters.java +++ b/src/jalview/gui/WsJobParameters.java @@ -237,22 +237,10 @@ public class WsJobParameters extends JPanel implements ItemListener, return false; } - protected JButton makeButton(String label, String tooltip, - ActionListener action) - { - JButton button = new JButton(); - button.setText(label); - 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; - } private void jbInit() { - updatepref = makeButton("Update", "Update the stored user preference", + updatepref = JvSwingUtils.makeButton("Update", "Update the stored user preference", new ActionListener() { @@ -261,7 +249,7 @@ public class WsJobParameters extends JPanel implements ItemListener, update_actionPerformed(e); } }); - deletepref = makeButton("Delete", "Delete the user preference", + deletepref = JvSwingUtils.makeButton("Delete", "Delete the user preference", new ActionListener() { @@ -270,7 +258,7 @@ public class WsJobParameters extends JPanel implements ItemListener, delete_actionPerformed(e); } }); - createpref = makeButton("Create", "Create a new preference", + createpref = JvSwingUtils.makeButton("Create", "Create a new preference", new ActionListener() { @@ -279,7 +267,7 @@ public class WsJobParameters extends JPanel implements ItemListener, create_actionPerformed(e); } }); - revertpref = makeButton("Revert", + revertpref = JvSwingUtils.makeButton("Revert", "Undo all changes to the current set", new ActionListener() { @@ -288,20 +276,14 @@ public class WsJobParameters extends JPanel implements ItemListener, revert_actionPerformed(e); } }); - startjob.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); - startjob.setText("Start"); - startjob.setToolTipText("Start Job"); - startjob.addActionListener(new ActionListener() + startjob = JvSwingUtils.makeButton("Start", "Start Job",new ActionListener() { public void actionPerformed(ActionEvent e) { startjob_actionPerformed(e); } }); - canceljob.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); - canceljob.setText("Cancel"); - canceljob.setToolTipText("Cancel Job"); - canceljob.addActionListener(new ActionListener() + canceljob = JvSwingUtils.makeButton("Cancel", "Cancel Job", new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -875,12 +857,12 @@ public class WsJobParameters extends JPanel implements ItemListener, finfo = parm.getFurtherDetails(); if (finfo != null) { - showDesc.setToolTipText("

Click to show brief description
Right click for further information.

"); + showDesc.setToolTipText(""+JvSwingUtils.wrapTooltip("Click to show brief description
Right click for further information.")+""); showDesc.addMouseListener(this); } else { - showDesc.setToolTipText("

Click to show brief description.

"); + showDesc.setToolTipText(""+JvSwingUtils.wrapTooltip("Click to show brief description.")+""); } showDesc.addActionListener(new ActionListener() { @@ -1228,15 +1210,15 @@ public class WsJobParameters extends JPanel implements ItemListener, { hasLink = true; // optlabel.setToolTipText("

"+opt.getDescription()+"

"); - enabled.setToolTipText("

" + opt.getDescription() - + "

"); + enabled.setToolTipText("" + JvSwingUtils.wrapTooltip(opt.getDescription()+"
") + + ""); // optlabel.addMouseListener(this); enabled.addMouseListener(this); } else { // optlabel.setToolTipText(opt.getDescription()); - enabled.setToolTipText(opt.getDescription()); + enabled.setToolTipText(""+JvSwingUtils.wrapTooltip(opt.getDescription())+""); } add(enabled, BorderLayout.NORTH); if (opt.getPossibleValues().size() > 1) @@ -1764,6 +1746,7 @@ public class WsJobParameters extends JPanel implements ItemListener, { isUserPreset = false; // Service defaults + setDescr.setText(""); updateTable(null, null); lastParmSet = SVC_DEF; }