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 */
021package org.biojava.bio.gui.sequence.tracklayout;
022
023import java.util.ArrayList;
024import java.util.List;
025
026import org.biojava.bio.seq.Sequence;
027import org.biojava.bio.symbol.Location;
028import org.biojava.bio.symbol.LocationTools;
029import org.biojava.bio.symbol.RangeLocation;
030
031
032/**
033 * An implementation of TrackLayout that that wraps a sequence over an arbitrary set of ranges
034 *
035 * @author Mark Southern
036 * @since 1.5
037 */
038public class UserDefinedTrackLayout implements TrackLayout {
039    private RangeLocation globalLocation;
040    private RangeLocation[] ranges;
041    private int wrap = 6;
042    private int wrapInc = 1;
043
044    public UserDefinedTrackLayout(RangeLocation[] ranges) {
045        this.ranges = ranges;
046    }
047
048    public void setSequence(Sequence seq) {
049    }
050
051    public void setRange(RangeLocation loc) {
052        this.globalLocation = loc;
053    }
054
055    public void setWrap(int wrap) {
056        this.wrap = wrap;
057    }
058
059    public int getWrap() {
060        return wrap;
061    }
062
063    public RangeLocation[] getRanges() {
064        List list = new ArrayList();
065
066        for (int i = 0; i < ranges.length; i++) {
067            Location loc = LocationTools.intersection(globalLocation, ranges[ i ]);
068
069            if (! loc.equals(Location.empty)) {
070                list.add(loc);
071            }
072        }
073
074        return ( RangeLocation[] ) list.toArray(new RangeLocation[ 0 ]);
075    }
076
077    public int getWrapIncrement() {
078        return wrapInc;
079    }
080
081    public void setWrapIncrement(int inc) {
082        wrapInc = inc;
083    }
084}