3 import jalview.datamodel.ColumnSelection;
4 import jalview.schemes.AnnotationColourGradient;
5 import jalview.util.MessageManager;
7 import java.awt.BorderLayout;
9 import java.awt.Dimension;
10 import java.awt.event.ActionEvent;
11 import java.awt.event.ActionListener;
13 import javax.swing.JButton;
14 import javax.swing.JComboBox;
15 import javax.swing.JInternalFrame;
16 import javax.swing.JLayeredPane;
17 import javax.swing.JPanel;
19 import net.miginfocom.swing.MigLayout;
21 @SuppressWarnings("serial")
22 public class AnnotationColumnChooser extends AnnotationRowFilter
25 private ColumnSelection oldColumnSelection;
27 private JComboBox<String> annotations;
29 JButton ok = new JButton();
31 JButton cancel = new JButton();
33 JPanel jPanel1 = new JPanel();
35 JPanel jPanel2 = new JPanel();
37 BorderLayout borderLayout1 = new BorderLayout();
39 private JComboBox<String> threshold = new JComboBox<String>();
42 public AnnotationColumnChooser(AlignViewport av, final AlignmentPanel ap)
45 frame = new JInternalFrame();
46 frame.setContentPane(this);
47 frame.setLayer(JLayeredPane.PALETTE_LAYER);
48 Desktop.addInternalFrame(frame, "Select By Annotation", 520, 215);
50 addSliderChangeListener();
51 addSliderMouseListeners();
53 if (av.getAlignment().getAlignmentAnnotation() == null)
57 setOldColumnSelection(av.getColumnSelection());
60 setAnnotations(new JComboBox<String>(
61 getAnnotationItems(seqAssociated.isSelected())));
62 populateThresholdComboBox(threshold);
64 if (av.getCurrentAnnotationColumnSelectionState() != null)
66 annotations.setSelectedIndex(av
67 .getCurrentAnnotationColumnSelectionState().getAnnotations()
69 threshold.setSelectedIndex(av
70 .getCurrentAnnotationColumnSelectionState().getThreshold()
77 } catch (Exception ex)
88 public AnnotationColumnChooser()
93 } catch (Exception ex)
99 private void jbInit() throws Exception
102 ok.setText(MessageManager.getString("action.ok"));
103 ok.addActionListener(new ActionListener()
106 public void actionPerformed(ActionEvent e)
108 ok_actionPerformed(e);
111 cancel.setOpaque(false);
112 cancel.setText(MessageManager.getString("action.cancel"));
113 cancel.addActionListener(new ActionListener()
116 public void actionPerformed(ActionEvent e)
118 cancel_actionPerformed(e);
122 getAnnotations().addActionListener(new ActionListener()
125 public void actionPerformed(ActionEvent e)
127 annotations_actionPerformed(e);
130 getThreshold().addActionListener(new ActionListener()
133 public void actionPerformed(ActionEvent e)
135 threshold_actionPerformed(e);
138 thresholdValue.addActionListener(new ActionListener()
141 public void actionPerformed(ActionEvent e)
143 thresholdValue_actionPerformed(e);
146 slider.setPaintLabels(false);
147 slider.setPaintTicks(true);
148 slider.setBackground(Color.white);
149 slider.setEnabled(false);
150 slider.setOpaque(false);
151 slider.setPreferredSize(new Dimension(100, 32));
152 thresholdValue.setEnabled(false);
153 thresholdValue.setColumns(7);
154 thresholdIsMin.setBackground(Color.white);
155 thresholdIsMin.setFont(JvSwingUtils.getLabelFont());
156 thresholdIsMin.setText(MessageManager
157 .getString("label.threshold_minmax"));
158 thresholdIsMin.addActionListener(new ActionListener()
161 public void actionPerformed(ActionEvent actionEvent)
163 thresholdIsMin_actionPerformed(actionEvent);
166 seqAssociated.setBackground(Color.white);
167 seqAssociated.setFont(JvSwingUtils.getLabelFont());
168 seqAssociated.setText(MessageManager
169 .getString("label.per_sequence_only"));
170 seqAssociated.addActionListener(new ActionListener()
174 public void actionPerformed(ActionEvent arg0)
176 seqAssociated_actionPerformed(arg0, annotations, seqAssociated);
180 this.setLayout(borderLayout1);
181 jPanel2.setLayout(new MigLayout("", "[left][center][right]", "[][][]"));
182 jPanel1.setBackground(Color.white);
183 jPanel2.setBackground(Color.white);
187 jPanel2.add(getAnnotations(), "grow, wrap");
188 jPanel2.add(seqAssociated, "wrap");
189 jPanel2.add(getThreshold(), "grow, wrap");
190 jPanel2.add(thresholdIsMin, "wrap");
191 jPanel2.add(slider, "grow");
192 jPanel2.add(thresholdValue, "grow");
193 this.add(jPanel1, java.awt.BorderLayout.SOUTH);
194 this.add(jPanel2, java.awt.BorderLayout.CENTER);
201 av.getColumnSelection().clear();
202 av.setColumnSelection(this.getOldColumnSelection());
205 public void valueChanged(boolean updateAllAnnotation)
207 getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
209 propagateSeqAssociatedThreshold(updateAllAnnotation,
210 getCurrentAnnotation());
211 ap.paintAlignment(false);
214 public JComboBox<String> getThreshold()
219 public void setThreshold(JComboBox<String> threshold)
221 this.threshold = threshold;
224 public JComboBox<String> getAnnotations()
229 public void setAnnotations(JComboBox<String> annotations)
231 this.annotations = annotations;
235 public void updateView()
237 changeColumnSelection();
239 void changeColumnSelection()
241 // Check if combobox is still adjusting
247 setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[getAnnotations()
248 .getSelectedIndex()]]);
251 int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
252 .getSelectedIndex());
254 slider.setEnabled(true);
255 thresholdValue.setEnabled(true);
256 thresholdIsMin.setEnabled(true);
258 if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD)
260 slider.setEnabled(false);
261 thresholdValue.setEnabled(false);
262 thresholdValue.setText("");
263 thresholdIsMin.setEnabled(false);
265 else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD
266 && getCurrentAnnotation().threshold == null)
268 getCurrentAnnotation()
269 .setThreshold(new jalview.datamodel.GraphLine(
270 (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
271 "Threshold", Color.black));
274 if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
277 float range = getCurrentAnnotation().graphMax * 1000
278 - getCurrentAnnotation().graphMin * 1000;
280 slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
281 slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
282 slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
283 thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
284 slider.setMajorTickSpacing((int) (range / 10f));
285 slider.setEnabled(true);
286 thresholdValue.setEnabled(true);
290 markColumnsContaining(getCurrentAnnotation(), selectedThresholdItem);
291 av.setCurrentAnnotationColumnSelectionState(this);
292 ap.alignmentChanged();
293 ap.paintAlignment(true);
296 public ColumnSelection getOldColumnSelection()
298 return oldColumnSelection;
301 public void setOldColumnSelection(ColumnSelection currentColumnSelection)
303 if (currentColumnSelection != null)
305 this.oldColumnSelection = new ColumnSelection();
306 this.oldColumnSelection.setElementsFrom(currentColumnSelection);