X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FJDatabaseTree.java;h=8d62433d5bab9b4d1d7c6c3b0136d9fa8b0617df;hb=afffa24481a7d3cb65ae41e0948c16a5f490f302;hp=c6b16b152eca0eb3b6f2fe42abdc053f4c3d924a;hpb=ad1ffbe2154b4171ca223c4400552def22c7606d;p=jalview.git
diff --git a/src/jalview/gui/JDatabaseTree.java b/src/jalview/gui/JDatabaseTree.java
index c6b16b1..8d62433 100644
--- a/src/jalview/gui/JDatabaseTree.java
+++ b/src/jalview/gui/JDatabaseTree.java
@@ -1,11 +1,30 @@
+/*
+ * 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 +32,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;
@@ -20,11 +41,11 @@ import java.util.List;
import java.util.Vector;
import javax.swing.JButton;
-import javax.swing.JFrame;
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 +60,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,20 +86,23 @@ 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
* identical DB sources, and should be collapsed.
*/
DefaultMutableTreeNode tn = null, root = new DefaultMutableTreeNode();
- Hashtable source = new Hashtable();
+ Hashtable source = new Hashtable<>();
sfetcher = sfetch;
String dbs[] = sfetch.getSupportedDb();
- Hashtable ht = new Hashtable();
+ Hashtable ht = new Hashtable<>();
for (int i = 0; i < dbs.length; i++)
{
tn = source.get(dbs[i]);
@@ -120,19 +147,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 +169,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 +199,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);
@@ -170,46 +210,54 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
private void sortTreeNodes(DefaultMutableTreeNode root)
{
- if (root.getChildCount()==0)
+ if (root.getChildCount() == 0)
{
return;
}
- int count=root.getChildCount();
- String[] names=new String[count];
- DefaultMutableTreeNode[] nodes=new DefaultMutableTreeNode[count];
- for (int i=0;i=0;i--)
+ for (int i = count - 1; i >= 0; i--)
{
root.add(nodes[i]);
}
}
- 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)
@@ -231,19 +279,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);
@@ -268,7 +320,6 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
protected void okPressed()
{
_setSelectionState();
- closeDialog();
}
@Override
@@ -280,7 +331,7 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
closeDialog();
}
- private void showDialog(Container parent)
+ void showDialog()
{
oldselection = selection;
oldtsel = tsel;
@@ -309,21 +360,27 @@ 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();
+ List srcs = new ArrayList<>();
if (tsel != null)
{
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());
@@ -332,26 +389,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;
}
}
}
@@ -391,29 +436,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
@@ -441,7 +487,7 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
return null;
}
StringBuffer sb = new StringBuffer();
- HashSet hs = new HashSet();
+ HashSet hs = new HashSet<>();
for (DbSourceProxy dbs : getSelectedSources())
{
String tq = dbs.getTestQuery();
@@ -458,7 +504,7 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
return sb.toString();
}
- List lstners = new Vector();
+ List lstners = new Vector<>();
public void addActionListener(ActionListener actionListener)
{
@@ -470,64 +516,19 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
lstners.remove(actionListener);
}
- public static void main(String args[])
- {
- Cache.getDasSourceRegistry();
- JDatabaseTree jdt = new JDatabaseTree(new jalview.ws.SequenceFetcher());
- JFrame foo = new JFrame();
- foo.setLayout(new BorderLayout());
- foo.add(jdt.getDatabaseSelectorButton(), BorderLayout.CENTER);
- foo.pack();
- foo.setVisible(true);
- int nultimes = 5;
- final Thread us = Thread.currentThread();
- jdt.addActionListener(new ActionListener()
- {
-
- @Override
- public void actionPerformed(ActionEvent e)
- {
- us.interrupt();
- }
- });
- do
- {
- try
- {
- Thread.sleep(50);
- } catch (InterruptedException x)
- {
- nultimes--;
- if (!jdt.hasSelection())
- {
- System.out.println("No Selection");
- }
- else
- {
- System.out.println("Selection: " + jdt.getSelectedItem());
- int s = 1;
- for (DbSourceProxy pr : jdt.getSelectedSources())
- {
- System.out.println("Source " + s++ + ": " + pr.getDbName()
- + " (" + pr.getDbSource() + ") Version "
- + pr.getDbVersion() + ". Test:\t" + pr.getTestQuery());
- }
- System.out.println("Test queries: " + jdt.getExampleQueries());
- }
- }
- } while (nultimes > 0 && foo.isVisible());
- foo.setVisible(false);
- }
@Override
public void keyPressed(KeyEvent arg0)
{
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();
}
}
@@ -545,4 +546,11 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
// TODO Auto-generated method stub
}
+
+ @Override
+ public void setVisible(boolean arg0)
+ {
+ System.out.println("setVisible: " + arg0);
+ super.setVisible(arg0);
+ }
}