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