2 * VARNA is a tool for the automated drawing, visualization and annotation
3 * of the secondary structure of RNA, designed as a companion software for
4 * web servers and databases. Copyright (C) 2008 Kevin Darty, Alain Denise
5 * and Yann Ponty. electronic mail : Yann.Ponty@lri.fr paper mail : LRI, bat
6 * 490 Université Paris-Sud 91405 Orsay Cedex France
8 * This file is part of VARNA version 3.1. VARNA version 3.1 is free
9 * software: you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software Foundation,
11 * either version 3 of the License, or (at your option) any later version.
13 * VARNA version 3.1 is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16 * Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with VARNA version 3.1. If not, see http://www.gnu.org/licenses.
21 package fr.orsay.lri.varna.views;
23 import java.awt.BorderLayout;
24 import java.awt.Dimension;
25 import java.awt.GridLayout;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28 import java.io.BufferedInputStream;
29 import java.io.BufferedReader;
31 import java.io.FileInputStream;
32 import java.io.FileNotFoundException;
33 import java.io.FileReader;
34 import java.io.IOException;
35 import java.io.PrintWriter;
36 import java.util.ArrayList;
38 import javax.swing.Box;
39 import javax.swing.BoxLayout;
40 import javax.swing.JButton;
41 import javax.swing.JComponent;
42 import javax.swing.JFileChooser;
43 import javax.swing.JOptionPane;
44 import javax.swing.JPanel;
45 import javax.swing.JScrollPane;
46 import javax.swing.JTable;
47 import javax.swing.filechooser.FileFilter;
49 import fr.orsay.lri.varna.VARNAPanel;
50 import fr.orsay.lri.varna.components.AnnotationTableModel;
51 import fr.orsay.lri.varna.controlers.ControleurTableAnnotations;
52 import fr.orsay.lri.varna.models.annotations.TextAnnotation;
53 import fr.orsay.lri.varna.models.rna.ModeleColorMap;
56 * a view for all annoted texts on the VARNAPanel
58 * @author Darty@lri.fr
61 public class VueListeAnnotations extends JPanel {
65 private static final long serialVersionUID = 1L;
68 * if this view is for removing annoted texts
70 public static final int REMOVE = 0;
72 * if this view is for editing annoted texts
74 public static final int EDIT = 1;
76 private VARNAPanel _vp;
77 private ArrayList<Object> data;
80 private AnnotationTableModel specialTableModel;
81 // BH SwingJS - this is never used in JavaScript
82 private static JFileChooser fc = new JFileChooser(){
83 public void approveSelection(){
84 File f = getSelectedFile();
85 if(f.exists() && getDialogType() == SAVE_DIALOG){
86 int result = JOptionPane.showConfirmDialog(this,"The file exists, overwrite?","Existing file",JOptionPane.YES_NO_OPTION);
88 case JOptionPane.YES_OPTION:
89 super.approveSelection();
91 case JOptionPane.NO_OPTION:
93 case JOptionPane.CLOSED_OPTION:
95 case JOptionPane.CANCEL_OPTION:
100 super.approveSelection();
112 public VueListeAnnotations(VARNAPanel vp, int type) {
113 super(new BorderLayout());
116 data = new ArrayList<Object>();
117 data.addAll(_vp.getListeAnnotations());
118 data.addAll(_vp.getRNA().getHighlightRegion());
119 data.addAll(_vp.getRNA().getChemProbAnnotations());
123 private void createView() {
124 specialTableModel = new AnnotationTableModel(data);
125 table = new JTable(specialTableModel);
126 ControleurTableAnnotations ctrl = new ControleurTableAnnotations(table,
128 table.addMouseListener(ctrl);
129 table.addMouseMotionListener(ctrl);
130 // table.setPreferredScrollableViewportSize(new Dimension(500, 100));
131 // TODO: Find equivalent in JRE 1.5
132 // table.setFillsViewportHeight(true);
133 // Create the scroll pane and add the table to it.
134 JScrollPane scrollPane = new JScrollPane(table);
136 add(scrollPane, BorderLayout.CENTER);
138 FileFilter CPAFiles = new FileFilter(){
139 public boolean accept(File f) {
140 return f.getName().toLowerCase().endsWith(".cpa") || f.isDirectory();
143 public String getDescription() {
144 return "Chemical Probing Annotations (*.cpa) Files";
148 fc.addChoosableFileFilter(CPAFiles);
149 fc.setFileFilter(CPAFiles);
152 JButton loadStyleButton = new JButton("Load");
153 loadStyleButton.addActionListener(new ActionListener(){
154 public void actionPerformed(ActionEvent e) {
155 if (fc.showOpenDialog(VueListeAnnotations.this)==JFileChooser.APPROVE_OPTION)
157 File file = fc.getSelectedFile();
159 BufferedReader br = new BufferedReader(new FileReader(file));
160 String s = br.readLine();
163 if (s.startsWith(TextAnnotation.HEADER_TEXT))
167 } catch (FileNotFoundException e1) {
168 e1.printStackTrace();
169 } catch (IOException e1) {
170 e1.printStackTrace();
176 JButton saveStyleButton = new JButton("Save");
177 saveStyleButton.addActionListener(new ActionListener(){
178 public void actionPerformed(ActionEvent e) {
179 if (fc.showSaveDialog(VueListeAnnotations.this)==JFileChooser.APPROVE_OPTION)
182 PrintWriter out = new PrintWriter(fc.getSelectedFile());
183 // TODO out.println(_gp.getColorMap().getParamEncoding());
185 } catch (FileNotFoundException e1) {
186 e1.printStackTrace();
187 } catch (IOException e1) {
188 e1.printStackTrace();
194 saveStyleButton.setAlignmentX(CENTER_ALIGNMENT);
195 loadStyleButton.setAlignmentX(CENTER_ALIGNMENT);
197 JPanel jp2 = new JPanel();
198 BoxLayout bl = new BoxLayout(jp2, BoxLayout.X_AXIS);
200 jp2.setAlignmentX(CENTER_ALIGNMENT);
201 jp2.add(loadStyleButton);
202 jp2.add(Box.createRigidArea(new Dimension(5,0)));
203 jp2.add(saveStyleButton);
204 this.add(jp2,BorderLayout.SOUTH);
208 UIvueListeAnnotations();
212 * Create the GUI and show it. For thread safety, this method should be
213 * invoked from the event-dispatching thread.
215 public void UIvueListeAnnotations() {
216 JComponent newContentPane = this;
217 newContentPane.setOpaque(true);
218 JOptionPane.showMessageDialog(_vp, newContentPane,
219 "Annotation edition", JOptionPane.PLAIN_MESSAGE);
222 public ArrayList<Object> getData() {
226 public void setData(ArrayList<Object> data) {
230 public VARNAPanel get_vp() {
234 public JTable getTable() {
238 public void setTable(JTable table) {
242 public AnnotationTableModel getSpecialTableModel() {
243 return specialTableModel;
246 public void setSpecialTableModel(AnnotationTableModel specialTableModel) {
247 this.specialTableModel = specialTableModel;