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