From eafbd1f2802db36625b54f9f2037e0df82afe2a5 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Wed, 2 Aug 2023 16:16:01 +0100 Subject: [PATCH] JAL-244 Fix buglet with automatic change in id column width not being recorded. More tests includeing wrapped format. --- src/jalview/bin/Commands.java | 2 +- src/jalview/gui/AlignFrame.java | 12 ++++--- src/jalview/gui/IdCanvas.java | 8 +++-- src/jalview/viewmodel/styles/ViewStyle.java | 4 +-- test/jalview/gui/AnnotationLabelsTest2.java | 51 +++++++++++++++++---------- 5 files changed, 49 insertions(+), 28 deletions(-) diff --git a/src/jalview/bin/Commands.java b/src/jalview/bin/Commands.java index 5211fa7..0cae97d 100644 --- a/src/jalview/bin/Commands.java +++ b/src/jalview/bin/Commands.java @@ -677,7 +677,7 @@ public class Commands AlignFrame af = afMap.get(id); if (af != null) { - af.setWrapFormat(wrap); + af.setWrapFormat(wrap, true); } } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 3e24e67..a61bead 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -3155,16 +3155,20 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void wrapMenuItem_actionPerformed(ActionEvent e) { - setWrapFormat(wrapMenuItem.isSelected()); + setWrapFormat(wrapMenuItem.isSelected(), false); } - public void setWrapFormat(boolean b) + public void setWrapFormat(boolean b, boolean setMenuItem) { scaleAbove.setVisible(b); scaleLeft.setVisible(b); scaleRight.setVisible(b); viewport.setWrapAlignment(b); alignPanel.updateLayout(); + if (setMenuItem) + { + wrapMenuItem.setSelected(b); + } } @Override @@ -4270,8 +4274,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { NewickFile fin = new NewickFile( new FileParse(cm.getNewick(), DataSourceType.PASTE)); - String title = aa.label + " " - + cm.getTreeMethod() + " tree" + (aa.sequenceRef != null + String title = aa.label + " " + cm.getTreeMethod() + " tree" + + (aa.sequenceRef != null ? (" for " + aa.sequenceRef.getDisplayId(false)) : ""); diff --git a/src/jalview/gui/IdCanvas.java b/src/jalview/gui/IdCanvas.java index ab21714..eb0715a 100755 --- a/src/jalview/gui/IdCanvas.java +++ b/src/jalview/gui/IdCanvas.java @@ -435,18 +435,20 @@ public class IdCanvas extends JPanel implements ViewportListenerI if (labels != null && alignViewport.isShowAnnotation()) { - int thisIdWidth = getWidth(); + int getWidth = getWidth(); + int thisIdWidth = getWidth; g.translate(0, ypos + (alheight * charHeight)); if (!manuallyAdjusted()) { int getAnnotationsIdWidth = labels.drawLabels(g, false, -1, false, null); thisIdWidth = idWidth < 0 ? getAnnotationsIdWidth : idWidth; - if (thisIdWidth > getWidth()) + if (thisIdWidth > getWidth) { this.setPreferredSize( - new Dimension(this.getHeight(), thisIdWidth)); + new Dimension(thisIdWidth, this.getHeight())); this.repaint(); + alignViewport.setIdWidth(thisIdWidth); } } labels.drawComponent(g, false, thisIdWidth); diff --git a/src/jalview/viewmodel/styles/ViewStyle.java b/src/jalview/viewmodel/styles/ViewStyle.java index 91f2f0c..715645a 100644 --- a/src/jalview/viewmodel/styles/ViewStyle.java +++ b/src/jalview/viewmodel/styles/ViewStyle.java @@ -20,10 +20,10 @@ */ package jalview.viewmodel.styles; -import jalview.api.ViewStyleI; - import java.awt.Color; +import jalview.api.ViewStyleI; + /** * A container for holding alignment view properties. View properties are * data-independent, which means they can be safely copied between views diff --git a/test/jalview/gui/AnnotationLabelsTest2.java b/test/jalview/gui/AnnotationLabelsTest2.java index e8fa9f1..ad97e8b 100644 --- a/test/jalview/gui/AnnotationLabelsTest2.java +++ b/test/jalview/gui/AnnotationLabelsTest2.java @@ -87,11 +87,11 @@ public class AnnotationLabelsTest2 groups = { "Functional", "testTask1" }, dataProvider = "openFilesWithIdWidthChanges") - public void testIdWidthChanges(String alignmentFilename, int idWidth1min, - int idWidth1max, int manualWidth, String structureFilename, - String paeFilename, boolean secondaryStructureView, - TFType temperatureFactorType, ViewerType viewerType, - int idWidth2min, int idWidth2max) + public void testIdWidthChanges(String alignmentFilename, boolean wrap, + int idWidth1min, int idWidth1max, int manualWidth, + String structureFilename, String paeFilename, + boolean secondaryStructureView, TFType temperatureFactorType, + ViewerType viewerType, int idWidth2min, int idWidth2max) { AlignFrame af = new FileLoader() .LoadFileWaitTillLoaded(alignmentFilename, DataSourceType.FILE); @@ -110,8 +110,19 @@ public class AnnotationLabelsTest2 idWidth = av.getIdWidth(); assertTrue(idWidth > idWidth1min, "idWidth (" + idWidth + ") is not greater than " + idWidth1min); - assertTrue(idWidth < idWidth1max, "idWidth (" + idWidth - + ") is not less wide than" + idWidth1max); + assertTrue(idWidth < idWidth1max, + "idWidth (" + idWidth + ") is not narrower than" + idWidth1max); + + // set wrap + if (wrap) + { + af.setWrapFormat(true, false); + idWidth = av.getIdWidth(); + assertTrue(idWidth > idWidth1min, "After wrap idWidth (" + idWidth + + ") is not greater than " + idWidth1min); + assertTrue(idWidth < idWidth1max, "After wrap idWidth (" + idWidth + + ") is not narrower than" + idWidth1max); + } AlignmentI al = av.getAlignment(); SequenceI s = al.getSequenceAt(0); @@ -134,18 +145,19 @@ public class AnnotationLabelsTest2 e.printStackTrace(); } + // idWidth = ap.getIdPanel().getWidth(); idWidth = av.getIdWidth(); assertTrue(idWidth > idWidth2min, "idWidth (" + idWidth + ") is not greater than " + idWidth2min); - assertTrue(idWidth < idWidth2max, "idWidth (" + idWidth - + ") is not less wide than" + idWidth2max); + assertTrue(idWidth < idWidth2max, + "idWidth (" + idWidth + ") is not narrower than" + idWidth2max); } @Test( groups = { "Functional", "testTask1" }, dataProvider = "openFilesWithIdWidthChanges") - public void testIdWidthNoChanges(String alignmentFilename, + public void testIdWidthNoChanges(String alignmentFilename, boolean wrap, int idWidth1min, int idWidth1max, int manualWidth, String structureFilename, String paeFilename, boolean secondaryStructureView, TFType temperatureFactorType, @@ -168,8 +180,8 @@ public class AnnotationLabelsTest2 idWidth = av.getIdWidth(); assertTrue(idWidth > idWidth1min, "idWidth (" + idWidth + ") is not greater than " + idWidth1min); - assertTrue(idWidth < idWidth1max, "idWidth (" + idWidth - + ") is not less wide than" + idWidth1max); + assertTrue(idWidth < idWidth1max, + "idWidth (" + idWidth + ") is not narrower than" + idWidth1max); AlignmentI al = av.getAlignment(); SequenceI s = al.getSequenceAt(0); @@ -207,6 +219,7 @@ public class AnnotationLabelsTest2 { /* String alignmentFilename, + boolean wrap, int idWidth1min, int idWidth1max, int manualWidth, // ignored by testIdWidthChanges() @@ -222,14 +235,16 @@ public class AnnotationLabelsTest2 // /* */ - { - // - "./test/files/annotation_label_width/sample.a2m", 50, 70, 100, + { "./test/files/annotation_label_width/sample.a2m", false, 50, 70, + 100, "./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb", "./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3_scores.json", - true, TFType.PLDDT, null, 115, 130 - // - }, + true, TFType.PLDDT, null, 115, 130 }, + { "./test/files/annotation_label_width/sample.a2m", true, 50, 70, + 100, + "./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb", + "./examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3_scores.json", + true, TFType.PLDDT, null, 115, 130 }, /* */ }; -- 1.7.10.2