001package jmri.jmrit.operations.locations; 002 003import java.awt.Color; 004import java.beans.PropertyChangeEvent; 005 006import javax.swing.JTable; 007import javax.swing.SwingUtilities; 008 009import org.slf4j.Logger; 010import org.slf4j.LoggerFactory; 011 012import jmri.jmrit.operations.locations.schedules.Schedule; 013import jmri.jmrit.operations.setup.Control; 014 015/** 016 * Table Model for edit of spurs used by operations 017 * 018 * @author Daniel Boudreau Copyright (C) 2008 019 */ 020public class SpurTableModel extends TrackTableModel { 021 022 public SpurTableModel() { 023 super(); 024 } 025 026 public void initTable(JTable table, Location location) { 027 super.initTable(table); 028 super.initTable(table, location, Track.SPUR); 029 } 030 031 @Override 032 protected void editTrack(int row) { 033 log.debug("Edit spur"); 034 if (tef != null) { 035 tef.dispose(); 036 } 037 // use invokeLater so new window appears on top 038 SwingUtilities.invokeLater(() -> { 039 tef = new SpurEditFrame(); 040 Track spur = _tracksList.get(row); 041 tef.initComponents(spur); 042 }); 043 } 044 045 @Override 046 public String getColumnName(int col) { 047 switch (col) { 048 case NAME_COLUMN: 049 return Bundle.getMessage("SpurName"); 050 default: 051 return super.getColumnName(col); 052 } 053 } 054 055 @Override 056 protected Color getForegroundColor(int row) { 057 Track spur = _tracksList.get(row); 058 if (!spur.checkScheduleValid().equals(Schedule.SCHEDULE_OKAY)) { 059 return Color.red; 060 } 061 return super.getForegroundColor(row); 062 } 063 064 // this table listens for changes to a location and it's spurs 065 @Override 066 public void propertyChange(PropertyChangeEvent e) { 067 if (Control.SHOW_PROPERTY) { 068 log.debug("Property change: ({}) old: ({}) new: ({})", e.getPropertyName(), e.getOldValue(), e 069 .getNewValue()); 070 } 071 super.propertyChange(e); 072 if (e.getSource().getClass().equals(Track.class)) { 073 Track track = ((Track) e.getSource()); 074 if (track.isSpur()) { 075 int row = _tracksList.indexOf(track); 076 if (Control.SHOW_PROPERTY) { 077 log.debug("Update spur table row: {} track: {}", row, track.getName()); 078 } 079 if (row >= 0) { 080 fireTableRowsUpdated(row, row); 081 } 082 } 083 } 084 } 085 086 private final static Logger log = LoggerFactory.getLogger(SpurTableModel.class); 087}