From 15c3c0e89d9157187e1ccc6962b115cb255dd04a Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Thu, 27 Jul 2023 17:28:48 +0100 Subject: [PATCH] JAL-244 Allow adjusting Id column width in wrap mode. Set Id column width in gui and image output with --wrap mode. --- src/jalview/bin/Commands.java | 30 +++++++----- src/jalview/gui/AlignFrame.java | 85 ++++++++++++++++++++------------- src/jalview/gui/AlignmentPanel.java | 10 ++-- src/jalview/gui/AnnotationLabels.java | 11 ++++- src/jalview/gui/IdCanvas.java | 18 ++++++- 5 files changed, 103 insertions(+), 51 deletions(-) diff --git a/src/jalview/bin/Commands.java b/src/jalview/bin/Commands.java index 838b381..e1c88e1 100644 --- a/src/jalview/bin/Commands.java +++ b/src/jalview/bin/Commands.java @@ -166,13 +166,9 @@ public class Commands if (avm == null) return true; - /* - * // script to execute after all loading is completed one way or another String - * groovyscript = m.get(Arg.GROOVY) == null ? null : - * m.get(Arg.GROOVY).getValue(); String file = m.get(Arg.OPEN) == null ? null : - * m.get(Arg.OPEN).getValue(); String data = null; FileFormatI format = null; - * DataSourceType protocol = null; - */ + // set wrap scope here so it can be applied after structures are opened + boolean wrap = false; + if (avm.containsArg(Arg.APPEND) || avm.containsArg(Arg.OPEN)) { commandArgsProvided = true; @@ -256,11 +252,6 @@ public class Commands af = fileLoader.LoadFileWaitTillLoaded(openFile, protocol, format); - // wrap alignment? - boolean wrap = ArgParser.getFromSubValArgOrPref(avm, Arg.WRAP, sv, - null, "WRAP_ALIGNMENT", false); - af.getCurrentView().setWrapAlignment(wrap); - // colour alignment? String colour = ArgParser.getFromSubValArgOrPref(avm, av, Arg.COLOUR, sv, null, "DEFAULT_COLOUR_PROT", ""); @@ -365,6 +356,12 @@ public class Commands false, false); } + // wrap alignment? do this last for formatting reasons + wrap = ArgParser.getFromSubValArgOrPref(avm, Arg.WRAP, sv, null, + "WRAP_ALIGNMENT", false); + // af.setWrapFormat(wrap) is applied after structures are opened for + // annotation reasons + // store the AlignFrame for this id afMap.put(id, af); @@ -689,6 +686,15 @@ public class Commands } } + if (wrap) + { + AlignFrame af = afMap.get(id); + if (af != null) + { + af.setWrapFormat(wrap); + } + } + /* boolean doShading = avm.getBoolean(Arg.TEMPFAC_SHADING); if (doShading) diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index ab705c2..7f9bfff 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -157,7 +157,6 @@ import jalview.viewmodel.AlignmentViewport; import jalview.viewmodel.ViewportRanges; import jalview.ws.DBRefFetcher; import jalview.ws.DBRefFetcher.FetchFinishedListenerI; -import jalview.ws.datamodel.alphafold.PAEContactMatrix; import jalview.ws.jws1.Discoverer; import jalview.ws.jws2.Jws2Discoverer; import jalview.ws.jws2.jabaws2.Jws2Instance; @@ -1456,9 +1455,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, protected void htmlMenuItem_actionPerformed(ActionEvent e) { HtmlSvgOutput htmlSVG = new HtmlSvgOutput(alignPanel); - try { + try + { htmlSVG.exportHTML(null); - } catch (ImageOutputException x) { + } catch (ImageOutputException x) + { // report problem to console and raise dialog } } @@ -1467,51 +1468,64 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void bioJSMenuItem_actionPerformed(ActionEvent e) { BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel); - try { - bjs.exportHTML(null); - } catch (ImageOutputException x) { - // report problem to console and raise dialog - } + try + { + bjs.exportHTML(null); + } catch (ImageOutputException x) + { + // report problem to console and raise dialog + } } public void createImageMap(File file, String image) { - try { - alignPanel.makePNGImageMap(file, image); - } catch (ImageOutputException x) { + try + { + alignPanel.makePNGImageMap(file, image); + } catch (ImageOutputException x) + { // report problem to console and raise dialog } } @Override - public void createPNG_actionPerformed(ActionEvent e) { - try{ + public void createPNG_actionPerformed(ActionEvent e) + { + try + { createPNG(null); } catch (ImageOutputException ioex) { // raise dialog, and report via console } } + @Override - public void createEPS_actionPerformed(ActionEvent e) { - try{ + public void createEPS_actionPerformed(ActionEvent e) + { + try + { createEPS(null); } catch (ImageOutputException ioex) { // raise dialog, and report via console } - + } + @Override - public void createSVG_actionPerformed(ActionEvent e) { - try{ + public void createSVG_actionPerformed(ActionEvent e) + { + try + { createSVG(null); } catch (ImageOutputException ioex) { // raise dialog, and report via console } - + } + /** * Creates a PNG image of the alignment and writes it to the given file. If * the file is null, the user is prompted to choose a file. @@ -1523,7 +1537,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, createPNG(f, null, BitmapImageSizing.nullBitmapImageSizing()); } - public void createPNG(File f, String renderer, BitmapImageSizing userBis) throws ImageOutputException + public void createPNG(File f, String renderer, BitmapImageSizing userBis) + throws ImageOutputException { alignPanel.makeAlignmentImage(TYPE.PNG, f, renderer, userBis); } @@ -1534,7 +1549,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @param f */ - public void createEPS(File f) throws ImageOutputException + public void createEPS(File f) throws ImageOutputException { createEPS(f, null); } @@ -1550,7 +1565,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, * * @param f */ - public void createSVG(File f) throws ImageOutputException + public void createSVG(File f) throws ImageOutputException { createSVG(f, null); } @@ -2341,12 +2356,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // annotation was duplicated earlier alignment.addAnnotation(sequences[i].getAnnotation()[a]); // take care of contact matrix too - ContactMatrixI cm=sequences[i].getContactMatrixFor(sequences[i].getAnnotation()[a]); - if (cm!=null) + ContactMatrixI cm = sequences[i] + .getContactMatrixFor(sequences[i].getAnnotation()[a]); + if (cm != null) { - alignment.addContactListFor(sequences[i].getAnnotation()[a], cm); + alignment.addContactListFor(sequences[i].getAnnotation()[a], + cm); } - + alignment.setAnnotationIndex(sequences[i].getAnnotation()[a], a); } @@ -3138,10 +3155,15 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void wrapMenuItem_actionPerformed(ActionEvent e) { - scaleAbove.setVisible(wrapMenuItem.isSelected()); - scaleLeft.setVisible(wrapMenuItem.isSelected()); - scaleRight.setVisible(wrapMenuItem.isSelected()); - viewport.setWrapAlignment(wrapMenuItem.isSelected()); + setWrapFormat(wrapMenuItem.isSelected()); + } + + public void setWrapFormat(boolean b) + { + scaleAbove.setVisible(b); + scaleLeft.setVisible(b); + scaleRight.setVisible(b); + viewport.setWrapAlignment(b); alignPanel.updateLayout(); } @@ -4239,8 +4261,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, return tp; } - public void showContactMapTree(AlignmentAnnotation aa, - ContactMatrixI cm) + public void showContactMapTree(AlignmentAnnotation aa, ContactMatrixI cm) { int x = 4, y = 5; int w = 400, h = 500; diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 8a43a4a..c7c03b3 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -297,7 +297,7 @@ public class AlignmentPanel extends GAlignmentPanel implements int afwidth = (alignFrame != null ? alignFrame.getWidth() : 300); int idWidth = Math.min(afwidth - 200, 2 * afwidth / 3); int maxwidth = Math.max(IdwidthAdjuster.MIN_ID_WIDTH, idWidth); - return calculateIdWidth(-1, false, true); + return calculateIdWidth(-1, false, false); } /** @@ -624,7 +624,8 @@ public class AlignmentPanel extends GAlignmentPanel implements ranges.setStartSeq(0); scalePanelHolder.setVisible(!wrap); hscroll.setVisible(!wrap); - idwidthAdjuster.setVisible(!wrap); + // Allow idPanel width adjustment in wrap mode + idwidthAdjuster.setVisible(true); if (wrap) { @@ -658,7 +659,7 @@ public class AlignmentPanel extends GAlignmentPanel implements } } - idSpaceFillerPanel1.setVisible(!wrap); + // idSpaceFillerPanel1.setVisible(!wrap); repaint(); } @@ -1437,8 +1438,7 @@ public class AlignmentPanel extends GAlignmentPanel implements { int seqPanelWidth = getSeqPanel().seqCanvas.getWidth(); - if (System.getProperty("java.awt.headless") != null - && System.getProperty("java.awt.headless").equals("true")) + if (Jalview.isHeadlessMode()) { seqPanelWidth = alignFrame.getWidth() - getVisibleIdWidth() - vscroll.getPreferredSize().width diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index afee3d0..241e0a3 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -1206,6 +1206,7 @@ public class AnnotationLabels extends JPanel Graphics dummy = g2d.create(); int newAnnotationIdWidth = drawLabels(dummy, clip, width, false, null); + dummy.dispose(); Dimension d = ap.calculateDefaultAlignmentIdWidth(); int alignmentIdWidth = d.width; if (iwa != null && !iwa.manuallyAdjusted()) @@ -1230,6 +1231,14 @@ public class AnnotationLabels extends JPanel } } } + else + { + Graphics2D g2d = (Graphics2D) g; + Graphics dummy = g2d.create(); + int newAnnotationIdWidth = drawLabels(dummy, clip, width, false, + null); + width = Math.max(newAnnotationIdWidth, givenWidth); + } drawLabels(g, clip, width, true, null); } @@ -1255,7 +1264,7 @@ public class AnnotationLabels extends JPanel boolean actuallyDraw, FontMetrics fmetrics) { int actualWidth = 0; - if (actuallyDraw && g != null) + if (g != null) { if (av.getFont().getSize() < 10) { diff --git a/src/jalview/gui/IdCanvas.java b/src/jalview/gui/IdCanvas.java index c94dee0..d9997a0 100755 --- a/src/jalview/gui/IdCanvas.java +++ b/src/jalview/gui/IdCanvas.java @@ -22,6 +22,7 @@ package jalview.gui; import java.awt.BorderLayout; import java.awt.Color; +import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; @@ -382,6 +383,12 @@ public class IdCanvas extends JPanel implements ViewportListenerI void drawIdsWrapped(Graphics2D g, AlignViewport alignViewport, int startSeq, int pageHeight) { + drawIdsWrapped(g, alignViewport, startSeq, pageHeight, -1); + } + + void drawIdsWrapped(Graphics2D g, AlignViewport alignViewport, + int startSeq, int pageHeight, int idWidth) + { int alignmentWidth = alignViewport.getAlignment().getWidth(); final int alheight = alignViewport.getAlignment().getHeight(); @@ -429,7 +436,16 @@ public class IdCanvas extends JPanel implements ViewportListenerI if (labels != null && alignViewport.isShowAnnotation()) { g.translate(0, ypos + (alheight * charHeight)); - labels.drawComponent(g, getWidth()); + int getAnnotationsIdWidth = labels.drawLabels(g, false, -1, false, + null); + int thisIdWidth = idWidth < 0 ? getAnnotationsIdWidth : idWidth; + if (thisIdWidth > getWidth()) + { + this.setPreferredSize( + new Dimension(this.getHeight(), thisIdWidth)); + this.repaint(); + } + labels.drawComponent(g, false, thisIdWidth); g.translate(0, -ypos - (alheight * charHeight)); } -- 1.7.10.2