X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FJDatabaseTree.java;h=0a6b9d64e9388f7c06acf22bc251aef06f3cef6a;hb=53b99b41ed7f26f2724f3ed87d524eb83c5208f4;hp=612b83ec2b82942871266a5f7ab6a57355526152;hpb=b57a02c25e335d033c97f8a6bacd6b54f62bd2b6;p=jalview.git
diff --git a/src/jalview/gui/JDatabaseTree.java b/src/jalview/gui/JDatabaseTree.java
index 612b83e..0a6b9d6 100644
--- a/src/jalview/gui/JDatabaseTree.java
+++ b/src/jalview/gui/JDatabaseTree.java
@@ -1,11 +1,31 @@
+/*
+ * 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.
+ *
+ * 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 .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.gui;
import jalview.bin.Cache;
+import jalview.util.MessageManager;
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;
@@ -13,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;
@@ -25,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;
@@ -39,16 +62,19 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
{
boolean allowMultiSelections = false;
+ public int action;
+
JButton getDatabaseSelectorButton()
{
- final JButton viewdbs = new JButton("--- Select Database ---");
+ 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;
@@ -62,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
@@ -120,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()
{
@@ -142,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;
@@ -159,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);
@@ -197,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);
@@ -209,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)
@@ -238,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);
@@ -275,7 +322,6 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
protected void okPressed()
{
_setSelectionState();
- closeDialog();
}
@Override
@@ -287,7 +333,7 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
closeDialog();
}
- private void showDialog(Container parent)
+ void showDialog()
{
oldselection = selection;
oldtsel = tsel;
@@ -316,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();
@@ -327,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());
@@ -339,26 +391,14 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
{
if (allowMultiSelections)
{
- srcs.addAll(sfetcher.getSourceProxy((String) dmt
- .getUserObject()));
+ srcs.addAll(sfetcher
+ .getSourceProxy((String) dmt.getUserObject()));
}
else
{
- if ((admt = dmt.getFirstLeaf()) != null
- && admt.getUserObject() != null)
- {
- // modify db selection to just first leaf.
- if (admt.getUserObject() instanceof DbSourceProxy)
- {
- srcs.add((DbSourceProxy) admt.getUserObject());
- }
- else
- {
- srcs.add(sfetcher.getSourceProxy(
- (String) admt.getUserObject()).get(0));
- }
- forcedFirstChild = true;
- }
+ srcs.add(sfetcher.getSourceProxy((String) dmt.getUserObject())
+ .get(0));
+ forcedFirstChild = true;
}
}
}
@@ -398,29 +438,30 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
}
}
+ dbstatex.setText(" ");
if (allowMultiSelections)
{
- dbstatus.setText("Selected "
- + srcs.size()
- + " database"
- + (srcs.size() == 1 ? "" : "s")
- + " to fetch from"
- + (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("Database: " + nm);
+ dbstatus.setText(MessageManager
+ .formatMessage("label.database_param", new String[]
+ { nm }));
if (qr.length() > 0)
{
- dbstatex.setText("Example: " + qr);
- }
- else
- {
- dbstatex.setText(" ");
+ dbstatex.setText(MessageManager
+ .formatMessage("label.example_param", new String[]
+ { qr }));
}
}
else
@@ -531,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();
}
}