From 2baf7a0fe3faf4133a387359b8ce2ba475176eec Mon Sep 17 00:00:00 2001 From: kiramt Date: Tue, 28 Feb 2017 14:48:25 +0000 Subject: [PATCH] JAL-2388 First move of endRes etc out of AlignmentViewport (in progress) --- src/jalview/api/AlignViewportI.java | 3 + src/jalview/gui/AlignViewport.java | 8 +- src/jalview/viewmodel/AlignmentViewport.java | 37 ++-- src/jalview/viewmodel/OverviewDimensions.java | 39 +++- src/jalview/viewmodel/ViewportPositionProps.java | 251 ++++++++++++++++++++++ src/jalview/viewmodel/ViewportProperties.java | 26 +++ 6 files changed, 341 insertions(+), 23 deletions(-) create mode 100644 src/jalview/viewmodel/ViewportPositionProps.java create mode 100644 src/jalview/viewmodel/ViewportProperties.java diff --git a/src/jalview/api/AlignViewportI.java b/src/jalview/api/AlignViewportI.java index 7a00231..6cdc998 100644 --- a/src/jalview/api/AlignViewportI.java +++ b/src/jalview/api/AlignViewportI.java @@ -33,6 +33,7 @@ import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.renderer.ResidueShaderI; import jalview.schemes.ColourSchemeI; +import jalview.viewmodel.ViewportPositionProps; import java.awt.Color; import java.util.Hashtable; @@ -46,6 +47,8 @@ import java.util.Map; public interface AlignViewportI extends ViewStyleI { + ViewportPositionProps getPosProps(); + int getEndRes(); int getStartRes(); diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 4c888a1..7bebfa9 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -51,6 +51,7 @@ import jalview.structure.StructureSelectionManager; import jalview.structure.VamsasSource; import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; +import jalview.viewmodel.ViewportPositionProps; import jalview.ws.params.AutoCalcSetting; import java.awt.Container; @@ -237,10 +238,11 @@ public class AlignViewport extends AlignmentViewport implements void init() { - setStartRes(0); + + /*setStartRes(0); setEndRes(alignment.getWidth() - 1); setStartSeq(0); - setEndSeq(alignment.getHeight() - 1); + setEndSeq(alignment.getHeight() - 1);*/ applyViewProperties(); String fontName = Cache.getDefault("FONT_NAME", "SansSerif"); @@ -307,6 +309,8 @@ public class AlignViewport extends AlignmentViewport implements { residueShading.setConsensus(hconsensus); } + + posProps = new ViewportPositionProps(this.alignment, this.viewStyle); } /** diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index b728efc..41248b1 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -78,6 +78,8 @@ import java.util.Map; public abstract class AlignmentViewport implements AlignViewportI, CommandListener, VamsasSource { + protected ViewportPositionProps posProps; + protected ViewStyleI viewStyle = new ViewStyle(); /** @@ -1285,13 +1287,13 @@ public abstract class AlignmentViewport implements AlignViewportI, */ private boolean followHighlight = true; - private int startRes; + /*private int startRes; private int endRes; private int startSeq; - private int endSeq; + private int endSeq;*/ /** * Property change listener for changes in alignment @@ -2645,36 +2647,45 @@ public abstract class AlignmentViewport implements AlignViewportI, } @Override + public ViewportPositionProps getPosProps() + { + return posProps; + } + + @Override public int getStartRes() { - return startRes; + return posProps.getStartRes(); } @Override public int getEndRes() { - return endRes; + return posProps.getEndRes(); } @Override public int getStartSeq() { - return startSeq; + return posProps.getStartSeq(); } public void setStartRes(int res) { - this.startRes = res; + posProps.setStartRes(res); + // this.startRes = res; } public void setStartSeq(int seq) { - this.startSeq = seq; + posProps.setStartSeq(seq); + // this.startSeq = seq; } public void setEndRes(int res) { - if (res > alignment.getWidth() - 1) + posProps.setEndRes(res); + /*if (res > alignment.getWidth() - 1) { // log.System.out.println(" Corrected res from " + res + " to maximum " + // (alignment.getWidth()-1)); @@ -2684,12 +2695,13 @@ public abstract class AlignmentViewport implements AlignViewportI, { res = 0; } - this.endRes = res; + this.endRes = res;*/ } public void setEndSeq(int seq) { - if (seq > alignment.getHeight()) + posProps.setEndSeq(seq); + /*if (seq > alignment.getHeight()) { seq = alignment.getHeight(); } @@ -2697,13 +2709,14 @@ public abstract class AlignmentViewport implements AlignViewportI, { seq = 0; } - this.endSeq = seq; + this.endSeq = seq;*/ } @Override public int getEndSeq() { - return endSeq; + return posProps.getEndSeq(); + // return endSeq; } /** diff --git a/src/jalview/viewmodel/OverviewDimensions.java b/src/jalview/viewmodel/OverviewDimensions.java index 9b55e55..b4c7c6d 100644 --- a/src/jalview/viewmodel/OverviewDimensions.java +++ b/src/jalview/viewmodel/OverviewDimensions.java @@ -39,6 +39,8 @@ public class OverviewDimensions private AlignViewportI av; + private ViewportPositionProps posProps; + private float scalew = 1f; private float scaleh = 1f; @@ -72,6 +74,7 @@ public class OverviewDimensions public OverviewDimensions(AlignViewportI avi) { this.av = avi; + this.posProps = av.getPosProps(); // scale the initial size of overviewpanel to shape of alignment float initialScale = (float) av.getAlignment().getWidth() @@ -84,7 +87,8 @@ public class OverviewDimensions graphHeight = 0; } - if (av.getAlignment().getWidth() > av.getAlignment().getHeight()) + if (posProps.getAlignmentWidthInCols() > posProps + .getAlignmentHeightInRows()) { // wider width = MAX_WIDTH; @@ -132,14 +136,21 @@ public class OverviewDimensions if (av.hasHiddenColumns()) { // Try smallest possible box - boxWidth = (int) ((av.getEndRes() - av.getStartRes() + 1) - * av.getCharWidth() * scalew); + boxWidth = (int) (posProps.convertResiduesToPixels(posProps + .getEndRes() - posProps.getStartRes() + 1) * scalew); + + // boxWidth = (int) ((av.getEndRes() - av.getStartRes() + 1) + // * av.getCharWidth() * scalew); } boxX = width - boxWidth; } - scrollCol = (int) (boxX / scalew / av.getCharWidth()); - scrollRow = (int) (boxY / scaleh / av.getCharHeight()); + scrollCol = posProps.convertPixelsToResidues(Math.round(boxX / scalew)); + scrollRow = posProps + .convertPixelsToSequences(Math.round(boxY / scaleh)); + + // scrollCol = (int) (boxX / scalew / av.getCharWidth()); + // scrollRow = (int) (boxY / scaleh / av.getCharHeight()); if (av.hasHiddenColumns()) { @@ -188,11 +199,21 @@ public class OverviewDimensions .adjustForHiddenSeqs(endSeq); } - boxX = (int) (startRes * av.getCharWidth() * scalew); - boxY = (int) (startSeq * av.getCharHeight() * scaleh); + boxX = Math.round(posProps.convertResiduesToPixels(startRes) * scalew); + boxY = Math.round(posProps.convertSequencesToPixels(startSeq) * scaleh); + + // boxX = (int) (startRes * av.getCharWidth() * scalew); + // boxY = (int) (startSeq * av.getCharHeight() * scaleh); + + boxWidth = Math.round(posProps.convertResiduesToPixels(endRes + - startRes + + 1) * scalew); + boxHeight = Math.round(posProps.convertSequencesToPixels(endSeq + - startSeq) + * scaleh); - boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew); - boxHeight = (int) ((endSeq - startSeq) * av.getCharHeight() * scaleh); + // boxWidth = (int) ((endRes - startRes + 1) * av.getCharWidth() * scalew); + // boxHeight = (int) ((endSeq - startSeq) * av.getCharHeight() * scaleh); } /** diff --git a/src/jalview/viewmodel/ViewportPositionProps.java b/src/jalview/viewmodel/ViewportPositionProps.java new file mode 100644 index 0000000..1bb49af --- /dev/null +++ b/src/jalview/viewmodel/ViewportPositionProps.java @@ -0,0 +1,251 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ +package jalview.viewmodel; + +import jalview.api.ViewStyleI; +import jalview.datamodel.AlignmentI; + +/** + * Supplies and updates viewport properties relating to position such as: start + * and end residues and sequences, hidden column/row adjustments, ratio of + * viewport to alignment etc + */ +public class ViewportPositionProps extends ViewportProperties +{ + // start residue of viewport + private int startRes; + + // end residue of viewport + private int endRes; + + // start sequence of viewport + private int startSeq; + + // end sequence of viewport + private int endSeq; + + // character height + private int charHeight; + + // character width + private int charWidth; + + // alignment + private AlignmentI al; + + // viewstyle + private ViewStyleI viewstyle; + + /** + * Constructor + * @param alignment TODO + */ + public ViewportPositionProps(AlignmentI alignment, ViewStyleI vstyle) + { + // initial values of viewport settings + this.startRes = 0; + this.endRes = alignment.getWidth() - 1; + this.startSeq = 0; + this.endSeq = alignment.getHeight() - 1; + this.al = alignment; + this.viewstyle = vstyle; + } + + public void setCharHeight(int h) + { + viewstyle.setCharHeight(h); + } + + public void setCharWidth(int w) + { + viewstyle.setCharWidth(w); + } + + // ways to update values + + // ways to notify of changes + + // ways to supply positional information + + /** + * Get alignment width + */ + public int getAlignmentWidthInCols() + { + return al.getWidth(); + } + + /** + * Get alignment height + */ + public int getAlignmentHeightInRows() + { + return al.getHeight(); + } + + public void setStartRes(int res) + { + if (res > al.getWidth() - 1) + { + res = al.getWidth() - 1; + } + else if (res < 0) + { + res = 0; + } + this.startRes = res; + } + + public void setEndRes(int res) + { + if (res > al.getWidth() - 1) + { + res = al.getWidth() - 1; + } + else if (res < 0) + { + res = 0; + } + this.endRes = res; + } + + public void setStartSeq(int seq) + { + if (seq > al.getHeight()) + { + seq = al.getHeight(); + } + else if (seq < 0) + { + seq = 0; + } + this.startSeq = seq; + } + + public void setEndSeq(int seq) + { + if (seq > al.getHeight()) + { + seq = al.getHeight(); + } + else if (seq < 0) + { + seq = 0; + } + this.endSeq = seq; + } + + /** + * Get start residue of viewport + */ + public int getStartRes() + { + return startRes; + } + + /** + * Get end residue of viewport + */ + public int getEndRes() + { + return endRes; + } + + /** + * Get start sequence of viewport + */ + public int getStartSeq() + { + return startSeq; + } + + /** + * Get end sequence of viewport + */ + public int getEndSeq() + { + return endSeq; + } + /** + * Get start residue of viewport + */ + public int getStartRes(boolean countHidden) + { + if (countHidden) + { + return 0; // av.getColumnSelection().adjustForHiddenColumns(startRes); + } + else + { + return startRes; + } + } + + /** + * Convert distance x in viewport pixels to a distance in number of residues + * + * @param x + * number of pixels + * @return number of residues + */ + public int convertPixelsToResidues(int x) + { + return Math.round((float) x / viewstyle.getCharWidth()); + // return (int) ((float) x / viewstyle.getCharWidth()); + } + + /** + * Convert distance y in viewport pixels to a distance in number of sequences + * + * @param y + * number of pixels + * @return number of sequences + */ + public int convertPixelsToSequences(int y) + { + return Math.round((float) y / viewstyle.getCharHeight()); + // return (int) ((float) y / viewstyle.getCharHeight()); + } + + /** + * Convert number of sequences s to a height in viewport pixels + * + * @param s + * number of sequences + * @return number of pixels + */ + public int convertSequencesToPixels(int s) + { + return (s * viewstyle.getCharHeight()); + } + + /** + * Convert number of residues r to a width in viewport pixels + * + * @param r + * number of residues + * @return number of pixels + */ + public int convertResiduesToPixels(int r) + { + return (r * viewstyle.getCharWidth()); + } +} diff --git a/src/jalview/viewmodel/ViewportProperties.java b/src/jalview/viewmodel/ViewportProperties.java new file mode 100644 index 0000000..246806e --- /dev/null +++ b/src/jalview/viewmodel/ViewportProperties.java @@ -0,0 +1,26 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ +package jalview.viewmodel; + +public abstract class ViewportProperties +{ + +} -- 1.7.10.2