From: gmungoc Date: Thu, 4 Oct 2018 13:08:58 +0000 (+0100) Subject: JAL-1244 status message for insert/delete gaps on single sequence X-Git-Tag: Release_2_11_0~17^2~84^2~4 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=065df5c0ed52645a42d9147bd547965fc4c12ee3;p=jalview.git JAL-1244 status message for insert/delete gaps on single sequence --- diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index e50e65d..bdaf85c 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -1188,43 +1188,30 @@ public class SeqPanel extends JPanel } } - StringBuilder message = new StringBuilder(64); - if (groupEditing) + /* + * initialise the edit command if there is not + * already one being extended + */ + if (editCommand == null) { - message.append("Edit group:"); - if (editCommand == null) + if (groupEditing) { editCommand = new EditCommand( MessageManager.getString("action.edit_group")); } - } - else - { - message.append("Edit sequence: " + seq.getName()); - String label = seq.getName(); - if (label.length() > 10) - { - label = label.substring(0, 10); - } - if (editCommand == null) + else { + String label = seq.getName(); + if (label.length() > 10) + { + label = label.substring(0, 10); + } editCommand = new EditCommand(MessageManager .formatMessage("label.edit_params", new String[] { label })); } } - if (insertGap) - { - message.append(" insert "); - } - else - { - message.append(" delete "); - } - - message.append(Math.abs(startres - lastres) + " gaps."); - ap.alignFrame.statusBar.setText(message.toString()); // Are we editing within a selection group? if (groupEditing || (sg != null @@ -1300,6 +1287,7 @@ public class SeqPanel extends JPanel if (groupEditing) { + ap.alignFrame.statusBar.setText(" "); // defer this as difficult! List vseqs = sg.getSequences(av.getHiddenRepSequences()); int g, groupSize = vseqs.size(); SequenceI[] groupSeqs = new SequenceI[groupSize]; @@ -1442,6 +1430,8 @@ public class SeqPanel extends JPanel else // ///Editing a single sequence/////////// { + String msg = getEditStatusMessage(insertGap, seq.getName()); + ap.alignFrame.statusBar.setText(msg); if (insertGap) { // dragging to the right @@ -1517,6 +1507,56 @@ public class SeqPanel extends JPanel seqCanvas.repaint(); } + /** + * Constructs an informative status bar message while dragging to insert or + * delete gaps + * + * @param insert + * @param seqName + * @return + */ + protected String getEditStatusMessage(boolean insert, String seqName) + { + /* + * add any inserts, and subtract any deletes, so far + */ + int count = 0; + for (Edit cmd : editCommand.getEdits()) + { + count += cmd.getAction() == Action.INSERT_GAP ? cmd.getNumber() + : -cmd.getNumber(); + } + + /* + * add the current action + */ + count += insert ? 1 : -1; + + if (count == 0) + { + /* + * inserts and deletes cancel out + */ + return " "; + } + StringBuilder message = new StringBuilder(64); + if (groupEditing) + { + message.append("Edit group:"); + } + else + { + message.append("Edit sequence: ").append(seqName); + } + + message.append(count > 0 ? " insert " : " delete "); + count = Math.abs(count); + message.append(String.valueOf(count)); + message.append(count > 1 ? " gaps" : " gap"); + String msg = message.toString(); + return msg; + } + void insertChar(int j, SequenceI[] seq, int fixedColumn) { int blankColumn = fixedColumn;