From 4313fc0bf442a0668d74224f78080b1182acb20d Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 9 Jul 2018 13:41:12 +0100 Subject: [PATCH] JAL-3060 entry points for createFeatures, amendFeatures --- src/jalview/gui/FeatureEditor.java | 101 +++++++++++++++++++++--------------- src/jalview/gui/Finder.java | 2 +- src/jalview/gui/PopupMenu.java | 18 +++---- src/jalview/gui/SeqPanel.java | 19 ++++--- 4 files changed, 78 insertions(+), 62 deletions(-) diff --git a/src/jalview/gui/FeatureEditor.java b/src/jalview/gui/FeatureEditor.java index a86725b..ad82612 100644 --- a/src/jalview/gui/FeatureEditor.java +++ b/src/jalview/gui/FeatureEditor.java @@ -75,6 +75,20 @@ public class FeatureEditor fr = alignPanel.getSeqPanel().seqCanvas.fr; } + public void amendFeatures(final List sequences, + final List features, + final Runnable responseHandler) + { + amendFeatures(sequences, features, false, responseHandler); + } + + public void createFeatures(final List sequences, + final List features, + final Runnable responseHandler) + { + amendFeatures(sequences, features, true, responseHandler); + } + /** * Presents a dialog allowing the user to add new features, or amend or delete * existing features. Currently this can be on @@ -99,14 +113,14 @@ public class FeatureEditor * @param responseHandler * boolean true RunResponse is run if features are created */ - public boolean amendFeatures(final List sequences, + private void amendFeatures(final List sequences, final List features, boolean create, final Runnable responseHandler) { featureIndex = 0; - + final JPanel mainPanel = new JPanel(new BorderLayout()); - + final JTextField name = new JTextField(25); name.getDocument().addDocumentListener(new DocumentListener() { @@ -115,20 +129,20 @@ public class FeatureEditor { warnIfTypeHidden(mainPanel, name.getText()); } - + @Override public void removeUpdate(DocumentEvent e) { warnIfTypeHidden(mainPanel, name.getText()); } - + @Override public void changedUpdate(DocumentEvent e) { warnIfTypeHidden(mainPanel, name.getText()); } }); - + final JTextField group = new JTextField(25); group.getDocument().addDocumentListener(new DocumentListener() { @@ -137,20 +151,20 @@ public class FeatureEditor { warnIfGroupHidden(mainPanel, group.getText()); } - + @Override public void removeUpdate(DocumentEvent e) { warnIfGroupHidden(mainPanel, group.getText()); } - + @Override public void changedUpdate(DocumentEvent e) { warnIfGroupHidden(mainPanel, group.getText()); } }); - + final JTextArea description = new JTextArea(3, 25); final JSpinner start = new JSpinner(); final JSpinner end = new JSpinner(); @@ -192,8 +206,7 @@ public class FeatureEditor */ final String ft = features.get(featureIndex).getType(); final String type = ft == null ? lastFeatureAdded : ft; - FeatureTypeSettings fcc = new FeatureTypeSettings( - fr, type); + FeatureTypeSettings fcc = new FeatureTypeSettings(fr, type); fcc.setRequestFocusEnabled(true); fcc.requestFocus(); fcc.addActionListener(new ActionListener() @@ -210,7 +223,7 @@ public class FeatureEditor } }); JPanel gridPanel = new JPanel(new GridLayout(3, 1)); - + if (!create && features.size() > 1) { /* @@ -236,7 +249,7 @@ public class FeatureEditor added.add(text); } choosePanel.add(overlaps); - + overlaps.addItemListener(new ItemListener() { @Override @@ -252,13 +265,13 @@ public class FeatureEditor group.setText(sf.getFeatureGroup()); start.setValue(new Integer(sf.getBegin())); end.setValue(new Integer(sf.getEnd())); - + SearchResultsI highlight = new SearchResults(); highlight.addResult(sequences.get(0), sf.getBegin(), sf.getEnd()); - - ap.getSeqPanel().seqCanvas - .highlightSearchResults(highlight, false); + + ap.getSeqPanel().seqCanvas.highlightSearchResults(highlight, + false); } FeatureColourI col = fr.getFeatureStyle(name.getText()); if (col == null) @@ -270,22 +283,22 @@ public class FeatureEditor updateColourButton(mainPanel, colour, col); } }); - + gridPanel.add(choosePanel); } - + JPanel namePanel = new JPanel(); gridPanel.add(namePanel); namePanel.add(new JLabel(MessageManager.getString("label.name:"), JLabel.RIGHT)); namePanel.add(name); - + JPanel groupPanel = new JPanel(); gridPanel.add(groupPanel); groupPanel.add(new JLabel(MessageManager.getString("label.group:"), JLabel.RIGHT)); groupPanel.add(group); - + JPanel colourPanel = new JPanel(); gridPanel.add(colourPanel); colourPanel.add(new JLabel(MessageManager.getString("label.colour"), @@ -299,18 +312,18 @@ public class FeatureEditor colour.setHorizontalTextPosition(SwingConstants.CENTER); colour.setVerticalTextPosition(SwingConstants.CENTER); mainPanel.add(gridPanel, BorderLayout.NORTH); - + JPanel descriptionPanel = new JPanel(); descriptionPanel.add(new JLabel( MessageManager.getString("label.description:"), JLabel.RIGHT)); description.setFont(JvSwingUtils.getTextAreaFont()); description.setLineWrap(true); descriptionPanel.add(new JScrollPane(description)); - + if (!create) { mainPanel.add(descriptionPanel, BorderLayout.SOUTH); - + JPanel startEndPanel = new JPanel(); startEndPanel.add(new JLabel(MessageManager.getString("label.start"), JLabel.RIGHT)); @@ -324,7 +337,7 @@ public class FeatureEditor { mainPanel.add(descriptionPanel, BorderLayout.CENTER); } - + /* * default feature type and group to that of the first feature supplied, * or to the last feature created if not supplied (null value) @@ -337,7 +350,7 @@ public class FeatureEditor : firstFeature.getFeatureGroup(); name.setText(featureType); group.setText(featureGroup); - + start.setValue(new Integer(firstFeature.getBegin())); end.setValue(new Integer(firstFeature.getEnd())); description.setText(firstFeature.getDescription()); @@ -356,18 +369,18 @@ public class FeatureEditor options = new Object[] { MessageManager.getString("action.ok"), MessageManager.getString("action.cancel") }; } - + String title = create ? MessageManager.getString("label.create_new_sequence_features") : MessageManager.formatMessage("label.amend_delete_features", new String[] { sequences.get(0).getName() }); - + /* * register responses and show the dialog */ JvOptionPane.newOptionDialog(Desktop.desktop).response( - + new RunResponse(JvOptionPane.OK_OPTION) { public void run() @@ -377,7 +390,7 @@ public class FeatureEditor final String enteredDescription = description.getText() .replaceAll("\n", " "); if (enteredType.length() > 0) - + { /* * update default values only if creating using default values @@ -393,7 +406,7 @@ public class FeatureEditor } } } - + if (create) { // NEW FEATURES ADDED @@ -408,14 +421,16 @@ public class FeatureEditor new FeaturesFile().parseDescriptionHTML(sf2, false); sequences.get(i).addSequenceFeature(sf2); } - + fr.setColour(enteredType, featureColour); - + fr.featuresAdded(); - + responseHandler.run(); } - } else { + } + else + { SequenceFeature sf = features.get(featureIndex); /* * Feature amended - YES_OPTION corresponds to the Amend button @@ -423,7 +438,8 @@ public class FeatureEditor * note we don't force the feature to be visible - the user has been * warned if a hidden feature type or group was entered */ - boolean refreshSettings = (!featureType.equals(enteredType) + boolean refreshSettings = (!featureType + .equals(enteredType) || !featureGroup.equals(enteredGroup)); refreshSettings |= (featureColour != oldColour); fr.setColour(enteredType, featureColour); @@ -437,24 +453,26 @@ public class FeatureEditor { // JSpinner doesn't accept invalid format data :-) } - + /* * replace the feature by deleting it and adding a new one * (to ensure integrity of SequenceFeatures data store) */ sequences.get(0).deleteFeature(sf); - SequenceFeature newSf = new SequenceFeature(sf, enteredType, - newBegin, newEnd, enteredGroup, sf.getScore()); + SequenceFeature newSf = new SequenceFeature(sf, + enteredType, newBegin, newEnd, enteredGroup, + sf.getScore()); newSf.setDescription(enteredDescription); new FeaturesFile().parseDescriptionHTML(newSf, false); // amend features dialog only updates one sequence at a time sequences.get(0).addSequenceFeature(newSf); - + if (refreshSettings) { fr.featuresAdded(); } } + ap.getSeqPanel().seqCanvas.highlightSearchResults(null, false); ap.paintAlignment(true, true); @@ -486,7 +504,6 @@ public class FeatureEditor JvOptionPane.YES_NO_CANCEL_OPTION, JvOptionPane.QUESTION_MESSAGE, null, options, MessageManager.getString("action.ok")); - return true; } /** @@ -503,7 +520,7 @@ public class FeatureEditor colour.setIcon(null); colour.setToolTipText(null); colour.setText(""); - + if (col.isSimpleColour()) { colour.setBackground(col.getColour()); diff --git a/src/jalview/gui/Finder.java b/src/jalview/gui/Finder.java index 244e6df..ef69aa8 100755 --- a/src/jalview/gui/Finder.java +++ b/src/jalview/gui/Finder.java @@ -227,7 +227,7 @@ public class Finder extends GFinder match.getEnd(), desc)); } - new FeatureEditor(ap).amendFeatures(seqs, features, true, new Runnable() + new FeatureEditor(ap).createFeatures(seqs, features, new Runnable() { @Override public void run() diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index cb94409..776fcd2 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -2038,15 +2038,15 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener */ if (!seqs.isEmpty()) { - new FeatureEditor(ap).amendFeatures(seqs, features, true, - new Runnable() - { - public void run() - { - ap.alignFrame.setShowSeqFeatures(true); - ap.av.setSearchResults(null); // clear highlighting - ap.repaint(); // draw new/amended features - }}); + new FeatureEditor(ap).createFeatures(seqs, features, new Runnable() + { + public void run() + { + ap.alignFrame.setShowSeqFeatures(true); + ap.av.setSearchResults(null); // clear highlighting + ap.repaint(); // draw new/amended features + } + }); } } diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index db0d902..5ae4a0e 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -1680,16 +1680,15 @@ public class SeqPanel extends JPanel * whether changes were made or not */ List seqs = Collections.singletonList(sequence); - new FeatureEditor(ap).amendFeatures(seqs, features, false, - new Runnable() - { - @Override - public void run() - { - av.setSearchResults(null); // clear highlighting - seqCanvas.repaint(); // draw new/amended features - } - }); + new FeatureEditor(ap).amendFeatures(seqs, features, new Runnable() + { + @Override + public void run() + { + av.setSearchResults(null); // clear highlighting + seqCanvas.repaint(); // draw new/amended features + } + }); } } } -- 1.7.10.2