001/*
002 *                  BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 * Created on Aug 23, 2006
021 *
022 */
023package org.biojava.nbio.structure.gui.util;
024
025
026/** a class that manages the conversion of sequence coordinate system to
027 * JPanel drawing coordinates
028 *
029 * @author Andreas Prlic
030 * @since 1.7
031 * @version %I% %G%
032 */
033public class CoordManager {
034
035
036        float scale;
037        int chainLength;
038
039        public CoordManager() {
040                super();
041                scale  = 1.0f;
042                chainLength = 0;
043        }
044
045        public void setLength(int length){
046                chainLength = length;
047        }
048
049        public void setScale(float scale){
050                this.scale = scale;
051        }
052
053
054        /** start counting at 0...
055         *
056         * @param panelPos
057         * @return the sequence position
058         */
059        protected int getSeqPos(int panelPos){
060
061
062                int seqPos = Math.round((panelPos - SequenceScalePanel.DEFAULT_X_START) / scale) ;
063                if ( seqPos < 0)
064                        seqPos = 0;
065                //int length = chainLength;
066                //if ( seqPos >= length)
067                 //   seqPos = length-1;
068                return seqPos;
069        }
070
071        protected int getPanelPos(int seqPos){
072
073                if ( seqPos < 0 )
074                        seqPos = 0;
075
076                //if ( seqPos >= length)
077                 //   seqPos = length-1;
078
079                int aminosize = Math.round(1*scale);
080                if ( aminosize < 1)
081                        aminosize = 1;
082
083                int panelPos = Math.round(seqPos * scale) + SequenceScalePanel.DEFAULT_X_START ;
084                return panelPos;
085        }
086
087
088}