X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAnnotationColumnChooser.java;h=6fc5fada40a2fa3ab2c23beb75ec76ab6c53fa8b;hb=d065bc916cb63af83cdab7319f5177a855724aba;hp=6cf359b700dbdb817e685eab58ce444937cc8bc3;hpb=14985603cea28569e295ddabb219da8034f1c7b2;p=jalview.git diff --git a/src/jalview/gui/AnnotationColumnChooser.java b/src/jalview/gui/AnnotationColumnChooser.java index 6cf359b..6fc5fad 100644 --- a/src/jalview/gui/AnnotationColumnChooser.java +++ b/src/jalview/gui/AnnotationColumnChooser.java @@ -21,8 +21,8 @@ package jalview.gui; -import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.HiddenColumns; +import jalview.io.cache.JvCacheableInputBox; import jalview.schemes.AnnotationColourGradient; import jalview.util.MessageManager; import jalview.viewmodel.annotationfilter.AnnotationFilterParameter; @@ -30,11 +30,13 @@ import jalview.viewmodel.annotationfilter.AnnotationFilterParameter; import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Color; +import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; -import java.util.Iterator; +import java.awt.event.KeyEvent; +import java.util.ArrayList; import javax.swing.ButtonGroup; import javax.swing.JCheckBox; @@ -43,10 +45,7 @@ import javax.swing.JInternalFrame; import javax.swing.JLayeredPane; import javax.swing.JPanel; import javax.swing.JRadioButton; -import javax.swing.JTextField; import javax.swing.border.TitledBorder; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; import net.miginfocom.swing.MigLayout; @@ -88,6 +87,10 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements private HiddenColumns oldHiddenColumns; + protected int MIN_WIDTH = 420; + + protected int MIN_HEIGHT = 430; + public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap) { super(av, ap); @@ -97,6 +100,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements Desktop.addInternalFrame(frame, MessageManager.getString("label.select_by_annotation"), 520, 215); + frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT)); addSliderChangeListener(); addSliderMouseListeners(); @@ -108,22 +112,25 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements setOldHiddenColumns(av.getAlignment().getHiddenColumns()); adjusting = true; - setAnnotations(new JComboBox(getAnnotationItems(false))); + setAnnotations(new JComboBox<>(getAnnotationItems(false))); populateThresholdComboBox(threshold); - + AnnotationColumnChooser lastChooser = av + .getAnnotationColumnSelectionState(); // restore Object state from the previous session if one exists - if (av.getAnnotationColumnSelectionState() != null) + if (lastChooser != null) { - currentSearchPanel = av.getAnnotationColumnSelectionState() + currentSearchPanel = lastChooser .getCurrentSearchPanel(); - currentStructureFilterPanel = av.getAnnotationColumnSelectionState() + currentStructureFilterPanel = lastChooser .getCurrentStructureFilterPanel(); - annotations.setSelectedIndex(av.getAnnotationColumnSelectionState() + annotations.setSelectedIndex(lastChooser .getAnnotations().getSelectedIndex()); - threshold.setSelectedIndex(av.getAnnotationColumnSelectionState() + threshold.setSelectedIndex(lastChooser .getThreshold().getSelectedIndex()); - actionOption = av.getAnnotationColumnSelectionState() + actionOption = lastChooser .getActionOption(); + percentThreshold.setSelected(lastChooser.percentThreshold + .isSelected()); } try @@ -151,6 +158,9 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements thresholdPanel.setFont(JvSwingUtils.getLabelFont()); thresholdPanel.setLayout(new MigLayout("", "[left][right]", "[][]")); + percentThreshold.setBackground(Color.white); + percentThreshold.setFont(JvSwingUtils.getLabelFont()); + JPanel actionPanel = new JPanel(); actionPanel.setBackground(Color.white); actionPanel.setFont(JvSwingUtils.getLabelFont()); @@ -174,8 +184,9 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements ngStructureFilterPanel = new StructureFilterPanel(this); thresholdPanel.add(getThreshold()); - thresholdPanel.add(thresholdValue, "wrap"); - thresholdPanel.add(slider, "grow, span, wrap"); + thresholdPanel.add(percentThreshold, "wrap"); + thresholdPanel.add(slider, "grow"); + thresholdPanel.add(thresholdValue, "span, wrap"); actionPanel.add(ok); actionPanel.add(cancel); @@ -233,21 +244,21 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements HiddenColumns oldHidden = av .getAnnotationColumnSelectionState() .getOldHiddenColumns(); - if (oldHidden != null && oldHidden.getHiddenRegions() != null - && !oldHidden.getHiddenRegions().isEmpty()) + if (oldHidden != null) { - for (Iterator itr = oldHidden.getHiddenRegions() - .iterator(); itr.hasNext();) + ArrayList regions = oldHidden.getHiddenColumnsCopy(); + for (int[] positions : regions) { - int positions[] = itr.next(); av.hideColumns(positions[0], positions[1]); } } + // TODO not clear why we need to hide all the columns (above) if we are + // going to copy the hidden columns over wholesale anyway av.getAlignment().setHiddenColumns(oldHidden); } + av.sendSelection(); ap.paintAlignment(true); } - } @Override @@ -282,12 +293,14 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements slider.setEnabled(true); thresholdValue.setEnabled(true); + percentThreshold.setEnabled(true); if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD) { slider.setEnabled(false); thresholdValue.setEnabled(false); thresholdValue.setText(""); + percentThreshold.setEnabled(false); // build filter params } else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD) @@ -308,7 +321,9 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000)); slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000)); slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000)); - thresholdValue.setText(getCurrentAnnotation().threshold.value + ""); + + setThresholdValueText(); + slider.setMajorTickSpacing((int) (range / 10f)); slider.setEnabled(true); thresholdValue.setEnabled(true); @@ -317,7 +332,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements // build filter params filterParams .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD); - if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH) + if (getCurrentAnnotation().isQuantitative()) { filterParams .setThresholdValue(getCurrentAnnotation().threshold.value); @@ -354,12 +369,10 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements if (currentSearchPanel != null) { - - if (!currentSearchPanel.searchBox.getText().isEmpty()) + if (!currentSearchPanel.searchBox.getUserInput().isEmpty()) { - currentSearchPanel.description.setEnabled(true); - currentSearchPanel.displayName.setEnabled(true); - filterParams.setRegexString(currentSearchPanel.searchBox.getText()); + filterParams.setRegexString(currentSearchPanel.searchBox + .getUserInput()); if (currentSearchPanel.displayName.isSelected()) { filterParams @@ -371,21 +384,20 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION); } } - else - { - currentSearchPanel.description.setEnabled(false); - currentSearchPanel.displayName.setEnabled(false); - } } + // show hidden columns here, before changing the column selection in + // filterAnnotations, because showing hidden columns has the side effect of + // adding them to the selection + av.showAllHiddenColumns(); av.getColumnSelection().filterAnnotations( getCurrentAnnotation().annotations, filterParams); - av.showAllHiddenColumns(); if (getActionOption() == ACTION_OPTION_HIDE) { av.hideSelectedColumns(); } + av.sendSelection(); filterParams = null; av.setAnnotationColumnSelectionState(this); @@ -477,12 +489,13 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements public void selectedAnnotationChanged() { String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW; - if (av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations() - .getSelectedIndex()]].graph != AlignmentAnnotation.NO_GRAPH) + if (av.getAlignment() + .getAlignmentAnnotation()[annmap[getAnnotations() + .getSelectedIndex()]].isQuantitative()) { currentView = AnnotationColumnChooser.GRAPH_VIEW; } - + saveCache(); gSearchPanel.syncState(); gFurtherActionPanel.syncState(); gStructureFilterPanel.syncState(); @@ -713,7 +726,10 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements private JCheckBox description = new JCheckBox(); - private JTextField searchBox = new JTextField(10); + private static final String FILTER_BY_ANN_CACHE_KEY = "CACHE.SELECT_FILTER_BY_ANNOT"; + + public JvCacheableInputBox searchBox = new JvCacheableInputBox<>( + FILTER_BY_ANN_CACHE_KEY); public SearchPanel(AnnotationColumnChooser aColChooser) { @@ -723,32 +739,26 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements this.setBorder(new TitledBorder(MessageManager .getString("label.search_filter"))); - JvSwingUtils.jvInitComponent(searchBox); + searchBox.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXX"); searchBox.setToolTipText(MessageManager .getString("info.enter_search_text_here")); - searchBox.getDocument().addDocumentListener(new DocumentListener() - { - @Override - public void insertUpdate(DocumentEvent e) - { - searchStringAction(); - } + searchBox.getEditor().getEditorComponent() + .addKeyListener(new java.awt.event.KeyAdapter() + { + @Override + public void keyPressed(KeyEvent e) + { + if (e.getKeyCode() == KeyEvent.VK_ENTER) + { + e.consume(); + searchStringAction(); + } + } + }); - @Override - public void removeUpdate(DocumentEvent e) - { - searchStringAction(); - } - @Override - public void changedUpdate(DocumentEvent e) - { - searchStringAction(); - } - }); JvSwingUtils.jvInitComponent(displayName, "label.label"); - displayName.setEnabled(false); displayName.addActionListener(new ActionListener() { @Override @@ -759,7 +769,6 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements }); JvSwingUtils.jvInitComponent(description, "label.description"); - description.setEnabled(false); description.addActionListener(new ActionListener() { @Override @@ -792,6 +801,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements aColChooser.setCurrentSearchPanel(this); aColChooser.updateView(); updateSearchPanelToolTips(); + searchBox.updateCache(); } public void syncState() @@ -805,7 +815,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements displayName.setEnabled(sp.displayName.isEnabled()); displayName.setSelected(sp.displayName.isSelected()); - searchBox.setText(sp.searchBox.getText()); + searchBox.setSelectedItem(sp.searchBox.getUserInput()); } updateSearchPanelToolTips(); } @@ -827,4 +837,25 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements } } + @Override + public void ok_actionPerformed() + { + saveCache(); + super.ok_actionPerformed(); + } + + @Override + public void cancel_actionPerformed() + { + saveCache(); + super.cancel_actionPerformed(); + } + + private void saveCache() + { + gSearchPanel.searchBox.persistCache(); + ngSearchPanel.searchBox.persistCache(); + gSearchPanel.searchBox.updateCache(); + ngSearchPanel.searchBox.updateCache(); + } }