X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FPopupMenu.java;h=f50b72b206c9da5fbe942c7e3698910a93d34dcc;hb=265e81c0b3599a09c312f17188e3a892e9d96c4e;hp=2f77959611f9b741dba1bea97a585de7e8494c53;hpb=3af9017e1f6c6d045c6c0d41245fcd7bfdae32a6;p=jalview.git diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 2f77959..f50b72b 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -32,6 +32,7 @@ import java.util.Collections; import java.util.Hashtable; import java.util.LinkedHashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.SortedMap; @@ -54,7 +55,7 @@ import jalview.analysis.AlignmentAnnotationUtils; import jalview.analysis.AlignmentUtils; import jalview.analysis.Conservation; import jalview.api.AlignViewportI; -import jalview.bin.Cache; +import jalview.bin.Console; import jalview.commands.ChangeCaseCommand; import jalview.commands.EditCommand; import jalview.commands.EditCommand.Action; @@ -86,6 +87,8 @@ import jalview.util.Platform; import jalview.util.StringUtils; import jalview.util.UrlLink; import jalview.viewmodel.seqfeatures.FeatureRendererModel; +import jalview.viewmodel.seqfeatures.IdColumn; +import jalview.viewmodel.seqfeatures.IdColumns; /** * The popup menu that is displayed on right-click on a sequence id, or in the @@ -228,13 +231,13 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener urlLink = new UrlLink(link); } catch (Exception foo) { - Cache.log.error("Exception for URLLink '" + link + "'", foo); + Console.error("Exception for URLLink '" + link + "'", foo); continue; } if (!urlLink.isValid()) { - Cache.log.error(urlLink.getInvalidMessage()); + Console.error(urlLink.getInvalidMessage()); continue; } @@ -357,14 +360,15 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener } /** - * Constructor for a PopupMenu for a click in the alignment panel (on a residue) + * Constructor for a PopupMenu for a click in the alignment panel (on a + * residue) * * @param ap - * the panel in which the mouse is clicked + * the panel in which the mouse is clicked * @param seq - * the sequence under the mouse + * the sequence under the mouse * @throws NullPointerException - * if seq is null + * if seq is null */ public PopupMenu(final AlignmentPanel ap, SequenceI seq, int column) { @@ -375,13 +379,13 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener * Constructor for a PopupMenu for a click in the sequence id panel * * @param alignPanel - * the panel in which the mouse is clicked + * the panel in which the mouse is clicked * @param seq - * the sequence under the mouse click + * the sequence under the mouse click * @param groupLinks - * templates for sequence external links + * templates for sequence external links * @throws NullPointerException - * if seq is null + * if seq is null */ public PopupMenu(final AlignmentPanel alignPanel, final SequenceI seq, List groupLinks) @@ -397,11 +401,10 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener * @param alignPanel * @param seq * @param column - * aligned column position (0...) + * aligned column position (0...) * @param groupLinks */ - private PopupMenu(boolean fromIdPanel, - final AlignmentPanel alignPanel, + private PopupMenu(boolean fromIdPanel, final AlignmentPanel alignPanel, final SequenceI seq, final int column, List groupLinks) { Objects.requireNonNull(seq); @@ -441,9 +444,10 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener /* * And repeat for the current selection group (if there is one): */ - final List selectedGroup = (alignPanel.av.getSelectionGroup() == null - ? Collections. emptyList() - : alignPanel.av.getSelectionGroup().getSequences()); + final List selectedGroup = (alignPanel.av + .getSelectionGroup() == null + ? Collections. emptyList() + : alignPanel.av.getSelectionGroup().getSequences()); buildAnnotationTypesMenus(groupShowAnnotationsMenu, groupHideAnnotationsMenu, selectedGroup); configureReferenceAnnotationsMenu(groupAddReferenceAnnotations, @@ -669,7 +673,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener buildGroupURLMenu(sg, groupLinks); } // Add a 'show all structures' for the current selection - Hashtable pdbe = new Hashtable<>(), reppdb = new Hashtable<>(); + Hashtable pdbe = new Hashtable<>(), + reppdb = new Hashtable<>(); SequenceI sqass = null; for (SequenceI sq : alignPanel.av.getSequenceSelection()) @@ -706,7 +711,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener { createGroupMenuItem.setVisible(true); unGroupMenuItem.setVisible(false); - editGroupMenu.setText(MessageManager.getString("action.edit_new_group")); + editGroupMenu + .setText(MessageManager.getString("action.edit_new_group")); } else { @@ -722,9 +728,38 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener rnaStructureMenu.setVisible(false); } + if (forIdPanel) + { + addDisplayColumnsMenu(); + } + addLinksAndFeatures(seq, column); } + void addDisplayColumnsMenu() + { + JMenu dis_cols = new JMenu( + MessageManager.getString("action.displayed_columns")); + final IdColumns id_cols = ap.av.getIdColumns(); + id_cols.updateTypeList(); + for (final IdColumn col : id_cols.getIdColumns()) + { + JMenuItem col_entry = new JCheckBoxMenuItem(col.getLabel(), + col.isVisible()); + col_entry.addActionListener(new ActionListener() + { + + @Override + public void actionPerformed(ActionEvent e) + { + id_cols.toggleVisible(col.getLabel()); + } + }); + dis_cols.add(col_entry); + } + add(dis_cols); + } + /** * Adds *
    @@ -733,8 +768,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener *
  • positional feature links (alignment panel popup menu)
  • *
  • feature details links (alignment panel popup menu)
  • *
- * If this panel is also showed complementary (CDS/protein) features, then links - * to their feature details are also added. + * If this panel is also showed complementary (CDS/protein) features, then + * links to their feature details are also added. * * @param seq * @param column @@ -837,15 +872,14 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener /* * show local rather than linked feature coordinates */ - int[] beginRange = mf.getMappedPositions(start, start); - int[] endRange = mf.getMappedPositions(end, end); - if (beginRange == null || endRange == null) + int[] localRange = mf.getMappedPositions(start, end); + if (localRange == null) { // e.g. variant extending to stop codon so not mappable return; } - start = beginRange[0]; - end = endRange[endRange.length - 1]; + start = localRange[0]; + end = localRange[localRange.length - 1]; } StringBuilder desc = new StringBuilder(); desc.append(sf.getType()).append(" ").append(String.valueOf(start)); @@ -1130,7 +1164,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener for (int d = 0; d < nd; d++) { DBRefEntry e = dbr.get(d); - String src = e.getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase(); + String src = e.getSource(); // jalview.util.DBRefUtils.getCanonicalName(dbr[d].getSource()).toUpperCase(Locale.ROOT); Object[] sarray = commonDbrefs.get(src); if (sarray == null) { @@ -1143,8 +1177,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener if (((String[]) sarray[1])[sq] == null) { - if (!e.hasMap() || (e.getMap() - .locateMappedRange(start, end) != null)) + if (!e.hasMap() + || (e.getMap().locateMappedRange(start, end) != null)) { ((String[]) sarray[1])[sq] = e.getAccessionId(); ((int[]) sarray[0])[0]++; @@ -1164,19 +1198,19 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener urlLink = new GroupUrlLink(link); } catch (Exception foo) { - Cache.log.error("Exception for GroupURLLink '" + link + "'", foo); + Console.error("Exception for GroupURLLink '" + link + "'", foo); continue; } if (!urlLink.isValid()) { - Cache.log.error(urlLink.getInvalidMessage()); + Console.error(urlLink.getInvalidMessage()); continue; } final String label = urlLink.getLabel(); boolean usingNames = false; // Now see which parts of the group apply for this URL String ltarget = urlLink.getTarget(); // jalview.util.DBRefUtils.getCanonicalName(urlLink.getTarget()); - Object[] idset = commonDbrefs.get(ltarget.toUpperCase()); + Object[] idset = commonDbrefs.get(ltarget.toUpperCase(Locale.ROOT)); String[] seqstr, ids; // input to makeUrl if (idset != null) { @@ -1783,7 +1817,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener } inserts.and(sq.getInsertionsAsBits()); } - hidden.clearAndHideColumns(inserts, ap.av.getSelectionGroup().getStartRes(), + hidden.clearAndHideColumns(inserts, + ap.av.getSelectionGroup().getStartRes(), ap.av.getSelectionGroup().getEndRes()); } @@ -1812,7 +1847,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener contents.append("

" + MessageManager.formatMessage( "label.create_sequence_details_report_annotation_for", new Object[] - { seq.getDisplayId(true) }) + "

"); + { seq.getDisplayId(true) }) + "

\n

"); new SequenceAnnotationReport(false).createSequenceAnnotationReport( contents, seq, true, true, ap.getSeqPanel().seqCanvas.fr); contents.append("

"); @@ -1982,15 +2017,11 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener MessageManager.getString("label.group_description")); dialog.showDialog(ap.alignFrame, MessageManager.getString("label.edit_group_name_description"), - new Runnable() - { - @Override - public void run() - { - sg.setName(dialog.getName()); - sg.setDescription(dialog.getDescription()); - refresh(); - } + () -> { + sg.setName(dialog.getName()); + sg.setDescription(dialog.getDescription()); + refresh(); + return null; }); } @@ -2013,8 +2044,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener /** * Shows a dialog where the sequence name and description may be edited. If a - * name containing spaces is entered, these are converted to underscores, with a - * warning message. + * name containing spaces is entered, these are converted to underscores, with + * a warning message. */ void sequenceName_actionPerformed() { @@ -2022,32 +2053,26 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener sequence.getDescription(), MessageManager.getString("label.sequence_name"), MessageManager.getString("label.sequence_description")); - dialog.showDialog(ap.alignFrame, - MessageManager.getString( - "label.edit_sequence_name_description"), - new Runnable() - { - @Override - public void run() + dialog.showDialog(ap.alignFrame, MessageManager + .getString("label.edit_sequence_name_description"), () -> { + if (dialog.getName() != null) { - if (dialog.getName() != null) + if (dialog.getName().indexOf(" ") > -1) { - if (dialog.getName().indexOf(" ") > -1) - { - JvOptionPane.showMessageDialog(ap, - MessageManager.getString( - "label.spaces_converted_to_underscores"), - MessageManager.getString( - "label.no_spaces_allowed_sequence_name"), - JvOptionPane.WARNING_MESSAGE); - } - sequence.setName(dialog.getName().replace(' ', '_')); - ap.paintAlignment(false, false); + JvOptionPane.showMessageDialog(ap, + MessageManager.getString( + "label.spaces_converted_to_underscores"), + MessageManager.getString( + "label.no_spaces_allowed_sequence_name"), + JvOptionPane.WARNING_MESSAGE); } - sequence.setDescription(dialog.getDescription()); - ap.av.firePropertyChange("alignment", null, - ap.av.getAlignment().getSequences()); + sequence.setName(dialog.getName().replace(' ', '_')); + ap.paintAlignment(false, false); } + sequence.setDescription(dialog.getDescription()); + ap.av.firePropertyChange("alignment", null, + ap.av.getAlignment().getSequences()); + return null; }); } @@ -2077,8 +2102,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener */ protected void outline_actionPerformed() { - String title = MessageManager - .getString("label.select_outline_colour"); + String title = MessageManager.getString("label.select_outline_colour"); ColourChooserListener listener = new ColourChooserListener() { @Override @@ -2088,8 +2112,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener refresh(); } }; - JalviewColourChooser.showColourChooser(Desktop.getDesktop(), - title, Color.BLUE, listener); + JalviewColourChooser.showColourChooser(Desktop.getDesktop(), title, + Color.BLUE, listener); } /** @@ -2270,25 +2294,20 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener seq.getSequenceAsString(sg.getStartRes(), sg.getEndRes() + 1), null, MessageManager.getString("label.edit_sequence"), null); dialog.showDialog(ap.alignFrame, - MessageManager.getString("label.edit_sequence"), - new Runnable() - { - @Override - public void run() - { - EditCommand editCommand = new EditCommand( - MessageManager.getString("label.edit_sequences"), - Action.REPLACE, - dialog.getName().replace(' ', - ap.av.getGapCharacter()), - sg.getSequencesAsArray( - ap.av.getHiddenRepSequences()), - sg.getStartRes(), sg.getEndRes() + 1, - ap.av.getAlignment()); - ap.alignFrame.addHistoryItem(editCommand); - ap.av.firePropertyChange("alignment", null, - ap.av.getAlignment().getSequences()); - } + MessageManager.getString("label.edit_sequence"), () -> { + EditCommand editCommand = new EditCommand( + MessageManager.getString("label.edit_sequences"), + Action.REPLACE, + dialog.getName().replace(' ', + ap.av.getGapCharacter()), + sg.getSequencesAsArray( + ap.av.getHiddenRepSequences()), + sg.getStartRes(), sg.getEndRes() + 1, + ap.av.getAlignment()); + ap.alignFrame.addHistoryItem(editCommand); + ap.av.firePropertyChange("alignment", null, + ap.av.getAlignment().getSequences()); + return null; }); } }