package jalview.gui; import java.awt.*; import jalview.io.*; import jalview.analysis.NJTree; import jalview.datamodel.*; import java.util.*; public class AlignViewport { int startRes; int endRes; int startSeq; int endSeq; boolean showScores; boolean showText; boolean showColourText; boolean showBoxes; boolean wrapAlignment; boolean groupEdit = false; RendererI renderer = new SequenceRenderer(); int charHeight; double charWidth; int chunkWidth; int chunkHeight; Color backgroundColour; Font font = new Font("SansSerif",Font.PLAIN,10); AlignmentI alignment; Selection sel = new Selection(); ColumnSelection colSel = new ColumnSelection(); OutputGenerator og; String visibleConsensus; int threshold; int increment; NJTree currentTree = null; int window = 50; int baseline = 30; Vector kmers; public AlignViewport(AlignmentI da, boolean showScores, boolean showText, boolean showBoxes, boolean wrapAlignment) { this(0,da.getWidth()-1,0,da.getHeight()-1,showScores, showText, showBoxes, wrapAlignment); setAlignment(da); } public AlignViewport(int startRes, int endRes, int startSeq, int endSeq, boolean showScores, boolean showText, boolean showBoxes, boolean wrapAlignment) { this.startRes = startRes; this.endRes = endRes; this.startSeq = startSeq; this.endSeq = endSeq; this.showScores = showScores; this.showText = showText; this.showBoxes = showBoxes; this.wrapAlignment = wrapAlignment; // og = new AlignmentOutputGenerator(this); setFont( font ); } public AlignViewport(int startRes, int endRes, int startSeq, int endSeq, boolean showScores, boolean showText, boolean showBoxes, boolean wrapAlignment, Color backgroundColour) { this(startRes,endRes,startSeq,endSeq,showScores,showText,showBoxes,wrapAlignment); this.backgroundColour = backgroundColour; } public String getVisibleConsensus() { return visibleConsensus; } Vector consensus = new Vector(); public Vector getConsensus(boolean recalculate) { if(recalculate || consensus.size()<1) { consensus = alignment.getAAFrequency(); StringBuffer sb = new StringBuffer(); Hashtable hash = null; for (int i = 0; i < consensus.size(); i++) { hash = (Hashtable) consensus.elementAt(i); sb.append(hash.get("maxResidue").toString().charAt(0)); } visibleConsensus = sb.toString(); } return consensus; } public int getStartRes() { return startRes; } public int getEndRes() { return endRes; } public int getStartSeq() { return startSeq; } public void setStartRes(int res) { this.startRes = res; } public void setStartSeq(int seq) { this.startSeq = seq; } public void setEndRes(int res) { if (res > alignment.getWidth()-1) { System.out.println(" Corrected res from " + res + " to maximum " + (alignment.getWidth()-1)); res = alignment.getWidth() -1; } if (res < 0) { res = 0; } this.endRes = res; } public void setEndSeq(int seq) { if (seq > alignment.getHeight()) { seq = alignment.getHeight(); } if (seq < 0) { seq = 0; } this.endSeq = seq; } public int getEndSeq() { return endSeq; } public void setFont(Font f) { font = f; javax.swing.JFrame temp = new javax.swing.JFrame(); temp.addNotify(); java.awt.FontMetrics fm = temp.getGraphics().getFontMetrics(font); setCharHeight(fm.getHeight()); setCharWidth(fm.charWidth('M')); } public Font getFont() { return font; } public void setCharWidth(double w) { this.charWidth = w; } public double getCharWidth() { return charWidth; } public void setCharHeight(int h) { this.charHeight = h; } public int getCharHeight() { return charHeight; } public void setChunkWidth(int w) { this.chunkWidth = w; } public int getChunkWidth() { return chunkWidth; } public void setChunkHeight(int h) { this.chunkHeight = h; } public int getChunkHeight() { return chunkHeight; } public AlignmentI getAlignment() { return alignment; } public void setAlignment(AlignmentI align) { this.alignment = align; } public void setShowScores(boolean state) { showScores = state; } public void setWrapAlignment(boolean state) { wrapAlignment = state; } public void setShowText(boolean state) { showText = state; } public boolean getColourText() { return showColourText; } public void setColourText(boolean state) { showColourText = state; } public void setShowBoxes(boolean state) { showBoxes = state; } public boolean getShowScores() { return showScores; } public boolean getWrapAlignment() { return wrapAlignment; } public boolean getShowText() { return showText; } public boolean getShowBoxes() { return showBoxes; } // public CommandParser getCommandLog() { /// return log; // } public boolean getGroupEdit() { return groupEdit; } public void setGroupEdit(boolean state) { groupEdit = state; } public String getGapCharacter() { return getAlignment().getGapCharacter(); } public void setGapCharacter(String gap) { if (getAlignment() != null) { getAlignment().setGapCharacter(gap); } } public void setThreshold(int thresh) { threshold = thresh; } public int getThreshold() { return threshold; } public void setIncrement(int inc) { increment = inc; } public int getIncrement() { return increment; } public int getIndex(int y) { int y1 = 0; int starty = getStartSeq(); int endy = getEndSeq(); for (int i = starty; i <= endy; i++) { if (i < alignment.getHeight() && alignment.getSequenceAt(i) != null) { int y2 = y1 + getCharHeight(); if (y>=y1 && y <=y2) { return i; } y1 = y2; } else { return -1; } } return -1; } public Selection getSelection() { return sel; } public ColumnSelection getColumnSelection() { return colSel; } public OutputGenerator getOutputGenerator() { return og; } public void resetSeqLimits(int height) { setStartSeq(0); setEndSeq(height/getCharHeight()); } public void setCurrentTree(NJTree tree) { currentTree = tree; } public NJTree getCurrentTree() { return currentTree; } public void setRenderer(RendererI rend) { this.renderer = rend; } public RendererI getRenderer() { return renderer; } public int getPIDWindow() { return window; } public void setPIDWindow(int window) { this.window = window; } public int getPIDBaseline() { return baseline; } public void setPIDBaseline(int baseline) { this.baseline = baseline; } public void setKmers(Vector kmers) { this.kmers = kmers; } public Vector getKmers() { return this.kmers; } }