/* * 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.appletgui; import jalview.datamodel.*; import java.awt.*; import java.util.*; import java.awt.event.*; public class FeatureSettings extends Panel implements ItemListener, MouseListener, MouseMotionListener { final FeatureRenderer fr; final AlignmentPanel ap; final AlignViewport av; final Frame frame; Panel groupPanel; Panel featurePanel = new Panel(); public FeatureSettings(AlignViewport av, final AlignmentPanel ap) { this.ap = ap; this.av = av; fr = ap.seqPanel.seqCanvas.getFeatureRenderer(); setTableData(); this.setLayout(new BorderLayout()); ScrollPane sp = new ScrollPane(); sp.add(featurePanel); add(sp, BorderLayout.CENTER); if(groupPanel!=null) { sp = new ScrollPane(); sp.add(groupPanel); add(sp, BorderLayout.NORTH); sp.validate(); sp.setSize( 100, 55); } frame = new Frame(); frame.add(this); int height = featurePanel.getComponentCount()*50 ; if (height>400) height = 400; jalview.bin.JalviewLite.addFrame(frame, "Feature Settings", 200, height); } void setTableData() { if(fr.featureGroups==null) fr.featureGroups = new Hashtable(); else fr.featureGroups.clear(); Vector allFeatures = new Vector(); Enumeration tmpfeatures; SequenceFeature sf; for (int i = 0; i < av.alignment.getHeight(); i++) { if (av.alignment.getSequenceAt(i).getSequenceFeatures() == null) continue; tmpfeatures = av.alignment.getSequenceAt(i).getSequenceFeatures().elements(); while (tmpfeatures.hasMoreElements()) { sf = (SequenceFeature) tmpfeatures.nextElement(); if (!allFeatures.contains(sf.getType())) { allFeatures.addElement(sf.getType()); Color col = fr.getColour(sf.getType()); boolean displayed = true; if (fr.featuresDisplayed != null) displayed = fr.featuresDisplayed.contains(sf.getType()); Checkbox check = new Checkbox(sf.getType(), displayed); check.addMouseListener(this); check.addMouseMotionListener(this); check.setBackground(col); check.addItemListener(this); featurePanel.add(check); } if(sf.getFeatureGroup()!=null && !fr.featureGroups.containsKey(sf.getFeatureGroup())) { fr.featureGroups.put(sf.getFeatureGroup(), new Boolean(true)); if(groupPanel==null) groupPanel = new Panel(); Checkbox check = new Checkbox(sf.getFeatureGroup(), true); check.setFont(new Font("Serif", Font.BOLD, 12)); check.addItemListener(this); groupPanel.add(check); } } } featurePanel.setLayout(new GridLayout(allFeatures.size(), 2, 10,5)); featurePanel.validate(); } public void itemStateChanged(ItemEvent evt) { if(evt!=null) { //Is the source a top level featureGroup? Checkbox source = (Checkbox) evt.getSource(); if (fr.featureGroups.containsKey(source.getLabel())) { fr.featureGroups.put(source.getLabel(), new Boolean(source.getState())); ap.seqPanel.seqCanvas.repaint(); if (ap.overviewPanel != null) ap.overviewPanel.updateOverviewImage(); return; } } Component[] comps = featurePanel.getComponents(); int cSize = comps.length; Object[][] data = new Object[cSize][3]; for (int i = 0; i < cSize; i++) { Checkbox check = (Checkbox) comps[i]; data[i][0] = check.getLabel(); data[i][1] = fr.getColour(check.getLabel()); data[i][2] = new Boolean(check.getState()); } fr.setFeaturePriority(data); ap.seqPanel.seqCanvas.repaint(); if (ap.overviewPanel != null) ap.overviewPanel.updateOverviewImage(); } Checkbox selectedCheck; boolean dragging = false; public void mousePressed(MouseEvent evt) { selectedCheck = (Checkbox)evt.getSource(); } public void mouseDragged(MouseEvent evt) { dragging = true; } public void mouseReleased(MouseEvent evt) { Component comp = null; Checkbox target = null; int height = evt.getY()+evt.getComponent().getLocation().y; if(height > this.getSize().height) { comp = featurePanel.getComponent(featurePanel.getComponentCount()-1); } else if(height < 0) { comp = featurePanel.getComponent(0); } else { comp = featurePanel.getComponentAt(evt.getX(), evt.getY() + evt.getComponent().getLocation().y); } if(comp!=null && comp instanceof Checkbox) target = (Checkbox)comp; if (selectedCheck != null && target != null && selectedCheck != target) { int targetIndex = -1; for(int i=0; i