X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FPopupMenu.java;h=3c32180ed65672a53b5ca215ae77487d7b7fdb9f;hb=747167089ecf8d6afc70d417f5a20352e029bd95;hp=2034b3fc0938849fa279766da2900f8a39adec38;hpb=6398c0217546a4d6943f63f670c2684c7c7274be;p=jalview.git
diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java
index 2034b3f..3c32180 100644
--- a/src/jalview/gui/PopupMenu.java
+++ b/src/jalview/gui/PopupMenu.java
@@ -20,12 +20,43 @@
*/
package jalview.gui;
+import java.util.Locale;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.BitSet;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Hashtable;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import java.util.Vector;
+
+import javax.swing.ButtonGroup;
+import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JInternalFrame;
+import javax.swing.JLabel;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
+import javax.swing.JRadioButtonMenuItem;
+import javax.swing.JScrollPane;
+
import jalview.analysis.AAFrequency;
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;
@@ -40,6 +71,7 @@ import jalview.datamodel.SequenceFeature;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
import jalview.gui.ColourMenuHelper.ColourChangeListener;
+import jalview.gui.JalviewColourChooser.ColourChooserListener;
import jalview.io.CountReader;
import jalview.io.FileFormatI;
import jalview.io.FileFormats;
@@ -54,37 +86,13 @@ import jalview.util.Comparison;
import jalview.util.GroupUrlLink;
import jalview.util.GroupUrlLink.UrlStringTooLongException;
import jalview.util.MessageManager;
+import jalview.util.Platform;
import jalview.util.StringUtils;
import jalview.util.UrlLink;
import jalview.viewmodel.seqfeatures.FeatureRendererModel;
-import java.awt.Color;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.BitSet;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Hashtable;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.SortedMap;
-import java.util.TreeMap;
-import java.util.Vector;
-
-import javax.swing.ButtonGroup;
-import javax.swing.JCheckBoxMenuItem;
-import javax.swing.JColorChooser;
-import javax.swing.JMenu;
-import javax.swing.JMenuItem;
-import javax.swing.JPopupMenu;
-import javax.swing.JRadioButtonMenuItem;
-
/**
* The popup menu that is displayed on right-click on a sequence id, or in the
* sequence alignment.
@@ -92,6 +100,11 @@ import javax.swing.JRadioButtonMenuItem;
public class PopupMenu extends JPopupMenu implements ColourChangeListener
{
/*
+ * maximum length of feature description to include in popup menu item text
+ */
+ private static final int FEATURE_DESC_MAX = 40;
+
+ /*
* true for ID Panel menu, false for alignment panel menu
*/
private final boolean forIdPanel;
@@ -221,13 +234,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;
}
@@ -294,7 +307,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener
jalview.util.BrowserLauncher.openURL(url);
} catch (Exception ex)
{
- JvOptionPane.showInternalMessageDialog(Desktop.desktop,
+ JvOptionPane.showInternalMessageDialog(Desktop.getDesktopPane(),
MessageManager.getString("label.web_browser_not_found_unix"),
MessageManager.getString("label.web_browser_not_found"),
JvOptionPane.WARNING_MESSAGE);
@@ -567,7 +580,6 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener
});
add(menuItem);
}
-
menuItem = new JMenuItem(
MessageManager.getString("action.hide_sequences"));
menuItem.addActionListener(new ActionListener()
@@ -691,6 +703,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener
{
buildGroupURLMenu(sg, groupLinks);
}
+ // TODO REMOVE FOR 2.12 ?
// Add a 'show all structures' for the current selection
Hashtable" + MessageManager.formatMessage(
"label.create_sequence_details_report_annotation_for",
new Object[]
- { seq.getDisplayId(true) }) + "
"); - new SequenceAnnotationReport(null).createSequenceAnnotationReport( + { seq.getDisplayId(true) }) + "
\n"); + new SequenceAnnotationReport(false).createSequenceAnnotationReport( contents, seq, true, true, ap.getSeqPanel().seqCanvas.fr); contents.append("
"); } - cap.setText("" + contents.toString() + ""); + contents.append(""); + String report = contents.toString(); + + JInternalFrame frame; + if (Platform.isJS()) + { + JLabel textLabel = new JLabel(); + textLabel.setText(report); + textLabel.setBackground(Color.WHITE); + JPanel pane = new JPanel(new BorderLayout()); + pane.setOpaque(true); + pane.setBackground(Color.WHITE); + pane.add(textLabel, BorderLayout.NORTH); + frame = new JInternalFrame(); + frame.getContentPane().add(new JScrollPane(pane)); + } + else + /** + * Java only + * + * @j2sIgnore + */ + { + CutAndPasteHtmlTransfer cap = new CutAndPasteHtmlTransfer(); + cap.setText(report); + frame = cap; + } - Desktop.addInternalFrame(cap, + Desktop.addInternalFrame(frame, MessageManager.formatMessage("label.sequence_details_for", (sequences.length == 1 ? new Object[] { sequences[0].getDisplayId(true) } @@ -1806,7 +1889,6 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener { MessageManager .getString("label.selection") })), 500, 400); - } protected void showNonconserved_actionPerformed() @@ -1925,30 +2007,27 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener } /** - * DOCUMENT ME! - * - * @param e - * DOCUMENT ME! + * Shows a dialog where group name and description may be edited */ protected void groupName_actionPerformed() { - SequenceGroup sg = getGroup(); EditNameDialog dialog = new EditNameDialog(sg.getName(), sg.getDescription(), - " " + MessageManager.getString("label.group_name") + " ", - MessageManager.getString("label.group_description") + " ", + MessageManager.getString("label.group_name"), + MessageManager.getString("label.group_description")); + dialog.showDialog(ap.alignFrame, MessageManager.getString("label.edit_group_name_description"), - ap.alignFrame); - - if (!dialog.accept) - { - return; - } - - sg.setName(dialog.getName()); - sg.setDescription(dialog.getDescription()); - refresh(); + new Runnable() + { + @Override + public void run() + { + sg.setName(dialog.getName()); + sg.setDescription(dialog.getDescription()); + refresh(); + } + }); } /** @@ -1977,41 +2056,34 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener { EditNameDialog dialog = new EditNameDialog(sequence.getName(), sequence.getDescription(), - " " + MessageManager.getString("label.sequence_name") - + " ", - MessageManager.getString("label.sequence_description") + " ", + MessageManager.getString("label.sequence_name"), + MessageManager.getString("label.sequence_description")); + dialog.showDialog(ap.alignFrame, MessageManager.getString( "label.edit_sequence_name_description"), - ap.alignFrame); - - if (!dialog.accept) - { - return; - } - - String name = dialog.getName(); - if (name != null) - { - if (name.indexOf(" ") > -1) - { - JvOptionPane.showMessageDialog(ap, - MessageManager - .getString("label.spaces_converted_to_backslashes"), - MessageManager - .getString("label.no_spaces_allowed_sequence_name"), - JvOptionPane.WARNING_MESSAGE); - name = name.replace(' ', '_'); - } - - sequence.setName(name); - ap.paintAlignment(false, false); - } - - sequence.setDescription(dialog.getDescription()); - - ap.av.firePropertyChange("alignment", null, - ap.av.getAlignment().getSequences()); - + new Runnable() + { + @Override + public void run() + { + if (dialog.getName() != null) + { + 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); + } + sequence.setDescription(dialog.getDescription()); + ap.av.notifyAlignment(); + } + }); } /** @@ -2036,24 +2108,23 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener } /** - * DOCUMENT ME! - * - * @param e - * DOCUMENT ME! + * Offers a colour chooser and sets the selected colour as the group outline */ protected void outline_actionPerformed() { - SequenceGroup sg = getGroup(); - Color col = JColorChooser.showDialog(this, - MessageManager.getString("label.select_outline_colour"), - Color.BLUE); - - if (col != null) + String title = MessageManager + .getString("label.select_outline_colour"); + ColourChooserListener listener = new ColourChooserListener() { - sg.setOutlineColour(col); - } - - refresh(); + @Override + public void colourSelected(Color c) + { + getGroup().setOutlineColour(c); + refresh(); + } + }; + JalviewColourChooser.showColourChooser(Desktop.getDesktopPane(), + title, Color.BLUE, listener); } /** @@ -2099,12 +2170,12 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener public void copy_actionPerformed() { - ap.alignFrame.copy_actionPerformed(null); + ap.alignFrame.copy_actionPerformed(); } public void cut_actionPerformed() { - ap.alignFrame.cut_actionPerformed(null); + ap.alignFrame.cut_actionPerformed(); } void changeCase(ActionEvent e) @@ -2141,9 +2212,8 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener startEnd, caseChange); ap.alignFrame.addHistoryItem(caseCommand); + ap.av.notifyAlignment(); - ap.av.firePropertyChange("alignment", null, - ap.av.getAlignment().getSequences()); } } @@ -2200,13 +2270,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener */ if (!seqs.isEmpty()) { - if (ap.getSeqPanel().seqCanvas.getFeatureRenderer() - .amendFeatures(seqs, features, true, ap)) - { - ap.alignFrame.setShowSeqFeatures(true); - ap.av.setSearchResults(null); // clear highlighting - ap.repaint(); // draw new/amended features - } + new FeatureEditor(ap, seqs, features, true).showDialog(); } } @@ -2219,7 +2283,12 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener } } - public void editSequence_actionPerformed(ActionEvent actionEvent) + /** + * Shows a dialog where sequence characters may be edited. Any changes are + * applied, and added as an available 'Undo' item in the edit commands + * history. + */ + public void editSequence_actionPerformed() { SequenceGroup sg = ap.av.getSelectionGroup(); @@ -2232,26 +2301,28 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener } EditNameDialog dialog = new EditNameDialog( - seq.getSequenceAsString(sg.getStartRes(), - sg.getEndRes() + 1), - null, MessageManager.getString("label.edit_sequence"), null, + seq.getSequenceAsString(sg.getStartRes(), sg.getEndRes() + 1), + null, MessageManager.getString("label.edit_sequence"), null); + dialog.showDialog(ap.alignFrame, MessageManager.getString("label.edit_sequence"), - ap.alignFrame); - - if (dialog.accept) - { - 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()); - } + 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.notifyAlignment(); + } + }); } }