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
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.
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.
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.
18 package fr.orsay.lri.varna.controlers;
20 import java.awt.Color;
21 import java.awt.event.ActionEvent;
22 import java.awt.event.ActionListener;
23 import java.awt.event.ComponentEvent;
24 import java.awt.event.ComponentListener;
26 import fr.orsay.lri.varna.components.BaseSpecialColorEditor;
27 import fr.orsay.lri.varna.models.BaseList;
28 import fr.orsay.lri.varna.models.rna.ModeleBase;
31 * BH SwingJS - additions here to allow asynchronous JColorChooser
33 public class ControleurBaseSpecialColorEditor implements ActionListener, ComponentListener { // BH SwingJS
35 private BaseSpecialColorEditor _specialColorEditor;
37 private int _selectedRow;
38 private int _selectedCol;
39 private Color _selectedColor;
40 private String _selectedColTitle;
42 public ControleurBaseSpecialColorEditor(BaseSpecialColorEditor specialColorEditor) {
43 _specialColorEditor = specialColorEditor;
47 * Handles events from the editor button and from the dialog's OK button.
49 public void actionPerformed(ActionEvent e) {
50 if (BaseSpecialColorEditor.getEDIT().equals(e.getActionCommand())) {
51 // The user has clicked the cell, so
52 // bring up the dialog.
53 _specialColorEditor.getButton().setBackground(
54 _specialColorEditor.getCurrentColor());
55 _specialColorEditor.getColorChooser().setColor(
56 _specialColorEditor.getCurrentColor());
58 // BH SwingJS in JavaScript, this is not modal.
59 // We have to set a callback to stop the editing.
61 _specialColorEditor.getDialog().removeComponentListener(this);
62 _specialColorEditor.getDialog().addComponentListener(this);
63 _specialColorEditor.getDialog().setVisible(true);
66 // Make the renderer reappear.
67 // BH SwingJS not so fast...
68 //_specialColorEditor.callFireEditingStopped();
70 } else { // User pressed dialog's "OK" button.
71 _specialColorEditor.setCurrentColor(_specialColorEditor
72 .getColorChooser().getColor());
74 _selectedRow = _specialColorEditor.get_vueBases().getTable()
77 _selectedCol = _specialColorEditor.get_vueBases().getTable()
80 _selectedColor = _specialColorEditor.getCurrentColor();
82 _selectedColTitle = _specialColorEditor.get_vueBases()
83 .getSpecialTableModel().getColumnName(_selectedCol);
84 BaseList lb = _specialColorEditor.get_vueBases().getDataAt(_selectedRow);
85 for(ModeleBase mb: lb.getBases())
87 applyColor(_selectedColTitle, _selectedColor,mb);
89 _specialColorEditor.get_vueBases().get_vp().repaint();
94 private void applyColor(String titreCol, Color couleur, ModeleBase mb) {
95 if (titreCol.equals("Inner Color")) {
97 .setBaseInnerColor(couleur);
98 } else if (titreCol.equals("Outline Color")) {
100 .setBaseOutlineColor(couleur);
101 } else if (titreCol.equals("Name Color")) {
103 .setBaseNameColor(couleur);
104 } else if (titreCol.equals("Number Color")) {
106 .setBaseNumberColor(couleur);
113 public void componentResized(ComponentEvent e) {
117 public void componentMoved(ComponentEvent e) {
121 public void componentShown(ComponentEvent e) {
125 public void componentHidden(ComponentEvent e) {
127 _specialColorEditor.callFireEditingStopped(); // BH SwingJS -- need to catch this