X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FJDatabaseTree.java;h=9ae764ed687870f5484bdb4379e2d54d11aa9738;hb=afe4b88500a5d61bc8d312909cfdde2b7cdd53df;hp=7722e529b00d443fb335badedbbdb3bebe741e52;hpb=865a855a4ca87eadb3e5ff284ed32ed307d9c34b;p=jalview.git
diff --git a/src/jalview/gui/JDatabaseTree.java b/src/jalview/gui/JDatabaseTree.java
index 7722e52..9ae764e 100644
--- a/src/jalview/gui/JDatabaseTree.java
+++ b/src/jalview/gui/JDatabaseTree.java
@@ -1,29 +1,32 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
- * 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;
-import jalview.bin.Cache;
+import java.util.Locale;
+
+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;
@@ -31,6 +34,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;
@@ -38,11 +43,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;
@@ -57,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;
@@ -80,20 +88,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]);
@@ -111,7 +122,7 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
}
else
{
- System.err.println("dupe ig for : " + dbs[i] + " \t"
+ jalview.bin.Console.errPrintln("dupe ig for : " + dbs[i] + " \t"
+ dbp.getDbName() + " (" + dbp.getDbSource() + ")");
source.remove(tn);
}
@@ -138,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()
{
@@ -160,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;
@@ -177,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);
@@ -205,18 +229,19 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
if (child.getUserObject() instanceof DbSourceProxy)
{
names[i] = ((DbSourceProxy) child.getUserObject()).getDbName()
- .toLowerCase();
+ .toLowerCase(Locale.ROOT);
}
else
{
- names[i] = ((String) child.getUserObject()).toLowerCase();
+ names[i] = ((String) child.getUserObject())
+ .toLowerCase(Locale.ROOT);
sortTreeNodes(child);
}
}
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);
@@ -227,14 +252,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)
@@ -256,19 +282,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);
@@ -293,7 +323,6 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
protected void okPressed()
{
_setSelectionState();
- closeDialog();
}
@Override
@@ -305,7 +334,7 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
closeDialog();
}
- private void showDialog(Container parent)
+ void showDialog()
{
oldselection = selection;
oldtsel = tsel;
@@ -334,21 +363,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());
@@ -357,13 +392,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;
}
}
@@ -404,29 +439,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
@@ -454,7 +490,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();
@@ -471,7 +507,7 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
return sb.toString();
}
- List lstners = new Vector();
+ List lstners = new Vector<>();
public void addActionListener(ActionListener actionListener)
{
@@ -483,64 +519,18 @@ 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();
}
}
@@ -558,4 +548,11 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener
// TODO Auto-generated method stub
}
+
+ @Override
+ public void setVisible(boolean arg0)
+ {
+ jalview.bin.Console.outPrintln("setVisible: " + arg0);
+ super.setVisible(arg0);
+ }
}