/* * Jalview - A Sequence Alignment Editor and Viewer * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ package jalview.gui; import jalview.datamodel.*; import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.util.*; import javax.swing.BorderFactory; import java.awt.event.*; import javax.swing.table.*; import java.io.*; import jalview.io.JalviewFileChooser; public class FeatureSettings extends JPanel { final FeatureRenderer fr; final AlignmentPanel ap; final AlignViewport av; Object [][] originalData; final JInternalFrame frame; JScrollPane scrollPane = new JScrollPane(); JTable table; public FeatureSettings(AlignViewport av, final AlignmentPanel ap) { this.ap = ap; this.av = av; fr = ap.seqPanel.seqCanvas.getFeatureRenderer(); av.alignment.getSequences(); frame = new JInternalFrame(); frame.setContentPane(this); Desktop.addInternalFrame(frame, "Sequence Feature Settings", 400, 300); setTableData(); final JSlider transparency = new JSlider(0, 70, 0); transparency.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { fr.setTransparency( (float) (100 - transparency.getValue()) / 100f); ap.repaint(); } }); JPanel transPanel = new JPanel(new FlowLayout()); transPanel.add(new JLabel("Transparency")); transPanel.add(transparency); ////////////////////////////////////////////// //We're going to need those OK cancel buttons JPanel buttonPanel = new JPanel(new FlowLayout()); JButton button = new JButton("OK"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try { frame.setClosed(true); } catch (Exception exe) {} } }); buttonPanel.add(button); button = new JButton("Cancel"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try { updateFeatureRenderer(originalData); frame.setClosed(true); } catch (Exception exe) {} } }); buttonPanel.add(button); button = new JButton("Load Colours"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { load(); } }); buttonPanel.add(button); button = new JButton("Save Colours"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { save(); } }); buttonPanel.add(button); this.setLayout(new BorderLayout()); JPanel bigPanel = new JPanel(new BorderLayout()); bigPanel.add(transPanel, BorderLayout.SOUTH); bigPanel.add(scrollPane, BorderLayout.CENTER); add(bigPanel, BorderLayout.CENTER); add(buttonPanel, BorderLayout.SOUTH); } void setTableData() { Vector allFeatures = new Vector(); Vector features; Enumeration e; SequenceFeature sf; for(int i=0; i< av.alignment.getHeight(); i++) { features = av.alignment.getSequenceAt(i).getDatasetSequence().getSequenceFeatures(); if(features==null) continue; e = features.elements(); while(e.hasMoreElements()) { sf = (SequenceFeature)e.nextElement(); if(!allFeatures.contains(sf.getType())) { allFeatures.addElement(sf.getType()); } } } if(allFeatures.size()<1) { try{ frame.setClosed(true); }catch(Exception ex){} return; } int fSize = allFeatures.size(); String type; boolean originalExists = false; if(originalData!=null) originalExists = true; else originalData = new Object[fSize][3]; Object [][] data = new Object[fSize][3]; for(int i=0; i