From 2e4b07838e7727d790ddb40e4381cb4ed1e84428 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Fri, 11 May 2018 16:34:35 +0100 Subject: [PATCH] JAL-2985 show label instead of checkbox for a required (Jalview) Option --- src/jalview/gui/OptsAndParamsPage.java | 83 +++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 28 deletions(-) diff --git a/src/jalview/gui/OptsAndParamsPage.java b/src/jalview/gui/OptsAndParamsPage.java index dcd07ef..1843f49 100644 --- a/src/jalview/gui/OptsAndParamsPage.java +++ b/src/jalview/gui/OptsAndParamsPage.java @@ -21,6 +21,7 @@ package jalview.gui; import jalview.util.MessageManager; +import jalview.ws.jws2.dm.JabaOption; import jalview.ws.params.ArgumentI; import jalview.ws.params.OptionI; import jalview.ws.params.ParameterI; @@ -115,41 +116,34 @@ public class OptsAndParamsPage JComboBox val; + /** + * Constructs and adds labels and controls to the panel for one Option + * + * @param opt + */ public OptionBox(OptionI opt) { option = opt; setLayout(new FlowLayout(FlowLayout.LEFT)); - enabled = new JCheckBox(); - enabled.setSelected(opt.isRequired()); // TODO: lock required options - enabled.setFont(new Font("Verdana", Font.PLAIN, 11)); - enabled.setText(""); - enabled.setText(opt.getName()); - enabled.addActionListener(this); - finfo = option.getFurtherDetails(); - String desc = opt.getDescription(); - if (finfo != null) - { - hasLink = true; + enabled = new JCheckBox(opt.getName()); + enabled.setSelected(opt.isRequired()); - enabled.setToolTipText(JvSwingUtils.wrapTooltip(true, - ((desc == null || desc.trim().length() == 0) - ? MessageManager.getString( - "label.opt_and_params_further_details") - : desc) + "
")); - enabled.addMouseListener(this); + /* + * If option is required, show a label, if optional a checkbox + * (but not for Jabaws pending JWS-126 resolution) + */ + if (opt.isRequired() && !(opt instanceof JabaOption)) + { + finfo = null; + add(new JLabel(opt.getName())); } else { - if (desc != null && desc.trim().length() > 0) - { - enabled.setToolTipText( - JvSwingUtils.wrapTooltip(true, opt.getDescription())); - } + finfo = option.getFurtherDetails(); + configureCheckbox(opt); + add(enabled); } - add(enabled); - // todo combo or radio buttons? val = new JComboBox<>(); for (String str : opt.getPossibleValues()) { @@ -161,12 +155,45 @@ public class OptsAndParamsPage val.addActionListener(this); add(val); } - // TODO: add actionListeners for popup (to open further info), - // and to update list of parameters if an option is enabled - // that takes a value. JBPNote: is this TODO still valid ? + setInitialValue(); } + /** + * Configures the checkbox that controls whether or not the option is + * selected + * + * @param opt + */ + protected void configureCheckbox(OptionI opt) + { + enabled.setFont(new Font("Verdana", Font.PLAIN, 11)); + enabled.addActionListener(this); + final String desc = opt.getDescription(); + if (finfo != null) + { + hasLink = true; + String description = desc; + if (desc == null || desc.trim().isEmpty()) + { + description = MessageManager + .getString("label.opt_and_params_further_details"); + } + description = description + "
"; + String text = JvSwingUtils.wrapTooltip(true, description); + enabled.setToolTipText(text); + enabled.addMouseListener(this); // for popup menu to show link + } + else + { + if (desc != null && desc.trim().length() > 0) + { + enabled.setToolTipText(JvSwingUtils.wrapTooltip(true, desc)); + } + } + } + @Override public void actionPerformed(ActionEvent e) { -- 1.7.10.2