--- /dev/null
+\r
+package jalview.appletgui;\r
+\r
+import java.awt.*;\r
+import java.applet.*;\r
+import java.awt.event.*;\r
+import java.util.*;\r
+\r
+public class Tooltip extends Canvas implements MouseListener,\r
+ MouseMotionListener\r
+{\r
+\r
+ private String [] tip;\r
+ protected Component owner;\r
+\r
+ private Container mainContainer;\r
+ private LayoutManager mainLayout;\r
+\r
+ private boolean shown;\r
+\r
+ private final int VERTICAL_OFFSET = 20;\r
+ private final int HORIZONTAL_ENLARGE = 10;\r
+\r
+ int fontHeight = 0;\r
+\r
+ Image linkImage;\r
+\r
+ FontMetrics fm;\r
+\r
+\r
+\r
+ public Tooltip(String tip, Component owner)\r
+ {\r
+ this.owner = owner;\r
+ owner.addMouseListener(this);\r
+ owner.addMouseMotionListener(this);\r
+ setBackground(new Color(255, 255, 220));\r
+ setTip(tip);\r
+ java.net.URL url = getClass().getResource("/images/link.gif");\r
+ if (url != null)\r
+ {\r
+ linkImage = java.awt.Toolkit.getDefaultToolkit().getImage(url);\r
+ }\r
+ }\r
+\r
+\r
+ public void paint(Graphics g)\r
+ {\r
+ g.drawRect(0,0,getSize().width -1, getSize().height -1);\r
+ int lindex, x;\r
+ for(int i=0; i<tip.length; i++)\r
+ {\r
+ x = 3;\r
+ lindex = tip[i].indexOf("%LINK%");\r
+ if(lindex!=-1)\r
+ {\r
+ if(lindex>0)\r
+ {\r
+ g.drawString(tip[i].substring(0, lindex), 3, (i+1)*fontHeight-3);\r
+ x+=fm.stringWidth(tip[i].substring(0, lindex)+3);\r
+ }\r
+ // g.drawString("(right click)", linkImage.getWidth(this)+6, (i+1)*fontHeight-3);\r
+ g.drawImage(linkImage, x, i * fontHeight, this);\r
+ }\r
+ else\r
+ g.drawString(tip[i], 3, (i+1)*fontHeight - 3);\r
+ }\r
+ }\r
+\r
+ private void addToolTip()\r
+ {\r
+ mainContainer.setLayout(null);\r
+ mainContainer.add(this, 0);\r
+ mainContainer.validate();\r
+ repaint();\r
+ shown = true;\r
+ }\r
+\r
+ void setTip(String tip)\r
+ {\r
+ fm = getFontMetrics(owner.getFont());\r
+ fontHeight = fm.getHeight();\r
+\r
+ int longestLine = 0;\r
+ StringTokenizer st = new StringTokenizer(tip, "\n");\r
+ this.tip = new String[st.countTokens()];\r
+ int index = 0;\r
+ while(st.hasMoreElements())\r
+ {\r
+ this.tip[index] = st.nextToken();\r
+ if(fm.stringWidth(this.tip[index])>longestLine)\r
+ longestLine = fm.stringWidth(this.tip[index]);\r
+ index ++;\r
+ }\r
+\r
+ setSize(longestLine + HORIZONTAL_ENLARGE,\r
+ fontHeight*this.tip.length);\r
+ }\r
+\r
+ void setTipLocation(int x, int y)\r
+ {\r
+\r
+ setLocation((owner.getLocationOnScreen().x - mainContainer.getLocationOnScreen().x) +x,\r
+ (owner.getLocationOnScreen().y - mainContainer.getLocationOnScreen().y + VERTICAL_OFFSET)+y);\r
+\r
+\r
+\r
+ // correction, whole tool tip must be visible\r
+ if (mainContainer.getSize().width < (getLocation().x + getSize().width))\r
+ {\r
+ setLocation(mainContainer.getSize().width - getSize().width,\r
+ getLocation().y);\r
+ }\r
+\r
+ }\r
+\r
+\r
+ private void removeToolTip() {\r
+ if (shown) {\r
+ mainContainer.remove(0);\r
+ mainContainer.setLayout(mainLayout);\r
+ mainContainer.validate();\r
+ }\r
+ shown = false;\r
+ }\r
+\r
+ private void findMainContainer() {\r
+ Container parent = owner.getParent();\r
+ while (true) {\r
+ if ((parent instanceof Applet) || (parent instanceof Frame)) {\r
+ mainContainer = parent;\r
+ break;\r
+ } else {\r
+ parent = parent.getParent();\r
+ }\r
+ }\r
+ mainLayout = mainContainer.getLayout();\r
+ }\r
+\r
+ public void mouseEntered(MouseEvent me)\r
+ { }\r
+\r
+ public void mouseExited(MouseEvent me)\r
+ {\r
+ removeToolTip();\r
+ }\r
+\r
+ public void mousePressed(MouseEvent me)\r
+ {\r
+ removeToolTip();\r
+ }\r
+\r
+ public void mouseReleased(MouseEvent me)\r
+ {}\r
+\r
+ public void mouseClicked(MouseEvent me)\r
+ {}\r
+\r
+ public void mouseMoved(MouseEvent me)\r
+ {\r
+ if (shown)\r
+ setTipLocation(me.getX(), me.getY());\r
+ else\r
+ {\r
+ findMainContainer();\r
+ addToolTip();\r
+ setTipLocation(me.getX(), me.getY());\r
+ }\r
+ }\r
+\r
+ public void mouseDragged(MouseEvent me)\r
+ {}\r
+}\r
--- /dev/null
+/*\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
+ */\r
+package jalview.gui;\r
+\r
+import jalview.jbgui.*;\r
+import javax.swing.table.AbstractTableModel;\r
+import javax.swing.event.*;\r
+import jalview.util.TableSorter;\r
+import java.awt.event.*;\r
+import javax.swing.*;\r
+import java.util.*;\r
+import java.net.*;\r
+\r
+import org.biojava.services.das.registry.DasCoordinateSystem;\r
+import org.biojava.services.das.registry.DasSource;\r
+import java.awt.BorderLayout;\r
+\r
+public class DasSourceBrowser extends GDasSourceBrowser\r
+ implements Runnable, ListSelectionListener\r
+{\r
+ static DasSource[] dasSources = null;\r
+\r
+ Hashtable localSources = null;\r
+\r
+ Vector selectedSources;\r
+\r
+ public DasSourceBrowser()\r
+ {\r
+ registryURL.setText(jalview.bin.Cache.getDefault("DAS_REGISTRY_URL",\r
+ "http://servlet.sanger.ac.uk/dasregistry/services/das_registry") );\r
+\r
+ setSelectedFromProperties();\r
+\r
+ displayFullDetails(null);\r
+ table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);\r
+\r
+ capabilities.addListSelectionListener(this);\r
+ coords1.addListSelectionListener(this);\r
+ coords2.addListSelectionListener(this);\r
+\r
+ //Ask to be notified of selection changes.\r
+ ListSelectionModel rowSM = table.getSelectionModel();\r
+ rowSM.addListSelectionListener(new ListSelectionListener()\r
+ {\r
+ public void valueChanged(ListSelectionEvent e)\r
+ {\r
+ //Ignore extra messages.\r
+ if (e.getValueIsAdjusting())\r
+ return;\r
+\r
+ ListSelectionModel lsm = (ListSelectionModel) e.getSource();\r
+ if (!lsm.isSelectionEmpty())\r
+ {\r
+ int selectedRow = lsm.getMinSelectionIndex();\r
+ displayFullDetails(table.getValueAt(selectedRow, 0).toString());\r
+ }\r
+ }\r
+ });\r
+\r
+ table.addMouseListener(new MouseAdapter()\r
+ {\r
+ public void mouseClicked(MouseEvent evt)\r
+ {\r
+ if(evt.getClickCount()==2\r
+ || SwingUtilities.isRightMouseButton(evt))\r
+ editRemoveLocalSource(evt);\r
+ }\r
+ });\r
+\r
+ if(dasSources==null)\r
+ {\r
+ Thread worker = new Thread(this);\r
+ worker.start();\r
+ }\r
+ else\r
+ {\r
+ init();\r
+ }\r
+ }\r
+\r
+ void init()\r
+ {\r
+ int dSize = dasSources.length;\r
+ Object[][] data = new Object[dSize][2];\r
+ for (int i = 0; i < dSize; i++)\r
+ {\r
+ data[i][0] = dasSources[i].getNickname();\r
+ data[i][1] = new Boolean(selectedSources.contains(dasSources[i].\r
+ getNickname()));\r
+ }\r
+\r
+ refreshTableData(data);\r
+ setCapabilities(dasSources);\r
+\r
+ javax.swing.SwingUtilities.invokeLater(new Runnable()\r
+ {\r
+ public void run()\r
+ {\r
+ TableSorter sorter = (TableSorter)table.getModel();\r
+ sorter.setSortingStatus(1, TableSorter.DESCENDING);\r
+ sorter.setSortingStatus(1, TableSorter.NOT_SORTED);\r
+ }\r
+ });\r
+\r
+ progressBar.setIndeterminate(false);\r
+ progressBar.setVisible(false);\r
+ addLocal.setVisible(true);\r
+ refresh.setVisible(true);\r
+ }\r
+\r
+\r
+ public void refreshTableData(Object[][] data)\r
+ {\r
+ TableSorter sorter = new TableSorter(new DASTableModel(data));\r
+ sorter.setTableHeader(table.getTableHeader());\r
+ table.setModel(sorter);\r
+ }\r
+\r
+ void displayFullDetails(String nickName)\r
+ {\r
+\r
+ StringBuffer text = new StringBuffer(\r
+ "<HTML><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">");\r
+\r
+ if (nickName == null)\r
+ {\r
+ fullDetails.setText(text +\r
+ "Select a DAS service from the table"\r
+ + " to read a full description here.</font></html>");\r
+ return;\r
+ }\r
+\r
+ int dSize = dasSources.length;\r
+ for (int i = 0; i < dSize; i++)\r
+ {\r
+ if (!dasSources[i].getNickname().equals(nickName))\r
+ continue;\r
+\r
+ DasSource ds = dasSources[i];\r
+\r
+ text.append("<font color=\"#0000FF\">Id:</font> " + dasSources[i].getId() +\r
+ "<br>");\r
+ text.append("<font color=\"#0000FF\">Nickname:</font> " +\r
+ dasSources[i].getNickname() + "<br>");\r
+ text.append("<font color=\"#0000FF\">URL:</font> " + dasSources[i].getUrl() +\r
+ "<br>");\r
+\r
+ text.append("<font color=\"#0000FF\">Admin Email:</font> <a href=\"mailto:"\r
+ +dasSources[i].getAdminemail()\r
+ +"\">"+dasSources[i].getAdminemail()+"</a>" +\r
+ "<br>");\r
+\r
+\r
+ text.append("<font color=\"#0000FF\">Registered at:</font> " + dasSources[i].getRegisterDate() +\r
+ "<br>");\r
+\r
+ text.append("<font color=\"#0000FF\">Last successful test:</font> " + dasSources[i].getLeaseDate() +\r
+ "<br>");\r
+\r
+ text.append("<font color=\"#0000FF\">Labels:</font> ");\r
+ for(int s=0; s<dasSources[i].getLabels().length; s++)\r
+ {\r
+ text.append( dasSources[i].getLabels()[s]);\r
+ if(s<dasSources[i].getLabels().length-1)\r
+ text.append(",");\r
+ text.append(" ");\r
+ }\r
+ text.append("<br>");\r
+\r
+\r
+\r
+ text.append("<font color=\"#0000FF\">Capabilities:</font> ");\r
+ String[] scap = dasSources[i].getCapabilities();\r
+ for (int j = 0; j < scap.length; j++)\r
+ {\r
+ text.append(scap[j]);\r
+ if (j < scap.length - 1)\r
+ text.append(", ");\r
+ }\r
+ text.append("<br>");\r
+\r
+ text.append("<font color=\"#0000FF\">Coordinates:</font> ");\r
+ DasCoordinateSystem[] dcs = ds.getCoordinateSystem();\r
+ for (int j = 0; j < dcs.length; j++)\r
+ {\r
+ text.append("(" + dcs[j].getUniqueId() + ") "\r
+ + dcs[j].getCategory() + ", " + dcs[j].getName());\r
+ if (dcs[j].getNCBITaxId() != 0)\r
+ text.append(", " + dcs[j].getNCBITaxId());\r
+ if (dcs[j].getOrganismName().length() > 0)\r
+ text.append(", " + dcs[j].getOrganismName());\r
+\r
+ text.append("<br>");\r
+ }\r
+\r
+ text.append("<font color=\"#0000FF\">Description:</font> " +\r
+ dasSources[i].getDescription() + "<br>");\r
+\r
+ if (dasSources[i].getHelperurl().length() > 0)\r
+ {\r
+ text.append("<font color=\"#0000FF\"><a href=\"" +\r
+ dasSources[i].getHelperurl()\r
+ + "\">Go to site</a></font<br>");\r
+ }\r
+\r
+ text.append("</font></html>");\r
+\r
+ break;\r
+ }\r
+\r
+ fullDetails.setText(text.toString());\r
+ javax.swing.SwingUtilities.invokeLater(new Runnable()\r
+ {\r
+ public void run()\r
+ {\r
+ fullDetailsScrollpane.getVerticalScrollBar().setValue(0);\r
+ }\r
+ });\r
+ }\r
+\r
+\r
+ public void run()\r
+ {\r
+ addLocal.setVisible(false);\r
+ refresh.setVisible(false);\r
+ progressBar.setVisible(true);\r
+ progressBar.setIndeterminate(true);\r
+\r
+ dasSources = jalview.io.DasSequenceFeatureFetcher.getDASSources();\r
+\r
+ appendLocalSources();\r
+\r
+ init();\r
+ }\r
+\r
+ public DasSource[] getDASSource()\r
+ {\r
+ if(dasSources==null)\r
+ {\r
+ dasSources = jalview.io.DasSequenceFeatureFetcher.getDASSources();\r
+ appendLocalSources();\r
+ }\r
+\r
+ return dasSources;\r
+ }\r
+\r
+ public void refresh_actionPerformed(ActionEvent e)\r
+ {\r
+ saveProperties(jalview.bin.Cache.applicationProperties);\r
+\r
+ Thread worker = new Thread(this);\r
+ worker.start();\r
+ }\r
+\r
+ private void setCapabilities(DasSource[] sources)\r
+ {\r
+ Vector vcapabilities = new Vector();\r
+ Vector vcoords = new Vector();\r
+ Vector vcoords2 = new Vector();\r
+\r
+ vcapabilities.addElement("All");\r
+ vcoords.addElement("All");\r
+ vcoords2.addElement("All");\r
+\r
+ for (int i = 0; i < sources.length; i++)\r
+ {\r
+ DasSource ds = sources[i];\r
+ String[] scap = ds.getCapabilities();\r
+ for (int s = 0; s < scap.length; s++)\r
+ {\r
+ if (!vcapabilities.contains(scap[s]))\r
+ {\r
+ vcapabilities.addElement(scap[s]);\r
+ }\r
+ }\r
+\r
+ DasCoordinateSystem[] dcs = ds.getCoordinateSystem();\r
+\r
+ for (int j = 0; j < dcs.length; j++)\r
+ {\r
+ if (!vcoords.contains(dcs[j].getCategory()))\r
+ vcoords.addElement(dcs[j].getCategory());\r
+\r
+ if (!vcoords2.contains(dcs[j].getName()))\r
+ vcoords2.addElement(dcs[j].getName());\r
+ }\r
+ }\r
+\r
+ capabilities.setListData(vcapabilities);\r
+ coords1.setListData(vcoords);\r
+ coords2.setListData(vcoords2);\r
+\r
+ javax.swing.SwingUtilities.invokeLater(new Runnable()\r
+ {\r
+ public void run()\r
+ {\r
+ capabilities.setSelectedIndex(0);\r
+ coords1.setSelectedIndex(0);\r
+ coords2.setSelectedIndex(0);\r
+ }\r
+ });\r
+ }\r
+\r
+ public void amendLocal(boolean newSource)\r
+ {\r
+ String url = "http://localhost:8080/", nickname = "";\r
+\r
+ if(!newSource)\r
+ {\r
+ int selectedRow = table.getSelectionModel().getMinSelectionIndex();\r
+ nickname = table.getValueAt(selectedRow, 0).toString();\r
+ url = ((DasSource)localSources.get(nickname)).getUrl();\r
+ }\r
+\r
+ JTextField nametf = new JTextField(nickname, 40);\r
+ JTextField urltf = new JTextField(url, 40);\r
+\r
+ JPanel panel = new JPanel(new BorderLayout());\r
+ JPanel pane12 = new JPanel(new BorderLayout());\r
+ pane12.add(new JLabel("Nickname: "), BorderLayout.CENTER);\r
+ pane12.add(nametf, BorderLayout.EAST);\r
+ panel.add(pane12, BorderLayout.NORTH);\r
+ pane12 = new JPanel(new BorderLayout());\r
+ pane12.add(new JLabel("URL: "), BorderLayout.CENTER);\r
+ pane12.add(urltf, BorderLayout.EAST);\r
+ panel.add(pane12, BorderLayout.SOUTH);\r
+\r
+\r
+ int reply = JOptionPane.showInternalConfirmDialog(Desktop.desktop,\r
+ panel, "Enter Nickname & URL of Local DAS Source",\r
+ JOptionPane.OK_CANCEL_OPTION);\r
+\r
+ if (reply != JOptionPane.OK_OPTION )\r
+ {\r
+ return;\r
+ }\r
+\r
+ if(!urltf.getText().endsWith("/"))\r
+ urltf.setText(urltf.getText()+"/");\r
+\r
+ DasSource local = new DasSource();\r
+\r
+ local.setUrl(urltf.getText());\r
+ local.setNickname(nametf.getText());\r
+\r
+\r
+ if(localSources==null)\r
+ localSources = new Hashtable();\r
+\r
+ localSources.put(local.getNickname(), local);\r
+\r
+ if(!newSource && !nickname.equals(nametf.getText()))\r
+ {\r
+ localSources.remove(nickname);\r
+ }\r
+\r
+ int size = dasSources.length;\r
+ int adjust = newSource ? 1 : 0;\r
+\r
+ Object[][] data = new Object[size+adjust][2];\r
+ for (int i = 0; i < size; i++)\r
+ {\r
+ if(!newSource && dasSources[i].getNickname().equals(nickname))\r
+ {\r
+ ((DasSource)dasSources[i]).setNickname(local.getNickname());\r
+ ((DasSource)dasSources[i]).setUrl(local.getUrl());\r
+ data[i][0] = local.getNickname();\r
+ data[i][1] = new Boolean(true);\r
+ }\r
+ else\r
+ {\r
+ data[i][0] = dasSources[i].getNickname();\r
+ data[i][1] = new Boolean(selectedSources.contains(dasSources[i].\r
+ getNickname()));\r
+ }\r
+ }\r
+\r
+ if(newSource)\r
+ {\r
+ data[size][0] = local.getNickname();\r
+ data[size][1] = new Boolean(true);\r
+ selectedSources.add(local.getNickname());\r
+ }\r
+\r
+ DasSource [] tmp = new DasSource[size+adjust];\r
+\r
+ System.arraycopy(dasSources, 0, tmp, 0, size);\r
+\r
+ if(newSource)\r
+ tmp[size] = local;\r
+\r
+ dasSources = tmp;\r
+\r
+ refreshTableData(data);\r
+\r
+ SwingUtilities.invokeLater(new Runnable()\r
+ {\r
+ public void run()\r
+ {\r
+ scrollPane.getVerticalScrollBar().setValue(\r
+ scrollPane.getVerticalScrollBar().getMaximum()\r
+ );\r
+ }\r
+ });\r
+\r
+ displayFullDetails(local.getNickname());\r
+ }\r
+\r
+ public void editRemoveLocalSource(MouseEvent evt)\r
+ {\r
+ int selectedRow = table.getSelectionModel().getMinSelectionIndex();\r
+ if(selectedRow==-1)\r
+ return;\r
+\r
+ String nickname = table.getValueAt(selectedRow, 0).toString();\r
+\r
+ if (!localSources.containsKey(nickname))\r
+ {\r
+ JOptionPane.showInternalMessageDialog(Desktop.desktop,\r
+ "You can only edit or remove local DAS Sources!",\r
+ "Public DAS source - not editable",\r
+ JOptionPane.WARNING_MESSAGE);\r
+ return;\r
+ }\r
+\r
+\r
+ Object[] options = {"Edit", "Remove", "Cancel"};\r
+ int choice = JOptionPane.showInternalOptionDialog(Desktop.desktop,\r
+ "Do you want to edit or remove "+nickname+"?",\r
+ "Edit / Remove Local DAS Source",\r
+ JOptionPane.YES_NO_CANCEL_OPTION,\r
+ JOptionPane.QUESTION_MESSAGE,\r
+ null,\r
+ options,\r
+ options[2]);\r
+\r
+ switch(choice)\r
+ {\r
+ case 0: amendLocal(false); break;\r
+ case 1:\r
+ localSources.remove(nickname);\r
+ selectedSources.remove(nickname);\r
+ Object[][] data = new Object[dasSources.length-1][2];\r
+ DasSource [] tmp = new DasSource[dasSources.length-1];\r
+ int index = 0;\r
+ for (int i = 0; i < dasSources.length; i++)\r
+ {\r
+ if (dasSources[i].getNickname().equals(nickname))\r
+ {\r
+ continue;\r
+ }\r
+ else\r
+ {\r
+ tmp[index] = dasSources[i];\r
+ data[index][0] = dasSources[i].getNickname();\r
+ data[index][1] = new Boolean(selectedSources.contains(dasSources[i].\r
+ getNickname()));\r
+ index++;\r
+ }\r
+ }\r
+ dasSources = tmp;\r
+ refreshTableData(data);\r
+ SwingUtilities.invokeLater(new Runnable()\r
+ {\r
+ public void run()\r
+ {\r
+ scrollPane.getVerticalScrollBar().setValue(\r
+ scrollPane.getVerticalScrollBar().getMaximum()\r
+ );\r
+ }\r
+ });\r
+\r
+ break;\r
+ }\r
+ }\r
+\r
+ void appendLocalSources()\r
+ {\r
+ if(localSources==null)\r
+ return;\r
+\r
+ int size = dasSources.length;\r
+ int lsize = localSources.size();\r
+\r
+ Object[][] data = new Object[size+lsize][2];\r
+ for (int i = 0; i < size; i++)\r
+ {\r
+ data[i][0] = dasSources[i].getNickname();\r
+ data[i][1] = new Boolean(selectedSources.contains(dasSources[i].\r
+ getNickname()));\r
+ }\r
+\r
+ DasSource [] tmp = new DasSource[size+lsize];\r
+ System.arraycopy(dasSources, 0, tmp, 0, size);\r
+\r
+ Enumeration en = localSources.keys();\r
+ int index = size;\r
+ while(en.hasMoreElements())\r
+ {\r
+ String key = en.nextElement().toString();\r
+ data[index][0] = key;\r
+ data[index][1] = new Boolean(false);\r
+ tmp[index] = new DasSource();\r
+ tmp[index].setNickname(key);\r
+ tmp[index].setUrl( ((DasSource)localSources.get(key)).getUrl() );\r
+\r
+ index++;\r
+ }\r
+\r
+ dasSources = tmp;\r
+\r
+ refreshTableData(data);\r
+ }\r
+\r
+ public void valueChanged(ListSelectionEvent evt)\r
+ {\r
+ //Called when the MainTable selection changes\r
+ if (evt.getValueIsAdjusting())\r
+ {\r
+ return;\r
+ }\r
+\r
+ displayFullDetails(null);\r
+\r
+ // Filter the displayed data sources\r
+ int dSize = dasSources.length;\r
+ ArrayList names = new ArrayList();\r
+ ArrayList selected = new ArrayList();\r
+ DasSource ds;\r
+\r
+ // capabilities.get\r
+ for (int i = 0; i < dSize; i++)\r
+ {\r
+ ds = dasSources[i];\r
+\r
+ if (!selectedInList(capabilities, ds.getCapabilities()))\r
+ {\r
+ continue;\r
+ }\r
+\r
+ DasCoordinateSystem[] dcs = ds.getCoordinateSystem();\r
+ for (int j = 0; j < dcs.length; j++)\r
+ {\r
+ if (selectedInList(coords1, new String[]\r
+ {dcs[j].getCategory()})\r
+ && selectedInList(coords2, new String[]\r
+ {dcs[j].getName()}))\r
+ {\r
+ names.add(ds.getNickname());\r
+ selected.add(new Boolean(\r
+ selectedSources.contains(ds.getNickname())));\r
+ break;\r
+ }\r
+ }\r
+ }\r
+\r
+ dSize = names.size();\r
+ Object[][] data = new Object[dSize][2];\r
+ for (int d = 0; d < dSize; d++)\r
+ {\r
+ data[d][0] = names.get(d);\r
+ data[d][1] = selected.get(d);\r
+ }\r
+\r
+ refreshTableData(data);\r
+ }\r
+\r
+ boolean selectedInList(JList list, String[] items)\r
+ {\r
+ Object[] selection = list.getSelectedValues();\r
+ for (int i = 0; i < selection.length; i++)\r
+ {\r
+ if (selection[i].equals("All"))\r
+ return true;\r
+\r
+ for (int j = 0; j < items.length; j++)\r
+ {\r
+ if (selection[i].equals(items[j]))\r
+ return true;\r
+ }\r
+ }\r
+\r
+ return false;\r
+ }\r
+\r
+ void setSelectedFromProperties()\r
+ {\r
+ String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE", "uniprot");\r
+ StringTokenizer st = new StringTokenizer(active, "\t");\r
+ selectedSources = new Vector();\r
+ while(st.hasMoreTokens())\r
+ {\r
+ selectedSources.addElement(st.nextToken());\r
+ }\r
+\r
+ String local = jalview.bin.Cache.getProperty("DAS_LOCAL_SOURCE");\r
+ if(local!=null)\r
+ {\r
+ if(localSources == null)\r
+ localSources = new Hashtable();\r
+\r
+ st = new StringTokenizer(local, "\t");\r
+ while(st.hasMoreTokens())\r
+ {\r
+ String token = st.nextToken();\r
+ int bar = token.indexOf("|");\r
+ DasSource source = new DasSource();\r
+\r
+ source.setUrl(token.substring(bar + 1));\r
+ source.setNickname(token.substring(0, bar));\r
+\r
+ localSources.put(source.getNickname(), source);\r
+ }\r
+ }\r
+ }\r
+\r
+ void saveProperties(Properties properties)\r
+ {\r
+ properties.setProperty("DAS_REGISTRY_URL", registryURL.getText());\r
+\r
+ StringBuffer sb = new StringBuffer();\r
+ for(int r=0; r<table.getModel().getRowCount(); r++)\r
+ {\r
+ if( ((Boolean)table.getValueAt(r,1)).booleanValue())\r
+ {\r
+ sb.append(table.getValueAt(r,0)+"\t");\r
+ }\r
+ }\r
+\r
+ properties.setProperty("DAS_ACTIVE_SOURCE", sb.toString() );\r
+\r
+ if(localSources!=null)\r
+ {\r
+ sb = new StringBuffer();\r
+ Enumeration en = localSources.keys();\r
+ while(en.hasMoreElements())\r
+ {\r
+ String token = en.nextElement().toString();\r
+ sb.append(token+"|"\r
+ + ((DasSource)localSources.get(token)).getUrl()\r
+ +"\t");\r
+ }\r
+\r
+ properties.setProperty("DAS_LOCAL_SOURCE", sb.toString());\r
+ }\r
+\r
+ }\r
+\r
+ class DASTableModel\r
+ extends AbstractTableModel\r
+ {\r
+\r
+ public DASTableModel(Object[][] data)\r
+ {\r
+ this.data = data;\r
+ }\r
+\r
+ private String[] columnNames = new String[] {"Nickname", "Use Source"};\r
+\r
+ private Object[][] data;\r
+\r
+ public int getColumnCount()\r
+ {\r
+ return columnNames.length;\r
+ }\r
+\r
+ public int getRowCount()\r
+ {\r
+ return data.length;\r
+ }\r
+\r
+ public String getColumnName(int col)\r
+ {\r
+ return columnNames[col];\r
+ }\r
+\r
+ public Object getValueAt(int row, int col)\r
+ {\r
+ return data[row][col];\r
+ }\r
+\r
+ /*\r
+ * JTable uses this method to determine the default renderer/\r
+ * editor for each cell. If we didn't implement this method,\r
+ * then the last column would contain text ("true"/"false"),\r
+ * rather than a check box.\r
+ */\r
+ public Class getColumnClass(int c)\r
+ {\r
+ return getValueAt(0, c).getClass();\r
+ }\r
+\r
+ /*\r
+ * Don't need to implement this method unless your table's\r
+ * editable.\r
+ */\r
+ public boolean isCellEditable(int row, int col)\r
+ {\r
+ //Note that the data/cell address is constant,\r
+ //no matter where the cell appears onscreen.\r
+ return col == 1;\r
+\r
+ }\r
+\r
+ /*\r
+ * Don't need to implement this method unless your table's\r
+ * data can change.\r
+ */\r
+ public void setValueAt(Object value, int row, int col)\r
+ {\r
+ data[row][col] = value;\r
+ fireTableCellUpdated(row, col);\r
+\r
+ String name = getValueAt(row,0).toString();\r
+ boolean selected = ((Boolean)value).booleanValue();\r
+\r
+ if(selectedSources.contains(name) && !selected)\r
+ selectedSources.remove(name);\r
+\r
+ if(!selectedSources.contains(name) && selected)\r
+ selectedSources.add(name);\r
+ }\r
+ }\r
+}\r
+\r
+\r
--- /dev/null
+/*\r
+* Jalview - A Sequence Alignment Editor and Viewer\r
+* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+*\r
+* This program is free software; you can redistribute it and/or\r
+* modify it under the terms of the GNU General Public License\r
+* as published by the Free Software Foundation; either version 2\r
+* of the License, or (at your option) any later version.\r
+*\r
+* This program is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+* GNU General Public License for more details.\r
+*\r
+* You should have received a copy of the GNU General Public License\r
+* along with this program; if not, write to the Free Software\r
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
+*/\r
+package jalview.io;\r
+\r
+import jalview.datamodel.*;\r
+\r
+import jalview.gui.*;\r
+\r
+import java.util.*;\r
+\r
+import java.net.URL;\r
+\r
+import org.biojava.dasobert.das.FeatureThread;\r
+import org.biojava.dasobert.dasregistry.Das1Source;\r
+import org.biojava.dasobert.eventmodel.FeatureEvent;\r
+import org.biojava.dasobert.eventmodel.FeatureListener;\r
+import org.biojava.services.das.registry.DasRegistryAxisClient;\r
+import org.biojava.services.das.registry.DasSource;\r
+\r
+\r
+import jalview.bin.Cache;\r
+\r
+\r
+\r
+/**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @author $author$\r
+ * @version $Revision$\r
+ */\r
+public class DasSequenceFeatureFetcher implements Runnable\r
+{\r
+ final AlignmentI dataset;\r
+ final AlignmentPanel ap;\r
+ StringBuffer sbuffer = new StringBuffer();\r
+\r
+\r
+\r
+ /**\r
+ * Creates a new SequenceFeatureFetcher object.\r
+ *\r
+ * @param align DOCUMENT ME!\r
+ * @param ap DOCUMENT ME!\r
+ */\r
+ public DasSequenceFeatureFetcher(AlignmentI align, AlignmentPanel ap)\r
+ {\r
+ this.dataset = align.getDataset();\r
+ this.ap = ap;\r
+\r
+ Thread thread = new Thread(this);\r
+ thread.start();\r
+ }\r
+ /**\r
+ * creates a jalview sequence feature from a das feature document\r
+ * @param dasfeature\r
+ * @return sequence feature object created using dasfeature information\r
+ */\r
+ SequenceFeature newSequenceFeature(Map dasfeature, String nickname)\r
+ {\r
+ try {\r
+ /**\r
+ * Different qNames for a DAS Feature - are string keys to the HashMaps in features\r
+ * "METHOD") ||\r
+ qName.equals("TYPE") ||\r
+ qName.equals("START") ||\r
+ qName.equals("END") ||\r
+ qName.equals("NOTE") ||\r
+ qName.equals("LINK") ||\r
+ qName.equals("SCORE")\r
+ */\r
+ String desc = new String();\r
+ if (dasfeature.containsKey("NOTE"))\r
+ desc+=(String) dasfeature.get("NOTE");\r
+\r
+\r
+ int start = 0, end = 0;\r
+ float score = 0f;\r
+\r
+ try{ start = Integer.parseInt( dasfeature.get("START").toString()); }\r
+ catch( Exception ex){}\r
+ try{ end = Integer.parseInt( dasfeature.get("END").toString()); }\r
+ catch (Exception ex){}\r
+ try{ score = Integer.parseInt( dasfeature.get("SCORE").toString()); }\r
+ catch (Exception ex){}\r
+\r
+\r
+ SequenceFeature f = new SequenceFeature(\r
+ (String) dasfeature.get("TYPE"),\r
+ desc,\r
+ start,\r
+ end,\r
+ score,\r
+ nickname);\r
+\r
+ if (dasfeature.containsKey("LINK"))\r
+ {\r
+ f.addLink(f.getType()+" "+f.begin+"_"+f.end\r
+ +"|"+ dasfeature.get("LINK"));\r
+ }\r
+ // (String) dasfeature.get("ID"),\r
+ //// (String) dasfeature.get("METHOD"),\r
+ // (String) dasfeature.get("SCORE"),\r
+ // null\r
+ // );\r
+\r
+ // System.out.println(nickname+" "+f.getType()+" "+f.begin+" "+f.end);\r
+ return f;\r
+ }\r
+ catch (Exception e) {\r
+ e.printStackTrace();\r
+ Cache.log.debug("Failed to parse "+dasfeature.toString(), e);\r
+ return null;\r
+ }\r
+ }\r
+ /**\r
+ * fetch and add das features to a sequence using the given source URL and Id to create a feature request\r
+ * @param seq\r
+ * @param SourceUrl\r
+ * @param id\r
+ */\r
+ protected void createFeatureFetcher(final Sequence seq,\r
+ final String sourceUrl,\r
+ String id,\r
+ String nickname) {\r
+ //////////////\r
+ /// fetch DAS features\r
+ final Das1Source source = new Das1Source();\r
+ source.setUrl(sourceUrl);\r
+ source.setNickname(nickname);\r
+\r
+\r
+ Cache.log.debug("new Das Feature Fetcher for " + id + " querying " +\r
+ sourceUrl);\r
+ if (id != null && id.length() > 0)\r
+ {\r
+ FeatureThread fetcher = new FeatureThread(id + ":" + seq.getStart() + "," +seq.getEnd()\r
+ , source);\r
+\r
+ fetcher.addFeatureListener(new FeatureListener()\r
+ {\r
+ public void comeBackLater(FeatureEvent e)\r
+ {\r
+ Cache.log.debug("das source " + e.getDasSource().getNickname() +\r
+ " asked us to come back in " + e.getComeBackLater() +\r
+ " secs.");\r
+ }\r
+\r
+ public void newFeatures(FeatureEvent e)\r
+ {\r
+ Das1Source ds = e.getDasSource();\r
+\r
+ Map[] features = e.getFeatures();\r
+ // add features to sequence\r
+ Cache.log.debug("das source " + ds.getUrl() + " returned " +\r
+ features.length + " features");\r
+\r
+\r
+ if (features.length > 0)\r
+ {\r
+ for (int i = 0; i < features.length; i++)\r
+ {\r
+\r
+ SequenceFeature f = newSequenceFeature(features[i],\r
+ source.getNickname());\r
+\r
+ if (seq.sequenceFeatures != null)\r
+ {\r
+ for (int j = 0; (f != null) && j < seq.sequenceFeatures.length;\r
+ j++)\r
+ {\r
+ if (seq.sequenceFeatures[j].equals(f))\r
+ {\r
+ f = null;\r
+ }\r
+ }\r
+ }\r
+ if (f != null)\r
+ {\r
+ seq.addSequenceFeature(f);\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+ );\r
+\r
+ //NOTE alignPanel listener will be called after the previous\r
+ //anonymous listener!!!\r
+ fetcher.addFeatureListener(ap);\r
+\r
+ fetcher.start();\r
+ }\r
+ }\r
+ /**\r
+ * Spawns a number of dasobert Fetcher threads to add features to sequences in the dataset\r
+ */\r
+ public void run()\r
+ {\r
+ DasSource [] sources = new jalview.gui.DasSourceBrowser().getDASSource();\r
+\r
+ String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE", "uniprot");\r
+ StringTokenizer st = new StringTokenizer(active, "\t");\r
+ Vector selectedSources = new Vector();\r
+ String token;\r
+ while (st.hasMoreTokens())\r
+ {\r
+ token = st.nextToken();\r
+ for(int i=0; i<sources.length; i++)\r
+ {\r
+ if(sources[i].getNickname().equals(token))\r
+ {\r
+ selectedSources.addElement(sources[i]);\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ // DasSource test = new DasSource();\r
+ // test.setUrl("http://localhost:8080/das/gffdb/");\r
+ //test.setNickname("Trixkid");\r
+ // selectedSources.addElement(test);\r
+\r
+\r
+ if(selectedSources == null || selectedSources.size()==0)\r
+ {\r
+ System.out.println("No DAS Sources active");\r
+ return;\r
+ }\r
+\r
+ try\r
+ {\r
+ int seqIndex = 0;\r
+ Vector sequences = dataset.getSequences();\r
+ while (seqIndex < sequences.size())\r
+ {\r
+ Sequence sequence = (Sequence) sequences.get(seqIndex);\r
+ Vector uprefs = jalview.util.DBRefUtils.selectRefs(sequence.getDBRef(), new String[] {"DBREF"});\r
+\r
+ for(int sourceIndex=0; sourceIndex<selectedSources.size(); sourceIndex++)\r
+ {\r
+ DasSource dasSource = (DasSource)selectedSources.elementAt(sourceIndex);\r
+\r
+ if (uprefs != null)\r
+ {\r
+ // we know the id for this entry, so don't note its ID in the unknownSequences list\r
+ for (int j = 0, k = uprefs.size(); j < k; j++)\r
+ {\r
+\r
+ createFeatureFetcher(sequence,\r
+ dasSource.getUrl(),\r
+ ( (DBRefEntry) uprefs.get(j)).getAccessionId(),\r
+ dasSource.getNickname());\r
+ }\r
+ }\r
+ else\r
+ {\r
+ String id = null;\r
+ // try and use the name as the sequence id\r
+ if (sequence.getName().indexOf("|") > -1)\r
+ {\r
+ id = sequence.getName().substring(\r
+ sequence.getName().lastIndexOf("|") + 1);\r
+ }\r
+ else\r
+ {\r
+ id = sequence.getName();\r
+ }\r
+ if (id != null)\r
+ {\r
+ // Should try to call a general feature fetcher that queries many sources with name to discover applicable ID references\r
+ createFeatureFetcher(sequence,\r
+ dasSource.getUrl(),\r
+ id,\r
+ dasSource.getNickname());\r
+ }\r
+ }\r
+ }\r
+\r
+ seqIndex++;\r
+ }\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ ex.printStackTrace();\r
+ }\r
+ }\r
+\r
+\r
+ public static DasSource[] getDASSources()\r
+ {\r
+ try\r
+ {\r
+ String registryURL = jalview.bin.Cache.getDefault("DAS_REGISTRY_URL",\r
+ "http://servlet.sanger.ac.uk/dasregistry/services/das_registry");\r
+\r
+\r
+ URL url = new URL(registryURL);\r
+\r
+ DasRegistryAxisClient client = new DasRegistryAxisClient(url);\r
+\r
+ DasSource[] services = client.listServices();\r
+\r
+ return services;\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ ex.printStackTrace();\r
+ }\r
+ return null;\r
+\r
+ }\r
+\r
+}\r
+\r
+\r
--- /dev/null
+/*\r
+ * Jalview - A Sequence Alignment Editor and Viewer\r
+ * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
+ */\r
+package jalview.jbgui;\r
+\r
+import javax.swing.*;\r
+import javax.swing.border.TitledBorder;\r
+import java.awt.event.ActionListener;\r
+import java.awt.event.ActionEvent;\r
+import java.awt.*;\r
+import javax.swing.BorderFactory;\r
+import javax.swing.event.HyperlinkListener;\r
+import javax.swing.event.HyperlinkEvent;\r
+import java.awt.Dimension;\r
+\r
+public class GDasSourceBrowser\r
+ extends JPanel\r
+{\r
+ public GDasSourceBrowser()\r
+ {\r
+ try\r
+ {\r
+ jbInit();\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ ex.printStackTrace();\r
+ }\r
+ }\r
+\r
+ private void jbInit()\r
+ throws Exception\r
+ {\r
+ this.setLayout(gridBagLayout1);\r
+ refresh.setText("Refresh Available Sources");\r
+ refresh.addActionListener(new ActionListener()\r
+ {\r
+ public void actionPerformed(ActionEvent e)\r
+ {\r
+ refresh_actionPerformed(e);\r
+ }\r
+ });\r
+ progressBar.setPreferredSize(new Dimension(450, 20));\r
+ progressBar.setString("");\r
+ scrollPane.setBorder(titledBorder1);\r
+ scrollPane.setBorder(BorderFactory.createEtchedBorder());\r
+ fullDetailsScrollpane.setBorder(BorderFactory.createEtchedBorder());\r
+ fullDetails.addHyperlinkListener(new HyperlinkListener()\r
+ {\r
+ public void hyperlinkUpdate(HyperlinkEvent e)\r
+ {\r
+ fullDetails_hyperlinkUpdate(e);\r
+ }\r
+ });\r
+ fullDetails.setEditable(false);\r
+ jLabel1.setText("<html><p align=\"right\">Show sources serving</p></html>");\r
+ jLabel2.setText("and");\r
+ jLabel3.setHorizontalAlignment(SwingConstants.RIGHT);\r
+ jLabel3.setText("<html><p align=\"right\">using coordinates</p></html>");\r
+ registryLabel.setHorizontalAlignment(SwingConstants.TRAILING);\r
+ registryLabel.setText("Use Registry");\r
+ addLocal.setText("Add Local Source");\r
+ addLocal.addActionListener(new ActionListener()\r
+ {\r
+ public void actionPerformed(ActionEvent e)\r
+ {\r
+ amendLocal(true);\r
+ }\r
+ });\r
+ jPanel1.setLayout(flowLayout1);\r
+ jPanel1.setMinimumSize(new Dimension(596, 30));\r
+ jPanel1.setPreferredSize(new Dimension(596, 30));\r
+ scrollPane.getViewport().add(table);\r
+ fullDetailsScrollpane.getViewport().add(fullDetails);\r
+ jScrollPane3.getViewport().add(coords1);\r
+ jScrollPane2.getViewport().add(capabilities);\r
+ jScrollPane4.getViewport().add(coords2);\r
+ jPanel1.add(refresh, null);\r
+ jPanel1.add(addLocal, null);\r
+ jPanel1.add(progressBar, null);\r
+ this.add(registryLabel, new GridBagConstraints(0, 2, 2, 1, 0.0, 0.0\r
+ , GridBagConstraints.WEST, GridBagConstraints.NONE,\r
+ new Insets(11, 2, 0, 0), 9, 2));\r
+ this.add(registryURL, new GridBagConstraints(2, 2, 5, 1, 1.0, 0.0\r
+ , GridBagConstraints.WEST,\r
+ GridBagConstraints.HORIZONTAL,\r
+ new Insets(6, 7, 0, 10), 393,\r
+ 3));\r
+ this.add(jLabel2, new GridBagConstraints(5, 1, 1, 1, 0.0, 0.0\r
+ , GridBagConstraints.WEST,\r
+ GridBagConstraints.NONE,\r
+ new Insets(36, 7, 35, 0), 5, 21));\r
+ this.add(jLabel3, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0\r
+ , GridBagConstraints.WEST,\r
+ GridBagConstraints.NONE,\r
+ new Insets(33, 0, 29, 0), 5, 16));\r
+ this.add(jLabel1,\r
+ new GridBagConstraints(0, 1, 1, GridBagConstraints.REMAINDER, 0.0,\r
+ 0.0\r
+ , GridBagConstraints.WEST,\r
+ GridBagConstraints.NONE,\r
+ new Insets( -60, 2, 0, 0), 5, 20));\r
+ this.add(jPanel1, new GridBagConstraints(0, 3, 7, 1, 1.0, 1.0\r
+ , GridBagConstraints.CENTER,\r
+ GridBagConstraints.HORIZONTAL,\r
+ new Insets(0, 0, 0, 0), 0, 0));\r
+ this.add(fullDetailsScrollpane, new GridBagConstraints(3, 0, 4, 1, 1.0, 1.0\r
+ , GridBagConstraints.CENTER, GridBagConstraints.BOTH,\r
+ new Insets(3, 0, 0, 3), 240, 130));\r
+ this.add(scrollPane, new GridBagConstraints(0, 0, 3, 1, 1.0, 1.0\r
+ , GridBagConstraints.CENTER,\r
+ GridBagConstraints.BOTH,\r
+ new Insets(3, 2, 0, 0), 150,\r
+ 130));\r
+ this.add(jScrollPane3, new GridBagConstraints(4, 1, 1, 1, 1.0, 1.0\r
+ , GridBagConstraints.CENTER,\r
+ GridBagConstraints.BOTH,\r
+ new Insets(9, 0, 0, 0), 80, 0));\r
+ this.add(jScrollPane2, new GridBagConstraints(1, 1, 2, 1, 1.0, 1.0\r
+ , GridBagConstraints.CENTER,\r
+ GridBagConstraints.BOTH,\r
+ new Insets(9, 0, 0, 0), 80, 0));\r
+ this.add(jScrollPane4, new GridBagConstraints(6, 1, 1, 1, 1.0, 1.0\r
+ , GridBagConstraints.CENTER,\r
+ GridBagConstraints.BOTH,\r
+ new Insets(9, 0, 0, 9), 80, 0));\r
+ }\r
+\r
+ protected JTable table = new JTable();\r
+ protected JEditorPane fullDetails = new JEditorPane("text/html", "");\r
+ TitledBorder titledBorder1 = new TitledBorder("Available DAS Sources");\r
+ protected JButton refresh = new JButton();\r
+ protected JProgressBar progressBar = new JProgressBar();\r
+ protected JScrollPane scrollPane = new JScrollPane();\r
+ TitledBorder titledBorder2 = new TitledBorder("Full Details");\r
+ protected JScrollPane fullDetailsScrollpane = new JScrollPane();\r
+ protected JList capabilities = new JList();\r
+ protected JList coords1 = new JList();\r
+ protected JList coords2 = new JList();\r
+ JLabel jLabel1 = new JLabel();\r
+ JLabel jLabel2 = new JLabel();\r
+ JLabel jLabel3 = new JLabel();\r
+ JScrollPane jScrollPane2 = new JScrollPane();\r
+ JScrollPane jScrollPane3 = new JScrollPane();\r
+ JScrollPane jScrollPane4 = new JScrollPane();\r
+ protected JTextField registryURL = new JTextField();\r
+ protected JLabel registryLabel = new JLabel();\r
+ protected JButton addLocal = new JButton();\r
+ JPanel jPanel1 = new JPanel();\r
+ FlowLayout flowLayout1 = new FlowLayout();\r
+ GridBagLayout gridBagLayout1 = new GridBagLayout();\r
+ public void refresh_actionPerformed(ActionEvent e)\r
+ {\r
+\r
+ }\r
+\r
+ public void fullDetails_hyperlinkUpdate(HyperlinkEvent e)\r
+ {\r
+ try{\r
+\r
+ if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)\r
+ jalview.util.BrowserLauncher.openURL(e.getURL().toString());\r
+ }\r
+ catch(Exception ex)\r
+ {\r
+ System.out.println(e.getURL());\r
+ ex.printStackTrace();\r
+ }\r
+ }\r
+\r
+ public void amendLocal(boolean newSource)\r
+ {\r
+\r
+ }\r
+\r
+}\r
--- /dev/null
+package jalview.util;\r
+\r
+import java.awt.*;\r
+import java.awt.event.*;\r
+import java.util.*;\r
+import java.util.List;\r
+\r
+import javax.swing.*;\r
+import javax.swing.event.TableModelEvent;\r
+import javax.swing.event.TableModelListener;\r
+import javax.swing.table.*;\r
+\r
+/**\r
+ * TableSorter is a decorator for TableModels; adding sorting\r
+ * functionality to a supplied TableModel. TableSorter does\r
+ * not store or copy the data in its TableModel; instead it maintains\r
+ * a map from the row indexes of the view to the row indexes of the\r
+ * model. As requests are made of the sorter (like getValueAt(row, col))\r
+ * they are passed to the underlying model after the row numbers\r
+ * have been translated via the internal mapping array. This way,\r
+ * the TableSorter appears to hold another copy of the table\r
+ * with the rows in a different order.\r
+ * <p/>\r
+ * TableSorter registers itself as a listener to the underlying model,\r
+ * just as the JTable itself would. Events recieved from the model\r
+ * are examined, sometimes manipulated (typically widened), and then\r
+ * passed on to the TableSorter's listeners (typically the JTable).\r
+ * If a change to the model has invalidated the order of TableSorter's\r
+ * rows, a note of this is made and the sorter will resort the\r
+ * rows the next time a value is requested.\r
+ * <p/>\r
+ * When the tableHeader property is set, either by using the\r
+ * setTableHeader() method or the two argument constructor, the\r
+ * table header may be used as a complete UI for TableSorter.\r
+ * The default renderer of the tableHeader is decorated with a renderer\r
+ * that indicates the sorting status of each column. In addition,\r
+ * a mouse listener is installed with the following behavior:\r
+ * <ul>\r
+ * <li>\r
+ * Mouse-click: Clears the sorting status of all other columns\r
+ * and advances the sorting status of that column through three\r
+ * values: {NOT_SORTED, ASCENDING, DESCENDING} (then back to\r
+ * NOT_SORTED again).\r
+ * <li>\r
+ * SHIFT-mouse-click: Clears the sorting status of all other columns\r
+ * and cycles the sorting status of the column through the same\r
+ * three values, in the opposite order: {NOT_SORTED, DESCENDING, ASCENDING}.\r
+ * <li>\r
+ * CONTROL-mouse-click and CONTROL-SHIFT-mouse-click: as above except\r
+ * that the changes to the column do not cancel the statuses of columns\r
+ * that are already sorting - giving a way to initiate a compound\r
+ * sort.\r
+ * </ul>\r
+ * <p/>\r
+ * This is a long overdue rewrite of a class of the same name that\r
+ * first appeared in the swing table demos in 1997.\r
+ *\r
+ * @author Philip Milne\r
+ * @author Brendon McLean\r
+ * @author Dan van Enckevort\r
+ * @author Parwinder Sekhon\r
+ * @version 2.0 02/27/04\r
+ */\r
+\r
+public class TableSorter extends AbstractTableModel {\r
+ protected TableModel tableModel;\r
+\r
+ public static final int DESCENDING = -1;\r
+ public static final int NOT_SORTED = 0;\r
+ public static final int ASCENDING = 1;\r
+\r
+ private static Directive EMPTY_DIRECTIVE = new Directive(-1, NOT_SORTED);\r
+\r
+ public static final Comparator COMPARABLE_COMAPRATOR = new Comparator() {\r
+ public int compare(Object o1, Object o2) {\r
+ return ((Comparable) o1).compareTo(o2);\r
+ }\r
+ };\r
+ public static final Comparator LEXICAL_COMPARATOR = new Comparator() {\r
+ public int compare(Object o1, Object o2) {\r
+ return o1.toString().compareTo(o2.toString());\r
+ }\r
+ };\r
+\r
+ private Row[] viewToModel;\r
+ private int[] modelToView;\r
+\r
+ private JTableHeader tableHeader;\r
+ private MouseListener mouseListener;\r
+ private TableModelListener tableModelListener;\r
+ private Map columnComparators = new HashMap();\r
+ private List sortingColumns = new ArrayList();\r
+\r
+ public TableSorter() {\r
+ this.mouseListener = new MouseHandler();\r
+ this.tableModelListener = new TableModelHandler();\r
+ }\r
+\r
+ public TableSorter(TableModel tableModel) {\r
+ this();\r
+ setTableModel(tableModel);\r
+ }\r
+\r
+ public TableSorter(TableModel tableModel, JTableHeader tableHeader) {\r
+ this();\r
+ setTableHeader(tableHeader);\r
+ setTableModel(tableModel);\r
+ }\r
+\r
+ private void clearSortingState() {\r
+ viewToModel = null;\r
+ modelToView = null;\r
+ }\r
+\r
+ public TableModel getTableModel() {\r
+ return tableModel;\r
+ }\r
+\r
+ public void setTableModel(TableModel tableModel) {\r
+ if (this.tableModel != null) {\r
+ this.tableModel.removeTableModelListener(tableModelListener);\r
+ }\r
+\r
+ this.tableModel = tableModel;\r
+ if (this.tableModel != null) {\r
+ this.tableModel.addTableModelListener(tableModelListener);\r
+ }\r
+\r
+ clearSortingState();\r
+ fireTableStructureChanged();\r
+ }\r
+\r
+ public JTableHeader getTableHeader() {\r
+ return tableHeader;\r
+ }\r
+\r
+ public void setTableHeader(JTableHeader tableHeader) {\r
+ if (this.tableHeader != null) {\r
+ this.tableHeader.removeMouseListener(mouseListener);\r
+ TableCellRenderer defaultRenderer = this.tableHeader.getDefaultRenderer();\r
+ if (defaultRenderer instanceof SortableHeaderRenderer) {\r
+ this.tableHeader.setDefaultRenderer(((SortableHeaderRenderer) defaultRenderer).tableCellRenderer);\r
+ }\r
+ }\r
+ this.tableHeader = tableHeader;\r
+ if (this.tableHeader != null) {\r
+ this.tableHeader.addMouseListener(mouseListener);\r
+ this.tableHeader.setDefaultRenderer(\r
+ new SortableHeaderRenderer(this.tableHeader.getDefaultRenderer()));\r
+ }\r
+ }\r
+\r
+ public boolean isSorting() {\r
+ return sortingColumns.size() != 0;\r
+ }\r
+\r
+ private Directive getDirective(int column) {\r
+ for (int i = 0; i < sortingColumns.size(); i++) {\r
+ Directive directive = (Directive)sortingColumns.get(i);\r
+ if (directive.column == column) {\r
+ return directive;\r
+ }\r
+ }\r
+ return EMPTY_DIRECTIVE;\r
+ }\r
+\r
+ public int getSortingStatus(int column) {\r
+ return getDirective(column).direction;\r
+ }\r
+\r
+ private void sortingStatusChanged() {\r
+ clearSortingState();\r
+ fireTableDataChanged();\r
+ if (tableHeader != null) {\r
+ tableHeader.repaint();\r
+ }\r
+ }\r
+\r
+ public void setSortingStatus(int column, int status) {\r
+ Directive directive = getDirective(column);\r
+ if (directive != EMPTY_DIRECTIVE) {\r
+ sortingColumns.remove(directive);\r
+ }\r
+ if (status != NOT_SORTED) {\r
+ sortingColumns.add(new Directive(column, status));\r
+ }\r
+ sortingStatusChanged();\r
+ }\r
+\r
+ protected Icon getHeaderRendererIcon(int column, int size) {\r
+ Directive directive = getDirective(column);\r
+ if (directive == EMPTY_DIRECTIVE) {\r
+ return null;\r
+ }\r
+ return new Arrow(directive.direction == DESCENDING, size, sortingColumns.indexOf(directive));\r
+ }\r
+\r
+ private void cancelSorting() {\r
+ sortingColumns.clear();\r
+ sortingStatusChanged();\r
+ }\r
+\r
+ public void setColumnComparator(Class type, Comparator comparator) {\r
+ if (comparator == null) {\r
+ columnComparators.remove(type);\r
+ } else {\r
+ columnComparators.put(type, comparator);\r
+ }\r
+ }\r
+\r
+ protected Comparator getComparator(int column) {\r
+ Class columnType = tableModel.getColumnClass(column);\r
+ Comparator comparator = (Comparator) columnComparators.get(columnType);\r
+ if (comparator != null) {\r
+ return comparator;\r
+ }\r
+ if (Comparable.class.isAssignableFrom(columnType)) {\r
+ return COMPARABLE_COMAPRATOR;\r
+ }\r
+ return LEXICAL_COMPARATOR;\r
+ }\r
+\r
+ private Row[] getViewToModel() {\r
+ if (viewToModel == null) {\r
+ int tableModelRowCount = tableModel.getRowCount();\r
+ viewToModel = new Row[tableModelRowCount];\r
+ for (int row = 0; row < tableModelRowCount; row++) {\r
+ viewToModel[row] = new Row(row);\r
+ }\r
+\r
+ if (isSorting()) {\r
+ Arrays.sort(viewToModel);\r
+ }\r
+ }\r
+ return viewToModel;\r
+ }\r
+\r
+ public int modelIndex(int viewIndex) {\r
+ return getViewToModel()[viewIndex].modelIndex;\r
+ }\r
+\r
+ private int[] getModelToView() {\r
+ if (modelToView == null) {\r
+ int n = getViewToModel().length;\r
+ modelToView = new int[n];\r
+ for (int i = 0; i < n; i++) {\r
+ modelToView[modelIndex(i)] = i;\r
+ }\r
+ }\r
+ return modelToView;\r
+ }\r
+\r
+ // TableModel interface methods\r
+\r
+ public int getRowCount() {\r
+ return (tableModel == null) ? 0 : tableModel.getRowCount();\r
+ }\r
+\r
+ public int getColumnCount() {\r
+ return (tableModel == null) ? 0 : tableModel.getColumnCount();\r
+ }\r
+\r
+ public String getColumnName(int column) {\r
+ return tableModel.getColumnName(column);\r
+ }\r
+\r
+ public Class getColumnClass(int column) {\r
+ return tableModel.getColumnClass(column);\r
+ }\r
+\r
+ public boolean isCellEditable(int row, int column) {\r
+ return tableModel.isCellEditable(modelIndex(row), column);\r
+ }\r
+\r
+ public Object getValueAt(int row, int column) {\r
+ return tableModel.getValueAt(modelIndex(row), column);\r
+ }\r
+\r
+ public void setValueAt(Object aValue, int row, int column) {\r
+ tableModel.setValueAt(aValue, modelIndex(row), column);\r
+ }\r
+\r
+ // Helper classes\r
+\r
+ private class Row implements Comparable {\r
+ private int modelIndex;\r
+\r
+ public Row(int index) {\r
+ this.modelIndex = index;\r
+ }\r
+\r
+ public int compareTo(Object o) {\r
+ int row1 = modelIndex;\r
+ int row2 = ((Row) o).modelIndex;\r
+\r
+ for (Iterator it = sortingColumns.iterator(); it.hasNext();) {\r
+ Directive directive = (Directive) it.next();\r
+ int column = directive.column;\r
+ Object o1 = tableModel.getValueAt(row1, column);\r
+ Object o2 = tableModel.getValueAt(row2, column);\r
+\r
+ int comparison = 0;\r
+ // Define null less than everything, except null.\r
+ if (o1 == null && o2 == null) {\r
+ comparison = 0;\r
+ } else if (o1 == null) {\r
+ comparison = -1;\r
+ } else if (o2 == null) {\r
+ comparison = 1;\r
+ } else {\r
+ comparison = getComparator(column).compare(o1, o2);\r
+ }\r
+ if (comparison != 0) {\r
+ return directive.direction == DESCENDING ? -comparison : comparison;\r
+ }\r
+ }\r
+ return 0;\r
+ }\r
+ }\r
+\r
+ private class TableModelHandler implements TableModelListener {\r
+ public void tableChanged(TableModelEvent e) {\r
+ // If we're not sorting by anything, just pass the event along.\r
+ if (!isSorting()) {\r
+ clearSortingState();\r
+ fireTableChanged(e);\r
+ return;\r
+ }\r
+\r
+ // If the table structure has changed, cancel the sorting; the\r
+ // sorting columns may have been either moved or deleted from\r
+ // the model.\r
+ if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {\r
+ cancelSorting();\r
+ fireTableChanged(e);\r
+ return;\r
+ }\r
+\r
+ // We can map a cell event through to the view without widening\r
+ // when the following conditions apply:\r
+ //\r
+ // a) all the changes are on one row (e.getFirstRow() == e.getLastRow()) and,\r
+ // b) all the changes are in one column (column != TableModelEvent.ALL_COLUMNS) and,\r
+ // c) we are not sorting on that column (getSortingStatus(column) == NOT_SORTED) and,\r
+ // d) a reverse lookup will not trigger a sort (modelToView != null)\r
+ //\r
+ // Note: INSERT and DELETE events fail this test as they have column == ALL_COLUMNS.\r
+ //\r
+ // The last check, for (modelToView != null) is to see if modelToView\r
+ // is already allocated. If we don't do this check; sorting can become\r
+ // a performance bottleneck for applications where cells\r
+ // change rapidly in different parts of the table. If cells\r
+ // change alternately in the sorting column and then outside of\r
+ // it this class can end up re-sorting on alternate cell updates -\r
+ // which can be a performance problem for large tables. The last\r
+ // clause avoids this problem.\r
+ int column = e.getColumn();\r
+ if (e.getFirstRow() == e.getLastRow()\r
+ && column != TableModelEvent.ALL_COLUMNS\r
+ && getSortingStatus(column) == NOT_SORTED\r
+ && modelToView != null) {\r
+ int viewIndex = getModelToView()[e.getFirstRow()];\r
+ fireTableChanged(new TableModelEvent(TableSorter.this,\r
+ viewIndex, viewIndex,\r
+ column, e.getType()));\r
+ return;\r
+ }\r
+\r
+ // Something has happened to the data that may have invalidated the row order.\r
+ clearSortingState();\r
+ fireTableDataChanged();\r
+ return;\r
+ }\r
+ }\r
+\r
+ private class MouseHandler extends MouseAdapter {\r
+ public void mouseClicked(MouseEvent e) {\r
+ JTableHeader h = (JTableHeader) e.getSource();\r
+ TableColumnModel columnModel = h.getColumnModel();\r
+ int viewColumn = columnModel.getColumnIndexAtX(e.getX());\r
+ int column = columnModel.getColumn(viewColumn).getModelIndex();\r
+ if (column != -1) {\r
+ int status = getSortingStatus(column);\r
+ if (!e.isControlDown()) {\r
+ cancelSorting();\r
+ }\r
+ // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or\r
+ // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.\r
+ status = status + (e.isShiftDown() ? -1 : 1);\r
+ status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1}\r
+ setSortingStatus(column, status);\r
+ }\r
+ }\r
+ }\r
+\r
+ private static class Arrow implements Icon {\r
+ private boolean descending;\r
+ private int size;\r
+ private int priority;\r
+\r
+ public Arrow(boolean descending, int size, int priority) {\r
+ this.descending = descending;\r
+ this.size = size;\r
+ this.priority = priority;\r
+ }\r
+\r
+ public void paintIcon(Component c, Graphics g, int x, int y) {\r
+ Color color = c == null ? Color.GRAY : c.getBackground();\r
+ // In a compound sort, make each succesive triangle 20%\r
+ // smaller than the previous one.\r
+ int dx = (int)(size/2*Math.pow(0.8, priority));\r
+ int dy = descending ? dx : -dx;\r
+ // Align icon (roughly) with font baseline.\r
+ y = y + 5*size/6 + (descending ? -dy : 0);\r
+ int shift = descending ? 1 : -1;\r
+ g.translate(x, y);\r
+\r
+ // Right diagonal.\r
+ g.setColor(color.darker());\r
+ g.drawLine(dx / 2, dy, 0, 0);\r
+ g.drawLine(dx / 2, dy + shift, 0, shift);\r
+\r
+ // Left diagonal.\r
+ g.setColor(color.brighter());\r
+ g.drawLine(dx / 2, dy, dx, 0);\r
+ g.drawLine(dx / 2, dy + shift, dx, shift);\r
+\r
+ // Horizontal line.\r
+ if (descending) {\r
+ g.setColor(color.darker().darker());\r
+ } else {\r
+ g.setColor(color.brighter().brighter());\r
+ }\r
+ g.drawLine(dx, 0, 0, 0);\r
+\r
+ g.setColor(color);\r
+ g.translate(-x, -y);\r
+ }\r
+\r
+ public int getIconWidth() {\r
+ return size;\r
+ }\r
+\r
+ public int getIconHeight() {\r
+ return size;\r
+ }\r
+ }\r
+\r
+ private class SortableHeaderRenderer implements TableCellRenderer {\r
+ private TableCellRenderer tableCellRenderer;\r
+\r
+ public SortableHeaderRenderer(TableCellRenderer tableCellRenderer) {\r
+ this.tableCellRenderer = tableCellRenderer;\r
+ }\r
+\r
+ public Component getTableCellRendererComponent(JTable table,\r
+ Object value,\r
+ boolean isSelected,\r
+ boolean hasFocus,\r
+ int row,\r
+ int column) {\r
+ Component c = tableCellRenderer.getTableCellRendererComponent(table,\r
+ value, isSelected, hasFocus, row, column);\r
+ if (c instanceof JLabel) {\r
+ JLabel l = (JLabel) c;\r
+ l.setHorizontalTextPosition(JLabel.LEFT);\r
+ int modelColumn = table.convertColumnIndexToModel(column);\r
+ l.setIcon(getHeaderRendererIcon(modelColumn, l.getFont().getSize()));\r
+ }\r
+ return c;\r
+ }\r
+ }\r
+\r
+ private static class Directive {\r
+ private int column;\r
+ private int direction;\r
+\r
+ public Directive(int column, int direction) {\r
+ this.column = column;\r
+ this.direction = direction;\r
+ }\r
+ }\r
+}\r