X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FViewSelectionMenu.java;h=f77f41054a4d7b6cf57c61c78341e7cf0f75874c;hb=5640ec0623c6d1205e62f9fe15292f32bfdab7d9;hp=5cad55db4cdb161fa57adb6a5253c84997b4cce4;hpb=24f64bdbc24848b66d96e9a30f72ee92e8633a3d;p=jalview.git
diff --git a/src/jalview/gui/ViewSelectionMenu.java b/src/jalview/gui/ViewSelectionMenu.java
index 5cad55d..f77f410 100644
--- a/src/jalview/gui/ViewSelectionMenu.java
+++ b/src/jalview/gui/ViewSelectionMenu.java
@@ -1,12 +1,36 @@
+/*
+ * 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.
+ *
+ * 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 .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.gui;
+import jalview.api.AlignmentViewPanel;
+import jalview.util.MessageManager;
+import jalview.util.Platform;
+
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;
@@ -20,25 +44,24 @@ import javax.swing.event.MenuListener;
* dialog/menu which allows the user to select/deselect specific views from a
* list of associated views.
*
+ * Includes patches related to JAL-641
+ *
* @author JimP
*
*/
public class ViewSelectionMenu extends JMenu
{
- public interface ViewSetProvider {
+ public interface ViewSetProvider
+ {
public AlignmentPanel[] getAllAlignmentPanels();
}
+
private ViewSetProvider _allviews;
- private List _selectedviews;
+
+ private List _selectedviews;
+
private ItemListener _handler;
- @Override
- protected void finalize() throws Throwable
- {
- _selectedviews=null;
- _handler=null;
- _allviews=null;
- super.finalize();
- }
+
/**
* create a new view selection menu. This menu has some standard entries
* (select all, invert selection), and a checkbox for every view. Mousing over
@@ -57,53 +80,93 @@ public class ViewSelectionMenu extends JMenu
* update any gui elements which need to reflect current
* selection/deselection state
*/
- public ViewSelectionMenu(String title,
- final ViewSetProvider allviews,
- final List selectedviews,
+ public ViewSelectionMenu(String title, final ViewSetProvider allviews,
+ final List selectedviews,
final ItemListener handler)
{
super(title);
this._allviews = allviews;
this._selectedviews = selectedviews;
- this._handler=handler;
+ this._handler = handler;
addMenuListener(new MenuListener()
{
-
+
@Override
public void menuSelected(MenuEvent e)
{
rebuild();
-
+
}
-
+
@Override
public void menuDeselected(MenuEvent e)
{
// TODO Auto-generated method stub
-
+
}
-
+
@Override
public void menuCanceled(MenuEvent e)
{
// TODO Auto-generated method stub
-
+
}
});
}
- private void rebuild() {
+
+ /**
+ * view selection modifier flag - indicates if an action key is pressed when
+ * menu selection event occurred.
+ */
+ private boolean append = false;
+
+ /**
+ * flag indicating if the itemStateChanged listener for view associated menu
+ * items is currently enabled
+ */
+ private boolean enabled = true;
+
+ private JMenuItem selectAll, invertSel;
+
+ private JCheckBoxMenuItem toggleview = null;
+
+ private void rebuild()
+ {
removeAll();
- AlignmentPanel[] allviews=_allviews.getAllAlignmentPanels();
- if (allviews==null)
+ AlignmentPanel[] allviews = _allviews.getAllAlignmentPanels();
+ if (allviews == null)
{
setVisible(false);
return;
}
if (allviews.length >= 2)
{
- JMenuItem item;
- add(item = new JMenuItem("Select all views"));
- item.addActionListener(new ActionListener()
+ // ensure we update menu state to reflect external selection list state
+ append = append || _selectedviews.size() > 1;
+ toggleview = new JCheckBoxMenuItem(
+ MessageManager.getString("label.select_many_views"), append);
+ toggleview.setToolTipText(
+ MessageManager.getString("label.toggle_enabled_views"));
+ toggleview.addItemListener(new ItemListener()
+ {
+
+ @Override
+ public void itemStateChanged(ItemEvent arg0)
+ {
+ if (enabled)
+ {
+ append = !append;
+ selectAll.setEnabled(append);
+ invertSel.setEnabled(append);
+ }
+
+ }
+
+ });
+ add(toggleview);
+ add(selectAll = new JMenuItem(
+ MessageManager.getString("label.select_all_views")));
+ selectAll.addActionListener(new ActionListener()
{
@Override
@@ -111,106 +174,119 @@ public class ViewSelectionMenu extends JMenu
{
for (Component c : getMenuComponents())
{
+ boolean t = append;
+ append = true;
if (c instanceof JCheckBoxMenuItem)
{
- if (!((JCheckBoxMenuItem) c).isSelected())
+ if (toggleview != c && !((JCheckBoxMenuItem) c).isSelected())
{
((JCheckBoxMenuItem) c).doClick();
}
}
+ append = t;
}
}
});
- add(item = new JMenuItem("Invert selection"));
- item.addActionListener(new ActionListener()
+ add(invertSel = new JMenuItem(
+ MessageManager.getString("label.invert_selection")));
+ invertSel.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
+ boolean t = append;
+ append = true;
for (Component c : getMenuComponents())
{
- if (c instanceof JCheckBoxMenuItem)
+ if (toggleview != c && c instanceof JCheckBoxMenuItem)
{
((JCheckBoxMenuItem) c).doClick();
}
}
+ append = t;
}
});
-
+ 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 ")
+ String nm = ((ap.getViewName() == null
+ || ap.getViewName().length() == 0) ? ""
+ : ap.getViewName() + " for ")
+ ap.alignFrame.getTitle();
- 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)
{
- if (e.getStateChange() == e.SELECTED)
- {
- _selectedviews.add(p);
- }
- else
+ if (enabled)
{
- _selectedviews.remove(p);
+ if (append)
+ {
+ enabled = false;
+ // toggle the inclusion state
+ if (_selectedviews.indexOf(ap) == -1)
+ {
+ _selectedviews.add(ap);
+ checkBox.setSelected(true);
+ }
+ else
+ {
+ _selectedviews.remove(ap);
+ checkBox.setSelected(false);
+ }
+ enabled = true;
+ _handler.itemStateChanged(e);
+ }
+ else
+ {
+ // Deselect everything and select this item only
+ _selectedviews.clear();
+ _selectedviews.add(ap);
+ enabled = false;
+ for (Component c : getMenuComponents())
+ {
+ if (c instanceof JCheckBoxMenuItem)
+ {
+ ((JCheckBoxMenuItem) c).setSelected(checkBox == c);
+ }
+ }
+ enabled = true;
+ // only fire event if we weren't selected before
+ _handler.itemStateChanged(e);
+ }
}
- _handler.itemStateChanged(e);
}
});
- a.addMouseListener(new MouseListener()
+ final ViewSelectionMenu us = this;
+ 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);
} catch (Exception ex)
{
}
- ;
}
@Override
public void mouseEntered(MouseEvent e)
{
-
try
{
- p.setSelected(true);
+ ap.setAlignFrameView();
} catch (Exception ex)
{
}
- ;
- }
-
- @Override
- public void mouseClicked(MouseEvent e)
- {
}
});
- add(a);
+ add(checkBox);
}
}