X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FFeatureTypeSettings.java;h=01ef48c0ed8bdd3b79ba58f8c25fd872929652f5;hb=d5888333a51923fe86a35262e11be07c22e2798b;hp=c3567315ab2564ad590d06ae805777f972a527a4;hpb=b320470d1ddb95476d3678477b72f6f791a51404;p=jalview.git diff --git a/src/jalview/gui/FeatureTypeSettings.java b/src/jalview/gui/FeatureTypeSettings.java index c356731..01ef48c 100644 --- a/src/jalview/gui/FeatureTypeSettings.java +++ b/src/jalview/gui/FeatureTypeSettings.java @@ -199,13 +199,11 @@ public class FeatureTypeSettings extends JalviewDialog */ private List filters; - // set white normally, black to debug layout - private Color debugBorderColour = Color.white; - private JPanel chooseFiltersPanel; - private JTabbedPane tabbedPane; - + // for alternative 2 tabs layout (Colour, Filters) +// private JTabbedPane tabbedPane; + /** * Constructor * @@ -256,7 +254,7 @@ public class FeatureTypeSettings extends JalviewDialog String title = MessageManager .formatMessage("label.display_settings_for", new String[] { theType }); - initDialogFrame(this, true, blocking, title, 600, 360); + initDialogFrame(this, true, blocking, title, 500, 500); waitForInput(); } @@ -295,8 +293,8 @@ public class FeatureTypeSettings extends JalviewDialog if (fc.isColourByAttribute()) { String[] attributeName = fc.getAttributeName(); - colourByTextCombo - .setSelectedItem(toAttributeDisplayName(attributeName)); + colourByTextCombo.setSelectedItem( + FeatureMatcher.toAttributeDisplayName(attributeName)); } else { @@ -325,6 +323,7 @@ public class FeatureTypeSettings extends JalviewDialog * Graduated colour, by score or attribute value range */ graduatedColour.setSelected(true); + updateColourMinMax(); // ensure min, max are set colourByRangeCombo.setEnabled(colourByRangeCombo.getItemCount() > 1); minColour.setEnabled(true); maxColour.setEnabled(true); @@ -336,8 +335,8 @@ public class FeatureTypeSettings extends JalviewDialog if (fc.isColourByAttribute()) { String[] attributeName = fc.getAttributeName(); - colourByRangeCombo - .setSelectedItem(toAttributeDisplayName(attributeName)); + colourByRangeCombo.setSelectedItem( + FeatureMatcher.toAttributeDisplayName(attributeName)); } else { @@ -402,8 +401,8 @@ public class FeatureTypeSettings extends JalviewDialog private void initialise() { this.setLayout(new BorderLayout()); - tabbedPane = new JTabbedPane(); - this.add(tabbedPane, BorderLayout.CENTER); +// tabbedPane = new JTabbedPane(); +// this.add(tabbedPane, BorderLayout.CENTER); /* * an ActionListener that applies colour changes @@ -418,18 +417,20 @@ public class FeatureTypeSettings extends JalviewDialog }; /* - * first tab: colour options + * first panel/tab: colour options */ JPanel coloursPanel = initialiseColoursPanel(); - tabbedPane.addTab(MessageManager.getString("action.colour"), - coloursPanel); +// tabbedPane.addTab(MessageManager.getString("action.colour"), +// coloursPanel); + this.add(coloursPanel, BorderLayout.NORTH); /* - * second tab: filter options + * second panel/tab: filter options */ JPanel filtersPanel = initialiseFiltersPanel(); - tabbedPane.addTab(MessageManager.getString("label.filters"), - filtersPanel); +// tabbedPane.addTab(MessageManager.getString("label.filters"), +// filtersPanel); + this.add(filtersPanel, BorderLayout.CENTER); JPanel okCancelPanel = initialiseOkCancelPanel(); @@ -478,7 +479,7 @@ public class FeatureTypeSettings extends JalviewDialog { // colour by attribute range minMax = FeatureAttributes.getInstance().getMinMax(featureType, - fromAttributeDisplayName(attName)); + FeatureMatcher.fromAttributeDisplayName(attName)); } return minMax; } @@ -735,15 +736,18 @@ public class FeatureTypeSettings extends JalviewDialog private JPanel initialiseColoursPanel() { JPanel colourByPanel = new JPanel(); + colourByPanel.setBackground(Color.white); colourByPanel.setLayout(new BoxLayout(colourByPanel, BoxLayout.Y_AXIS)); + JvSwingUtils.createTitledBorder(colourByPanel, + MessageManager.getString("action.colour"), true); /* * simple colour radio button and colour picker */ JPanel simpleColourPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); simpleColourPanel.setBackground(Color.white); - JvSwingUtils.createTitledBorder(simpleColourPanel, - MessageManager.getString("label.simple"), true); +// JvSwingUtils.createTitledBorder(simpleColourPanel, +// MessageManager.getString("label.simple"), true); colourByPanel.add(simpleColourPanel); simpleColour = new JRadioButton( @@ -907,7 +911,8 @@ public class FeatureTypeSettings extends JalviewDialog String byWhat = (String) colourByTextCombo.getSelectedItem(); if (!LABEL_18N.equals(byWhat)) { - fc.setAttributeName(fromAttributeDisplayName(byWhat)); + fc.setAttributeName( + FeatureMatcher.fromAttributeDisplayName(byWhat)); } return fc; } @@ -964,7 +969,7 @@ public class FeatureTypeSettings extends JalviewDialog String byWhat = (String) colourByRangeCombo.getSelectedItem(); if (!SCORE_18N.equals(byWhat)) { - fc.setAttributeName(fromAttributeDisplayName(byWhat)); + fc.setAttributeName(FeatureMatcher.fromAttributeDisplayName(byWhat)); } /* @@ -989,30 +994,6 @@ public class FeatureTypeSettings extends JalviewDialog return fc; } - /** - * A helper method that converts a 'compound' attribute name from its display - * form, e.g. CSQ:PolyPhen to array form, e.g. { "CSQ", "PolyPhen" } - * - * @param attribute - * @return - */ - private String[] fromAttributeDisplayName(String attribute) - { - return attribute == null ? null : attribute.split(COLON); - } - - /** - * A helper method that converts a 'compound' attribute name to its display - * form, e.g. CSQ:PolyPhen from its array form, e.g. { "CSQ", "PolyPhen" } - * - * @param attName - * @return - */ - private String toAttributeDisplayName(String[] attName) - { - return attName == null ? "" : String.join(COLON, attName); - } - @Override protected void raiseClosed() { @@ -1159,7 +1140,7 @@ public class FeatureTypeSettings extends JalviewDialog { continue; } - displayAtts.add(toAttributeDisplayName(attName)); + displayAtts.add(FeatureMatcher.toAttributeDisplayName(attName)); String desc = fa.getDescription(featureType, attName); if (desc != null && desc.length() > MAX_TOOLTIP_LENGTH) { @@ -1210,7 +1191,6 @@ public class FeatureTypeSettings extends JalviewDialog { JPanel andOrPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); andOrPanel.setBackground(Color.white); - andOrPanel.setBorder(BorderFactory.createLineBorder(debugBorderColour)); andFilters = new JRadioButton(MessageManager.getString("label.and")); orFilters = new JRadioButton(MessageManager.getString("label.or")); ActionListener actionListener = new ActionListener() @@ -1293,7 +1273,6 @@ public class FeatureTypeSettings extends JalviewDialog for (FeatureMatcherI filter : filters) { JPanel row = addFilter(filter, attNames, filterIndex); - row.setBorder(BorderFactory.createLineBorder(debugBorderColour)); chooseFiltersPanel.add(row); filterIndex++; } @@ -1383,7 +1362,8 @@ public class FeatureTypeSettings extends JalviewDialog } else { - attCombo.setSelectedItem(toAttributeDisplayName(attName)); + attCombo.setSelectedItem( + FeatureMatcher.toAttributeDisplayName(attName)); } attCombo.addItemListener(new ItemListener() { @@ -1429,16 +1409,13 @@ public class FeatureTypeSettings extends JalviewDialog * disable pattern field for condition 'Present / NotPresent' */ Condition selectedCondition = (Condition) condCombo.getSelectedItem(); - if (!selectedCondition.needsAPattern()) - { - patternField.setEnabled(false); - } + patternField.setEnabled(selectedCondition.needsAPattern()); /* * if a numeric condition is selected, show the value range * as a tooltip on the value input field */ - setPatternTooltip(filterBy, selectedCondition, patternField); + setNumericHints(filterBy, selectedCondition, patternField); /* * add remove button if filter is populated (non-empty pattern) @@ -1486,21 +1463,26 @@ public class FeatureTypeSettings extends JalviewDialog } else { - item = toAttributeDisplayName(filter.getAttribute()); + item = FeatureMatcher.toAttributeDisplayName(filter.getAttribute()); } attCombo.setSelectedItem(item); return item; } /** - * If a numeric comparison condition is selected, retrieve the min-max range for - * the value (score or attribute), and set it as a tooltip on the value file + * If a numeric comparison condition is selected, retrieves the min-max range + * for the value (score or attribute), and sets it as a tooltip on the value + * field. If the field is currently empty, then pre-populates it with + * * * @param attName * @param selectedCondition * @param patternField */ - private void setPatternTooltip(String attName, + private void setNumericHints(String attName, Condition selectedCondition, JTextField patternField) { patternField.setToolTipText(""); @@ -1510,9 +1492,26 @@ public class FeatureTypeSettings extends JalviewDialog float[] minMax = getMinMax(attName); if (minMax != null) { - String tip = String.format("(%s - %s)", - DECFMT_2_2.format(minMax[0]), DECFMT_2_2.format(minMax[1])); + String minFormatted = DECFMT_2_2.format(minMax[0]); + String maxFormatted = DECFMT_2_2.format(minMax[1]); + String tip = String.format("(%s - %s)", minFormatted, maxFormatted); patternField.setToolTipText(tip); + if (patternField.getText().isEmpty()) + { + if (selectedCondition == Condition.GE + || selectedCondition == Condition.GT) + { + patternField.setText(minFormatted); + } + else + { + if (selectedCondition == Condition.LE + || selectedCondition == Condition.LT) + { + patternField.setText(maxFormatted); + } + } + } } } } @@ -1533,7 +1532,7 @@ public class FeatureTypeSettings extends JalviewDialog JComboBox condCombo, JTextField patternField) { Datatype type = FeatureAttributes.getInstance().getDatatype(featureType, - fromAttributeDisplayName(attName)); + FeatureMatcher.fromAttributeDisplayName(attName)); if (LABEL_18N.equals(attName)) { type = Datatype.Character; @@ -1549,10 +1548,11 @@ public class FeatureTypeSettings extends JalviewDialog ItemListener listener = condCombo.getItemListeners()[0]; condCombo.removeItemListener(listener); boolean condIsValid = false; + condCombo.removeAllItems(); for (Condition c : Condition.values()) { - if ((c.isNumeric() && type != Datatype.Character) + if ((c.isNumeric() && type == Datatype.Number) || (!c.isNumeric() && type != Datatype.Number)) { condCombo.addItem(c); @@ -1575,8 +1575,6 @@ public class FeatureTypeSettings extends JalviewDialog condCombo.setSelectedIndex(0); } - condCombo.addItemListener(listener); - /* * clear pattern if it is now invalid for condition */ @@ -1594,6 +1592,11 @@ public class FeatureTypeSettings extends JalviewDialog patternField.setText(""); } } + + /* + * restore the listener + */ + condCombo.addItemListener(listener); } /** @@ -1670,10 +1673,11 @@ public class FeatureTypeSettings extends JalviewDialog Condition cond = (Condition) condCombo.getSelectedItem(); String pattern = valueField.getText().trim(); - setPatternTooltip(attName, cond, valueField); + setNumericHints(attName, cond, valueField); if (pattern.length() == 0 && cond.needsAPattern()) { + valueField.setEnabled(true); // ensure pattern field is enabled! return false; } @@ -1693,7 +1697,7 @@ public class FeatureTypeSettings extends JalviewDialog else { km = FeatureMatcher.byAttribute(cond, pattern, - fromAttributeDisplayName(attName)); + FeatureMatcher.fromAttributeDisplayName(attName)); } filters.set(filterIndex, km); @@ -1709,7 +1713,7 @@ public class FeatureTypeSettings extends JalviewDialog public void showTab(boolean coloursTab) { setVisible(true); - tabbedPane.setSelectedIndex(coloursTab ? 0 : 1); +// tabbedPane.setSelectedIndex(coloursTab ? 0 : 1); } /**