JAL-1553 added applet support for the select-column-by-annotation-row feature
[jalview.git] / src / jalview / appletgui / AnnotationRowFilter.java
1 package jalview.appletgui;
2
3 import jalview.schemes.AnnotationColourGradient;
4 import jalview.util.MessageManager;
5
6 import java.awt.Button;
7 import java.awt.Checkbox;
8 import java.awt.Choice;
9 import java.awt.Frame;
10 import java.awt.Panel;
11 import java.awt.Scrollbar;
12 import java.awt.TextField;
13 import java.awt.event.ActionEvent;
14 import java.util.Vector;
15
16
17
18 @SuppressWarnings("serial")
19 public abstract class AnnotationRowFilter extends Panel
20 {
21   protected AlignViewport av;
22
23   protected AlignmentPanel ap;
24
25   protected int[] annmap;
26
27   protected boolean enableSeqAss = false;
28
29   private jalview.datamodel.AlignmentAnnotation currentAnnotation;
30
31   protected boolean adjusting = false;
32
33   protected Checkbox currentColours = new Checkbox();
34
35   protected Panel minColour = new Panel();
36
37   protected Panel maxColour = new Panel();
38
39   protected Checkbox seqAssociated = new Checkbox();
40
41   protected Checkbox thresholdIsMin = new Checkbox();
42
43   protected Scrollbar slider = new Scrollbar(Scrollbar.HORIZONTAL);
44
45   protected TextField thresholdValue = new TextField(20);
46
47   protected Frame frame;
48
49   protected Button ok = new Button();
50
51   protected Button cancel = new Button();
52
53   /**
54    * enabled if the user is dragging the slider - try to keep updates to a
55    * minimun
56    */
57   protected boolean sliderDragging = false;
58
59
60   public AnnotationRowFilter(AlignViewport av, final AlignmentPanel ap)
61   {
62     this.av = av;
63     this.ap = ap;
64   }
65
66   public AnnotationRowFilter()
67   {
68
69   }
70
71
72   public Vector getAnnotationItems(boolean isSeqAssociated)
73   {
74     Vector list = new Vector();
75     int index = 1;
76     int[] anmap = new int[av.getAlignment().getAlignmentAnnotation().length];
77     for (int i = 0; i < av.getAlignment().getAlignmentAnnotation().length; i++)
78     {
79       if (av.getAlignment().getAlignmentAnnotation()[i].sequenceRef == null)
80       {
81         if (isSeqAssociated)
82         {
83           continue;
84         }
85       }
86       else
87       {
88         enableSeqAss = true;
89       }
90       String label = av.getAlignment().getAlignmentAnnotation()[i].label;
91       if (!list.contains(label))
92       {
93         anmap[list.size()] = i;
94         list.add(label);
95
96       }
97       else
98       {
99         if (!isSeqAssociated)
100         {
101           anmap[list.size()] = i;
102           list.add(label + "_" + (index++));
103         }
104       }
105     }
106     this.annmap = new int[list.size()];
107     System.arraycopy(anmap, 0, this.annmap, 0, this.annmap.length);
108     return list;
109   }
110
111   protected int getSelectedThresholdItem(int indexValue)
112   {
113     int selectedThresholdItem = -1;
114     if (indexValue == 1)
115     {
116       selectedThresholdItem = AnnotationColourGradient.ABOVE_THRESHOLD;
117     }
118     else if (indexValue == 2)
119     {
120       selectedThresholdItem = AnnotationColourGradient.BELOW_THRESHOLD;
121     }
122     return selectedThresholdItem;
123   }
124
125   public void modelChanged()
126   {
127     seqAssociated.setEnabled(enableSeqAss);
128   }
129
130   public void ok_actionPerformed(ActionEvent e)
131   {
132     updateView();
133     frame.setVisible(false);
134   }
135
136   public void cancel_actionPerformed(ActionEvent e)
137   {
138     reset();
139     ap.paintAlignment(true);
140     frame.setVisible(false);
141   }
142
143   public void thresholdCheck_actionPerformed(ActionEvent e)
144   {
145     updateView();
146   }
147
148   public void annotations_actionPerformed(ActionEvent e)
149   {
150     updateView();
151   }
152
153   public void threshold_actionPerformed(ActionEvent e)
154   {
155     updateView();
156   }
157
158   public void thresholdValue_actionPerformed(ActionEvent e)
159   {
160     try
161     {
162       float f = Float.parseFloat(thresholdValue.getText());
163       slider.setValue((int) (f * 1000));
164       updateView();
165     } catch (NumberFormatException ex)
166     {
167     }
168   }
169
170
171   protected void populateThresholdComboBox(Choice threshold)
172   {
173     threshold.addItem(MessageManager
174             .getString("label.threshold_feature_no_thereshold"));
175     threshold.addItem(MessageManager
176             .getString("label.threshold_feature_above_thereshold"));
177     threshold.addItem(MessageManager
178             .getString("label.threshold_feature_below_thereshold"));
179   }
180
181
182   public jalview.datamodel.AlignmentAnnotation getCurrentAnnotation()
183   {
184     return currentAnnotation;
185   }
186
187   public void setCurrentAnnotation(
188           jalview.datamodel.AlignmentAnnotation currentAnnotation)
189   {
190     this.currentAnnotation = currentAnnotation;
191   }
192
193   public abstract void valueChanged(boolean updateAllAnnotation);
194
195   public abstract void updateView();
196
197   public abstract void reset();
198 }