X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FFeatureSettings.java;h=ffa01d59983ce246d24d8673ffea562612664abd;hb=e894eb87d40be6e8452d19032ddffe80dad5f804;hp=7dae70387af45bd3f515697e9a661035d0cb1790;hpb=daeacba9a61069114333b550a987242d8e47e7f7;p=jalview.git diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 7dae703..ffa01d5 100755 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -1,496 +1,755 @@ -/* - * 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-1; ro--) + { + type = fr.renderOrder[ro]; + + if(!visibleChecks.contains(type)) + continue; + + data[dataIndex][0] = type; + data[dataIndex][1] = fr.getColour(type); + data[dataIndex][2] = new Boolean(af.getViewport().featuresDisplayed.containsKey(type)); + dataIndex++; + visibleChecks.removeElement(type); + } + } + + fSize = visibleChecks.size(); + for(int i=0; i0) + { + iSize = af.getViewport().getSelectionGroup().getSize(false); + dataset = new SequenceI[iSize]; + seqs = af.getViewport().getSelectionGroup(). + getSequencesInOrder( + af.getViewport().getAlignment()); + } + else + { + iSize = af.getViewport().getAlignment().getHeight(); + seqs = af.getViewport().getAlignment().getSequencesArray(); + } + + dataset = new SequenceI[iSize]; + for (int i = 0; i < iSize; i++) + { + dataset[i] = seqs[i].getDatasetSequence(); + } + + new jalview.io.DasSequenceFeatureFetcher( + dataset, + af, + selectedSources); + + af.getViewport().setShowSequenceFeatures(true); + af.showSeqFeatures.setSelected(true); + } + + public void saveDAS_actionPerformed(ActionEvent e) + { + dassourceBrowser.saveProperties(jalview.bin.Cache.applicationProperties); + } + + ///////////////////////////////////////////////////////////////////////// + // http://java.sun.com/docs/books/tutorial/uiswing/components/table.html + ///////////////////////////////////////////////////////////////////////// + class FeatureTableModel + extends AbstractTableModel + { + FeatureTableModel(Object[][] data) + { + this.data = data; + } + + private String[] columnNames = {"Feature Type", "Colour","Display"}; + private Object[][] data; + + public Object[][] getData() + { + return data; + } + + public void setData(Object[][] data) + { + this.data = data; + } + + public int getColumnCount() { + return columnNames.length; + } + + public Object[] getRow(int row) + { + return data[row]; + } + + public int getRowCount() { + return data.length; + } + + public String getColumnName(int col) { + return columnNames[col]; + } + + public Object getValueAt(int row, int col) { + return data[row][col]; + } + + public Class getColumnClass(int c) { + return getValueAt(0, c).getClass(); + } + + public boolean isCellEditable(int row, int col) { + return col==0 ? false:true; + } + + public void setValueAt(Object value, int row, int col) { + data[row][col] = value; + fireTableCellUpdated(row, col); + updateFeatureRenderer(data); + } + + } + class ColorRenderer extends JLabel + implements TableCellRenderer { + javax.swing.border.Border unselectedBorder = null; + javax.swing.border.Border selectedBorder = null; + + public ColorRenderer() { + setOpaque(true); //MUST do this for background to show up. + } + + public Component getTableCellRendererComponent( + JTable table, Object color, + boolean isSelected, boolean hasFocus, + int row, int column) { + Color newColor = (Color)color; + setBackground(newColor); + if (isSelected) { + if (selectedBorder == null) { + selectedBorder = BorderFactory.createMatteBorder(2,5,2,5, + table.getSelectionBackground()); + } + setBorder(selectedBorder); + } else { + if (unselectedBorder == null) { + unselectedBorder = BorderFactory.createMatteBorder(2,5,2,5, + table.getBackground()); + } + setBorder(unselectedBorder); + } + + setToolTipText("RGB value: " + newColor.getRed() + ", " + + newColor.getGreen() + ", " + + newColor.getBlue()); + return this; + } + } +} + + class ColorEditor extends AbstractCellEditor + implements TableCellEditor, + ActionListener { + Color currentColor; + JButton button; + JColorChooser colorChooser; + JDialog dialog; + protected static final String EDIT = "edit"; + + public ColorEditor() { + //Set up the editor (from the table's point of view), + //which is a button. + //This button brings up the color chooser dialog, + //which is the editor from the user's point of view. + button = new JButton(); + button.setActionCommand(EDIT); + button.addActionListener(this); + button.setBorderPainted(false); + //Set up the dialog that the button brings up. + colorChooser = new JColorChooser(); + dialog = JColorChooser.createDialog(button, + "Select new Colour", + true, //modal + colorChooser, + this, //OK button handler + null); //no CANCEL button handler + } + + /** + * Handles events from the editor button and from + * the dialog's OK button. + */ + public void actionPerformed(ActionEvent e) { + + if (EDIT.equals(e.getActionCommand())) { + //The user has clicked the cell, so + //bring up the dialog. + button.setBackground(currentColor); + colorChooser.setColor(currentColor); + dialog.setVisible(true); + + //Make the renderer reappear. + fireEditingStopped(); + + } else { //User pressed dialog's "OK" button. + currentColor = colorChooser.getColor(); + } + } + + //Implement the one CellEditor method that AbstractCellEditor doesn't. + public Object getCellEditorValue() { + return currentColor; + } + + //Implement the one method defined by TableCellEditor. + public Component getTableCellEditorComponent(JTable table, + Object value, + boolean isSelected, + int row, + int column) { + currentColor = (Color)value; + return button; + } +}