From cca50cb3aee94f3ed1a5e504d45b8d8b665f8c5b Mon Sep 17 00:00:00 2001 From: Charles Ofoegbu Date: Fri, 5 Dec 2014 12:23:07 +0000 Subject: [PATCH] Change the Html export to utilize svg --- src/jalview/gui/AlignFrame.java | 87 ++++----- src/jalview/gui/AlignViewport.java | 25 ++- src/jalview/gui/AlignmentPanel.java | 284 ++++++++++++++++++------------ src/jalview/gui/AnnotationExporter.java | 2 +- src/jalview/gui/AnnotationLabels.java | 35 ++-- src/jalview/gui/AnnotationPanel.java | 18 +- src/jalview/gui/AppJmol.java | 4 +- src/jalview/gui/ChimeraViewFrame.java | 4 +- src/jalview/gui/FeatureRenderer.java | 8 +- src/jalview/gui/FeatureSettings.java | 2 +- src/jalview/gui/Finder.java | 6 +- src/jalview/gui/FontChooser.java | 2 +- src/jalview/gui/HTMLOptions.java | 143 +++++++++++++++ src/jalview/gui/IdCanvas.java | 32 ++-- src/jalview/gui/IdPanel.java | 26 ++- src/jalview/gui/IdwidthAdjuster.java | 4 +- src/jalview/gui/Jalview2XML.java | 34 ++-- src/jalview/gui/Jalview2XML_V1.java | 4 +- src/jalview/gui/OverviewPanel.java | 2 +- src/jalview/gui/PopupMenu.java | 4 +- src/jalview/gui/RedundancyPanel.java | 4 +- src/jalview/gui/ScalePanel.java | 4 +- src/jalview/gui/SeqCanvas.java | 7 +- src/jalview/gui/SeqPanel.java | 2 +- src/jalview/gui/SliderPanel.java | 2 +- src/jalview/io/HtmlSvgOutput.java | 264 +++++++++++++++++++++++++++ src/jalview/math/AlignmentDimension.java | 35 ++++ 27 files changed, 794 insertions(+), 250 deletions(-) create mode 100644 src/jalview/gui/HTMLOptions.java create mode 100644 src/jalview/io/HtmlSvgOutput.java create mode 100644 src/jalview/math/AlignmentDimension.java diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 2a804ad..3180993 100644 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -57,7 +57,7 @@ import jalview.io.AnnotationFile; import jalview.io.FeaturesFile; import jalview.io.FileLoader; import jalview.io.FormatAdapter; -import jalview.io.HTMLOutput; +import jalview.io.HtmlSvgOutput; import jalview.io.IdentifyFile; import jalview.io.JalviewFileChooser; import jalview.io.JalviewFileView; @@ -379,7 +379,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, .getKeyCode() <= KeyEvent.VK_NUMPAD9)) && Character.isDigit(evt.getKeyChar())) { - alignPanel.seqPanel.numberPressed(evt.getKeyChar()); + alignPanel.getSeqPanel().numberPressed(evt.getKeyChar()); } switch (evt.getKeyCode()) @@ -397,7 +397,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } if (viewport.cursorMode) { - alignPanel.seqPanel.moveCursor(0, 1); + alignPanel.getSeqPanel().moveCursor(0, 1); } break; @@ -408,7 +408,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } if (viewport.cursorMode) { - alignPanel.seqPanel.moveCursor(0, -1); + alignPanel.getSeqPanel().moveCursor(0, -1); } break; @@ -416,11 +416,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, case KeyEvent.VK_LEFT: if (evt.isAltDown() || !viewport.cursorMode) { - slideSequences(false, alignPanel.seqPanel.getKeyboardNo1()); + slideSequences(false, alignPanel.getSeqPanel().getKeyboardNo1()); } else { - alignPanel.seqPanel.moveCursor(-1, 0); + alignPanel.getSeqPanel().moveCursor(-1, 0); } break; @@ -428,18 +428,18 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, case KeyEvent.VK_RIGHT: if (evt.isAltDown() || !viewport.cursorMode) { - slideSequences(true, alignPanel.seqPanel.getKeyboardNo1()); + slideSequences(true, alignPanel.getSeqPanel().getKeyboardNo1()); } else { - alignPanel.seqPanel.moveCursor(1, 0); + alignPanel.getSeqPanel().moveCursor(1, 0); } break; case KeyEvent.VK_SPACE: if (viewport.cursorMode) { - alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown() + alignPanel.getSeqPanel().insertGapAtCursor(evt.isControlDown() || evt.isShiftDown() || evt.isAltDown()); } break; @@ -463,7 +463,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, } else { - alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown() + alignPanel.getSeqPanel().deleteGapAtCursor(evt.isControlDown() || evt.isShiftDown() || evt.isAltDown()); } @@ -472,19 +472,19 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, case KeyEvent.VK_S: if (viewport.cursorMode) { - alignPanel.seqPanel.setCursorRow(); + alignPanel.getSeqPanel().setCursorRow(); } break; case KeyEvent.VK_C: if (viewport.cursorMode && !evt.isControlDown()) { - alignPanel.seqPanel.setCursorColumn(); + alignPanel.getSeqPanel().setCursorColumn(); } break; case KeyEvent.VK_P: if (viewport.cursorMode) { - alignPanel.seqPanel.setCursorPosition(); + alignPanel.getSeqPanel().setCursorPosition(); } break; @@ -492,20 +492,20 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, case KeyEvent.VK_COMMA: if (viewport.cursorMode) { - alignPanel.seqPanel.setCursorRowAndColumn(); + alignPanel.getSeqPanel().setCursorRowAndColumn(); } break; case KeyEvent.VK_Q: if (viewport.cursorMode) { - alignPanel.seqPanel.setSelectionAreaAtCursor(true); + alignPanel.getSeqPanel().setSelectionAreaAtCursor(true); } break; case KeyEvent.VK_M: if (viewport.cursorMode) { - alignPanel.seqPanel.setSelectionAreaAtCursor(false); + alignPanel.getSeqPanel().setSelectionAreaAtCursor(false); } break; @@ -516,10 +516,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { (viewport.cursorMode ? "on" : "off") })); if (viewport.cursorMode) { - alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes; - alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq; + alignPanel.getSeqPanel().seqCanvas.cursorX = viewport.startRes; + alignPanel.getSeqPanel().seqCanvas.cursorY = viewport.startSeq; } - alignPanel.seqPanel.seqCanvas.repaint(); + alignPanel.getSeqPanel().seqCanvas.repaint(); break; case KeyEvent.VK_F1: @@ -738,14 +738,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, abovePIDThreshold.setSelected(av.getAbovePIDThreshold()); conservationMenuItem.setSelected(av.getConservationSelected()); seqLimits.setSelected(av.getShowJVSuffix()); - idRightAlign.setSelected(av.rightAlignIds); + idRightAlign.setSelected(av.isRightAlignIds()); centreColumnLabelsMenuItem.setState(av.centreColumnLabels); renderGapsMenuItem.setSelected(av.renderGaps); wrapMenuItem.setSelected(av.wrapAlignment); scaleAbove.setVisible(av.wrapAlignment); scaleLeft.setVisible(av.wrapAlignment); scaleRight.setVisible(av.wrapAlignment); - annotationPanelMenuItem.setState(av.showAnnotation); + annotationPanelMenuItem.setState(av.isShowAnnotation()); /* * Show/hide annotations only enabled if annotation panel is shown */ @@ -896,7 +896,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public FeatureRenderer getFeatureRenderer() { - return alignPanel.seqPanel.seqCanvas.getFeatureRenderer(); + return alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer(); } @Override @@ -1227,9 +1227,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override protected void htmlMenuItem_actionPerformed(ActionEvent e) { - new HTMLOutput(alignPanel, - alignPanel.seqPanel.seqCanvas.getSequenceRenderer(), - alignPanel.seqPanel.seqCanvas.getFeatureRenderer()); + // new HTMLOutput(alignPanel, + // alignPanel.getSeqPanel().seqCanvas.getSequenceRenderer(), + // alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()); + new HtmlSvgOutput(alignPanel); } public void createImageMap(File file, String image) @@ -1296,7 +1297,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, public void exportAnnotations_actionPerformed(ActionEvent e) { new AnnotationExporter().exportAnnotations(alignPanel, - viewport.showAnnotation ? viewport.getAlignment() + viewport.isShowAnnotation() ? viewport.getAlignment() .getAlignmentAnnotation() : null, viewport .getAlignment().getGroups(), ((Alignment) viewport .getAlignment()).alignmentProperties); @@ -1622,7 +1623,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (viewport.cursorMode) { sg.add(viewport.getAlignment().getSequenceAt( - alignPanel.seqPanel.seqCanvas.cursorY)); + alignPanel.getSeqPanel().seqCanvas.cursorY)); } else if (viewport.getSelectionGroup() != null && viewport.getSelectionGroup().getSize() != viewport @@ -1672,7 +1673,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { if (viewport.cursorMode) { - alignPanel.seqPanel.moveCursor(size, 0); + alignPanel.getSeqPanel().moveCursor(size, 0); } else { @@ -1683,7 +1684,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { if (viewport.cursorMode) { - alignPanel.seqPanel.moveCursor(-size, 0); + alignPanel.getSeqPanel().moveCursor(-size, 0); } else { @@ -2111,9 +2112,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // >>>This is a fix for the moment, until a better solution is // found!!<<< - af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer() + af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer() .transferSettings( - alignPanel.seqPanel.seqCanvas.getFeatureRenderer()); + alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()); // TODO: maintain provenance of an alignment, rather than just make the // title a concatenation of operations. @@ -2171,9 +2172,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, // >>>This is a fix for the moment, until a better solution is // found!!<<< - af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer() + af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer() .transferSettings( - alignPanel.seqPanel.seqCanvas.getFeatureRenderer()); + alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer()); // TODO: maintain provenance of an alignment, rather than just make the // title a concatenation of operations. @@ -2337,14 +2338,14 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { if (viewport.cursorMode) { - alignPanel.seqPanel.keyboardNo1 = null; - alignPanel.seqPanel.keyboardNo2 = null; + alignPanel.getSeqPanel().keyboardNo1 = null; + alignPanel.getSeqPanel().keyboardNo2 = null; } viewport.setSelectionGroup(null); viewport.getColumnSelection().clear(); viewport.setSelectionGroup(null); - alignPanel.seqPanel.seqCanvas.highlightSearchResults(null); - alignPanel.idPanel.idCanvas.searchResults = null; + alignPanel.getSeqPanel().seqCanvas.highlightSearchResults(null); + alignPanel.getIdPanel().getIdCanvas().searchResults = null; alignPanel.paintAlignment(true); PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId()); viewport.sendSelection(); @@ -2745,7 +2746,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, { viewport.setShowJVSuffix(seqLimits.isSelected()); - alignPanel.idPanel.idCanvas.setPreferredSize(alignPanel + alignPanel.getIdPanel().getIdCanvas().setPreferredSize(alignPanel .calculateIdWidth()); alignPanel.paintAlignment(true); } @@ -2753,7 +2754,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, @Override public void idRightAlign_actionPerformed(ActionEvent e) { - viewport.rightAlignIds = idRightAlign.isSelected(); + viewport.setRightAlignIds(idRightAlign.isSelected()); alignPanel.paintAlignment(true); } @@ -2775,7 +2776,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener, if (viewport.followHighlight = this.followHighlightMenuItem.getState()) { alignPanel.scrollToPosition( - alignPanel.seqPanel.seqCanvas.searchResults, false); + alignPanel.getSeqPanel().seqCanvas.searchResults, false); } } @@ -4882,7 +4883,7 @@ this, try { featuresFile = new FeaturesFile(file, type).parse(viewport - .getAlignment().getDataset(), alignPanel.seqPanel.seqCanvas + .getAlignment().getDataset(), alignPanel.getSeqPanel().seqCanvas .getFeatureRenderer().featureColours, false, jalview.bin.Cache.getDefault("RELAXEDSEQIDMATCHING", false)); } catch (Exception ex) @@ -4894,10 +4895,10 @@ this, { viewport.showSequenceFeatures = true; showSeqFeatures.setSelected(true); - if (alignPanel.seqPanel.seqCanvas.fr != null) + if (alignPanel.getSeqPanel().seqCanvas.fr != null) { // update the min/max ranges where necessary - alignPanel.seqPanel.seqCanvas.fr.findAllFeatures(true); + alignPanel.getSeqPanel().seqCanvas.fr.findAllFeatures(true); } if (featureSettings != null) { diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index d24f6c4..40f95e2 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -97,7 +97,7 @@ public class AlignViewport extends AlignmentViewport implements boolean showSequenceFeatures = false; - boolean showAnnotation = true; + private boolean showAnnotation = true; SequenceAnnotationOrder sortAnnotationsBy = null; @@ -149,7 +149,7 @@ public class AlignViewport extends AlignmentViewport implements Color textColour2 = Color.white; - boolean rightAlignIds = false; + private boolean rightAlignIds = false; /** * Creates a new AlignViewport object. @@ -286,9 +286,9 @@ public class AlignViewport extends AlignmentViewport implements antiAlias = Cache.getDefault("ANTI_ALIAS", false); showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true); - showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true); + setShowAnnotation(Cache.getDefault("SHOW_ANNOTATIONS", true)); - rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false); + setRightAlignIds(Cache.getDefault("RIGHT_ALIGN_IDS", false)); centreColumnLabels = Cache.getDefault("CENTRE_COLUMN_LABELS", false); autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true); @@ -839,7 +839,7 @@ public class AlignViewport extends AlignmentViewport implements */ public boolean getShowAnnotation() { - return showAnnotation; + return isShowAnnotation(); } /** @@ -1293,4 +1293,19 @@ public class AlignViewport extends AlignmentViewport implements { this.showAutocalculatedAbove = showAutocalculatedAbove; } + + public boolean isShowAnnotation() + { + return showAnnotation; + } + + public boolean isRightAlignIds() + { + return rightAlignIds; + } + + public void setRightAlignIds(boolean rightAlignIds) + { + this.rightAlignIds = rightAlignIds; + } } diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index 5527f1e..e4a4c90 100644 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -29,6 +29,7 @@ import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.jbgui.GAlignmentPanel; +import jalview.math.AlignmentDimension; import jalview.schemes.ResidueProperties; import jalview.structure.StructureSelectionManager; import jalview.util.MessageManager; @@ -66,20 +67,21 @@ public class AlignmentPanel extends GAlignmentPanel implements OverviewPanel overviewPanel; - SeqPanel seqPanel; + private SeqPanel seqPanel; - IdPanel idPanel; + private IdPanel idPanel; + private boolean headless; IdwidthAdjuster idwidthAdjuster; /** DOCUMENT ME!! */ public AlignFrame alignFrame; - ScalePanel scalePanel; + private ScalePanel scalePanel; - AnnotationPanel annotationPanel; + private AnnotationPanel annotationPanel; - AnnotationLabels alabels; + private AnnotationLabels alabels; // this value is set false when selection area being dragged boolean fastPaint = true; @@ -100,23 +102,23 @@ public class AlignmentPanel extends GAlignmentPanel implements { alignFrame = af; this.av = av; - seqPanel = new SeqPanel(av, this); - idPanel = new IdPanel(av, this); + setSeqPanel(new SeqPanel(av, this)); + setIdPanel(new IdPanel(av, this)); - scalePanel = new ScalePanel(av, this); + setScalePanel(new ScalePanel(av, this)); - idPanelHolder.add(idPanel, BorderLayout.CENTER); + idPanelHolder.add(getIdPanel(), BorderLayout.CENTER); idwidthAdjuster = new IdwidthAdjuster(this); idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER); - annotationPanel = new AnnotationPanel(this); - alabels = new AnnotationLabels(this); + setAnnotationPanel(new AnnotationPanel(this)); + setAlabels(new AnnotationLabels(this)); - annotationScroller.setViewportView(annotationPanel); - annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER); + annotationScroller.setViewportView(getAnnotationPanel()); + annotationSpaceFillerHolder.add(getAlabels(), BorderLayout.CENTER); - scalePanelHolder.add(scalePanel, BorderLayout.CENTER); - seqPanelHolder.add(seqPanel, BorderLayout.CENTER); + scalePanelHolder.add(getScalePanel(), BorderLayout.CENTER); + seqPanelHolder.add(getSeqPanel(), BorderLayout.CENTER); setScrollValues(0, 0); @@ -166,13 +168,13 @@ public class AlignmentPanel extends GAlignmentPanel implements idSpaceFillerPanel1.setPreferredSize(new Dimension(10, av.charHeight + fm.getDescent())); - idPanel.idCanvas.gg = null; - seqPanel.seqCanvas.img = null; - annotationPanel.adjustPanelHeight(); + getIdPanel().getIdCanvas().gg = null; + getSeqPanel().seqCanvas.img = null; + getAnnotationPanel().adjustPanelHeight(); Dimension d = calculateIdWidth(); d.setSize(d.width + 4, d.height); - idPanel.idCanvas.setPreferredSize(d); + getIdPanel().getIdCanvas().setPreferredSize(d); hscrollFillerPanel.setPreferredSize(d); if (overviewPanel != null) @@ -240,7 +242,7 @@ public class AlignmentPanel extends GAlignmentPanel implements if (al.getAlignmentAnnotation() != null) { - fm = c.getFontMetrics(alabels.getFont()); + fm = c.getFontMetrics(getAlabels().getFont()); while (i < al.getAlignmentAnnotation().length) { @@ -266,7 +268,7 @@ public class AlignmentPanel extends GAlignmentPanel implements public void highlightSearchResults(SearchResults results) { scrollToPosition(results); - seqPanel.seqCanvas.highlightSearchResults(results); + getSeqPanel().seqCanvas.highlightSearchResults(results); } /** @@ -371,8 +373,8 @@ public class AlignmentPanel extends GAlignmentPanel implements void scrollToWrappedVisible(int res) { - int cwidth = seqPanel.seqCanvas - .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth()); + int cwidth = getSeqPanel().seqCanvas + .getWrappedCanvasWidth(getSeqPanel().seqCanvas.getWidth()); if (res < av.getStartRes() || res >= (av.getStartRes() + cwidth)) { vscroll.setValue((res / cwidth)); @@ -441,7 +443,7 @@ public class AlignmentPanel extends GAlignmentPanel implements */ protected void validateAnnotationDimensions(boolean adjustPanelHeight) { - int height = annotationPanel.adjustPanelHeight(); + int height = getAnnotationPanel().adjustPanelHeight(); int theight = av.getCharHeight() * (av.getAlignment().getHeight() + (!av.hasHiddenRows() ? 0 @@ -503,7 +505,7 @@ public class AlignmentPanel extends GAlignmentPanel implements annotationScroller.setVisible(false); annotationSpaceFillerHolder.setVisible(false); } - else if (av.showAnnotation) + else if (av.isShowAnnotation()) { annotationScroller.setVisible(true); annotationSpaceFillerHolder.setVisible(true); @@ -603,10 +605,10 @@ public class AlignmentPanel extends GAlignmentPanel implements width = av.getColumnSelection().findColumnPosition(width); } - av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.charWidth)) - 1); + av.setEndRes((x + (getSeqPanel().seqCanvas.getWidth() / av.charWidth)) - 1); - hextent = seqPanel.seqCanvas.getWidth() / av.charWidth; - vextent = seqPanel.seqCanvas.getHeight() / av.charHeight; + hextent = getSeqPanel().seqCanvas.getWidth() / av.charWidth; + vextent = getSeqPanel().seqCanvas.getHeight() / av.charHeight; if (hextent > width) { @@ -658,7 +660,7 @@ public class AlignmentPanel extends GAlignmentPanel implements { int x = hscroll.getValue(); av.setStartRes(x); - av.setEndRes((x + (seqPanel.seqCanvas.getWidth() / av.getCharWidth())) - 1); + av.setEndRes((x + (getSeqPanel().seqCanvas.getWidth() / av.getCharWidth())) - 1); } if (evt.getSource() == vscroll) @@ -669,8 +671,8 @@ public class AlignmentPanel extends GAlignmentPanel implements { if (offy > -1) { - int rowSize = seqPanel.seqCanvas - .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth()); + int rowSize = getSeqPanel().seqCanvas + .getWrappedCanvasWidth(getSeqPanel().seqCanvas.getWidth()); av.setStartRes(offy * rowSize); av.setEndRes((offy + 1) * rowSize); } @@ -692,7 +694,7 @@ public class AlignmentPanel extends GAlignmentPanel implements { av.setStartSeq(offy); av.setEndSeq(offy - + (seqPanel.seqCanvas.getHeight() / av.getCharHeight())); + + (getSeqPanel().seqCanvas.getHeight() / av.getCharHeight())); } } @@ -723,13 +725,13 @@ public class AlignmentPanel extends GAlignmentPanel implements if (scrollX != 0 || scrollY != 0) { - idPanel.idCanvas.fastPaint(scrollY); - seqPanel.seqCanvas.fastPaint(scrollX, scrollY); - scalePanel.repaint(); + getIdPanel().getIdCanvas().fastPaint(scrollY); + getSeqPanel().seqCanvas.fastPaint(scrollX, scrollY); + getScalePanel().repaint(); if (av.getShowAnnotation() && scrollX != 0) { - annotationPanel.fastPaint(scrollX); + getAnnotationPanel().fastPaint(scrollX); } } } @@ -769,7 +771,7 @@ public class AlignmentPanel extends GAlignmentPanel implements { invalidate(); - Dimension d = idPanel.idCanvas.getPreferredSize(); + Dimension d = getIdPanel().getIdCanvas().getPreferredSize(); idPanelHolder.setPreferredSize(d); hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12)); validate(); @@ -783,13 +785,13 @@ public class AlignmentPanel extends GAlignmentPanel implements maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; } - int canvasWidth = seqPanel.seqCanvas - .getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth()); + int canvasWidth = getSeqPanel().seqCanvas + .getWrappedCanvasWidth(getSeqPanel().seqCanvas.getWidth()); if (canvasWidth > 0) { int max = maxwidth - / seqPanel.seqCanvas - .getWrappedCanvasWidth(seqPanel.seqCanvas + / getSeqPanel().seqCanvas + .getWrappedCanvasWidth(getSeqPanel().seqCanvas .getWidth()) + 1; vscroll.setMaximum(max); vscroll.setUnitIncrement(1); @@ -905,9 +907,9 @@ public class AlignmentPanel extends GAlignmentPanel implements int pagesHigh = ((av.getAlignment().getHeight() / totalSeq) + 1) * pheight; - if (av.showAnnotation) + if (av.isShowAnnotation()) { - pagesHigh += annotationPanel.adjustPanelHeight() + 3; + pagesHigh += getAnnotationPanel().adjustPanelHeight() + 3; } pagesHigh /= pheight; @@ -919,7 +921,7 @@ public class AlignmentPanel extends GAlignmentPanel implements // draw Scale pg.translate(idWidth, 0); - scalePanel.drawScale(pg, startRes, endRes, pwidth - idWidth, + getScalePanel().drawScale(pg, startRes, endRes, pwidth - idWidth, scaleHeight); pg.translate(-idWidth, scaleHeight); @@ -928,7 +930,7 @@ public class AlignmentPanel extends GAlignmentPanel implements Color currentColor = null; Color currentTextColor = null; - pg.setFont(idPanel.idCanvas.idfont); + pg.setFont(getIdPanel().getIdCanvas().getIdfont()); SequenceI seq; for (int i = startSeq; i < endSeq; i++) @@ -953,7 +955,7 @@ public class AlignmentPanel extends GAlignmentPanel implements pg.setColor(currentTextColor); int xPos = 0; - if (av.rightAlignIds) + if (av.isRightAlignIds()) { fm = pg.getFontMetrics(); xPos = idWidth @@ -972,17 +974,17 @@ public class AlignmentPanel extends GAlignmentPanel implements // draw main sequence panel pg.translate(idWidth, 0); - seqPanel.seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0); + getSeqPanel().seqCanvas.drawPanel(pg, startRes, endRes, startSeq, endSeq, 0); - if (av.showAnnotation && (endSeq == av.getAlignment().getHeight())) + if (av.isShowAnnotation() && (endSeq == av.getAlignment().getHeight())) { // draw annotation - need to offset for current scroll position - int offset = -alabels.scrollOffset; + int offset = -getAlabels().getScrollOffset(); pg.translate(0, offset); pg.translate(-idWidth - 3, (endSeq - startSeq) * av.charHeight + 3); - alabels.drawComponent(pg, idWidth); + getAlabels().drawComponent(pg, idWidth); pg.translate(idWidth + 3, 0); - annotationPanel.renderer.drawComponent(annotationPanel, av, + getAnnotationPanel().renderer.drawComponent(getAnnotationPanel(), av, pg, -1, startRes, endRes + 1); pg.translate(0, -offset); } @@ -1013,9 +1015,9 @@ public class AlignmentPanel extends GAlignmentPanel implements int annotationHeight = 0; AnnotationLabels labels = null; - if (av.showAnnotation) + if (av.isShowAnnotation()) { - annotationHeight = annotationPanel.adjustPanelHeight(); + annotationHeight = getAnnotationPanel().adjustPanelHeight(); labels = new AnnotationLabels(av); } @@ -1036,7 +1038,7 @@ public class AlignmentPanel extends GAlignmentPanel implements maxwidth = av.getColumnSelection().findColumnPosition(maxwidth) - 1; } - int resWidth = seqPanel.seqCanvas.getWrappedCanvasWidth(pwidth + int resWidth = getSeqPanel().seqCanvas.getWrappedCanvasWidth(pwidth - idWidth); int totalHeight = cHeight * (maxwidth / resWidth + 1); @@ -1059,11 +1061,11 @@ public class AlignmentPanel extends GAlignmentPanel implements { for (int i = 0; i < av.getAlignment().getHeight(); i++) { - pg.setFont(idPanel.idCanvas.idfont); + pg.setFont(getIdPanel().getIdCanvas().getIdfont()); SequenceI s = av.getAlignment().getSequenceAt(i); String string = s.getDisplayId(av.getShowJVSuffix()); int xPos = 0; - if (av.rightAlignIds) + if (av.isRightAlignIds()) { FontMetrics fm = pg.getFontMetrics(); xPos = idWidth - fm.stringWidth(string) - 4; @@ -1088,7 +1090,7 @@ public class AlignmentPanel extends GAlignmentPanel implements pg.translate(idWidth, 0); - seqPanel.seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight, + getSeqPanel().seqCanvas.drawWrappedPanel(pg, pwidth - idWidth, totalHeight, 0); if ((pi * pheight) < totalHeight) @@ -1108,7 +1110,7 @@ public class AlignmentPanel extends GAlignmentPanel implements * * @return */ - int getVisibleIdWidth() + public int getVisibleIdWidth() { return getVisibleIdWidth(true); } @@ -1122,7 +1124,7 @@ public class AlignmentPanel extends GAlignmentPanel implements * be returned * @return */ - int getVisibleIdWidth(boolean onscreen) + public int getVisibleIdWidth(boolean onscreen) { // see if rendering offscreen - check preferences and calc width accordingly if (!onscreen && Cache.getDefault("FIGURE_AUTOIDWIDTH", false)) @@ -1133,7 +1135,7 @@ public class AlignmentPanel extends GAlignmentPanel implements if (onscreen || (idwidth = Cache.getIntegerProperty("FIGURE_FIXEDIDWIDTH")) == null) { - return (idPanel.getWidth() > 0 ? idPanel.getWidth() + return (getIdPanel().getWidth() > 0 ? getIdPanel().getWidth() : calculateIdWidth().width + 4); } return idwidth.intValue() + 4; @@ -1142,7 +1144,7 @@ public class AlignmentPanel extends GAlignmentPanel implements void makeAlignmentImage(jalview.util.ImageMaker.TYPE type, File file) { long progress = System.currentTimeMillis(); - boolean headless = (System.getProperty("java.awt.headless") != null && System + headless = (System.getProperty("java.awt.headless") != null && System .getProperty("java.awt.headless").equals("true")); if (alignFrame != null && !headless) { @@ -1153,44 +1155,9 @@ public class AlignmentPanel extends GAlignmentPanel implements } try { - int maxwidth = av.getAlignment().getWidth(); - if (av.hasHiddenColumns()) - { - maxwidth = av.getColumnSelection().findColumnPosition(maxwidth); - } - - int height = ((av.getAlignment().getHeight() + 1) * av.charHeight) - + scalePanel.getHeight(); - int width = getVisibleIdWidth(false) + (maxwidth * av.charWidth); - - if (av.getWrapAlignment()) - { - height = getWrappedHeight(); - if (headless) - { - // need to obtain default alignment width and then add in any - // additional allowance for id margin - // this duplicates the calculation in getWrappedHeight but adjusts for - // offscreen idWith - width = alignFrame.getWidth() - vscroll.getPreferredSize().width - - alignFrame.getInsets().left - - alignFrame.getInsets().right - getVisibleIdWidth() - + getVisibleIdWidth(false); - } - else - { - width = seqPanel.getWidth() + getVisibleIdWidth(false); - } - - } - else if (av.getShowAnnotation()) - { - height += annotationPanel.adjustPanelHeight() + 3; - } - + AlignmentDimension aDimension = getAlignmentDimension(); try { - jalview.util.ImageMaker im; final String imageAction, imageTitle; if (type == jalview.util.ImageMaker.TYPE.PNG) @@ -1209,13 +1176,15 @@ public class AlignmentPanel extends GAlignmentPanel implements imageTitle = alignFrame.getTitle(); } - im = new jalview.util.ImageMaker(this, type, imageAction, width, - height, file, imageTitle); + im = new jalview.util.ImageMaker(this, type, imageAction, + aDimension.getWidth(), aDimension.getHeight(), file, + imageTitle); if (av.getWrapAlignment()) { if (im.getGraphics() != null) { - printWrappedAlignment(im.getGraphics(), width, height, 0); + printWrappedAlignment(im.getGraphics(), aDimension.getWidth(), + aDimension.getHeight(), 0); im.writeImage(); } } @@ -1223,7 +1192,8 @@ public class AlignmentPanel extends GAlignmentPanel implements { if (im.getGraphics() != null) { - printUnwrapped(im.getGraphics(), width, height, 0); + printUnwrapped(im.getGraphics(), aDimension.getWidth(), + aDimension.getHeight(), 0); im.writeImage(); } } @@ -1247,6 +1217,46 @@ public class AlignmentPanel extends GAlignmentPanel implements } } + public AlignmentDimension getAlignmentDimension() + { + int maxwidth = av.getAlignment().getWidth(); + if (av.hasHiddenColumns()) + { + maxwidth = av.getColumnSelection().findColumnPosition(maxwidth); + } + + int height = ((av.getAlignment().getHeight() + 1) * av.charHeight) + + getScalePanel().getHeight(); + int width = getVisibleIdWidth(false) + (maxwidth * av.charWidth); + + if (av.getWrapAlignment()) + { + height = getWrappedHeight(); + if (headless) + { + // need to obtain default alignment width and then add in any + // additional allowance for id margin + // this duplicates the calculation in getWrappedHeight but adjusts for + // offscreen idWith + width = alignFrame.getWidth() - vscroll.getPreferredSize().width + - alignFrame.getInsets().left + - alignFrame.getInsets().right - getVisibleIdWidth() + + getVisibleIdWidth(false); + } + else + { + width = getSeqPanel().getWidth() + getVisibleIdWidth(false); + } + + } + else if (av.getShowAnnotation()) + { + height += getAnnotationPanel().adjustPanelHeight() + 3; + } + return new AlignmentDimension(width, height); + + } + /** * DOCUMENT ME! */ @@ -1410,7 +1420,7 @@ public class AlignmentPanel extends GAlignmentPanel implements int getWrappedHeight() { - int seqPanelWidth = seqPanel.seqCanvas.getWidth(); + int seqPanelWidth = getSeqPanel().seqCanvas.getWidth(); if (System.getProperty("java.awt.headless") != null && System.getProperty("java.awt.headless").equals("true")) @@ -1420,7 +1430,7 @@ public class AlignmentPanel extends GAlignmentPanel implements - alignFrame.getInsets().left - alignFrame.getInsets().right; } - int chunkWidth = seqPanel.seqCanvas + int chunkWidth = getSeqPanel().seqCanvas .getWrappedCanvasWidth(seqPanelWidth); int hgap = av.charHeight; @@ -1430,9 +1440,9 @@ public class AlignmentPanel extends GAlignmentPanel implements } int annotationHeight = 0; - if (av.showAnnotation) + if (av.isShowAnnotation()) { - annotationHeight = annotationPanel.adjustPanelHeight(); + annotationHeight = getAnnotationPanel().adjustPanelHeight(); } int cHeight = av.getAlignment().getHeight() * av.charHeight + hgap @@ -1455,15 +1465,15 @@ public class AlignmentPanel extends GAlignmentPanel implements */ public void closePanel() { - PaintRefresher.RemoveComponent(seqPanel.seqCanvas); - PaintRefresher.RemoveComponent(idPanel.idCanvas); + PaintRefresher.RemoveComponent(getSeqPanel().seqCanvas); + PaintRefresher.RemoveComponent(getIdPanel().getIdCanvas()); PaintRefresher.RemoveComponent(this); if (av != null) { jalview.structure.StructureSelectionManager ssm = av .getStructureSelectionManager(); - ssm.removeStructureViewerListener(seqPanel, null); - ssm.removeSelectionListener(seqPanel); + ssm.removeStructureViewerListener(getSeqPanel(), null); + ssm.removeSelectionListener(getSeqPanel()); av.setAlignment(null); av = null; } @@ -1554,14 +1564,64 @@ public class AlignmentPanel extends GAlignmentPanel implements public void updateFeatureRenderer(FeatureRenderer fr) { - fr.transferSettings(seqPanel.seqCanvas.getFeatureRenderer()); + fr.transferSettings(getSeqPanel().seqCanvas.getFeatureRenderer()); } public void updateFeatureRendererFrom(FeatureRenderer fr) { - if (seqPanel.seqCanvas.getFeatureRenderer() != null) + if (getSeqPanel().seqCanvas.getFeatureRenderer() != null) { - seqPanel.seqCanvas.getFeatureRenderer().transferSettings(fr); + getSeqPanel().seqCanvas.getFeatureRenderer().transferSettings(fr); } } + + public ScalePanel getScalePanel() + { + return scalePanel; + } + + public void setScalePanel(ScalePanel scalePanel) + { + this.scalePanel = scalePanel; + } + + public SeqPanel getSeqPanel() + { + return seqPanel; + } + + public void setSeqPanel(SeqPanel seqPanel) + { + this.seqPanel = seqPanel; + } + + public AnnotationPanel getAnnotationPanel() + { + return annotationPanel; + } + + public void setAnnotationPanel(AnnotationPanel annotationPanel) + { + this.annotationPanel = annotationPanel; + } + + public AnnotationLabels getAlabels() + { + return alabels; + } + + public void setAlabels(AnnotationLabels alabels) + { + this.alabels = alabels; + } + + public IdPanel getIdPanel() + { + return idPanel; + } + + public void setIdPanel(IdPanel idPanel) + { + this.idPanel = idPanel; + } } diff --git a/src/jalview/gui/AnnotationExporter.java b/src/jalview/gui/AnnotationExporter.java index 315c3e2..c68b2b1 100644 --- a/src/jalview/gui/AnnotationExporter.java +++ b/src/jalview/gui/AnnotationExporter.java @@ -215,7 +215,7 @@ public class AnnotationExporter extends JPanel return fcols; } Enumeration en = ap.av.featuresDisplayed.keys(); - FeatureRenderer fr = ap.seqPanel.seqCanvas.getFeatureRenderer(); // consider + FeatureRenderer fr = ap.getSeqPanel().seqCanvas.getFeatureRenderer(); // consider // higher // level // method ? diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index 6e8417f..501df8a 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -99,7 +99,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, int selectedRow; - int scrollOffset = 0; + private int scrollOffset = 0; Font font = new Font("Arial", Font.PLAIN, 11); @@ -143,7 +143,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, addMouseListener(this); addMouseMotionListener(this); - addMouseWheelListener(ap.annotationPanel); + addMouseWheelListener(ap.getAnnotationPanel()); } public AnnotationLabels(AlignViewport av) @@ -325,7 +325,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, */ public void mousePressed(MouseEvent evt) { - getSelectedRow(evt.getY() - scrollOffset); + getSelectedRow(evt.getY() - getScrollOffset()); oldY = evt.getY(); } @@ -338,7 +338,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, public void mouseReleased(MouseEvent evt) { int start = selectedRow; - getSelectedRow(evt.getY() - scrollOffset); + getSelectedRow(evt.getY() - getScrollOffset()); int end = selectedRow; if (start != end) @@ -360,7 +360,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, resizePanel = false; dragEvent = null; repaint(); - ap.annotationPanel.repaint(); + ap.getAnnotationPanel().repaint(); } /** @@ -439,7 +439,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, { resizePanel = evt.getY() < 10; - getSelectedRow(evt.getY() - scrollOffset); + getSelectedRow(evt.getY() - getScrollOffset()); if (selectedRow > -1 && ap.av.getAlignment().getAlignmentAnnotation().length > selectedRow) @@ -533,7 +533,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, { // todo: make the ap scroll to the selection - not necessary, first // click highlights/scrolls, second selects - ap.seqPanel.ap.idPanel.highlightSearchResults(null); + ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null); ap.av.setSelectionGroup(// new SequenceGroup( aa[selectedRow].groupRef); // ); ap.paintAlignment(false); @@ -542,7 +542,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, } else { - ap.seqPanel.ap.idPanel + ap.getSeqPanel().ap.getIdPanel() .highlightSearchResults(aa[selectedRow].groupRef .getSequences(null)); } @@ -552,13 +552,13 @@ public class AnnotationLabels extends JPanel implements MouseListener, { if (evt.getClickCount() == 1) { - ap.seqPanel.ap.idPanel.highlightSearchResults(Arrays + ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(Arrays .asList(new SequenceI[] { aa[selectedRow].sequenceRef })); } else if (evt.getClickCount() >= 2) { - ap.seqPanel.ap.idPanel.highlightSearchResults(null); + ap.getSeqPanel().ap.getIdPanel().highlightSearchResults(null); SequenceGroup sg = ap.av.getSelectionGroup(); if (sg!=null) { @@ -696,7 +696,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, { // TODO: pass on reference to ap so the view can be updated. aaa.groupRef.setIgnoreGapsConsensus(cbmi.getState()); - ap.annotationPanel.paint(ap.annotationPanel.getGraphics()); + ap.getAnnotationPanel().paint(ap.getAnnotationPanel().getGraphics()); } else { @@ -962,7 +962,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, g.setColor(Color.white); g.fillRect(0, 0, getWidth(), getHeight()); - g.translate(0, scrollOffset); + g.translate(0, getScrollOffset()); g.setColor(Color.black); AlignmentAnnotation[] aa = av.getAlignment().getAlignmentAnnotation(); @@ -976,7 +976,7 @@ public class AnnotationLabels extends JPanel implements MouseListener, int ofontH = fontHeight; int sOffset = 0; int visHeight = 0; - int[] visr = (ap != null && ap.annotationPanel != null) ? ap.annotationPanel + int[] visr = (ap != null && ap.getAnnotationPanel() != null) ? ap.getAnnotationPanel() .getVisibleVRange() : null; if (clip && visr != null) { @@ -1116,13 +1116,13 @@ public class AnnotationLabels extends JPanel implements MouseListener, if (resizePanel) { - g.drawImage(image, 2, 0 - scrollOffset, this); + g.drawImage(image, 2, 0 - getScrollOffset(), this); } else if (dragEvent != null && aa != null) { g.setColor(Color.lightGray); g.drawString(aa[selectedRow].label, dragEvent.getX(), - dragEvent.getY() - scrollOffset); + dragEvent.getY() - getScrollOffset()); } if (!av.wrapAlignment && ((aa == null) || (aa.length < 1))) @@ -1132,4 +1132,9 @@ public class AnnotationLabels extends JPanel implements MouseListener, 18); } } + + public int getScrollOffset() + { + return scrollOffset; + } } diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index 9f56206..3a97f96 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -241,7 +241,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, public void adjustmentValueChanged(AdjustmentEvent evt) { // update annotation label display - ap.alabels.setScrollOffset(-evt.getValue()); + ap.getAlabels().setScrollOffset(-evt.getValue()); } /** @@ -566,7 +566,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, return; } - ap.scalePanel.mousePressed(evt); + ap.getScalePanel().mousePressed(evt); } @@ -582,7 +582,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, graphStretch = -1; graphStretchY = -1; mouseDragging = false; - ap.scalePanel.mouseReleased(evt); + ap.getScalePanel().mouseReleased(evt); } /** @@ -594,7 +594,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, @Override public void mouseEntered(MouseEvent evt) { - ap.scalePanel.mouseEntered(evt); + ap.getScalePanel().mouseEntered(evt); } /** @@ -606,7 +606,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, @Override public void mouseExited(MouseEvent evt) { - ap.scalePanel.mouseExited(evt); + ap.getScalePanel().mouseExited(evt); } /** @@ -632,7 +632,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, } else { - ap.scalePanel.mouseDragged(evt); + ap.getScalePanel().mouseDragged(evt); } } @@ -809,7 +809,7 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, { try { - image = new BufferedImage(imgWidth, ap.annotationPanel.getHeight(), + image = new BufferedImage(imgWidth, ap.getAnnotationPanel().getHeight(), BufferedImage.TYPE_INT_RGB); } catch (OutOfMemoryError oom) { @@ -1013,9 +1013,9 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI, @Override public int[] getVisibleVRange() { - if (ap != null && ap.alabels != null) + if (ap != null && ap.getAlabels() != null) { - int sOffset = -ap.alabels.scrollOffset; + int sOffset = -ap.getAlabels().getScrollOffset(); int visHeight = sOffset + ap.annotationSpaceFillerHolder.getHeight(); bounds[0] = sOffset; bounds[1] = visHeight; diff --git a/src/jalview/gui/AppJmol.java b/src/jalview/gui/AppJmol.java index fcb31eb..4dfd18a 100644 --- a/src/jalview/gui/AppJmol.java +++ b/src/jalview/gui/AppJmol.java @@ -315,9 +315,9 @@ public class AppJmol extends GStructureViewer implements Runnable, // TODO : Fix multiple seq to one chain issue here. ap.getStructureSelectionManager().setMapping(seq, chains, alreadyMapped, AppletFormatAdapter.FILE); - if (ap.seqPanel.seqCanvas.fr != null) + if (ap.getSeqPanel().seqCanvas.fr != null) { - ap.seqPanel.seqCanvas.fr.featuresAdded(); + ap.getSeqPanel().seqCanvas.fr.featuresAdded(); ap.paintAlignment(true); } diff --git a/src/jalview/gui/ChimeraViewFrame.java b/src/jalview/gui/ChimeraViewFrame.java index 02865e1..2f84d28 100644 --- a/src/jalview/gui/ChimeraViewFrame.java +++ b/src/jalview/gui/ChimeraViewFrame.java @@ -244,9 +244,9 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable, // TODO : Fix multiple seq to one chain issue here. ap.getStructureSelectionManager().setMapping(seq, chains, alreadyMapped, AppletFormatAdapter.FILE); - if (ap.seqPanel.seqCanvas.fr != null) + if (ap.getSeqPanel().seqCanvas.fr != null) { - ap.seqPanel.seqCanvas.fr.featuresAdded(); + ap.getSeqPanel().seqCanvas.fr.featuresAdded(); ap.paintAlignment(true); } diff --git a/src/jalview/gui/FeatureRenderer.java b/src/jalview/gui/FeatureRenderer.java index d2d9c9c..cbdf2ef 100644 --- a/src/jalview/gui/FeatureRenderer.java +++ b/src/jalview/gui/FeatureRenderer.java @@ -84,10 +84,10 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer { this.ap = ap; this.av = ap.av; - if (ap != null && ap.seqPanel != null && ap.seqPanel.seqCanvas != null - && ap.seqPanel.seqCanvas.fr != null) + if (ap != null && ap.getSeqPanel() != null && ap.getSeqPanel().seqCanvas != null + && ap.getSeqPanel().seqCanvas.fr != null) { - transferSettings(ap.seqPanel.seqCanvas.fr); + transferSettings(ap.getSeqPanel().seqCanvas.fr); } } @@ -1095,7 +1095,7 @@ public class FeatureRenderer implements jalview.api.FeatureRenderer highlight.addResult(sequences[0], features[index].getBegin(), features[index].getEnd()); - ap.seqPanel.seqCanvas.highlightSearchResults(highlight); + ap.getSeqPanel().seqCanvas.highlightSearchResults(highlight); } Object col = getFeatureStyle(name.getText()); diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 2210148..9748f42 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -527,7 +527,7 @@ public class FeatureSettings extends JPanel { fr.featureGroups.put(check.getText(), new Boolean(check.isSelected())); - af.alignPanel.seqPanel.seqCanvas.repaint(); + af.alignPanel.getSeqPanel().seqCanvas.repaint(); if (af.alignPanel.overviewPanel != null) { af.alignPanel.overviewPanel.updateOverviewImage(); diff --git a/src/jalview/gui/Finder.java b/src/jalview/gui/Finder.java index 8eddc06..acdaf92 100755 --- a/src/jalview/gui/Finder.java +++ b/src/jalview/gui/Finder.java @@ -182,7 +182,7 @@ public class Finder extends GFinder searchResults.getResultEnd(i), "Search Results"); } - if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs, + if (ap.getSeqPanel().seqCanvas.getFeatureRenderer().amendFeatures(seqs, features, true, ap)) { ap.alignFrame.showSeqFeatures.setSelected(true); @@ -229,11 +229,11 @@ public class Finder extends GFinder if ((idMatch.size() > 0)) { haveResults = true; - ap.idPanel.highlightSearchResults(idMatch); + ap.getIdPanel().highlightSearchResults(idMatch); } else { - ap.idPanel.highlightSearchResults(null); + ap.getIdPanel().highlightSearchResults(null); } if (searchResults.getSize() > 0) diff --git a/src/jalview/gui/FontChooser.java b/src/jalview/gui/FontChooser.java index b6116d9..36e4c52 100755 --- a/src/jalview/gui/FontChooser.java +++ b/src/jalview/gui/FontChooser.java @@ -129,7 +129,7 @@ public class FontChooser extends GFontChooser public void smoothFont_actionPerformed(ActionEvent e) { ap.av.antiAlias = smoothFont.isSelected(); - ap.annotationPanel.image = null; + ap.getAnnotationPanel().image = null; ap.paintAlignment(true); } diff --git a/src/jalview/gui/HTMLOptions.java b/src/jalview/gui/HTMLOptions.java new file mode 100644 index 0000000..0ef4710 --- /dev/null +++ b/src/jalview/gui/HTMLOptions.java @@ -0,0 +1,143 @@ +package jalview.gui; + +import jalview.util.MessageManager; + +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.BorderFactory; +import javax.swing.ButtonGroup; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JRadioButton; + +public class HTMLOptions extends JPanel +{ + JDialog dialog; + + public boolean cancelled = false; + + String value; + + public HTMLOptions() + { + try + { + jbInit(); + } catch (Exception ex) + { + ex.printStackTrace(); + } + + ButtonGroup bg = new ButtonGroup(); + bg.add(lineart); + bg.add(text); + + JOptionPane pane = new JOptionPane(null, JOptionPane.DEFAULT_OPTION, + JOptionPane.DEFAULT_OPTION, null, new Object[] + { this }); + + dialog = pane.createDialog(Desktop.desktop, "HTML Rendering options"); + dialog.setVisible(true); + + } + + private void jbInit() throws Exception + { + lineart.setFont(JvSwingUtils.getLabelFont()); + lineart.setText(MessageManager.getString("label.lineart")); + text.setFont(JvSwingUtils.getLabelFont()); + text.setText(MessageManager.getString("action.text")); + text.setSelected(true); + askAgain.setFont(JvSwingUtils.getLabelFont()); + askAgain.setText(MessageManager.getString("label.dont_ask_me_again")); + ok.setText(MessageManager.getString("action.ok")); + ok.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + ok_actionPerformed(e); + } + }); + cancel.setText(MessageManager.getString("action.cancel")); + cancel.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + cancel_actionPerformed(e); + } + }); + jLabel1.setFont(JvSwingUtils.getLabelFont()); + jLabel1.setText("Select HTML character rendering style"); + this.setLayout(borderLayout1); + jPanel3.setBorder(BorderFactory.createEtchedBorder()); + jPanel2.add(text); + jPanel2.add(lineart); + jPanel2.add(askAgain); + jPanel1.add(ok); + jPanel1.add(cancel); + jPanel3.add(jLabel1); + jPanel3.add(jPanel2); + this.add(jPanel3, java.awt.BorderLayout.CENTER); + this.add(jPanel1, java.awt.BorderLayout.SOUTH); + } + + JRadioButton lineart = new JRadioButton(); + + JRadioButton text = new JRadioButton(); + + JCheckBox askAgain = new JCheckBox(); + + JButton ok = new JButton(); + + JButton cancel = new JButton(); + + JPanel jPanel1 = new JPanel(); + + JLabel jLabel1 = new JLabel(); + + JPanel jPanel2 = new JPanel(); + + JPanel jPanel3 = new JPanel(); + + BorderLayout borderLayout1 = new BorderLayout(); + + public void ok_actionPerformed(ActionEvent e) + { + if (lineart.isSelected()) + { + value = "Lineart"; + } + else + { + value = "Text"; + } + + if (!askAgain.isSelected()) + { + jalview.bin.Cache.applicationProperties.remove("HTML_RENDERING"); + } + else + { + jalview.bin.Cache.setProperty("HTML_RENDERING", value); + } + + dialog.setVisible(false); + } + + public void cancel_actionPerformed(ActionEvent e) + { + cancelled = true; + dialog.setVisible(false); + } + + public String getValue() + { + return value; + } +} diff --git a/src/jalview/gui/IdCanvas.java b/src/jalview/gui/IdCanvas.java index 91b23e4..6810fed 100755 --- a/src/jalview/gui/IdCanvas.java +++ b/src/jalview/gui/IdCanvas.java @@ -60,7 +60,7 @@ public class IdCanvas extends JPanel AnnotationPanel ap; - Font idfont; + private Font idfont; /** * Creates a new IdCanvas object. @@ -119,7 +119,7 @@ public class IdCanvas extends JPanel gg.setColor(Color.black); } - if (av.rightAlignIds) + if (av.isRightAlignIds()) { xPos = panelWidth - fm.stringWidth(s.getDisplayId(av.getShowJVSuffix())) - 4; @@ -247,15 +247,15 @@ public class IdCanvas extends JPanel { if (av.seqNameItalics) { - idfont = new Font(av.getFont().getName(), Font.ITALIC, av.getFont() - .getSize()); + setIdfont(new Font(av.getFont().getName(), Font.ITALIC, av.getFont() + .getSize())); } else { - idfont = av.getFont(); + setIdfont(av.getFont()); } - gg.setFont(idfont); + gg.setFont(getIdfont()); fm = gg.getFontMetrics(); if (av.antiAlias) @@ -279,7 +279,7 @@ public class IdCanvas extends JPanel int annotationHeight = 0; - if (av.showAnnotation) + if (av.isShowAnnotation()) { if (ap == null) { @@ -316,13 +316,13 @@ public class IdCanvas extends JPanel } else { - gg.setFont(idfont); + gg.setFont(getIdfont()); } drawIdString(gg, s, i, 0, ypos); } - if (labels != null && av.showAnnotation) + if (labels != null && av.isShowAnnotation()) { gg.translate(0, ypos + (alheight * av.charHeight)); labels.drawComponent(gg, getWidth()); @@ -383,7 +383,7 @@ public class IdCanvas extends JPanel String string = sequence.getDisplayId(av.getShowJVSuffix()); - if (av.rightAlignIds) + if (av.isRightAlignIds()) { xPos = panelWidth - fm.stringWidth(string) - 4; } @@ -474,7 +474,7 @@ public class IdCanvas extends JPanel } else { - gg.setFont(idfont); + gg.setFont(getIdfont()); } } @@ -489,4 +489,14 @@ public class IdCanvas extends JPanel searchResults = list; repaint(); } + + public Font getIdfont() + { + return idfont; + } + + public void setIdfont(Font idfont) + { + this.idfont = idfont; + } } diff --git a/src/jalview/gui/IdPanel.java b/src/jalview/gui/IdPanel.java index 6b1109a..3486f72 100755 --- a/src/jalview/gui/IdPanel.java +++ b/src/jalview/gui/IdPanel.java @@ -52,7 +52,7 @@ import javax.swing.ToolTipManager; public class IdPanel extends JPanel implements MouseListener, MouseMotionListener, MouseWheelListener { - protected IdCanvas idCanvas; + private IdCanvas idCanvas; protected AlignViewport av; @@ -81,11 +81,11 @@ public class IdPanel extends JPanel implements MouseListener, { this.av = av; alignPanel = parent; - idCanvas = new IdCanvas(av); + setIdCanvas(new IdCanvas(av)); linkImageURL = getClass().getResource("/images/link.gif").toString(); seqAnnotReport = new SequenceAnnotationReport(linkImageURL); setLayout(new BorderLayout()); - add(idCanvas, BorderLayout.CENTER); + add(getIdCanvas(), BorderLayout.CENTER); addMouseListener(this); addMouseMotionListener(this); addMouseWheelListener(this); @@ -102,7 +102,7 @@ public class IdPanel extends JPanel implements MouseListener, @Override public void mouseMoved(MouseEvent e) { - SeqPanel sp = alignPanel.seqPanel; + SeqPanel sp = alignPanel.getSeqPanel(); int seq = Math.max(0, sp.findSeq(e)); if (seq > -1 && seq < av.getAlignment().getHeight()) { @@ -128,7 +128,7 @@ public class IdPanel extends JPanel implements MouseListener, { mouseDragging = true; - int seq = Math.max(0, alignPanel.seqPanel.findSeq(e)); + int seq = Math.max(0, alignPanel.getSeqPanel().findSeq(e)); if (seq < lastid) { @@ -202,7 +202,7 @@ public class IdPanel extends JPanel implements MouseListener, return; } - int seq = alignPanel.seqPanel.findSeq(e); + int seq = alignPanel.getSeqPanel().findSeq(e); String url = null; int i = 0; String id = av.getAlignment().getSequenceAt(seq).getName(); @@ -315,7 +315,7 @@ public class IdPanel extends JPanel implements MouseListener, return; } - int seq = alignPanel.seqPanel.findSeq(e); + int seq = alignPanel.getSeqPanel().findSeq(e); if (SwingUtilities.isRightMouseButton(e)) { @@ -443,7 +443,7 @@ public class IdPanel extends JPanel implements MouseListener, */ public void highlightSearchResults(List list) { - idCanvas.setHighlighted(list); + getIdCanvas().setHighlighted(list); if (list == null) { @@ -459,6 +459,16 @@ public class IdPanel extends JPanel implements MouseListener, } } + public IdCanvas getIdCanvas() + { + return idCanvas; + } + + public void setIdCanvas(IdCanvas idCanvas) + { + this.idCanvas = idCanvas; + } + // this class allows scrolling off the bottom of the visible alignment class ScrollThread extends Thread { diff --git a/src/jalview/gui/IdwidthAdjuster.java b/src/jalview/gui/IdwidthAdjuster.java index 0c53c58..6c9c400 100755 --- a/src/jalview/gui/IdwidthAdjuster.java +++ b/src/jalview/gui/IdwidthAdjuster.java @@ -119,12 +119,12 @@ public class IdwidthAdjuster extends JPanel implements MouseListener, { active = true; - Dimension d = ap.idPanel.idCanvas.getPreferredSize(); + Dimension d = ap.getIdPanel().getIdCanvas().getPreferredSize(); int dif = evt.getX() - oldX; if (((d.width + dif) > 20) || (dif > 0)) { - ap.idPanel.idCanvas.setPreferredSize(new Dimension(d.width + dif, + ap.getIdPanel().getIdCanvas().setPreferredSize(new Dimension(d.width + dif, d.height)); ap.paintAlignment(true); } diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index b608b95..8ddd050 100644 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -1127,7 +1127,7 @@ public class Jalview2XML view.setShowBoxes(av.getShowBoxes()); view.setShowColourText(av.getColourText()); view.setShowFullId(av.getShowJVSuffix()); - view.setRightAlignIds(av.rightAlignIds); + view.setRightAlignIds(av.isRightAlignIds()); view.setShowSequenceFeatures(av.showSequenceFeatures); view.setShowText(av.getShowText()); view.setShowUnconserved(av.getShowUnconserved()); @@ -1149,7 +1149,7 @@ public class Jalview2XML { jalview.schemabinding.version2.FeatureSettings fs = new jalview.schemabinding.version2.FeatureSettings(); - String[] renderOrder = ap.seqPanel.seqCanvas.getFeatureRenderer().renderOrder; + String[] renderOrder = ap.getSeqPanel().seqCanvas.getFeatureRenderer().renderOrder; Vector settingsAdded = new Vector(); Object gstyle = null; @@ -1158,7 +1158,7 @@ public class Jalview2XML { for (int ro = 0; ro < renderOrder.length; ro++) { - gstyle = ap.seqPanel.seqCanvas.getFeatureRenderer() + gstyle = ap.getSeqPanel().seqCanvas.getFeatureRenderer() .getFeatureStyle(renderOrder[ro]); Setting setting = new Setting(); setting.setType(renderOrder[ro]); @@ -1176,13 +1176,13 @@ public class Jalview2XML } else { - setting.setColour(ap.seqPanel.seqCanvas.getFeatureRenderer() + setting.setColour(ap.getSeqPanel().seqCanvas.getFeatureRenderer() .getColour(renderOrder[ro]).getRGB()); } setting.setDisplay(av.featuresDisplayed .containsKey(renderOrder[ro])); - float rorder = ap.seqPanel.seqCanvas.getFeatureRenderer() + float rorder = ap.getSeqPanel().seqCanvas.getFeatureRenderer() .getOrder(renderOrder[ro]); if (rorder > -1) { @@ -1194,7 +1194,7 @@ public class Jalview2XML } // Make sure we save none displayed feature settings - Iterator en = ap.seqPanel.seqCanvas.getFeatureRenderer().featureColours + Iterator en = ap.getSeqPanel().seqCanvas.getFeatureRenderer().featureColours .keySet().iterator(); while (en.hasNext()) { @@ -1206,11 +1206,11 @@ public class Jalview2XML Setting setting = new Setting(); setting.setType(key); - setting.setColour(ap.seqPanel.seqCanvas.getFeatureRenderer() + setting.setColour(ap.getSeqPanel().seqCanvas.getFeatureRenderer() .getColour(key).getRGB()); setting.setDisplay(false); - float rorder = ap.seqPanel.seqCanvas.getFeatureRenderer() + float rorder = ap.getSeqPanel().seqCanvas.getFeatureRenderer() .getOrder(key); if (rorder > -1) { @@ -1219,7 +1219,7 @@ public class Jalview2XML fs.addSetting(setting); settingsAdded.addElement(key); } - en = ap.seqPanel.seqCanvas.getFeatureRenderer().featureGroups + en = ap.getSeqPanel().seqCanvas.getFeatureRenderer().featureGroups .keySet().iterator(); Vector groupsAdded = new Vector(); while (en.hasNext()) @@ -1231,7 +1231,7 @@ public class Jalview2XML } Group g = new Group(); g.setName(grp); - g.setDisplay(((Boolean) ap.seqPanel.seqCanvas + g.setDisplay(((Boolean) ap.getSeqPanel().seqCanvas .getFeatureRenderer().featureGroups.get(grp)) .booleanValue()); fs.addGroup(g); @@ -3472,7 +3472,7 @@ public class Jalview2XML af.viewport.setConservationSelected(view.getConservationSelected()); af.viewport.setShowJVSuffix(view.getShowFullId()); - af.viewport.rightAlignIds = view.getRightAlignIds(); + af.viewport.setRightAlignIds(view.getRightAlignIds()); af.viewport.setFont(new java.awt.Font(view.getFontName(), view .getFontStyle(), view.getFontSize())); af.alignPanel.fontChanged(); @@ -3633,24 +3633,24 @@ public class Jalview2XML gc.setColourByLabel(setting.getColourByLabel()); } // and put in the feature colour table. - af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setColour( + af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer().setColour( setting.getType(), gc); } else { - af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setColour( + af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer().setColour( setting.getType(), new java.awt.Color(setting.getColour())); } renderOrder[fs] = setting.getType(); if (setting.hasOrder()) { - af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setOrder( + af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer().setOrder( setting.getType(), setting.getOrder()); } else { - af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setOrder( + af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer().setOrder( setting.getType(), fs / jms.getFeatureSettings().getSettingCount()); } @@ -3660,9 +3660,9 @@ public class Jalview2XML setting.getColour())); } } - af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().renderOrder = renderOrder; + af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer().renderOrder = renderOrder; Hashtable fgtable; - af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featureGroups = fgtable = new Hashtable(); + af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer().featureGroups = fgtable = new Hashtable(); for (int gs = 0; gs < jms.getFeatureSettings().getGroupCount(); gs++) { Group grp = jms.getFeatureSettings().getGroup(gs); diff --git a/src/jalview/gui/Jalview2XML_V1.java b/src/jalview/gui/Jalview2XML_V1.java index 9263cd9..9a58f51 100755 --- a/src/jalview/gui/Jalview2XML_V1.java +++ b/src/jalview/gui/Jalview2XML_V1.java @@ -422,7 +422,7 @@ public class Jalview2XML_V1 { Setting setting = jms.getFeatureSettings().getSetting(fs); - af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().setColour( + af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer().setColour( setting.getType(), new java.awt.Color(setting.getColour())); renderOrder[fs] = setting.getType(); @@ -433,7 +433,7 @@ public class Jalview2XML_V1 setting.getColour())); } } - af.alignPanel.seqPanel.seqCanvas.getFeatureRenderer().renderOrder = renderOrder; + af.alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer().renderOrder = renderOrder; } af.setMenusFromViewport(af.viewport); diff --git a/src/jalview/gui/OverviewPanel.java b/src/jalview/gui/OverviewPanel.java index e8555f7..95e14b4 100755 --- a/src/jalview/gui/OverviewPanel.java +++ b/src/jalview/gui/OverviewPanel.java @@ -256,7 +256,7 @@ public class OverviewPanel extends JPanel implements Runnable if (av.showSequenceFeatures) { - fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer()); + fr.transferSettings(ap.getSeqPanel().seqCanvas.getFeatureRenderer()); } int alwidth = av.getAlignment().getWidth(); diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 9976471..1a7235f 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -1933,7 +1933,7 @@ public class PopupMenu extends JPopupMenu true, true, false, - (ap.seqPanel.seqCanvas.fr != null) ? ap.seqPanel.seqCanvas.fr.minmax + (ap.getSeqPanel().seqCanvas.fr != null) ? ap.getSeqPanel().seqCanvas.fr.minmax : null); contents.append("

"); } @@ -2650,7 +2650,7 @@ public class PopupMenu extends JPopupMenu System.arraycopy(features, 0, tfeatures, 0, rsize); features = tfeatures; seqs = rseqs; - if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs, + if (ap.getSeqPanel().seqCanvas.getFeatureRenderer().amendFeatures(seqs, features, true, ap)) { ap.alignFrame.setShowSeqFeatures(true); diff --git a/src/jalview/gui/RedundancyPanel.java b/src/jalview/gui/RedundancyPanel.java index ab0a0b8..c8a0ec7 100755 --- a/src/jalview/gui/RedundancyPanel.java +++ b/src/jalview/gui/RedundancyPanel.java @@ -107,7 +107,7 @@ public class RedundancyPanel extends GSliderPanel implements Runnable { public void internalFrameClosing(InternalFrameEvent evt) { - ap.idPanel.idCanvas.setHighlighted(null); + ap.getIdPanel().getIdCanvas().setHighlighted(null); } }); @@ -197,7 +197,7 @@ public class RedundancyPanel extends GSliderPanel implements Runnable redundantSequences.add(originalSequences[i]); } } - ap.idPanel.idCanvas.setHighlighted(redundantSequences); + ap.getIdPanel().getIdCanvas().setHighlighted(redundantSequences); } /** diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index f2c5154..568062b 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -327,7 +327,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, { if (mouseDragging) { - ap.seqPanel.scrollCanvas(null); + ap.getSeqPanel().scrollCanvas(null); } } @@ -335,7 +335,7 @@ public class ScalePanel extends JPanel implements MouseMotionListener, { if (mouseDragging) { - ap.seqPanel.scrollCanvas(evt); + ap.getSeqPanel().scrollCanvas(evt); } } diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index d73ee70..54abcc2 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -573,7 +573,7 @@ public class SeqCanvas extends JComponent drawPanel(g, startRes, endx, 0, al.getHeight(), ypos); - if (av.showAnnotation) + if (av.isShowAnnotation()) { g.translate(0, cHeight + ypos + 3); if (annotations == null) @@ -598,7 +598,7 @@ public class SeqCanvas extends JComponent int getAnnotationHeight() { - if (!av.showAnnotation) + if (!av.isShowAnnotation()) { return 0; } @@ -627,7 +627,8 @@ public class SeqCanvas extends JComponent * @param offset * DOCUMENT ME! */ - void drawPanel(Graphics g1, int startRes, int endRes, int startSeq, + public void drawPanel(Graphics g1, int startRes, int endRes, + int startSeq, int endSeq, int offset) { if (!av.hasHiddenColumns()) diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index c10a4a9..de1ffdf 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -750,7 +750,7 @@ public class SeqPanel extends JPanel implements MouseListener, sequence.getDatasetSequence(), rpos = sequence.findPosition(res)); seqARep.appendFeatures(tooltipText, rpos, features, - this.ap.seqPanel.seqCanvas.fr.minmax); + this.ap.getSeqPanel().seqCanvas.fr.minmax); } if (tooltipText.length() == 6) // { diff --git a/src/jalview/gui/SliderPanel.java b/src/jalview/gui/SliderPanel.java index 81b3bd3..cbd0d58 100755 --- a/src/jalview/gui/SliderPanel.java +++ b/src/jalview/gui/SliderPanel.java @@ -300,7 +300,7 @@ public class SliderPanel extends GSliderPanel } } - ap.seqPanel.seqCanvas.repaint(); + ap.getSeqPanel().seqCanvas.repaint(); } /** diff --git a/src/jalview/io/HtmlSvgOutput.java b/src/jalview/io/HtmlSvgOutput.java new file mode 100644 index 0000000..4643858 --- /dev/null +++ b/src/jalview/io/HtmlSvgOutput.java @@ -0,0 +1,264 @@ +package jalview.io; + +import jalview.datamodel.SequenceI; +import jalview.gui.AlignViewport; +import jalview.gui.AlignmentPanel; +import jalview.gui.AnnotationPanel; +import jalview.gui.FeatureRenderer; +import jalview.gui.HTMLOptions; +import jalview.math.AlignmentDimension; +import jalview.util.MessageManager; + +import java.awt.Color; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.print.Printable; +import java.awt.print.PrinterException; +import java.io.File; +import java.io.FileOutputStream; + +import org.jfree.graphics2d.svg.SVGGraphics2D; +import org.jfree.graphics2d.svg.SVGHints; + +public class HtmlSvgOutput +{ + AlignViewport av; + + FeatureRenderer fr; + AlignmentPanel ap; + + AnnotationPanel annotationPanel; + + public HtmlSvgOutput(AlignmentPanel ap) + { + + this.av = ap.av; + this.ap = ap; + this.annotationPanel = ap.getAnnotationPanel(); + generateHtmlSvgOutput(); + } + + public void generateHtmlSvgOutput() + { + File file = null; + try + { + JalviewFileChooser chooser = getHTMLChooser(); + chooser.setFileView(new jalview.io.JalviewFileView()); + chooser.setDialogTitle(ap.alignFrame.getTitle()); + chooser.setToolTipText(MessageManager.getString("action.save")); + int value = chooser.showSaveDialog(ap.alignFrame); + + if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION) + { + jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser + .getSelectedFile().getParent()); + file = chooser.getSelectedFile(); + } + + AlignmentDimension aDimension = ap.getAlignmentDimension(); + SVGGraphics2D g1 = new SVGGraphics2D(aDimension.getWidth(), + aDimension.getHeight()); + SVGGraphics2D g2 = new SVGGraphics2D(aDimension.getWidth(), + aDimension.getHeight()); + + String renderStyle = jalview.bin.Cache.getDefault("HTML_RENDERING", + "Prompt each time"); + + // If we need to prompt, and if the GUI is visible then + // Prompt for rendering style + if (renderStyle.equalsIgnoreCase("Prompt each time") + && !(System.getProperty("java.awt.headless") != null && System + .getProperty("java.awt.headless").equals("true"))) + { + HTMLOptions svgOption = new HTMLOptions(); + renderStyle = svgOption.getValue(); + + if (renderStyle == null || svgOption.cancelled) + { + return; + } + } + + if (renderStyle.equalsIgnoreCase("lineart")) + { + g1.setRenderingHint(SVGHints.KEY_DRAW_STRING_TYPE, + SVGHints.VALUE_DRAW_STRING_TYPE_VECTOR); + g2.setRenderingHint(SVGHints.KEY_DRAW_STRING_TYPE, + SVGHints.VALUE_DRAW_STRING_TYPE_VECTOR); + } + printUnwrapped(aDimension.getWidth(), aDimension.getHeight(), 0, g1, + g2); + FileOutputStream out = new FileOutputStream(file); + + String titleSvgData = g1.getSVGDocument(); + String alignSvgData = g2.getSVGDocument(); + String htmlData = getHtml(titleSvgData, alignSvgData); + + out.write(htmlData.getBytes()); + out.flush(); + out.close(); + + jalview.util.BrowserLauncher.openURL("file:///" + file); + } catch (Exception e) + { + e.printStackTrace(); + } + } + + static JalviewFileChooser getHTMLChooser() + { + return new jalview.io.JalviewFileChooser( + jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] + { "html" }, new String[] + { "Hypertext Markup Language" }, "Hypertext Markup Language"); + } + + public int printUnwrapped(int pwidth, int pheight, int pi, Graphics... pg) + throws PrinterException + { + int idWidth = ap.getVisibleIdWidth(false); + FontMetrics fm = ap.getFontMetrics(av.getFont()); + int scaleHeight = av.getCharHeight() + fm.getDescent(); + + pg[0].setColor(Color.white); + pg[0].fillRect(0, 0, pwidth, pheight); + pg[0].setFont(av.getFont()); + + // ////////////////////////////////// + // / How many sequences and residues can we fit on a printable page? + int totalRes = (pwidth - idWidth) / av.getCharWidth(); + int totalSeq = (pheight - scaleHeight) / av.getCharHeight() - 1; + int pagesWide = (av.getAlignment().getWidth() / totalRes) + 1; + + // /////////////////////////// + // / Only print these sequences and residues on this page + int startRes; + + // /////////////////////////// + // / Only print these sequences and residues on this page + int endRes; + + // /////////////////////////// + // / Only print these sequences and residues on this page + int startSeq; + + // /////////////////////////// + // / Only print these sequences and residues on this page + int endSeq; + startRes = (pi % pagesWide) * totalRes; + endRes = (startRes + totalRes) - 1; + + if (endRes > (av.getAlignment().getWidth() - 1)) + { + endRes = av.getAlignment().getWidth() - 1; + } + startSeq = (pi / pagesWide) * totalSeq; + endSeq = startSeq + totalSeq; + if (endSeq > av.getAlignment().getHeight()) + { + endSeq = av.getAlignment().getHeight(); + } + int pagesHigh = ((av.getAlignment().getHeight() / totalSeq) + 1) + * pheight; + if (av.isShowAnnotation()) + { + pagesHigh += ap.getAnnotationPanel().adjustPanelHeight() + 3; + } + pagesHigh /= pheight; + if (pi >= (pagesWide * pagesHigh)) + { + return Printable.NO_SUCH_PAGE; + } + + // draw Scale + pg[1].translate(0, 0); + ap.getScalePanel().drawScale(pg[1], startRes, endRes, pwidth - idWidth, + scaleHeight); + pg[1].translate(-idWidth, scaleHeight); + + // ////////////// + // Draw the ids + Color currentColor = null; + Color currentTextColor = null; + pg[0].translate(0, scaleHeight); + pg[0].setFont(ap.getIdPanel().getIdCanvas().getIdfont()); + SequenceI seq; + for (int i = startSeq; i < endSeq; i++) + { + seq = av.getAlignment().getSequenceAt(i); + if ((av.getSelectionGroup() != null) + && av.getSelectionGroup().getSequences(null).contains(seq)) + { + currentColor = Color.gray; + currentTextColor = Color.black; + } + else + { + currentColor = av.getSequenceColour(seq); + currentTextColor = Color.black; + } + pg[0].setColor(currentColor); + pg[0].fillRect(0, (i - startSeq) * av.getCharHeight(), idWidth, + av.getCharHeight()); + pg[0].setColor(currentTextColor); + int xPos = 0; + if (av.isRightAlignIds()) + { + fm = pg[0].getFontMetrics(); + xPos = idWidth + - fm.stringWidth(seq.getDisplayId(av.getShowJVSuffix())) + - 4; + } + pg[0].drawString( + seq.getDisplayId(av.getShowJVSuffix()), + xPos, + (((i - startSeq) * av.getCharHeight()) + av.getCharHeight()) + - (av.getCharHeight() / 5)); + } + pg[0].setFont(av.getFont()); + pg[0].translate(idWidth, 0); + + // draw main sequence panel + pg[1].translate(idWidth, 0); + ap.getSeqPanel().seqCanvas.drawPanel(pg[1], startRes, endRes, startSeq, + endSeq, 0); + if (av.isShowAnnotation() && (endSeq == av.getAlignment().getHeight())) + { + // draw annotation label - need to offset for current scroll position + int offset = -ap.getAlabels().getScrollOffset(); + pg[0].translate(0, offset); + pg[0].translate(-idWidth - 3, + (endSeq - startSeq) * av.getCharHeight() + 3); + ap.getAlabels().drawComponent(pg[0], idWidth); + pg[0].translate(idWidth + 3, 0); + pg[0].translate(0, -offset); + + // draw annotation - need to offset for current scroll position + pg[1].translate(0, offset); + pg[1].translate(-idWidth - 3, + (endSeq - startSeq) * av.getCharHeight() + 3); + pg[1].translate(idWidth + 3, 0); + ap.getAnnotationPanel().renderer.drawComponent( + ap.getAnnotationPanel(), av, pg[1], -1, startRes, endRes + 1); + pg[1].translate(0, -offset); + } + + return Printable.PAGE_EXISTS; + } + + private String getHtml(String titleSvg, String alignmentSvg) + { + StringBuilder htmlSvg = new StringBuilder(); + htmlSvg.append("" + + "
" + + "
"); + htmlSvg.append(titleSvg); + htmlSvg.append("
").append(alignmentSvg); + htmlSvg.append("
"); + return htmlSvg.toString(); + } +} diff --git a/src/jalview/math/AlignmentDimension.java b/src/jalview/math/AlignmentDimension.java new file mode 100644 index 0000000..ea3abf4 --- /dev/null +++ b/src/jalview/math/AlignmentDimension.java @@ -0,0 +1,35 @@ +package jalview.math; + +public class AlignmentDimension +{ + private int width; + + private int height; + + public AlignmentDimension(int width, int height) + { + this.width = width; + this.height = height; + } + + public int getWidth() + { + return width; + } + + public void setWidth(int width) + { + this.width = width; + } + + public int getHeight() + { + return height; + } + + public void setHeight(int height) + { + this.height = height; + } + +} -- 1.7.10.2