--- /dev/null
+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 <table width=350><tr><td></td> field
+ * @param ttext
+ * @return
+ */
+ public static String wrapTooltip(String ttext)
+ {
+ if (ttext.length()<60)
+ {
+ return ttext;
+ } else {
+ return "<table width=350 border=0><tr><td>"+ttext+"</td></tr></table>";
+ }
+ }
+ 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;
+ }
+
+}
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()
{
update_actionPerformed(e);
}
});
- deletepref = makeButton("Delete", "Delete the user preference",
+ deletepref = JvSwingUtils.makeButton("Delete", "Delete the user preference",
new ActionListener()
{
delete_actionPerformed(e);
}
});
- createpref = makeButton("Create", "Create a new preference",
+ createpref = JvSwingUtils.makeButton("Create", "Create a new preference",
new ActionListener()
{
create_actionPerformed(e);
}
});
- revertpref = makeButton("Revert",
+ revertpref = JvSwingUtils.makeButton("Revert",
"Undo all changes to the current set", new ActionListener()
{
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)
{
finfo = parm.getFurtherDetails();
if (finfo != null)
{
- showDesc.setToolTipText("<html><p>Click to show brief description<br><img src=\"" + linkImageURL + "\"/> Right click for further information.</p></html>");
+ showDesc.setToolTipText("<html>"+JvSwingUtils.wrapTooltip("Click to show brief description<br><img src=\"" + linkImageURL + "\"/> Right click for further information.")+"</html>");
showDesc.addMouseListener(this);
}
else
{
- showDesc.setToolTipText("<html><p>Click to show brief description.</p></html>");
+ showDesc.setToolTipText("<html>"+JvSwingUtils.wrapTooltip("Click to show brief description.")+"</html>");
}
showDesc.addActionListener(new ActionListener()
{
{
hasLink = true;
// optlabel.setToolTipText("<html><p>"+opt.getDescription()+"</p><img src=\""+linkImageURL+"\"/></html>");
- enabled.setToolTipText("<html><p>" + opt.getDescription()
- + "</p><img src=\"" + linkImageURL + "\"/></html>");
+ enabled.setToolTipText("<html>" + JvSwingUtils.wrapTooltip(opt.getDescription()+"<br><img src=\"" + linkImageURL + "\"/>")
+ + "</html>");
// optlabel.addMouseListener(this);
enabled.addMouseListener(this);
}
else
{
// optlabel.setToolTipText(opt.getDescription());
- enabled.setToolTipText(opt.getDescription());
+ enabled.setToolTipText("<html>"+JvSwingUtils.wrapTooltip(opt.getDescription())+"</html>");
}
add(enabled, BorderLayout.NORTH);
if (opt.getPossibleValues().size() > 1)
{
isUserPreset = false;
// Service defaults
+ setDescr.setText("");
updateTable(null, null);
lastParmSet = SVC_DEF;
}