/************************************************************************************
MRailSim - a model railway simulation program - http://mrailsim.sourceforge.net/
Copyright (C) 2004,2007 Bernd Arnold
This program 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.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
************************************************************************************/
package net.sf.mrailsim.rails;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import net.sf.mrailsim.shared.Coordinates;
public class TrackStraight extends Track {
/**
* Initializes a straight track
* @param id Unique id of the new track
* @param length How long the track is
* @param j The junction with positions and node connectors
*/
TrackStraight( long id, int length, Junction j ) {
super( id, length, j );
}
public void draw( Graphics g ) {
Coordinates coord1 = junction.getCurrentPosition().getNodeConnectorList().get( 0 ).getNode( 0 ).getCoordinates();
Coordinates coord2 = junction.getCurrentPosition().getNodeConnectorList().get( 0 ).getNode( 1 ).getCoordinates();
if ( coord1 != null && coord2 != null ) {
Graphics2D g2 = (Graphics2D) g;
g2.setColor( Color.BLACK );
g2.setStroke( new BasicStroke( 8 ) );
g2.drawLine( coord1.getX(), coord1.getY(), coord2.getX(), coord2.getY() );
if ( isOccupied() ) {
float[] dashs = { 20.0f, 15.0f };
g.setColor( Color.RED );
g2.setStroke( new BasicStroke( 3.0f, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_MITER, 1.0f, dashs, 0.0f ) );
g2.drawLine( coord1.getX(), coord1.getY(), coord2.getX(), coord2.getY() );
}
}
}
}