2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 import java.awt.event.*;
26 import java.beans.PropertyChangeEvent;
27 import java.beans.PropertyChangeListener;
30 import javax.swing.event.*;
31 import javax.swing.table.*;
33 import jalview.analysis.AlignmentSorter;
34 import jalview.commands.OrderCommand;
35 import jalview.datamodel.*;
38 public class FeatureSettings extends JPanel
40 DasSourceBrowser dassourceBrowser;
42 jalview.ws.DasSequenceFeatureFetcher dasFeatureFetcher;
44 JPanel settingsPane = new JPanel();
46 JPanel dasSettingsPane = new JPanel();
48 final FeatureRenderer fr;
50 public final AlignFrame af;
52 Object[][] originalData;
54 final JInternalFrame frame;
56 JScrollPane scrollPane = new JScrollPane();
62 JSlider transparency = new JSlider();
64 JPanel transPanel = new JPanel(new FlowLayout());
66 public FeatureSettings(AlignFrame af)
69 fr = af.getFeatureRenderer();
71 transparency.setMaximum(100 - (int) (fr.transparency * 100));
76 } catch (Exception ex)
82 table.getTableHeader().setFont(new Font("Verdana", Font.PLAIN, 12));
83 table.setFont(new Font("Verdana", Font.PLAIN, 12));
84 table.setDefaultRenderer(Color.class, new ColorRenderer());
86 table.setDefaultEditor(Color.class, new ColorEditor());
88 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
90 table.addMouseListener(new MouseAdapter()
92 public void mousePressed(MouseEvent evt)
94 selectedRow = table.rowAtPoint(evt.getPoint());
95 if (javax.swing.SwingUtilities.isRightMouseButton(evt))
97 popupSort((String) table.getValueAt(selectedRow, 0), fr.minmax,
98 evt.getX(), evt.getY());
103 table.addMouseMotionListener(new MouseMotionAdapter()
105 public void mouseDragged(MouseEvent evt)
107 int newRow = table.rowAtPoint(evt.getPoint());
108 if (newRow != selectedRow && selectedRow != -1 && newRow != -1)
110 Object[] temp = new Object[3];
111 temp[0] = table.getValueAt(selectedRow, 0);
112 temp[1] = table.getValueAt(selectedRow, 1);
113 temp[2] = table.getValueAt(selectedRow, 2);
115 table.setValueAt(table.getValueAt(newRow, 0), selectedRow, 0);
116 table.setValueAt(table.getValueAt(newRow, 1), selectedRow, 1);
117 table.setValueAt(table.getValueAt(newRow, 2), selectedRow, 2);
119 table.setValueAt(temp[0], newRow, 0);
120 table.setValueAt(temp[1], newRow, 1);
121 table.setValueAt(temp[2], newRow, 2);
123 selectedRow = newRow;
128 scrollPane.setViewportView(table);
130 dassourceBrowser = new DasSourceBrowser();
131 dasSettingsPane.add(dassourceBrowser, BorderLayout.CENTER);
133 if (af.getViewport().featuresDisplayed == null
134 || fr.renderOrder == null)
136 fr.findAllFeatures(true); // display everything!
140 final PropertyChangeListener change;
141 final FeatureSettings fs = this;
142 fr.addPropertyChangeListener(change = new PropertyChangeListener()
144 public void propertyChange(PropertyChangeEvent evt)
146 if (!fs.resettingTable && !fs.handlingUpdate)
148 fs.handlingUpdate = true;
149 fs.resetTable(null); // new groups may be added with new seuqence
150 // feature types only
151 fs.handlingUpdate = false;
157 frame = new JInternalFrame();
158 frame.setContentPane(this);
159 Desktop.addInternalFrame(frame, "Sequence Feature Settings", 400, 450);
161 .addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
163 public void internalFrameClosed(
164 javax.swing.event.InternalFrameEvent evt)
166 fr.removePropertyChangeListener(change);
169 frame.setLayer(JLayeredPane.PALETTE_LAYER);
172 protected void popupSort(final String type, final Hashtable minmax,
175 JPopupMenu men = new JPopupMenu("Settings for " + type);
176 JMenuItem scr = new JMenuItem("Sort by Score");
178 final FeatureSettings me = this;
179 scr.addActionListener(new ActionListener()
182 public void actionPerformed(ActionEvent e)
184 me.sortByScore(new String[]
189 JMenuItem dens = new JMenuItem("Sort by Density");
190 dens.addActionListener(new ActionListener()
193 public void actionPerformed(ActionEvent e)
195 me.sortByDens(new String[]
203 final Object typeMinMax = minmax.get(type);
204 final JCheckBoxMenuItem chb = new JCheckBoxMenuItem("Vary Height");
205 chb.setSelected(minmax.get(type) != null);
206 chb.addActionListener(new ActionListener()
209 public void actionPerformed(ActionEvent e)
211 chb.setState(chb.getState());
214 minmax.put(type, null);
218 minmax.put(type, typeMinMax);
225 men.show(table, x, y);
229 * true when Feature Settings are updating from feature renderer
231 private boolean handlingUpdate = false;
234 * contains a float[3] for each feature type string. created by setTableData
236 Hashtable typeWidth = null;
238 synchronized public void setTableData()
240 if (fr.featureGroups == null)
242 fr.featureGroups = new Hashtable();
244 Vector allFeatures = new Vector();
245 Vector allGroups = new Vector();
246 SequenceFeature[] tmpfeatures;
248 for (int i = 0; i < af.getViewport().alignment.getHeight(); i++)
250 if (af.getViewport().alignment.getSequenceAt(i).getDatasetSequence()
251 .getSequenceFeatures() == null)
256 tmpfeatures = af.getViewport().alignment.getSequenceAt(i)
257 .getDatasetSequence().getSequenceFeatures();
260 while (index < tmpfeatures.length)
262 if (tmpfeatures[index].begin == 0 && tmpfeatures[index].end == 0)
268 if (tmpfeatures[index].getFeatureGroup() != null)
270 group = tmpfeatures[index].featureGroup;
271 if (!allGroups.contains(group))
273 allGroups.addElement(group);
276 checkGroupState(group);
281 if (!allFeatures.contains(tmpfeatures[index].getType()))
283 allFeatures.addElement(tmpfeatures[index].getType());
297 * @return true if group has been seen before and is already added to set.
299 private boolean checkGroupState(String group)
302 if (fr.featureGroups.containsKey(group))
304 visible = ((Boolean) fr.featureGroups.get(group)).booleanValue();
308 visible = true; // new group is always made visible
311 if (groupPanel == null)
313 groupPanel = new JPanel();
316 boolean alreadyAdded = false;
317 for (int g = 0; g < groupPanel.getComponentCount(); g++)
319 if (((JCheckBox) groupPanel.getComponent(g)).getText().equals(group))
322 ((JCheckBox) groupPanel.getComponent(g)).setSelected(visible);
333 fr.featureGroups.put(group, new Boolean(visible));
334 final String grp = group;
335 final JCheckBox check = new JCheckBox(group, visible);
336 check.setFont(new Font("Serif", Font.BOLD, 12));
337 check.addItemListener(new ItemListener()
339 public void itemStateChanged(ItemEvent evt)
341 fr.featureGroups.put(check.getText(), new Boolean(check
343 af.alignPanel.seqPanel.seqCanvas.repaint();
344 if (af.alignPanel.overviewPanel != null)
346 af.alignPanel.overviewPanel.updateOverviewImage();
349 resetTable(new String[]
353 groupPanel.add(check);
357 boolean resettingTable = false;
359 synchronized void resetTable(String[] groupChanged)
361 if (resettingTable == true)
365 resettingTable = true;
366 typeWidth = new Hashtable();
367 // TODO: change avWidth calculation to 'per-sequence' average and use long
369 float[] avWidth = null;
370 SequenceFeature[] tmpfeatures;
371 String group = null, type;
372 Vector visibleChecks = new Vector();
374 // Find out which features should be visible depending on which groups
375 // are selected / deselected
376 // and recompute average width ordering
377 for (int i = 0; i < af.getViewport().alignment.getHeight(); i++)
380 tmpfeatures = af.getViewport().alignment.getSequenceAt(i)
381 .getDatasetSequence().getSequenceFeatures();
382 if (tmpfeatures == null)
388 while (index < tmpfeatures.length)
390 group = tmpfeatures[index].featureGroup;
392 if (tmpfeatures[index].begin == 0 && tmpfeatures[index].end == 0)
398 if (group == null || fr.featureGroups.get(group) == null
399 || ((Boolean) fr.featureGroups.get(group)).booleanValue())
402 checkGroupState(group);
403 type = tmpfeatures[index].getType();
404 if (!visibleChecks.contains(type))
406 visibleChecks.addElement(type);
409 if (!typeWidth.containsKey(tmpfeatures[index].getType()))
411 typeWidth.put(tmpfeatures[index].getType(),
412 avWidth = new float[3]);
416 avWidth = (float[]) typeWidth.get(tmpfeatures[index].getType());
419 if (tmpfeatures[index].getBegin() > tmpfeatures[index].getEnd())
421 avWidth[1] += 1 + tmpfeatures[index].getBegin()
422 - tmpfeatures[index].getEnd();
426 avWidth[1] += 1 + tmpfeatures[index].getEnd()
427 - tmpfeatures[index].getBegin();
433 int fSize = visibleChecks.size();
434 Object[][] data = new Object[fSize][3];
437 if (fr.renderOrder != null)
440 fr.findAllFeatures(groupChanged != null); // prod to update
441 // colourschemes. but don't
443 // First add the checks in the previous render order,
444 // in case the window has been closed and reopened
445 for (int ro = fr.renderOrder.length - 1; ro > -1; ro--)
447 type = fr.renderOrder[ro];
449 if (!visibleChecks.contains(type))
454 data[dataIndex][0] = type;
455 data[dataIndex][1] = fr.getColour(type);
456 data[dataIndex][2] = new Boolean(af.getViewport().featuresDisplayed
459 visibleChecks.removeElement(type);
463 fSize = visibleChecks.size();
464 for (int i = 0; i < fSize; i++)
466 // These must be extra features belonging to the group
467 // which was just selected
468 type = visibleChecks.elementAt(i).toString();
469 data[dataIndex][0] = type;
471 data[dataIndex][1] = fr.getColour(type);
472 if (data[dataIndex][1] == null)
474 // "Colour has been updated in another view!!"
475 fr.renderOrder = null;
479 data[dataIndex][2] = new Boolean(true);
483 if (originalData == null)
485 originalData = new Object[data.length][3];
486 System.arraycopy(data, 0, originalData, 0, data.length);
489 table.setModel(new FeatureTableModel(data));
490 table.getColumnModel().getColumn(0).setPreferredWidth(200);
492 if (groupPanel != null)
494 groupPanel.setLayout(new GridLayout(fr.featureGroups.size() / 4 + 1,
497 groupPanel.validate();
498 bigPanel.add(groupPanel, BorderLayout.NORTH);
501 updateFeatureRenderer(data, groupChanged != null);
502 resettingTable = false;
506 * reorder data based on the featureRenderers global priority list.
510 private void ensureOrder(Object[][] data)
512 boolean sort = false;
513 float[] order = new float[data.length];
514 for (int i = 0; i < order.length; i++)
516 order[i] = fr.getOrder(data[i][0].toString());
518 order[i] = fr.setOrder(data[i][0].toString(), i / order.length);
520 sort = sort || order[i - 1] > order[i];
523 jalview.util.QuickSort.sort(order, data);
528 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
529 .getProperty("LAST_DIRECTORY"), new String[]
530 { "fc" }, new String[]
531 { "Sequence Feature Colours" }, "Sequence Feature Colours");
532 chooser.setFileView(new jalview.io.JalviewFileView());
533 chooser.setDialogTitle("Load Feature Colours");
534 chooser.setToolTipText("Load");
536 int value = chooser.showOpenDialog(this);
538 if (value == JalviewFileChooser.APPROVE_OPTION)
540 File file = chooser.getSelectedFile();
544 InputStreamReader in = new InputStreamReader(new FileInputStream(
547 jalview.binding.JalviewUserColours jucs = new jalview.binding.JalviewUserColours();
548 jucs = (jalview.binding.JalviewUserColours) jucs.unmarshal(in);
550 for (int i = jucs.getColourCount() - 1; i >= 0; i--)
553 fr.setColour(name = jucs.getColour(i).getName(), new Color(
554 Integer.parseInt(jucs.getColour(i).getRGB(), 16)));
555 fr.setOrder(name, (i == 0) ? 0 : i / jucs.getColourCount());
560 Object[][] data = ((FeatureTableModel) table.getModel())
563 updateFeatureRenderer(data, false);
566 } catch (Exception ex)
568 System.out.println("Error loading User Colour File\n" + ex);
575 JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
576 .getProperty("LAST_DIRECTORY"), new String[]
577 { "fc" }, new String[]
578 { "Sequence Feature Colours" }, "Sequence Feature Colours");
579 chooser.setFileView(new jalview.io.JalviewFileView());
580 chooser.setDialogTitle("Save Feature Colour Scheme");
581 chooser.setToolTipText("Save");
583 int value = chooser.showSaveDialog(this);
585 if (value == JalviewFileChooser.APPROVE_OPTION)
587 String choice = chooser.getSelectedFile().getPath();
588 jalview.binding.JalviewUserColours ucs = new jalview.binding.JalviewUserColours();
589 ucs.setSchemeName("Sequence Features");
592 PrintWriter out = new PrintWriter(new OutputStreamWriter(
593 new FileOutputStream(choice), "UTF-8"));
595 Enumeration e = fr.featureColours.keys();
596 float[] sortOrder = new float[fr.featureColours.size()];
597 String[] sortTypes = new String[fr.featureColours.size()];
599 while (e.hasMoreElements())
601 sortTypes[i] = e.nextElement().toString();
602 sortOrder[i] = fr.getOrder(sortTypes[i]);
605 jalview.util.QuickSort.sort(sortOrder, sortTypes);
607 for (i = 0; i < sortTypes.length; i++)
609 jalview.binding.Colour col = new jalview.binding.Colour();
610 col.setName(sortTypes[i]);
611 col.setRGB(jalview.util.Format.getHexString(fr.getColour(col
617 } catch (Exception ex)
619 ex.printStackTrace();
624 public void invertSelection()
626 for (int i = 0; i < table.getRowCount(); i++)
628 Boolean value = (Boolean) table.getValueAt(i, 2);
630 table.setValueAt(new Boolean(!value.booleanValue()), i, 2);
634 public void orderByAvWidth()
636 if (table == null || table.getModel() == null)
638 Object[][] data = ((FeatureTableModel) table.getModel()).getData();
639 float[] width = new float[data.length];
643 for (int i = 0; i < data.length; i++)
645 awidth = (float[]) typeWidth.get(data[i][0]);
648 width[i] = awidth[1] / awidth[0];// *awidth[0]*awidth[2]; - better
649 // weight - but have to make per
650 // sequence, too (awidth[2])
651 // if (width[i]==1) // hack to distinguish single width sequences.
661 boolean sort = false;
662 for (int i = 0; i < width.length; i++)
664 // awidth = (float[]) typeWidth.get(data[i][0]);
667 width[i] = fr.getOrder(data[i][0].toString());
670 width[i] = fr.setOrder(data[i][0].toString(), i / data.length);
675 width[i] /= max; // normalize
676 fr.setOrder(data[i][0].toString(), width[i]); // store for later
679 sort = sort || width[i - 1] > width[i];
682 jalview.util.QuickSort.sort(width, data);
683 // update global priority order
685 updateFeatureRenderer(data, false);
693 frame.setClosed(true);
694 } catch (Exception exe)
700 public void updateFeatureRenderer(Object[][] data)
702 updateFeatureRenderer(data, true);
705 private void updateFeatureRenderer(Object[][] data, boolean visibleNew)
707 fr.setFeaturePriority(data, visibleNew);
708 af.alignPanel.paintAlignment(true);
711 int selectedRow = -1;
713 JTabbedPane tabbedPane = new JTabbedPane();
715 BorderLayout borderLayout1 = new BorderLayout();
717 BorderLayout borderLayout2 = new BorderLayout();
719 BorderLayout borderLayout3 = new BorderLayout();
721 JPanel bigPanel = new JPanel();
723 BorderLayout borderLayout4 = new BorderLayout();
725 JButton invert = new JButton();
727 JPanel buttonPanel = new JPanel();
729 JButton cancel = new JButton();
731 JButton ok = new JButton();
733 JButton loadColours = new JButton();
735 JButton saveColours = new JButton();
737 JPanel dasButtonPanel = new JPanel();
739 JButton fetchDAS = new JButton();
741 JButton saveDAS = new JButton();
743 JButton cancelDAS = new JButton();
745 JButton optimizeOrder = new JButton();
747 JButton sortByScore = new JButton();
749 JButton sortByDens = new JButton();
751 JPanel transbuttons = new JPanel(new BorderLayout());
753 private void jbInit() throws Exception
755 this.setLayout(borderLayout1);
756 settingsPane.setLayout(borderLayout2);
757 dasSettingsPane.setLayout(borderLayout3);
758 bigPanel.setLayout(borderLayout4);
759 invert.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
760 invert.setText("Invert Selection");
761 invert.addActionListener(new ActionListener()
763 public void actionPerformed(ActionEvent e)
768 optimizeOrder.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
769 optimizeOrder.setText("Optimise Order");
770 optimizeOrder.addActionListener(new ActionListener()
772 public void actionPerformed(ActionEvent e)
777 sortByScore.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
778 sortByScore.setText("Seq sort by Score");
779 sortByScore.addActionListener(new ActionListener()
781 public void actionPerformed(ActionEvent e)
786 sortByDens.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
787 sortByDens.setText("Seq Sort by density");
788 sortByDens.addActionListener(new ActionListener()
790 public void actionPerformed(ActionEvent e)
795 cancel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
796 cancel.setText("Cancel");
797 cancel.addActionListener(new ActionListener()
799 public void actionPerformed(ActionEvent e)
801 updateFeatureRenderer(originalData);
805 ok.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
807 ok.addActionListener(new ActionListener()
809 public void actionPerformed(ActionEvent e)
814 loadColours.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
815 loadColours.setText("Load Colours");
816 loadColours.addActionListener(new ActionListener()
818 public void actionPerformed(ActionEvent e)
823 saveColours.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
824 saveColours.setText("Save Colours");
825 saveColours.addActionListener(new ActionListener()
827 public void actionPerformed(ActionEvent e)
832 transparency.addChangeListener(new ChangeListener()
834 public void stateChanged(ChangeEvent evt)
836 fr.setTransparency((float) (100 - transparency.getValue()) / 100f);
837 af.alignPanel.paintAlignment(true);
841 transparency.setMaximum(70);
842 fetchDAS.setText("Fetch DAS Features");
843 fetchDAS.addActionListener(new ActionListener()
845 public void actionPerformed(ActionEvent e)
847 fetchDAS_actionPerformed(e);
850 saveDAS.setText("Save as default");
851 saveDAS.addActionListener(new ActionListener()
853 public void actionPerformed(ActionEvent e)
855 saveDAS_actionPerformed(e);
858 dasButtonPanel.setBorder(BorderFactory.createEtchedBorder());
859 dasSettingsPane.setBorder(null);
860 cancelDAS.setEnabled(false);
861 cancelDAS.setText("Cancel Fetch");
862 cancelDAS.addActionListener(new ActionListener()
864 public void actionPerformed(ActionEvent e)
866 cancelDAS_actionPerformed(e);
869 this.add(tabbedPane, java.awt.BorderLayout.CENTER);
870 tabbedPane.addTab("Feature Settings", settingsPane);
871 tabbedPane.addTab("DAS Settings", dasSettingsPane);
872 bigPanel.add(transPanel, java.awt.BorderLayout.SOUTH);
873 transPanel.add(transparency);
874 transbuttons.add(invert, java.awt.BorderLayout.NORTH);
875 transbuttons.add(optimizeOrder, java.awt.BorderLayout.SOUTH);
876 transPanel.add(transbuttons);
878 buttonPanel.add(cancel);
879 buttonPanel.add(loadColours);
880 buttonPanel.add(saveColours);
881 buttonPanel.add(sortByScore);
882 buttonPanel.add(sortByDens);
883 bigPanel.add(scrollPane, java.awt.BorderLayout.CENTER);
884 dasSettingsPane.add(dasButtonPanel, java.awt.BorderLayout.SOUTH);
885 dasButtonPanel.add(fetchDAS);
886 dasButtonPanel.add(cancelDAS);
887 dasButtonPanel.add(saveDAS);
888 settingsPane.add(bigPanel, java.awt.BorderLayout.CENTER);
889 settingsPane.add(buttonPanel, java.awt.BorderLayout.SOUTH);
892 protected void sortByDens(String[] typ)
894 sortBy(typ, "Sort by Density", AlignmentSorter.FEATURE_DENSITY);
897 protected void sortBy(String[] typ, String methodText, final String method)
901 typ = getDisplayedFeatureTypes();
904 gps = getDisplayedFeatureGroups();
907 for (int i = 0; i < typ.length; i++)
909 System.err.println("Sorting on Types:" + typ[i]);
915 for (int i = 0; i < gps.length; i++)
917 System.err.println("Sorting on groups:" + gps[i]);
920 AlignmentPanel alignPanel = af.alignPanel;
921 AlignmentI al = alignPanel.av.getAlignment();
924 SequenceGroup sg = alignPanel.av.getSelectionGroup();
927 start = sg.getStartRes();
928 stop = sg.getEndRes();
933 stop = al.getWidth();
935 SequenceI[] oldOrder = al.getSequencesArray();
936 AlignmentSorter.sortByFeature(typ, gps, start, stop, al, method);
937 af.addHistoryItem(new OrderCommand(methodText, oldOrder, alignPanel.av
939 alignPanel.paintAlignment(true);
943 protected void sortByScore(String[] typ)
945 sortBy(typ, "Sort by Feature Score", AlignmentSorter.FEATURE_SCORE);
948 private String[] getDisplayedFeatureTypes()
953 synchronized (fr.renderOrder)
955 typ = new String[fr.renderOrder.length];
956 System.arraycopy(fr.renderOrder, 0, typ, 0, typ.length);
957 for (int i = 0; i < typ.length; i++)
959 if (af.viewport.featuresDisplayed.get(typ[i]) == null)
969 private String[] getDisplayedFeatureGroups()
975 if (fr.featureGroups != null)
977 Enumeration en = fr.featureGroups.keys();
978 gps = new String[fr.featureColours.size()];
980 boolean valid = false;
981 while (en.hasMoreElements())
983 String gp = (String) en.nextElement();
984 Boolean on = (Boolean) fr.featureGroups.get(gp);
985 if (on != null && on.booleanValue())
991 while (g < gps.length)
1004 public void fetchDAS_actionPerformed(ActionEvent e)
1006 fetchDAS.setEnabled(false);
1007 cancelDAS.setEnabled(true);
1008 Vector selectedSources = dassourceBrowser.getSelectedSources();
1009 doDasFeatureFetch(selectedSources, true, true);
1013 * get the features from selectedSources for all or the current selection
1015 * @param selectedSources
1016 * @param checkDbRefs
1017 * @param promptFetchDbRefs
1019 private void doDasFeatureFetch(Vector selectedSources,
1020 boolean checkDbRefs, boolean promptFetchDbRefs)
1022 SequenceI[] dataset, seqs;
1024 AlignViewport vp = af.getViewport();
1025 if (vp.getSelectionGroup() != null
1026 && vp.getSelectionGroup().getSize() > 0)
1028 iSize = vp.getSelectionGroup().getSize();
1029 dataset = new SequenceI[iSize];
1030 seqs = vp.getSelectionGroup().getSequencesInOrder(vp.getAlignment());
1034 iSize = vp.getAlignment().getHeight();
1035 seqs = vp.getAlignment().getSequencesArray();
1038 dataset = new SequenceI[iSize];
1039 for (int i = 0; i < iSize; i++)
1041 dataset[i] = seqs[i].getDatasetSequence();
1044 cancelDAS.setEnabled(true);
1045 dasFeatureFetcher = new jalview.ws.DasSequenceFeatureFetcher(dataset,
1046 this, selectedSources, checkDbRefs, promptFetchDbRefs);
1047 af.getViewport().setShowSequenceFeatures(true);
1048 af.showSeqFeatures.setSelected(true);
1052 * blocking call to initialise the das source browser
1054 public void initDasSources()
1056 dassourceBrowser.initDasSources();
1060 * examine the current list of das sources and return any matching the given
1061 * nicknames in sources
1064 * Vector of Strings to resolve to DAS source nicknames.
1065 * @return sources that are present in source list.
1067 public Vector resolveSourceNicknames(Vector sources)
1069 return dassourceBrowser.resolveSourceNicknames(sources);
1073 * get currently selected das sources. ensure you have called initDasSources
1074 * before calling this.
1076 * @return vector of selected das source nicknames
1078 public Vector getSelectedSources()
1080 return dassourceBrowser.getSelectedSources();
1084 * properly initialise DAS fetcher and then initiate a new thread to fetch
1085 * features from the named sources (rather than any turned on by default)
1089 public void fetchDasFeatures(Vector sources)
1092 Vector resolved = resolveSourceNicknames(sources);
1093 if (resolved.size() == 0)
1095 resolved = dassourceBrowser.getSelectedSources();
1097 if (resolved.size() > 0)
1099 final Vector dassources = resolved;
1100 SwingUtilities.invokeLater(new Runnable()
1105 fetchDAS.setEnabled(false);
1106 cancelDAS.setEnabled(true);
1107 doDasFeatureFetch(dassources, true, false);
1114 public void saveDAS_actionPerformed(ActionEvent e)
1117 .saveProperties(jalview.bin.Cache.applicationProperties);
1120 public void complete()
1122 fetchDAS.setEnabled(true);
1123 cancelDAS.setEnabled(false);
1126 public void cancelDAS_actionPerformed(ActionEvent e)
1128 if (dasFeatureFetcher != null)
1130 dasFeatureFetcher.cancel();
1132 fetchDAS.setEnabled(true);
1133 cancelDAS.setEnabled(false);
1136 public void noDasSourceActive()
1139 JOptionPane.showInternalConfirmDialog(Desktop.desktop,
1140 "No das sources were selected.\n"
1141 + "Please select some sources and\n" + " try again.",
1142 "No Sources Selected", JOptionPane.DEFAULT_OPTION,
1143 JOptionPane.INFORMATION_MESSAGE);
1146 // ///////////////////////////////////////////////////////////////////////
1147 // http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
1148 // ///////////////////////////////////////////////////////////////////////
1149 class FeatureTableModel extends AbstractTableModel
1151 FeatureTableModel(Object[][] data)
1156 private String[] columnNames =
1157 { "Feature Type", "Colour", "Display" };
1159 private Object[][] data;
1161 public Object[][] getData()
1166 public void setData(Object[][] data)
1171 public int getColumnCount()
1173 return columnNames.length;
1176 public Object[] getRow(int row)
1181 public int getRowCount()
1186 public String getColumnName(int col)
1188 return columnNames[col];
1191 public Object getValueAt(int row, int col)
1193 return data[row][col];
1196 public Class getColumnClass(int c)
1198 return getValueAt(0, c).getClass();
1201 public boolean isCellEditable(int row, int col)
1203 return col == 0 ? false : true;
1206 public void setValueAt(Object value, int row, int col)
1208 data[row][col] = value;
1209 fireTableCellUpdated(row, col);
1210 updateFeatureRenderer(data);
1215 class ColorRenderer extends JLabel implements TableCellRenderer
1217 javax.swing.border.Border unselectedBorder = null;
1219 javax.swing.border.Border selectedBorder = null;
1221 public ColorRenderer()
1223 setOpaque(true); // MUST do this for background to show up.
1226 public Component getTableCellRendererComponent(JTable table,
1227 Object color, boolean isSelected, boolean hasFocus, int row,
1230 Color newColor = (Color) color;
1231 setBackground(newColor);
1234 if (selectedBorder == null)
1236 selectedBorder = BorderFactory.createMatteBorder(2, 5, 2, 5,
1237 table.getSelectionBackground());
1239 setBorder(selectedBorder);
1243 if (unselectedBorder == null)
1245 unselectedBorder = BorderFactory.createMatteBorder(2, 5, 2, 5,
1246 table.getBackground());
1248 setBorder(unselectedBorder);
1251 setToolTipText("RGB value: " + newColor.getRed() + ", "
1252 + newColor.getGreen() + ", " + newColor.getBlue());
1258 class ColorEditor extends AbstractCellEditor implements TableCellEditor,
1265 JColorChooser colorChooser;
1269 protected static final String EDIT = "edit";
1271 public ColorEditor()
1273 // Set up the editor (from the table's point of view),
1274 // which is a button.
1275 // This button brings up the color chooser dialog,
1276 // which is the editor from the user's point of view.
1277 button = new JButton();
1278 button.setActionCommand(EDIT);
1279 button.addActionListener(this);
1280 button.setBorderPainted(false);
1281 // Set up the dialog that the button brings up.
1282 colorChooser = new JColorChooser();
1283 dialog = JColorChooser.createDialog(button, "Select new Colour", true, // modal
1284 colorChooser, this, // OK button handler
1285 null); // no CANCEL button handler
1289 * Handles events from the editor button and from the dialog's OK button.
1291 public void actionPerformed(ActionEvent e)
1294 if (EDIT.equals(e.getActionCommand()))
1296 // The user has clicked the cell, so
1297 // bring up the dialog.
1298 button.setBackground(currentColor);
1299 colorChooser.setColor(currentColor);
1300 dialog.setVisible(true);
1302 // Make the renderer reappear.
1303 fireEditingStopped();
1307 { // User pressed dialog's "OK" button.
1308 currentColor = colorChooser.getColor();
1312 // Implement the one CellEditor method that AbstractCellEditor doesn't.
1313 public Object getCellEditorValue()
1315 return currentColor;
1318 // Implement the one method defined by TableCellEditor.
1319 public Component getTableCellEditorComponent(JTable table, Object value,
1320 boolean isSelected, int row, int column)
1322 currentColor = (Color) value;