package jalview.appletgui; import jalview.datamodel.AlignmentAnnotation; import jalview.schemes.AnnotationColourGradient; import jalview.util.MessageManager; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollBar; import javax.swing.JTextField; import java.awt.event.ActionEvent; import java.util.Vector; @SuppressWarnings("serial") public abstract class AnnotationRowFilter extends JPanel { protected AlignViewport av; protected AlignmentPanel ap; protected int[] annmap; protected boolean enableSeqAss = false; private AlignmentAnnotation currentAnnotation; protected boolean adjusting = false; protected JCheckBox currentColours = new JCheckBox(); protected JPanel minColour = new JPanel(); protected JPanel maxColour = new JPanel(); protected JCheckBox seqAssociated = new JCheckBox(); protected JCheckBox thresholdIsMin = new JCheckBox(); protected JScrollBar slider = new JScrollBar(JScrollBar.HORIZONTAL); protected JTextField thresholdValue = new JTextField(20); protected JFrame frame; protected JButton ok = new JButton(); protected JButton cancel = new JButton(); /** * enabled if the user is dragging the slider - try to keep updates to a * minimun */ protected boolean sliderDragging = false; public AnnotationRowFilter(AlignViewport av, final AlignmentPanel ap) { this.av = av; this.ap = ap; } public AnnotationRowFilter() { } public Vector getAnnotationItems(boolean isSeqAssociated) { Vector list = new Vector(); int index = 1; int[] anmap = new int[av.getAlignment().getAlignmentAnnotation().length]; for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++) { if (av.getAlignment().getAlignmentAnnotation()[i].sequenceRef == null) { if (isSeqAssociated) { continue; } } else { enableSeqAss = true; } String label = av.getAlignment().getAlignmentAnnotation()[i].label; if (!list.contains(label)) { anmap[list.size()] = i; list.add(label); } else { if (!isSeqAssociated) { anmap[list.size()] = i; list.add(label + "_" + (index++)); } } } this.annmap = new int[list.size()]; System.arraycopy(anmap, 0, this.annmap, 0, this.annmap.length); return list; } protected int getSelectedThresholdItem(int indexValue) { int selectedThresholdItem = -1; if (indexValue == 1) { selectedThresholdItem = AnnotationColourGradient.ABOVE_THRESHOLD; } else if (indexValue == 2) { selectedThresholdItem = AnnotationColourGradient.BELOW_THRESHOLD; } return selectedThresholdItem; } public void modelChanged() { seqAssociated.setEnabled(enableSeqAss); } public void ok_actionPerformed(ActionEvent e) { updateView(); frame.setVisible(false); } public void cancel_actionPerformed(ActionEvent e) { reset(); ap.paintAlignment(true); frame.setVisible(false); } public void thresholdCheck_actionPerformed(ActionEvent e) { updateView(); } public void annotations_actionPerformed(ActionEvent e) { updateView(); } public void threshold_actionPerformed(ActionEvent e) { updateView(); } public void thresholdValue_actionPerformed(ActionEvent e) { try { float f = Float.parseFloat(thresholdValue.getText()); slider.setValue((int) (f * 1000)); updateView(); } catch (NumberFormatException ex) { } } protected void populateThresholdComboBox(Choice threshold) { threshold.addItem(MessageManager .getString("label.threshold_feature_no_thereshold")); threshold.addItem(MessageManager .getString("label.threshold_feature_above_thereshold")); threshold.addItem(MessageManager .getString("label.threshold_feature_below_thereshold")); } public AlignmentAnnotation getCurrentAnnotation() { return currentAnnotation; } public void setCurrentAnnotation(AlignmentAnnotation currentAnnotation) { this.currentAnnotation = currentAnnotation; } public abstract void valueChanged(boolean updateAllAnnotation); public abstract void updateView(); public abstract void reset(); }