JAL-1807 update
[jalviewjs.git] / unused / 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 javax.swing.JButton;
8 import javax.swing.JCheckBox;
9 import javax.swing.JFrame;
10 import javax.swing.JPanel;
11 import javax.swing.JScrollBar;
12 import javax.swing.JTextField;
13 import java.awt.event.ActionEvent;
14 import java.util.Vector;
15
16
17
18 @SuppressWarnings("serial")
19 public abstract class AnnotationRowFilter extends JPanel
20 {
21   protected AlignViewport av;
22
23   protected AlignmentPanel ap;
24
25   protected int[] annmap;
26
27   protected boolean enableSeqAss = false;
28
29   private AlignmentAnnotation currentAnnotation;
30
31   protected boolean adjusting = false;
32
33   protected JCheckBox currentColours = new JCheckBox();
34
35   protected JPanel minColour = new JPanel();
36
37   protected JPanel maxColour = new JPanel();
38
39   protected JCheckBox seqAssociated = new JCheckBox();
40
41   protected JCheckBox thresholdIsMin = new JCheckBox();
42
43   protected JScrollBar slider = new JScrollBar(JScrollBar.HORIZONTAL);
44
45   protected JTextField thresholdValue = new JTextField(20);
46
47   protected JFrame frame;
48
49   protected JButton ok = new JButton();
50
51   protected JButton cancel = new JButton();
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 AlignmentAnnotation getCurrentAnnotation()
183   {
184     return currentAnnotation;
185   }
186
187   public void setCurrentAnnotation(AlignmentAnnotation currentAnnotation)
188   {
189     this.currentAnnotation = currentAnnotation;
190   }
191
192   public abstract void valueChanged(boolean updateAllAnnotation);
193
194   public abstract void updateView();
195
196   public abstract void reset();
197 }