JAL-3060 tidy Cancel dialog action handler code
[jalview.git] / src / jalview / gui / TreeCanvas.java
index 3494fb8..b83dc12 100755 (executable)
@@ -27,6 +27,7 @@ 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.schemes.ColourSchemeProperty;
 import jalview.schemes.UserColourScheme;
@@ -279,8 +280,9 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
         g.drawString(nodeLabel, xstart + 2, ypos - 2);
       }
 
-      String name = (markPlaceholders && node.isPlaceholder()) ? (PLACEHOLDER + node
-              .getName()) : node.getName();
+      String name = (markPlaceholders && node.isPlaceholder())
+              ? (PLACEHOLDER + node.getName())
+              : node.getName();
 
       int charWidth = fm.stringWidth(name) + 3;
       int charHeight = font.getSize();
@@ -332,9 +334,10 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
         g.fillRect(xend - 2, ypos - 2, 4, 4);
       }
 
-      int ystart = (int) (((SequenceNode) node.left()).ycount * chunk)
-              + offy;
-      int yend = (int) (((SequenceNode) node.right()).ycount * chunk)
+      int ystart = (node.left() == null ? 0
+              : (int) (((SequenceNode) node.left()).ycount * chunk)) + offy;
+      int yend = (node.right() == null ? 0
+              : (int) (((SequenceNode) node.right()).ycount * chunk))
               + offy;
 
       Rectangle pos = new Rectangle(xend - 2, ypos - 2, 5, 5);
@@ -423,8 +426,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
 
     SequenceNode top = tree.getTopNode();
 
-    double wscale = ((width * .8) - (offx * 2))
-            / tree.getMaxHeight();
+    double wscale = ((width * .8) - (offx * 2)) / tree.getMaxHeight();
 
     if (top.count == 0)
     {
@@ -653,8 +655,9 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
 
     if (tree == null)
     {
-      g.drawString(MessageManager.getString("label.calculating_tree")
-              + "....", 20, getHeight() / 2);
+      g.drawString(
+              MessageManager.getString("label.calculating_tree") + "....",
+              20, getHeight() / 2);
     }
     else
     {
@@ -665,9 +668,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
         repaint();
       }
 
-      if (fitToWindow
-              || (!fitToWindow && (scrollPane.getHeight() > ((fm
-                      .getHeight() * nameHash.size()) + offy))))
+      if (fitToWindow || (!fitToWindow && (scrollPane
+              .getHeight() > ((fm.getHeight() * nameHash.size()) + offy))))
       {
         draw(g, scrollPane.getWidth(), scrollPane.getHeight());
         setPreferredSize(null);
@@ -751,7 +753,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
         g2.setColor(Color.gray);
       }
 
-      int x = (int) ((threshold * (getWidth() - labelLength - (2 * offx))) + offx);
+      int x = (int) ((threshold * (getWidth() - labelLength - (2 * offx)))
+              + offx);
 
       g2.drawLine(x, 0, x, getHeight());
     }
@@ -839,15 +842,17 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
    */
   void chooseSubtreeColour()
   {
-    Color col = JColorChooser.showDialog(this,
-            MessageManager.getString("label.select_subtree_colour"),
-            highlightNode.color);
-    if (col != null)
-    {
-      setColor(highlightNode, col);
-      PaintRefresher.Refresh(tp, ap.av.getSequenceSetId());
-      repaint();
-    }
+    String ttl = MessageManager.getString("label.select_subtree_colour");
+    ColourChooserListener listener = new ColourChooserListener() {
+      @Override
+      public void colourSelected(Color c)
+      {
+        setColor(highlightNode, c);
+        PaintRefresher.Refresh(tp, ap.av.getSequenceSetId());
+        repaint();
+      }
+    };
+    JalviewColourChooser.showColourChooser(this, ttl,  highlightNode.color, listener);
   }
 
   @Override
@@ -860,8 +865,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
     if (ob instanceof SequenceNode)
     {
       highlightNode = (SequenceNode) ob;
-      this.setToolTipText("<html>"
-              + MessageManager.getString("label.highlightnode"));
+      this.setToolTipText(
+              "<html>" + MessageManager.getString("label.highlightnode"));
       repaint();
 
     }
@@ -1006,9 +1011,8 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
         }
         else
         {
-          cs = ColourSchemeProperty.getColourScheme(sg,
-                  ColourSchemeProperty.getColourName(av
-                          .getGlobalColourScheme()));
+          cs = ColourSchemeProperty.getColourScheme(sg, ColourSchemeProperty
+                  .getColourName(av.getGlobalColourScheme()));
         }
         // cs is null if shading is an annotationColourGradient
         // if (cs != null)
@@ -1028,8 +1032,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
       for (int a = 0; a < aps.length; a++)
       {
         if (aps[a].av.getGlobalColourScheme() != null
-                && aps[a].av.getResidueShading()
-                        .conservationApplied())
+                && aps[a].av.getResidueShading().conservationApplied())
         {
           Conservation c = new Conservation("Group", sg.getSequences(null),
                   sg.getStartRes(), sg.getEndRes());