{
x = av.getAlignment().getHiddenColumns().visibleToAbsoluteColumn(x);
}
-
- if (x >= av.getAlignment().getWidth())
- {
- res = av.getAlignment().getWidth() - 1;
- }
- else
- {
- res = x;
- }
+ res = Math.min(x, av.getAlignment().getWidth() - 1);
min = res;
max = res;
*/
protected void rightMouseButtonPressed(MouseEvent evt, final int res)
{
+ JPopupMenu pop = buildPopupMenu(res);
+ if (pop.getSubElements().length > 0)
+ {
+ pop.show(this, evt.getX(), evt.getY());
+ }
+ }
+
+ /**
+ * Builds a popup menu with 'Hide' or 'Reveal' options, or both, or neither
+ *
+ * @param res
+ * column number (0..)
+ * @return
+ */
+ protected JPopupMenu buildPopupMenu(final int res)
+ {
JPopupMenu pop = new JPopupMenu();
/*
- * grab the hidden range in case mouseMoved nulls it
+ * logic here depends on 'reveal', set in mouseMoved;
+ * grab the hidden range in case mouseMoved nulls it later
*/
final int[] hiddenRange = reveal;
if (hiddenRange != null)
});
pop.add(item);
}
- pop.show(this, evt.getX(), evt.getY());
}
- else if (av.getColumnSelection().contains(res))
+
+ if (av.getColumnSelection().contains(res))
{
JMenuItem item = new JMenuItem(
MessageManager.getString("label.hide_columns"));
}
});
pop.add(item);
- pop.show(this, evt.getX(), evt.getY());
}
+ return pop;
}
/**
import jalview.datamodel.SequenceI;
import jalview.io.DataSourceType;
import jalview.io.FileLoader;
+import jalview.util.MessageManager;
import jalview.viewmodel.ViewportRanges;
import java.awt.event.MouseEvent;
+import javax.swing.JMenuItem;
+import javax.swing.JPopupMenu;
+
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
assertEquals(sg.getEndRes(), 30);
}
+ @Test(groups = "Functional")
+ public void testBuildPopupMenu()
+ {
+ final String hide = MessageManager.getString("label.hide_columns");
+ final String reveal = MessageManager.getString("label.reveal");
+ final String revealAll = MessageManager.getString("action.reveal_all");
+
+ String seq1 = ">Seq1\nANTOFAGASTA";
+ AlignFrame alignFrame = new FileLoader().LoadFileWaitTillLoaded(seq1,
+ DataSourceType.PASTE);
+ ScalePanel scalePanel = alignFrame.alignPanel.getScalePanel();
+ AlignViewport viewport = alignFrame.getViewport();
+ int cw = viewport.getCharWidth();
+
+ /*
+ * hide columns 3-4 (counting from 0)
+ */
+ viewport.hideColumns(3, 4);
+ alignFrame.alignPanel.updateLayout();
+
+ /*
+ * verify popup menu left/right of hidden column marker
+ * NB need to call mouseMoved first as this sets field 'reveal'
+ */
+ int xPos = 1 * cw + 2; // 2 columns left of hidden marker
+ MouseEvent mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1,
+ false);
+ scalePanel.mouseMoved(mouse);
+ JPopupMenu popup = scalePanel.buildPopupMenu(1);
+ assertEquals(popup.getSubElements().length, 0);
+
+ /*
+ * popup just left of hidden marker has 'Reveal'
+ */
+ xPos = 2 * cw + 2;
+ mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false);
+ scalePanel.mouseMoved(mouse);
+ popup = scalePanel.buildPopupMenu(2);
+ assertEquals(popup.getSubElements().length, 1);
+ assertEquals(((JMenuItem) popup.getSubElements()[0]).getText(), reveal);
+
+ /*
+ * popup just right of hidden marker has 'Reveal'
+ */
+ xPos = 3 * cw + 2;
+ mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false);
+ scalePanel.mouseMoved(mouse);
+ popup = scalePanel.buildPopupMenu(5); // allowing for 2 hidden columns
+ assertEquals(popup.getSubElements().length, 1);
+ assertEquals(((JMenuItem) popup.getSubElements()[0]).getText(), reveal);
+
+ /*
+ * popup further right is empty
+ */
+ xPos = 4 * cw + 2;
+ mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false);
+ scalePanel.mouseMoved(mouse);
+ popup = scalePanel.buildPopupMenu(6); // allowing for 2 hidden columns
+ assertEquals(popup.getSubElements().length, 0);
+
+ /*
+ * 'drag' to select columns around the hidden column marker
+ */
+ xPos = 1 * cw + 2;
+ mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false);
+ scalePanel.mousePressed(mouse);
+ scalePanel.mouseDragged(mouse);
+ xPos = 5 * cw + 2;
+ mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false);
+ scalePanel.mouseReleased(mouse);
+
+ /*
+ * popup 2 columns left of marker: 'Hide' only
+ */
+ xPos = 1 * cw + 2;
+ mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false);
+ scalePanel.mouseMoved(mouse);
+ popup = scalePanel.buildPopupMenu(1);
+ assertEquals(popup.getSubElements().length, 1);
+ assertEquals(((JMenuItem) popup.getSubElements()[0]).getText(), hide);
+
+ /*
+ * popup just left of marker: 'Reveal' and 'Hide'
+ */
+ xPos = 2 * cw + 2;
+ mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false);
+ scalePanel.mouseMoved(mouse);
+ popup = scalePanel.buildPopupMenu(1);
+ assertEquals(popup.getSubElements().length, 2);
+ assertEquals(((JMenuItem) popup.getSubElements()[0]).getText(), reveal);
+ assertEquals(((JMenuItem) popup.getSubElements()[1]).getText(), hide);
+
+ /*
+ * popup just right of marker: 'Reveal' and 'Hide'
+ */
+ xPos = 3 * cw + 2;
+ mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false);
+ scalePanel.mouseMoved(mouse);
+ popup = scalePanel.buildPopupMenu(5);
+ assertEquals(popup.getSubElements().length, 2);
+ assertEquals(((JMenuItem) popup.getSubElements()[0]).getText(), reveal);
+ assertEquals(((JMenuItem) popup.getSubElements()[1]).getText(), hide);
+
+ /*
+ * hiding a second region adds option 'Reveal all' to 'Reveal'
+ */
+ viewport.hideColumns(6, 7);
+ alignFrame.alignPanel.updateLayout();
+ xPos = 3 * cw + 2;
+ mouse = new MouseEvent(scalePanel, 0, 1, 0, xPos, 0, 1, false);
+ scalePanel.mouseMoved(mouse);
+ popup = scalePanel.buildPopupMenu(5);
+ assertEquals(popup.getSubElements().length, 3);
+ assertEquals(((JMenuItem) popup.getSubElements()[0]).getText(), reveal);
+ assertEquals(((JMenuItem) popup.getSubElements()[1]).getText(),
+ revealAll);
+ assertEquals(((JMenuItem) popup.getSubElements()[2]).getText(), hide);
+
+ alignFrame.deselectAllSequenceMenuItem_actionPerformed(null);
+ popup = scalePanel.buildPopupMenu(5);
+ assertEquals(popup.getSubElements().length, 2);
+ assertEquals(((JMenuItem) popup.getSubElements()[0]).getText(), reveal);
+ assertEquals(((JMenuItem) popup.getSubElements()[1]).getText(),
+ revealAll);
+ }
+
@BeforeClass(alwaysRun = true)
public static void setUpBeforeClass() throws Exception
{