import jalview.datamodel.SequenceI;
import jalview.renderer.ResidueShaderI;
import jalview.schemes.ColourSchemeI;
+import jalview.viewmodel.ViewportPositionProps;
import java.awt.Color;
import java.util.Hashtable;
public interface AlignViewportI extends ViewStyleI
{
+ ViewportPositionProps getPosProps();
+
int getEndRes();
int getStartRes();
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;
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");
{
residueShading.setConsensus(hconsensus);
}
+
+ posProps = new ViewportPositionProps(this.alignment, this.viewStyle);
}
/**
public abstract class AlignmentViewport implements AlignViewportI,
CommandListener, VamsasSource
{
+ protected ViewportPositionProps posProps;
+
protected ViewStyleI viewStyle = new ViewStyle();
/**
*/
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
}
@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));
{
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();
}
{
seq = 0;
}
- this.endSeq = seq;
+ this.endSeq = seq;*/
}
@Override
public int getEndSeq()
{
- return endSeq;
+ return posProps.getEndSeq();
+ // return endSeq;
}
/**
private AlignViewportI av;
+ private ViewportPositionProps posProps;
+
private float scalew = 1f;
private float scaleh = 1f;
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()
graphHeight = 0;
}
- if (av.getAlignment().getWidth() > av.getAlignment().getHeight())
+ if (posProps.getAlignmentWidthInCols() > posProps
+ .getAlignmentHeightInRows())
{
// wider
width = MAX_WIDTH;
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())
{
.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);
}
/**
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ * 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());
+ }
+}
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.viewmodel;
+
+public abstract class ViewportProperties
+{
+
+}