3 import jalview.schemes.AnnotationColourGradient;
4 import jalview.util.MessageManager;
6 import java.awt.BorderLayout;
8 import java.awt.Dimension;
9 import java.awt.event.ActionEvent;
10 import java.awt.event.ActionListener;
12 import javax.swing.JButton;
13 import javax.swing.JComboBox;
14 import javax.swing.JInternalFrame;
15 import javax.swing.JLayeredPane;
16 import javax.swing.JPanel;
18 import net.miginfocom.swing.MigLayout;
20 @SuppressWarnings("serial")
21 public class AnnotationColumnChooser extends AnnotationRowFilter
24 private JComboBox<String> annotations;
26 JButton ok = new JButton();
28 JButton cancel = new JButton();
30 JPanel jPanel1 = new JPanel();
32 JPanel jPanel2 = new JPanel();
34 BorderLayout borderLayout1 = new BorderLayout();
36 private JComboBox<String> threshold = new JComboBox<String>();
39 public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
42 frame = new JInternalFrame();
43 frame.setContentPane(this);
44 frame.setLayer(JLayeredPane.PALETTE_LAYER);
45 Desktop.addInternalFrame(frame, "Select By Annotation", 520, 215);
47 addSliderChangeListener();
48 addSliderMouseListeners();
50 if (av.getAlignment().getAlignmentAnnotation() == null)
57 setAnnotations(new JComboBox<String>(
58 getAnnotationItems(seqAssociated.isSelected())));
59 populateThresholdComboBox(threshold);
61 if (av.getCurrentAnnotationColumnSelectionState() != null)
63 annotations.setSelectedIndex(av
64 .getCurrentAnnotationColumnSelectionState().getAnnotations()
66 threshold.setSelectedIndex(av
67 .getCurrentAnnotationColumnSelectionState().getThreshold()
74 } catch (Exception ex)
85 public AnnotationColumnChooser()
90 } catch (Exception ex)
96 private void jbInit() throws Exception
99 ok.setText(MessageManager.getString("action.ok"));
100 ok.addActionListener(new ActionListener()
103 public void actionPerformed(ActionEvent e)
105 ok_actionPerformed(e);
108 cancel.setOpaque(false);
109 cancel.setText(MessageManager.getString("action.cancel"));
110 cancel.addActionListener(new ActionListener()
113 public void actionPerformed(ActionEvent e)
115 cancel_actionPerformed(e);
119 getAnnotations().addActionListener(new ActionListener()
122 public void actionPerformed(ActionEvent e)
124 annotations_actionPerformed(e);
127 getThreshold().addActionListener(new ActionListener()
130 public void actionPerformed(ActionEvent e)
132 threshold_actionPerformed(e);
135 thresholdValue.addActionListener(new ActionListener()
138 public void actionPerformed(ActionEvent e)
140 thresholdValue_actionPerformed(e);
143 slider.setPaintLabels(false);
144 slider.setPaintTicks(true);
145 slider.setBackground(Color.white);
146 slider.setEnabled(false);
147 slider.setOpaque(false);
148 slider.setPreferredSize(new Dimension(100, 32));
149 thresholdValue.setEnabled(false);
150 thresholdValue.setColumns(7);
151 thresholdIsMin.setBackground(Color.white);
152 thresholdIsMin.setFont(JvSwingUtils.getLabelFont());
153 thresholdIsMin.setText(MessageManager
154 .getString("label.threshold_minmax"));
155 thresholdIsMin.addActionListener(new ActionListener()
158 public void actionPerformed(ActionEvent actionEvent)
160 thresholdIsMin_actionPerformed(actionEvent);
163 seqAssociated.setBackground(Color.white);
164 seqAssociated.setFont(JvSwingUtils.getLabelFont());
165 seqAssociated.setText(MessageManager
166 .getString("label.per_sequence_only"));
167 seqAssociated.addActionListener(new ActionListener()
171 public void actionPerformed(ActionEvent arg0)
173 seqAssociated_actionPerformed(arg0, annotations, seqAssociated);
177 this.setLayout(borderLayout1);
178 jPanel2.setLayout(new MigLayout("", "[left][center][right]", "[][][]"));
179 jPanel1.setBackground(Color.white);
180 jPanel2.setBackground(Color.white);
184 jPanel2.add(getAnnotations(), "grow, wrap");
185 jPanel2.add(seqAssociated, "wrap");
186 jPanel2.add(getThreshold(), "grow, wrap");
187 jPanel2.add(thresholdIsMin, "wrap");
188 jPanel2.add(slider, "grow");
189 jPanel2.add(thresholdValue, "grow");
190 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
191 this.add(jPanel2, java.awt.BorderLayout.CENTER);
198 av.getColumnSelection().clear();
201 public void valueChanged(boolean updateAllAnnotation)
203 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
205 propagateSeqAssociatedThreshold(updateAllAnnotation,
206 getCurrentAnnotation());
207 ap.paintAlignment(false);
210 public JComboBox<String> getThreshold()
215 public void setThreshold(JComboBox<String> threshold)
217 this.threshold = threshold;
220 public JComboBox<String> getAnnotations()
225 public void setAnnotations(JComboBox<String> annotations)
227 this.annotations = annotations;
231 public void updateView()
233 changeColumnSelection();
235 void changeColumnSelection()
237 // Check if combobox is still adjusting
243 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
244 .getSelectedIndex()]]);
247 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
248 .getSelectedIndex());
250 slider.setEnabled(true);
251 thresholdValue.setEnabled(true);
252 thresholdIsMin.setEnabled(true);
254 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
256 slider.setEnabled(false);
257 thresholdValue.setEnabled(false);
258 thresholdValue.setText("");
259 thresholdIsMin.setEnabled(false);
261 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD
262 && getCurrentAnnotation().threshold == null)
264 getCurrentAnnotation()
265 .setThreshold(new jalview.datamodel.GraphLine(
266 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
267 "Threshold", Color.black));
270 if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
273 float range = getCurrentAnnotation().graphMax * 1000
274 - getCurrentAnnotation().graphMin * 1000;
276 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
277 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
278 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
279 thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
280 slider.setMajorTickSpacing((int) (range / 10f));
281 slider.setEnabled(true);
282 thresholdValue.setEnabled(true);
286 markColumnsContaining(getCurrentAnnotation(), selectedThresholdItem);
287 av.setCurrentAnnotationColumnSelectionState(this);
288 ap.alignmentChanged();
289 ap.paintAlignment(true);