From: gmungoc Date: Tue, 14 Jul 2020 08:44:46 +0000 (+0100) Subject: JAL-1421 types added to nameHash and nodeHash maps X-Git-Tag: Develop-2_11_2_0-d20201215~24^2~15^2~6^2~3 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=080fea8156db2a9fe6126d353e02f0a51942b231;p=jalview.git JAL-1421 types added to nameHash and nodeHash maps --- diff --git a/src/jalview/gui/TreeCanvas.java b/src/jalview/gui/TreeCanvas.java index 29ba52b..baaec82 100755 --- a/src/jalview/gui/TreeCanvas.java +++ b/src/jalview/gui/TreeCanvas.java @@ -20,19 +20,6 @@ */ package jalview.gui; -import jalview.analysis.Conservation; -import jalview.analysis.TreeModel; -import jalview.api.AlignViewportI; -import jalview.datamodel.Sequence; -import jalview.datamodel.SequenceGroup; -import jalview.datamodel.SequenceI; -import jalview.datamodel.SequenceNode; -import jalview.gui.JalviewColourChooser.ColourChooserListener; -import jalview.schemes.ColourSchemeI; -import jalview.structure.SelectionSource; -import jalview.util.Format; -import jalview.util.MessageManager; - import java.awt.Color; import java.awt.Dimension; import java.awt.Font; @@ -49,9 +36,10 @@ import java.awt.print.PageFormat; import java.awt.print.Printable; import java.awt.print.PrinterException; import java.awt.print.PrinterJob; -import java.util.Enumeration; import java.util.Hashtable; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import java.util.Vector; import javax.swing.JPanel; @@ -59,6 +47,19 @@ import javax.swing.JScrollPane; import javax.swing.SwingUtilities; import javax.swing.ToolTipManager; +import jalview.analysis.Conservation; +import jalview.analysis.TreeModel; +import jalview.api.AlignViewportI; +import jalview.datamodel.Sequence; +import jalview.datamodel.SequenceGroup; +import jalview.datamodel.SequenceI; +import jalview.datamodel.SequenceNode; +import jalview.gui.JalviewColourChooser.ColourChooserListener; +import jalview.schemes.ColourSchemeI; +import jalview.structure.SelectionSource; +import jalview.util.Format; +import jalview.util.MessageManager; + /** * DOCUMENT ME! * @@ -103,9 +104,9 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, int labelLength = -1; - Hashtable nameHash = new Hashtable(); + Map nameHash = new Hashtable<>(); - Hashtable nodeHash = new Hashtable(); + Map nodeHash = new Hashtable<>(); SequenceNode highlightNode; @@ -378,31 +379,25 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, */ public Object findElement(int x, int y) { - Enumeration keys = nameHash.keys(); - - while (keys.hasMoreElements()) + for (Entry entry : nameHash.entrySet()) { - Object ob = keys.nextElement(); - Rectangle rect = (Rectangle) nameHash.get(ob); + Rectangle rect = (Rectangle) nameHash.get(entry.getValue()); if ((x >= rect.x) && (x <= (rect.x + rect.width)) && (y >= rect.y) && (y <= (rect.y + rect.height))) { - return ob; + return entry.getKey(); } } - keys = nodeHash.keys(); - - while (keys.hasMoreElements()) + for (Entry entry : nodeHash.entrySet()) { - Object ob = keys.nextElement(); - Rectangle rect = (Rectangle) nodeHash.get(ob); + Rectangle rect = entry.getValue(); if ((x >= rect.x) && (x <= (rect.x + rect.width)) && (y >= rect.y) && (y <= (rect.y + rect.height))) { - return ob; + return entry.getKey(); } } @@ -464,9 +459,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, if ((node.left() == null) && (node.right() == null)) { double height = node.height; - double dist = node.dist; - - int xstart = (int) ((height - dist) * wscale) + offx; +// double dist = node.dist; +// int xstart = (int) ((height - dist) * wscale) + offx; int xend = (int) (height * wscale) + offx; int ypos = (int) (node.ycount * chunk) + offy; @@ -651,13 +645,14 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, { fm = g.getFontMetrics(font); - if (nameHash.size() == 0) + int nameCount = nameHash.size(); + if (nameCount == 0) { repaint(); } if (fitToWindow || (!fitToWindow && (scrollPane - .getHeight() > ((fm.getHeight() * nameHash.size()) + offy)))) + .getHeight() > ((fm.getHeight() * nameCount) + offy)))) { draw(g, scrollPane.getWidth(), scrollPane.getHeight()); setPreferredSize(null); @@ -665,8 +660,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable, else { setPreferredSize(new Dimension(scrollPane.getWidth(), - fm.getHeight() * nameHash.size())); - draw(g, scrollPane.getWidth(), fm.getHeight() * nameHash.size()); + fm.getHeight() * nameCount)); + draw(g, scrollPane.getWidth(), fm.getHeight() * nameCount); } scrollPane.revalidate();