JAL-1690 refining 'copy format from' as applied to splitframe panels
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 1 May 2015 08:11:29 +0000 (09:11 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 1 May 2015 08:11:29 +0000 (09:11 +0100)
resources/lang/Messages.properties
src/jalview/appletgui/AlignmentPanel.java
src/jalview/appletgui/IdwidthAdjuster.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/AlignmentPanel.java
src/jalview/gui/ViewSelectionMenu.java

index 42dfca9..e25fb93 100644 (file)
@@ -534,7 +534,10 @@ label.dark_colour = Dark Colour
 label.light_colour = Light Colour
 label.highlightnode = Left click to select leaves.<br>Double-click to invert leaves.<br>Right click to change colour.
 label.load_colour_scheme = Load colour scheme
+label.copy_format_from = Copy format from
 label.toggle_enabled_views = When enabled, allows many views to be selected.
+label.select_all_views = Select all views
+label.select_many_views = Select many views
 label.edit_notes_parameter_set = Click to edit the notes for this parameter set.
 label.open_local_file = Open local file
 label.enable_automatically_sort_alignment_when_open_new_tree = Enable this to automatically sort<br>the alignment when you open<br> a new tree.
@@ -740,7 +743,6 @@ label.fetch_all_param = Fetch all {0}
 label.paste_new_window = Paste To New Window
 label.settings_for_param = Settings for {0}
 label.view_params = View {0}
-label.select_all_views = Select all views
 label.all_views = All Views
 label.align_sequences_to_existing_alignment = Align sequences to an existing alignment
 label.realign_with_params = Realign with {0}
index 5a2c5ef..0516533 100644 (file)
@@ -983,7 +983,11 @@ public class AlignmentPanel extends Panel implements AdjustmentListener,
   {
     invalidate();
     Dimension d = idPanel.idCanvas.getSize();
-    idPanel.idCanvas.setSize(d.width, seqPanel.seqCanvas.getSize().height);
+    final int canvasHeight = seqPanel.seqCanvas.getSize().height;
+    if (canvasHeight != d.height)
+    {
+      idPanel.idCanvas.setSize(d.width, canvasHeight);
+    }
 
     if (av.getWrapAlignment())
     {
index f5530d5..b537112 100755 (executable)
  */
 package jalview.appletgui;
 
-import java.awt.*;
-import java.awt.event.*;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.Panel;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
 
 public class IdwidthAdjuster extends Panel implements MouseListener,
         MouseMotionListener
@@ -57,6 +63,26 @@ public class IdwidthAdjuster extends Panel implements MouseListener,
   {
     active = false;
     repaint();
+
+    /*
+     * If in a SplitFrame with co-scaled alignments, set the other's id width to
+     * match; note applet does not (yet) store this in ViewStyle
+     */
+    /*
+     * Code disabled for now as it doesn't work, don't know why; idCanvas width
+     * keeps resetting to a previous value (actually two alternating values!)
+     */
+    // final AlignViewportI viewport = ap.getAlignViewport();
+    // if (viewport.getCodingComplement() != null
+    // && viewport.isScaleProteinAsCdna())
+    // {
+    // Dimension d = ap.idPanel.idCanvas.getSize();
+    // SplitFrame sf = ap.alignFrame.getSplitFrame();
+    // final AlignmentPanel otherPanel =
+    // sf.getComplement(ap.alignFrame).alignPanel;
+    // otherPanel.setIdWidth(d.width, d.height);
+    // otherPanel.repaint();
+    // }
   }
 
   public void mouseEntered(MouseEvent evt)
@@ -77,13 +103,13 @@ public class IdwidthAdjuster extends Panel implements MouseListener,
     Dimension d = ap.idPanel.idCanvas.getSize();
     int dif = evt.getX() - oldX;
 
-    if (d.width + dif > 20 || dif > 0)
+    final int newWidth = d.width + dif;
+    if (newWidth > 20 || dif > 0)
     {
-      ap.setIdWidth(d.width + dif, d.height);
-      this.setSize(d.width + dif, getSize().height);
+      ap.setIdWidth(newWidth, d.height);
+      this.setSize(newWidth, getSize().height);
       oldX = evt.getX();
     }
-
   }
 
   public void mouseMoved(MouseEvent evt)
index fcf4301..80838e2 100644 (file)
@@ -364,7 +364,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
 
     final List<AlignmentPanel> selviews = new ArrayList<AlignmentPanel>();
     final List<AlignmentPanel> origview = new ArrayList<AlignmentPanel>();
-    ViewSelectionMenu vsel = new ViewSelectionMenu("Transfer colours from",
+    final String menuLabel = MessageManager
+            .getString("label.copy_format_from");
+    ViewSelectionMenu vsel = new ViewSelectionMenu(menuLabel,
             new ViewSetProvider()
             {
 
@@ -373,7 +375,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               {
                 origview.clear();
                 origview.add(alignPanel);
-                return Desktop.getAlignmentPanels(null);
+                // make an array of all alignment panels except for this one
+                List<AlignmentPanel> aps = new ArrayList<AlignmentPanel>(
+                        Arrays.asList(Desktop.getAlignmentPanels(null)));
+                aps.remove(AlignFrame.this.alignPanel);
+                return aps.toArray(new AlignmentPanel[aps.size()]);
               }
             }, selviews, new ItemListener()
             {
@@ -383,32 +389,43 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
               {
                 if (origview.size() > 0)
                 {
+                  final AlignmentPanel ap = origview.get(0);
+
+                  /*
+                   * Copy the ViewStyle of the selected panel to 'this one'.
+                   * Don't change value of 'scaleProteinAsCdna' unless copying
+                   * from a SplitFrame.
+                   */
                   ViewStyleI vs = selviews.get(0).getAlignViewport()
                           .getViewStyle();
-                  origview.get(0).getAlignViewport().setViewStyle(vs);
-                  AlignViewportI complement = origview.get(0)
-                          .getAlignViewport().getCodingComplement();
-                  if (complement != null)
+                  boolean fromSplitFrame = selviews.get(0)
+                          .getAlignViewport().getCodingComplement() != null;
+                  if (!fromSplitFrame)
+                  {
+                    vs.setScaleProteinAsCdna(ap.getAlignViewport()
+                            .getViewStyle().isScaleProteinAsCdna());
+                  }
+                  ap.getAlignViewport().setViewStyle(vs);
+
+                  /*
+                   * Also rescale ViewStyle of SplitFrame complement if there is
+                   * one _and_ it is set to 'scaledProteinAsCdna'; we don't copy
+                   * the whole ViewStyle (allow cDNA protein to have different
+                   * fonts)
+                   */
+                  AlignViewportI complement = ap.getAlignViewport()
+                          .getCodingComplement();
+                  if (complement != null && vs.isScaleProteinAsCdna())
                   {
                     AlignFrame af = Desktop.getAlignFrameFor(complement);
-                    if (complement.isNucleotide())
-                    {
-                      complement.setViewStyle(vs);
-                      vs.setCharWidth(vs.getCharWidth() / 3);
-                    }
-                    else
-                    {
-                      int rw = vs.getCharWidth();
-                      vs.setCharWidth(rw * 3);
-                      complement.setViewStyle(vs);
-                      vs.setCharWidth(rw);
-                    }
-                    af.alignPanel.updateLayout();
+                    ((SplitFrame) af.getSplitViewContainer())
+                            .adjustLayout();
                     af.setMenusForViewport();
                   }
-                  origview.get(0).updateLayout();
-                  origview.get(0).setSelected(true);
-                  origview.get(0).alignFrame.setMenusForViewport();
+
+                  ap.updateLayout();
+                  ap.setSelected(true);
+                  ap.alignFrame.setMenusForViewport();
 
                 }
               }
index 80f568d..5bc46f4 100644 (file)
@@ -1616,11 +1616,17 @@ public class AlignmentPanel extends GAlignmentPanel implements
   {
     try
     {
+      if (alignFrame.getSplitViewContainer() != null)
+      {
+        /*
+         * bring enclosing SplitFrame to front first if there is one
+         */
+        ((SplitFrame) alignFrame.getSplitViewContainer()).setSelected(b);
+      }
       alignFrame.setSelected(b);
     } catch (Exception ex)
     {
     }
-    ;
 
     if (b)
     {
index 5a16e2e..e12fb5b 100644 (file)
  */
 package jalview.gui;
 
-import jalview.util.MessageManager;
-
 import java.awt.Component;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
+import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
-import java.awt.event.MouseListener;
 import java.util.List;
 
 import javax.swing.JCheckBoxMenuItem;
@@ -37,6 +35,8 @@ import javax.swing.JMenuItem;
 import javax.swing.event.MenuEvent;
 import javax.swing.event.MenuListener;
 
+import jalview.util.MessageManager;
+
 /**
  * this is an implementation of an abstract Jalview GUI class that provides a
  * dialog/menu which allows the user to select/deselect specific views from a
@@ -150,7 +150,8 @@ public class ViewSelectionMenu extends JMenu
     {
       // ensure we update menu state to reflect external selection list state
       append = append || _selectedviews.size() > 1;
-      toggleview = new JCheckBoxMenuItem("Select many views", append);
+      toggleview = new JCheckBoxMenuItem(
+              MessageManager.getString("label.select_many_views"), append);
       toggleview.setToolTipText(MessageManager
               .getString("label.toggle_enabled_views"));
       toggleview.addItemListener(new ItemListener()
@@ -216,15 +217,14 @@ public class ViewSelectionMenu extends JMenu
       invertSel.setEnabled(append);
       selectAll.setEnabled(append);
     }
-    for (AlignmentPanel ap : allviews)
+    for (final AlignmentPanel ap : allviews)
     {
       String nm = ((ap.getViewName() == null || ap.getViewName().length() == 0) ? ""
               : ap.getViewName() + " for ")
               + ap.alignFrame.getTitle();
-      final JCheckBoxMenuItem a = new JCheckBoxMenuItem(nm,
+      final JCheckBoxMenuItem checkBox = new JCheckBoxMenuItem(nm,
               _selectedviews.contains(ap));
-      final AlignmentPanel p = ap;
-      a.addItemListener(new ItemListener()
+      checkBox.addItemListener(new ItemListener()
       {
         @Override
         public void itemStateChanged(ItemEvent e)
@@ -235,15 +235,15 @@ public class ViewSelectionMenu extends JMenu
             {
               enabled = false;
               // toggle the inclusion state
-              if (_selectedviews.indexOf(p) == -1)
+              if (_selectedviews.indexOf(ap) == -1)
               {
-                _selectedviews.add(p);
-                a.setSelected(true);
+                _selectedviews.add(ap);
+                checkBox.setSelected(true);
               }
               else
               {
-                _selectedviews.remove(p);
-                a.setSelected(false);
+                _selectedviews.remove(ap);
+                checkBox.setSelected(false);
               }
               enabled = true;
               _handler.itemStateChanged(e);
@@ -252,13 +252,13 @@ public class ViewSelectionMenu extends JMenu
             {
               // Deselect everything and select this item only
               _selectedviews.clear();
-              _selectedviews.add(p);
+              _selectedviews.add(ap);
               enabled = false;
               for (Component c : getMenuComponents())
               {
                 if (c instanceof JCheckBoxMenuItem)
                 {
-                  ((JCheckBoxMenuItem) c).setSelected(a == c);
+                  ((JCheckBoxMenuItem) c).setSelected(checkBox == c);
                 }
               }
               enabled = true;
@@ -268,54 +268,31 @@ public class ViewSelectionMenu extends JMenu
           }
         }
       });
-      a.addMouseListener(new MouseListener()
+      checkBox.addMouseListener(new MouseAdapter()
       {
-
-        @Override
-        public void mouseReleased(MouseEvent e)
-        {
-          // TODO Auto-generated method stub
-
-        }
-
-        @Override
-        public void mousePressed(MouseEvent e)
-        {
-          // TODO Auto-generated method stub
-
-        }
-
         @Override
         public void mouseExited(MouseEvent e)
         {
           try
           {
-            p.setSelected(false);
+            ap.setSelected(false);
           } catch (Exception ex)
           {
           }
-          ;
         }
 
         @Override
         public void mouseEntered(MouseEvent e)
         {
-
           try
           {
-            p.setSelected(true);
+            ap.setSelected(true);
           } catch (Exception ex)
           {
           }
-          ;
-        }
-
-        @Override
-        public void mouseClicked(MouseEvent e)
-        {
         }
       });
-      add(a);
+      add(checkBox);
     }
   }