001package net.kreatious.pianoleopard.painter.layout;
002
003import java.awt.Dimension;
004import java.awt.Rectangle;
005
006import net.kreatious.pianoleopard.midi.event.EventPair;
007import net.kreatious.pianoleopard.midi.event.NoteEvent;
008import net.kreatious.pianoleopard.midi.event.PedalEvent;
009
010/**
011 * Provides the default layout coordinates used for drawing events.
012 *
013 * @author Jay-R Studer
014 */
015public class DefaultEventLayout implements EventLayout {
016    private final YStrategy yStrategy = new DownwardsYStrategy();
017    private final XNoteStrategy xNoteStrategy = new DefaultXNoteStrategy();
018    private final XPedalStrategy xPedalStrategy = new DefaultXPedalStrategy();
019
020    /**
021     * Constructs a new {@link DefaultEventLayout} with the specified initial
022     * component dimensions.
023     *
024     * @param componentDimension
025     *            the initial component layout dimensions
026     */
027    public DefaultEventLayout(Dimension componentDimension) {
028        setComponentDimensions(componentDimension);
029    }
030
031    @Override
032    public void layoutNote(long currentTime, EventPair<NoteEvent> event, Rectangle rect) {
033        yStrategy.layout(currentTime, event, rect);
034        xNoteStrategy.layout(event.getOn(), rect);
035    }
036
037    @Override
038    public void layoutPedal(long currentTime, EventPair<PedalEvent> event, Rectangle rect) {
039        yStrategy.layout(currentTime, event, rect);
040        xPedalStrategy.layout(event.getOn(), rect);
041    }
042
043    @Override
044    public void setComponentDimensions(Dimension dimension) {
045        yStrategy.setComponentDimensions(dimension);
046        xNoteStrategy.setComponentDimensions(dimension);
047        xPedalStrategy.setComponentDimensions(dimension);
048    }
049
050    @Override
051    public long getHighestVisibleTime(long currentTime) {
052        return yStrategy.getHighestVisibleTime(currentTime);
053    }
054
055    @Override
056    public long getLowestVisibleTime(long currentTime) {
057        return yStrategy.getLowestVisibleTime(currentTime);
058    }
059}