JAL-3026 srcjar files for VARNA and log4j
[jalview.git] / srcjar / fr / orsay / lri / varna / views / VueBPThickness.java
1 /*
2  VARNA is a tool for the automated drawing, visualization and annotation of the secondary structure of RNA, designed as a companion software for web servers and databases.
3  Copyright (C) 2008  Kevin Darty, Alain Denise and Yann Ponty.
4  electronic mail : Yann.Ponty@lri.fr
5  paper mail : LRI, bat 490 Université Paris-Sud 91405 Orsay Cedex France
6
7  This file is part of VARNA version 3.1.
8  VARNA version 3.1 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
9  as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
10
11  VARNA version 3.1 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  See the GNU General Public License for more details.
14
15  You should have received a copy of the GNU General Public License along with VARNA version 3.1.
16  If not, see http://www.gnu.org/licenses.
17  */
18 package fr.orsay.lri.varna.views;
19
20 import java.awt.Dimension;
21 import java.awt.FlowLayout;
22 import java.util.ArrayList;
23
24 import javax.swing.JLabel;
25 import javax.swing.JPanel;
26 import javax.swing.JSlider;
27 import javax.swing.event.ChangeEvent;
28 import javax.swing.event.ChangeListener;
29
30 import fr.orsay.lri.varna.VARNAPanel;
31 import fr.orsay.lri.varna.controlers.ControleurSliderLabel;
32 import fr.orsay.lri.varna.models.VARNAConfig;
33 import fr.orsay.lri.varna.models.rna.ModeleBP;
34
35 public class VueBPThickness implements ChangeListener {
36
37         private VARNAPanel _vp;
38         ArrayList<ModeleBP> _msbp;
39         private JSlider _thicknessSlider;
40         private JPanel panel;
41
42         private ArrayList<Double> _backupThicknesses = new ArrayList<Double>();
43
44         private double FACTOR = 10.0;
45
46         public VueBPThickness(VARNAPanel vp, ArrayList<ModeleBP> msbp) {
47                 _vp = vp;
48                 _msbp = msbp;
49                 backupThicknesses();
50
51                 _thicknessSlider = new JSlider(JSlider.HORIZONTAL, 1, 100,
52                                 (int) (msbp.get(0).getStyle().getThickness(
53                                                 VARNAConfig.DEFAULT_BP_THICKNESS) * FACTOR));
54                 _thicknessSlider.setMajorTickSpacing(10);
55                 _thicknessSlider.setPaintTicks(true);
56                 _thicknessSlider.setPaintLabels(false);
57                 _thicknessSlider.setPreferredSize(new Dimension(500, 50));
58
59                 JLabel thicknessLabel = new JLabel(String.valueOf(msbp.get(0).getStyle()
60                                 .getThickness(VARNAConfig.DEFAULT_BP_THICKNESS)));
61                 thicknessLabel.setPreferredSize(new Dimension(50, thicknessLabel
62                                 .getPreferredSize().height));
63                 _thicknessSlider.addChangeListener(new ControleurSliderLabel(
64                                 thicknessLabel, 1.0 / FACTOR));
65                 _thicknessSlider.addChangeListener(this);
66
67                 panel = new JPanel();
68                 panel.setLayout(new FlowLayout(FlowLayout.LEFT));
69
70                 JLabel labelZ = new JLabel("Thickness:");
71
72                 panel.add(labelZ);
73                 panel.add(_thicknessSlider);
74                 panel.add(thicknessLabel);
75         }
76
77         private void backupThicknesses() {
78                 for (int i = 0; i < _msbp.size(); i++) {
79                         this._backupThicknesses.add(_msbp.get(i).getStyle().getThickness(
80                                         VARNAConfig.DEFAULT_BP_THICKNESS));
81                 }
82         }
83
84         public void restoreThicknesses() {
85                 for (int i = 0; i < _msbp.size(); i++) {
86                         _msbp.get(i).getStyle().setThickness(_backupThicknesses.get(i));
87                 }
88         }
89
90         public JPanel getPanel() {
91                 return panel;
92         }
93
94         public double getThickness() {
95                 return (double) _thicknessSlider.getValue() / FACTOR;
96         }
97
98         public VARNAPanel get_vp() {
99                 return _vp;
100         }
101
102         public void stateChanged(ChangeEvent e) {
103                 for (int i = 0; i < _msbp.size(); i++) {
104                         _msbp.get(i).getStyle().setThickness(
105                                         ((double) _thicknessSlider.getValue()) / FACTOR);
106                 }
107                 _vp.repaint();
108         }
109 }