import jalview.bin.Cache;
import jalview.bin.Console;
import jalview.bin.Jalview;
+import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.HiddenColumns;
import jalview.datamodel.SearchResultsI;
Dimension r = null;
if (av.getIdWidth() < 0)
{
- 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);
- r = calculateIdWidth(maxwidth);
+ r = calculateDefaultAlignmentIdWidth();
av.setIdWidth(r.width);
}
else
return r;
}
+ public Dimension calculateDefaultAlignmentIdWidth()
+ {
+ 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, false);
+ }
+
/**
* Calculate the width of the alignment labels based on the displayed names
* and any bounds on label width set in preferences.
*/
protected Dimension calculateIdWidth(int maxwidth)
{
+ return calculateIdWidth(maxwidth, true, false);
+ }
+
+ public Dimension calculateIdWidth(int maxwidth,
+ boolean includeAnnotations, boolean visibleOnly)
+ {
Container c = new Container();
FontMetrics fm = c.getFontMetrics(
}
// Also check annotation label widths
- i = 0;
-
- if (al.getAlignmentAnnotation() != null)
+ if (includeAnnotations && al.getAlignmentAnnotation() != null)
{
- fm = c.getFontMetrics(getAlabels().getFont());
-
- while (i < al.getAlignmentAnnotation().length)
+ if (Jalview.isHeadlessMode())
{
- String label = al.getAlignmentAnnotation()[i].label;
- int stringWidth = fm.stringWidth(label);
+ AnnotationLabels aal = getAlabels();
+ int stringWidth = aal.drawLabels(null, false, idWidth, false, false, fm);
idWidth = Math.max(idWidth, stringWidth);
- i++;
+ }
+ else
+ {
+ fm = c.getFontMetrics(getAlabels().getFont());
+
+ for (i = 0; i < al.getAlignmentAnnotation().length; i++)
+ {
+ AlignmentAnnotation aa = al.getAlignmentAnnotation()[i];
+ if (visibleOnly && !aa.visible)
+ {
+ continue;
+ }
+ String label = aa.label;
+ int stringWidth = fm.stringWidth(label);
+ idWidth = Math.max(idWidth, stringWidth);
+ }
}
}
// not be called directly by programs.
// I note that addNotify() is called in several areas of Jalview.
- int annotationHeight = getAnnotationPanel().adjustPanelHeight();
- annotationHeight = getAnnotationPanel()
- .adjustForAlignFrame(adjustPanelHeight, annotationHeight);
+ AnnotationPanel ap = getAnnotationPanel();
+ int annotationHeight = ap.adjustPanelHeight();
+ annotationHeight = ap.adjustForAlignFrame(adjustPanelHeight,
+ annotationHeight);
hscroll.addNotify();
- annotationScroller.setPreferredSize(
- new Dimension(annotationScroller.getWidth(), annotationHeight));
-
Dimension e = idPanel.getSize();
- alabels.setSize(new Dimension(e.width, annotationHeight));
+ int idWidth = e.width;
+ boolean manuallyAdjusted = this.getIdPanel().getIdCanvas()
+ .manuallyAdjusted();
+ annotationScroller.setPreferredSize(new Dimension(
+ manuallyAdjusted ? idWidth : annotationScroller.getWidth(),
+ annotationHeight));
+
+ alabels.setPreferredSize(new Dimension(idWidth, annotationHeight));
annotationSpaceFillerHolder.setPreferredSize(new Dimension(
- annotationSpaceFillerHolder.getWidth(), annotationHeight));
+ manuallyAdjusted ? idWidth
+ : annotationSpaceFillerHolder.getWidth(),
+ annotationHeight));
annotationScroller.validate();
annotationScroller.addNotify();
+ ap.validate();
}
/**
boolean wrap = av.getWrapAlignment();
ViewportRanges ranges = av.getRanges();
ranges.setStartSeq(0);
- scalePanelHolder.setVisible(!wrap);
+ // scalePanelHolder.setVisible(!wrap);
hscroll.setVisible(!wrap);
- idwidthAdjuster.setVisible(!wrap);
+ // Allow idPanel width adjustment in wrap mode
+ idwidthAdjuster.setVisible(true);
if (wrap)
{
}
}
- idSpaceFillerPanel1.setVisible(!wrap);
+ // idSpaceFillerPanel1.setVisible(!wrap);
repaint();
}
public void paintComponent(Graphics g)
{
invalidate(); // needed so that the id width adjuster works correctly
-
Dimension d = getIdPanel().getIdCanvas().getPreferredSize();
- idPanelHolder.setPreferredSize(d);
- hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12));
+ int idWidth = d.width;
+
+ // check wrapped alignment as at least 1 residue width
+ if (av.getWrapAlignment())
+ {
+ SeqCanvas sc = this.getSeqPanel().seqCanvas;
+ if (sc != null && sc.getWidth() < sc.getMinimumWrappedCanvasWidth())
+ {
+ // need to make some adjustments
+ idWidth -= (sc.getMinimumWrappedCanvasWidth() - sc.getWidth());
+ av.setIdWidth(idWidth);
+ av.getAlignPanel().getIdPanel().getIdCanvas()
+ .setManuallyAdjusted(true);
+
+ validateAnnotationDimensions(false);
+ }
+ }
+
+ idPanelHolder.setPreferredSize(new Dimension(idWidth, d.height));
+ hscrollFillerPanel.setPreferredSize(new Dimension(idWidth, 12));
validate(); // needed so that the id width adjuster works correctly
List<SequenceI> selection = av.getSelectionGroup() == null ? null
: av.getSelectionGroup().getSequences(null);
idCanvas.drawIds((Graphics2D) idGraphics, av, startSeq, endSeq - 1,
- selection);
+ selection, false);
idGraphics.setFont(av.getFont());
idGraphics.translate(0, -scaleHeight);
int offset = getAlabels().getScrollOffset();
idGraphics.translate(0, -offset);
idGraphics.translate(0, alignmentDrawnHeight);
- getAlabels().drawComponent(idGraphics, idWidth);
+ getAlabels().drawComponentNotGUI(idGraphics, idWidth);
idGraphics.translate(0, -alignmentDrawnHeight);
/*
* draw sequence ids and annotation labels (if shown)
*/
IdCanvas idCanvas = getIdPanel().getIdCanvas();
- idCanvas.drawIdsWrapped((Graphics2D) g, av, 0, totalHeight);
+ idCanvas.drawIdsWrappedNoGUI((Graphics2D) g, av, 0, totalHeight);
g.translate(idWidth, 0);
}
int w = getIdPanel().getWidth();
+ w = this.calculateIdWidth(-1, true, true).width;
return (w > 0 ? w : calculateIdWidth().width);
}
- void makeAlignmentImage(ImageMaker.TYPE type, File file, String renderer) throws ImageOutputException
+ void makeAlignmentImage(ImageMaker.TYPE type, File file, String renderer)
+ throws ImageOutputException
{
makeAlignmentImage(type, file, renderer,
BitmapImageSizing.nullBitmapImageSizing());
final int borderBottomOffset = 5;
AlignmentDimension aDimension = getAlignmentDimension();
+
// todo use a lambda function in place of callback here?
ImageWriterI writer = new ImageWriterI()
{
}
- public void makePNGImageMap(File imgMapFile, String imageName) throws ImageOutputException
+ public void makePNGImageMap(File imgMapFile, String imageName)
+ throws ImageOutputException
{
// /////ONLY WORKS WITH NON WRAPPED ALIGNMENTS
// ////////////////////////////////////////////
} catch (Exception ex)
{
- throw new ImageOutputException("couldn't write ImageMap due to unexpected error",ex);
+ throw new ImageOutputException(
+ "couldn't write ImageMap due to unexpected error", ex);
}
} // /////////END OF IMAGE MAP
{
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