X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FJDatabaseTree.java;h=0a6b9d64e9388f7c06acf22bc251aef06f3cef6a;hb=bd894ca9f2aae448653d7431ab8a170e1105e85c;hp=7343eab31025f6bf63d2bb3eb885105d54496b33;hpb=a8f483d04205bb8273ee311c12968b7e86d205fa;p=jalview.git
diff --git a/src/jalview/gui/JDatabaseTree.java b/src/jalview/gui/JDatabaseTree.java
index 7343eab..0a6b9d6 100644
--- a/src/jalview/gui/JDatabaseTree.java
+++ b/src/jalview/gui/JDatabaseTree.java
@@ -1,19 +1,21 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* This file is part of Jalview.
*
* Jalview 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 3 of the License, or (at your option) any later version.
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
*
* Jalview 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 Jalview. If not, see .
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
* The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.gui;
@@ -24,7 +26,6 @@ import jalview.ws.seqfetcher.DbSourceProxy;
import java.awt.BorderLayout;
import java.awt.Component;
-import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
@@ -32,6 +33,8 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Hashtable;
@@ -44,6 +47,7 @@ import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTree;
+import javax.swing.ToolTipManager;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
@@ -58,16 +62,19 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
{
boolean allowMultiSelections = false;
+ public int action;
+
JButton getDatabaseSelectorButton()
{
- final JButton viewdbs = new JButton(MessageManager.getString("action.select_ddbb"));
+ final JButton viewdbs = new JButton(
+ MessageManager.getString("action.select_ddbb"));
viewdbs.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent arg0)
{
- showDialog(null);
+ showDialog();
}
});
return viewdbs;
@@ -81,10 +88,13 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
private JLabel dbstatus, dbstatex;
+ private JPanel mainPanel = new JPanel(new BorderLayout());
+
public JDatabaseTree(jalview.ws.SequenceFetcher sfetch)
{
- initDialogFrame(this, true, false, "Select Database Retrieval Source",
- 650, 490);
+ mainPanel.add(this);
+ initDialogFrame(mainPanel, true, false, MessageManager
+ .getString("label.select_database_retrieval_source"), 650, 490);
/*
* Dynamically generated database list will need a translation function from
* internal source to externally distinct names. UNIPROT and UP_NAME are
@@ -139,19 +149,19 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
}
// and sort the tree
sortTreeNodes(root);
- svp = new JScrollPane();
- // svp.setAutoscrolls(true);
dbviews = new JTree(new DefaultTreeModel(root, false));
dbviews.setCellRenderer(new DbTreeRenderer(this));
- dbviews.getSelectionModel().setSelectionMode(
- TreeSelectionModel.SINGLE_TREE_SELECTION);
- svp.getViewport().setView(dbviews);
- // svp.getViewport().setMinimumSize(new Dimension(300,200));
- // svp.setSize(300,250);
- // JPanel panel=new JPanel();
- // panel.setSize(new Dimension(350,220));
- // panel.add(svp);
+ dbviews.getSelectionModel()
+ .setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
+ svp = new JScrollPane(dbviews);
+ svp.setMinimumSize(new Dimension(100, 200));
+ svp.setPreferredSize(new Dimension(200, 400));
+ svp.setMaximumSize(new Dimension(300, 600));
+
+ JPanel panel = new JPanel(new BorderLayout());
+ panel.setSize(new Dimension(350, 220));
+ panel.add(svp);
dbviews.addTreeSelectionListener(new TreeSelectionListener()
{
@@ -161,8 +171,21 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
_setSelectionState();
}
});
- JPanel jc = new JPanel(new BorderLayout()), j = new JPanel(
- new FlowLayout());
+ dbviews.addMouseListener(new MouseAdapter()
+ {
+
+ @Override
+ public void mousePressed(MouseEvent e)
+ {
+ if (e.getClickCount() == 2)
+ {
+ okPressed();
+ closeDialog();
+ }
+ }
+ });
+ JPanel jc = new JPanel(new BorderLayout()),
+ j = new JPanel(new FlowLayout());
jc.add(svp, BorderLayout.CENTER);
java.awt.Font f;
@@ -178,8 +201,8 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
dbstat.add(dbstatex);
jc.add(dbstat, BorderLayout.SOUTH);
jc.validate();
- // j.setPreferredSize(new Dimension(300,50));
add(jc, BorderLayout.CENTER);
+ ok.setEnabled(false);
j.add(ok);
j.add(cancel);
add(j, BorderLayout.SOUTH);
@@ -216,8 +239,8 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
}
else
{
- throw new Error(
- "Implementation Error: Can't reorder this tree. Not DefaultMutableTreeNode.");
+ throw new Error(MessageManager
+ .getString("error.implementation_error_cant_reorder_tree"));
}
}
jalview.util.QuickSort.sort(names, nodes);
@@ -228,14 +251,15 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
}
}
- private class DbTreeRenderer extends DefaultTreeCellRenderer implements
- TreeCellRenderer
+ private class DbTreeRenderer extends DefaultTreeCellRenderer
+ implements TreeCellRenderer
{
JDatabaseTree us;
public DbTreeRenderer(JDatabaseTree me)
{
us = me;
+ ToolTipManager.sharedInstance().registerComponent(dbviews);
}
private Component returnLabel(String txt)
@@ -257,19 +281,23 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
value = vl.getUserObject();
if (value instanceof DbSourceProxy)
{
- val = (((DbSourceProxy) value).getDbName());
+ val = ((DbSourceProxy) value).getDbName();
+ if (((DbSourceProxy) value).getDescription() != null)
+ { // getName()
+ this.setToolTipText(((DbSourceProxy) value).getDescription());
+ }
}
else
{
if (value instanceof String)
{
- val = ((String) value);
+ val = (String) value;
}
}
}
if (value == null)
{
- val = ("");
+ val = "";
}
return super.getTreeCellRendererComponent(tree, val, selected,
expanded, leaf, row, hasFocus);
@@ -294,7 +322,6 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
protected void okPressed()
{
_setSelectionState();
- closeDialog();
}
@Override
@@ -306,7 +333,7 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
closeDialog();
}
- private void showDialog(Container parent)
+ void showDialog()
{
oldselection = selection;
oldtsel = tsel;
@@ -335,10 +362,12 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
{
return;
}
+ ok.setEnabled(false);
if (dbviews.getSelectionCount() == 0)
{
selection = null;
}
+
tsel = dbviews.getSelectionPaths();
boolean forcedFirstChild = false;
List srcs = new ArrayList();
@@ -346,10 +375,14 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
{
for (TreePath tp : tsel)
{
- DefaultMutableTreeNode admt, dmt = (DefaultMutableTreeNode) tp
- .getLastPathComponent();
+ DefaultMutableTreeNode admt,
+ dmt = (DefaultMutableTreeNode) tp.getLastPathComponent();
if (dmt.getUserObject() != null)
{
+ /*
+ * enable OK button once a selection has been made
+ */
+ ok.setEnabled(true);
if (dmt.getUserObject() instanceof DbSourceProxy)
{
srcs.add((DbSourceProxy) dmt.getUserObject());
@@ -358,13 +391,13 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
{
if (allowMultiSelections)
{
- srcs.addAll(sfetcher.getSourceProxy((String) dmt
- .getUserObject()));
+ srcs.addAll(sfetcher
+ .getSourceProxy((String) dmt.getUserObject()));
}
else
{
- srcs.add(sfetcher.getSourceProxy((String) dmt
- .getUserObject()).get(0));
+ srcs.add(sfetcher.getSourceProxy((String) dmt.getUserObject())
+ .get(0));
forcedFirstChild = true;
}
}
@@ -405,23 +438,30 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
}
}
+ dbstatex.setText(" ");
if (allowMultiSelections)
{
- dbstatus.setText(MessageManager.formatMessage("label.selected_database_to_fetch_from", new String[]{Integer.valueOf(srcs.size()).toString(),(srcs.size() == 1 ? "" : "s"),(srcs.size() > 0 ? " with " + x + " test quer" + (x == 1 ? "y" : "ies") : ".")}));
- dbstatex.setText(" ");
+ dbstatus.setText(MessageManager.formatMessage(
+ "label.selected_database_to_fetch_from", new String[]
+ { Integer.valueOf(srcs.size()).toString(),
+ (srcs.size() == 1 ? "" : "s"),
+ (srcs.size() > 0
+ ? " with " + x + " test quer"
+ + (x == 1 ? "y" : "ies")
+ : ".") }));
}
else
{
if (nm.length() > 0)
{
- dbstatus.setText(MessageManager.formatMessage("label.database_param",new String[]{nm}));
+ dbstatus.setText(MessageManager
+ .formatMessage("label.database_param", new String[]
+ { nm }));
if (qr.length() > 0)
{
- dbstatex.setText(MessageManager.formatMessage("label.example_param", new String[]{qr}));
- }
- else
- {
- dbstatex.setText(" ");
+ dbstatex.setText(MessageManager
+ .formatMessage("label.example_param", new String[]
+ { qr }));
}
}
else
@@ -532,10 +572,13 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
{
if (!arg0.isConsumed() && arg0.getKeyCode() == KeyEvent.VK_ENTER)
{
+ action = arg0.getKeyCode();
okPressed();
+ closeDialog();
}
if (!arg0.isConsumed() && arg0.getKeyChar() == KeyEvent.VK_ESCAPE)
{
+ action = arg0.getKeyCode();
cancelPressed();
}
}