X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=srcjar%2Ffr%2Forsay%2Flri%2Fvarna%2Fviews%2FVueColorMapStyle.java;fp=srcjar%2Ffr%2Forsay%2Flri%2Fvarna%2Fviews%2FVueColorMapStyle.java;h=6a1a836dbc5b4fd5cd5d3c767363f3699ecd7a9b;hb=4898f0ae429e0c61ddba72ca46be89b34bb4df8b;hp=0000000000000000000000000000000000000000;hpb=5a6ac5b535856903629234ad43a71319a91ebee5;p=jalview.git diff --git a/srcjar/fr/orsay/lri/varna/views/VueColorMapStyle.java b/srcjar/fr/orsay/lri/varna/views/VueColorMapStyle.java new file mode 100644 index 0000000..6a1a836 --- /dev/null +++ b/srcjar/fr/orsay/lri/varna/views/VueColorMapStyle.java @@ -0,0 +1,305 @@ +package fr.orsay.lri.varna.views; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Comparator; + +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JColorChooser; +import javax.swing.JComboBox; +import javax.swing.JDialog; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.filechooser.FileFilter; + +import fr.orsay.lri.varna.VARNAPanel; +import fr.orsay.lri.varna.components.GradientEditorPanel; +import fr.orsay.lri.varna.models.VARNAConfig; +import fr.orsay.lri.varna.models.rna.ModeleColorMap; +import fr.orsay.lri.varna.models.rna.ModeleColorMap.NamedColorMapTypes; + +public class VueColorMapStyle extends JPanel implements ActionListener, ItemListener, PropertyChangeListener { + private VARNAPanel _vp; + private GradientEditorPanel _gp; + private JComboBox _cb; + private JTextField _code; + private ModeleColorMap _backup; + // TODO BH SwingJS note that the save dialog is never used in JavaScript + private static JFileChooser fc = new JFileChooser(){ + public void approveSelection(){ + File f = getSelectedFile(); + if(f.exists() && getDialogType() == SAVE_DIALOG){ + int result = JOptionPane.showConfirmDialog(this,"The file exists, overwrite?","Existing file",JOptionPane.YES_NO_OPTION); + switch(result){ + case JOptionPane.YES_OPTION: + super.approveSelection(); + return; + case JOptionPane.NO_OPTION: + return; + case JOptionPane.CLOSED_OPTION: + return; + case JOptionPane.CANCEL_OPTION: + cancelSelection(); + return; + } + } + super.approveSelection(); + } + }; + + public VueColorMapStyle(VARNAPanel vp) + { + super(); + _vp = vp; + init(); + } + + private void init() + { + JLabel gradientCaption = new JLabel("Click gradient to add new color..."); + _gp = new GradientEditorPanel(_vp.getColorMap().clone()); + _backup = _vp.getColorMap(); + _gp.setPreferredSize(new Dimension(300,70)); + _gp.addPropertyChangeListener(this); + + JPanel codePanel = new JPanel(); + JLabel codeCaption = new JLabel("Param. code: "); + codeCaption.setVisible(true); + _code = new JTextField(""); + _code.setFont(Font.decode("Monospaced-PLAIN-12")); + _code.setEditable(true); + _code.addFocusListener(new FocusListener(){ + + public void focusGained(FocusEvent arg0) { + _code.setSelectionStart(0); + _code.setSelectionEnd(_code.getText().length()); + } + + public void focusLost(FocusEvent arg0) { + } + }); + _code.setVisible(false); + + NamedColorMapTypes[] palettes = ModeleColorMap.NamedColorMapTypes.values(); + Arrays.sort(palettes,new Comparator(){ + public int compare(ModeleColorMap.NamedColorMapTypes arg0, ModeleColorMap.NamedColorMapTypes arg1) { + return arg0.getId().compareTo(arg1.getId()); + } + }); + Object[] finalArray = new Object[palettes.length+1]; + int selected = -1; + for (int i=0;i