001package jmri.jmrit.timetable;
002
003/**
004 * Define the content of a Segment record.
005 *
006 * @author Dave Sand Copyright (C) 2018
007 */
008public class Segment {
009
010    /**
011     * Create a new segment with default values.
012     * @param layoutId The parent layout id.
013     * @throws IllegalArgumentException SEGMENT_ADD_FAIL
014     */
015    public Segment(int layoutId) {
016        if (_dm.getLayout(layoutId) == null) {
017            throw new IllegalArgumentException(TimeTableDataManager.SEGMENT_ADD_FAIL);
018        }
019        _segmentId = _dm.getNextId("Segment");  // NOI18N
020        _layoutId = layoutId;
021        _dm.addSegment(_segmentId, this);
022    }
023
024    public Segment(int segmentId, int layoutId, String segmentName) {
025        _segmentId = segmentId;
026        _layoutId = layoutId;
027        setSegmentName(segmentName);
028    }
029
030    TimeTableDataManager _dm = TimeTableDataManager.getDataManager();
031
032    private final int _segmentId;
033    private final int _layoutId;
034    private String _segmentName = Bundle.getMessage("NewSegmentName");  // NOI18N
035
036    /**
037     * Make a copy of the segment.
038     * @param layoutId The new layoutId, if zero use the current layout id.
039     * @return a new segment instance.
040     */
041    public Segment getCopy(int layoutId) {
042        if (layoutId == 0) layoutId = getLayoutId();
043        Segment copy = new Segment(layoutId);
044        copy.setSegmentName(Bundle.getMessage("DuplicateCopyName", _segmentName));
045        return copy;
046    }
047
048    public int getSegmentId() {
049        return _segmentId;
050    }
051
052    public int getLayoutId() {
053        return _layoutId;
054    }
055
056    public String getSegmentName() {
057        return _segmentName;
058    }
059
060    public void setSegmentName(String newName) {
061        _segmentName = newName;
062    }
063
064    @Override
065    public String toString() {
066        return _segmentName;
067    }
068
069//     private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(Segment.class);
070
071}