1 package fr.orsay.lri.varna.views;
5 import java.awt.Dimension;
6 import java.awt.FlowLayout;
7 import java.awt.GridLayout;
8 import java.awt.event.ActionEvent;
9 import java.awt.event.ActionListener;
10 import java.awt.event.ItemEvent;
11 import java.awt.event.ItemListener;
13 import javax.swing.JButton;
14 import javax.swing.JComboBox;
15 import javax.swing.JLabel;
16 import javax.swing.JOptionPane;
17 import javax.swing.JPanel;
18 import javax.swing.JSpinner;
19 import javax.swing.SpinnerNumberModel;
20 import javax.swing.event.ChangeEvent;
21 import javax.swing.event.ChangeListener;
23 import fr.orsay.lri.varna.VARNAPanel;
24 import fr.orsay.lri.varna.models.annotations.ChemProbAnnotation;
25 import fr.orsay.lri.varna.models.annotations.HighlightRegionAnnotation;
28 public class VueChemProbAnnotation implements ChangeListener, ActionListener, ItemListener {
30 protected VARNAPanel _vp;
32 protected ChemProbAnnotation _an;
33 private static int CONTROL_HEIGHT = 50;
34 private static int TITLE_WIDTH = 70;
35 private static int CONTROL_WIDTH = 200;
36 protected JButton color = new JButton();
38 JComboBox outward = new JComboBox(new String[]{"Inward","Outward"});
39 JComboBox type = new JComboBox(ChemProbAnnotation.ChemProbAnnotationType.values());
41 public VueChemProbAnnotation(VARNAPanel vp, ChemProbAnnotation an) {
46 panel.setLayout(new FlowLayout(FlowLayout.LEFT));
49 JPanel outlinep = new JPanel();
50 JLabel l1 = new JLabel("Color: ");
51 l1.setPreferredSize(new Dimension(TITLE_WIDTH,CONTROL_HEIGHT));
52 color.setContentAreaFilled(false);
53 color.setOpaque(true);
54 color.setPreferredSize(new Dimension(CONTROL_WIDTH,CONTROL_HEIGHT));
55 color.setBackground(_an.getColor());
56 color.addActionListener(this);
57 color.setActionCommand("outline");
62 JPanel radiusp = new JPanel();
63 l1 = new JLabel("Intensity: ");
64 l1.setPreferredSize(new Dimension(TITLE_WIDTH,CONTROL_HEIGHT));
65 SpinnerNumberModel jm = new SpinnerNumberModel(_an.getIntensity(),0.01,10.0,0.01);
66 intensity = new JSpinner(jm);
68 radiusp.add(intensity);
69 intensity.addChangeListener(this);
71 JPanel dirp = new JPanel();
72 l1 = new JLabel("Direction: ");
73 l1.setPreferredSize(new Dimension(TITLE_WIDTH,CONTROL_HEIGHT));
74 outward.addItemListener(this);
78 JPanel typep = new JPanel();
79 l1 = new JLabel("Type: ");
80 l1.setPreferredSize(new Dimension(TITLE_WIDTH,CONTROL_HEIGHT));
81 type.addItemListener(this);
87 JPanel jp = new JPanel();
88 jp.setLayout(new GridLayout(4,1));
96 public JPanel getPanel() {
100 public VARNAPanel get_vp() {
104 HighlightRegionAnnotation _backup = null;
106 public boolean show() {
107 boolean accept = false;
108 intensity.setValue(_an.getIntensity());
109 color.setBackground(_an.getColor());
110 type.setSelectedItem(_an.getType());
111 outward.setSelectedItem((_an.isOut()?"Inward":"Outward"));
113 if (JOptionPane.showConfirmDialog(_vp, getPanel(),
114 "Edit chemical probing annotation", JOptionPane.OK_CANCEL_OPTION,
115 JOptionPane.PLAIN_MESSAGE) == JOptionPane.OK_OPTION)
123 public void stateChanged(ChangeEvent e) {
124 if (e.getSource().equals(intensity))
126 Object val = intensity.getValue();
127 if (val instanceof Double)
129 _an.setIntensity(((Double)val).doubleValue());
136 public void actionPerformed(ActionEvent e) {
137 if (e.getActionCommand().equals("outline")) {
138 // BH j2s SwingJS asynchronous for JavaScript; synchronous for Java
139 _vp.getVARNAUI().showColorDialog("Choose new outline color", _an.getColor(), new Runnable() {
143 Color c = (Color) _vp.getVARNAUI().dialogReturnValue;
146 color.setBackground(_an.getColor());
156 public void itemStateChanged(ItemEvent e) {
157 if (e.getSource()==outward)
159 _an.setOut(!e.getItem().equals("Outward"));
162 else if ((e.getSource()==type)&&(e.getItem() instanceof ChemProbAnnotation.ChemProbAnnotationType))
164 ChemProbAnnotation.ChemProbAnnotationType t = (ChemProbAnnotation.ChemProbAnnotationType) e.getItem();