From: <dan...@us...> - 2012-07-31 19:48:05
|
Revision: 20915 http://jmri.svn.sourceforge.net/jmri/?rev=20915&view=rev Author: dan_boudreau Date: 2012-07-31 19:47:59 +0000 (Tue, 31 Jul 2012) Log Message: ----------- New operations feature, show planned pickups in the location table. Modified Paths: -------------- trunk/jmri/java/src/jmri/jmrit/operations/locations/JmritOperationsLocationsBundle.properties trunk/jmri/java/src/jmri/jmrit/operations/locations/Location.java trunk/jmri/java/src/jmri/jmrit/operations/locations/LocationEditFrame.java trunk/jmri/java/src/jmri/jmrit/operations/locations/Track.java trunk/jmri/java/src/jmri/jmrit/operations/locations/TrackTableModel.java Modified: trunk/jmri/java/src/jmri/jmrit/operations/locations/JmritOperationsLocationsBundle.properties =================================================================== --- trunk/jmri/java/src/jmri/jmrit/operations/locations/JmritOperationsLocationsBundle.properties 2012-07-31 08:09:27 UTC (rev 20914) +++ trunk/jmri/java/src/jmri/jmrit/operations/locations/JmritOperationsLocationsBundle.properties 2012-07-31 19:47:59 UTC (rev 20915) @@ -54,6 +54,7 @@ Pickup = Pick ups Drop = Set outs Pool = Pool +PlanPickUp = Planned TrainLocation = This location is serviced by trains traveling TrainTrack = This track is serviced by trains traveling TrainYard = This yard is serviced by trains traveling Modified: trunk/jmri/java/src/jmri/jmrit/operations/locations/Location.java =================================================================== --- trunk/jmri/java/src/jmri/jmrit/operations/locations/Location.java 2012-07-31 08:09:27 UTC (rev 20914) +++ trunk/jmri/java/src/jmri/jmrit/operations/locations/Location.java 2012-07-31 19:47:59 UTC (rev 20915) @@ -731,7 +731,7 @@ public Pool getPoolByName(String name) { Pool pool; Enumeration<Pool> en =_poolHashTable.elements(); - for (int i = 0; i < _poolHashTable.size(); i++){ + while (en.hasMoreElements()) { pool = en.nextElement(); if (pool.getName().equals(name)) return pool; @@ -766,7 +766,7 @@ public List<Pool> getPoolsByNameList(){ List<Pool> pools = new ArrayList<Pool>(); Enumeration<Pool> en =_poolHashTable.elements(); - for (int i = 0; i < _poolHashTable.size(); i++){ + while (en.hasMoreElements()) { pools.add(en.nextElement()); } return pools; @@ -779,6 +779,20 @@ public boolean hasPools(){ return _poolHashTable.size()>0; } + + /** + * Used to determine if there are any planned pickups at this location. + * @return True if there are planned pickups + */ + public boolean hasPlannedPickups(){ + List<String> tracks = getTrackIdsByIdList(); + for (int i=0; i<tracks.size(); i++){ + Track track = getTrackById(tracks.get(i)); + if (track.getIgnoreUsedLengthPercentage()>0) + return true; + } + return false; + } public void dispose(){ List<String> tracks = getTrackIdsByIdList(); Modified: trunk/jmri/java/src/jmri/jmrit/operations/locations/LocationEditFrame.java =================================================================== --- trunk/jmri/java/src/jmri/jmrit/operations/locations/LocationEditFrame.java 2012-07-31 08:09:27 UTC (rev 20914) +++ trunk/jmri/java/src/jmri/jmrit/operations/locations/LocationEditFrame.java 2012-07-31 19:47:59 UTC (rev 20915) @@ -22,7 +22,7 @@ /** * Frame for user edit of location * - * @author Dan Boudreau Copyright (C) 2008, 2010, 2011 + * @author Dan Boudreau Copyright (C) 2008, 2010, 2011, 2012 * @version $Revision$ */ @@ -31,16 +31,16 @@ static final ResourceBundle rb = ResourceBundle.getBundle("jmri.jmrit.operations.locations.JmritOperationsLocationsBundle"); YardTableModel yardModel = new YardTableModel(); - javax.swing.JTable yardTable = new javax.swing.JTable(yardModel); + JTable yardTable = new JTable(yardModel); JScrollPane yardPane; SidingTableModel sidingModel = new SidingTableModel(); - javax.swing.JTable sidingTable = new javax.swing.JTable(sidingModel); + JTable sidingTable = new JTable(sidingModel); JScrollPane sidingPane; InterchangeTableModel interchangeModel = new InterchangeTableModel(); - javax.swing.JTable interchangeTable = new javax.swing.JTable(interchangeModel); + JTable interchangeTable = new JTable(interchangeModel); JScrollPane interchangePane; StagingTableModel stagingModel = new StagingTableModel(); - javax.swing.JTable stagingTable = new javax.swing.JTable(stagingModel); + JTable stagingTable = new JTable(stagingModel); JScrollPane stagingPane; LocationManager manager; Modified: trunk/jmri/java/src/jmri/jmrit/operations/locations/Track.java =================================================================== --- trunk/jmri/java/src/jmri/jmrit/operations/locations/Track.java 2012-07-31 08:09:27 UTC (rev 20914) +++ trunk/jmri/java/src/jmri/jmrit/operations/locations/Track.java 2012-07-31 19:47:59 UTC (rev 20915) @@ -136,6 +136,7 @@ public static final String TRACK_TYPE_CHANGED_PROPERTY = "trackType"; public static final String LOADS_CHANGED_PROPERTY = "TrackLoads"; public static final String POOL_CHANGED_PROPERTY = "TrackPool"; + public static final String PLANNEDPICKUPS_CHANGED_PROPERTY = "PlannedPickUps"; public Track(String id, String name, String type, Location location){ log.debug("New track " + name + " " + id); @@ -342,7 +343,7 @@ int old = _ignoreUsedLengthPercentage; _ignoreUsedLengthPercentage = percentage; if (old != percentage) - setDirtyAndFirePropertyChange("ignoreUsedLengthPercentage", Integer.toString(old), Integer.toString(percentage)); + setDirtyAndFirePropertyChange(PLANNEDPICKUPS_CHANGED_PROPERTY, Integer.toString(old), Integer.toString(percentage)); } public int getIgnoreUsedLengthPercentage(){ Modified: trunk/jmri/java/src/jmri/jmrit/operations/locations/TrackTableModel.java =================================================================== --- trunk/jmri/java/src/jmri/jmrit/operations/locations/TrackTableModel.java 2012-07-31 08:09:27 UTC (rev 20914) +++ trunk/jmri/java/src/jmri/jmrit/operations/locations/TrackTableModel.java 2012-07-31 19:47:59 UTC (rev 20915) @@ -5,24 +5,24 @@ import java.beans.*; import javax.swing.*; -import javax.swing.table.TableCellEditor; -import javax.swing.table.TableColumnModel; - +import javax.swing.table.AbstractTableModel; +import javax.swing.table.TableColumn; import java.util.ArrayList; import java.util.List; import java.util.ResourceBundle; import jmri.jmrit.operations.setup.Control; +import jmri.util.swing.XTableColumnModel; import jmri.util.table.ButtonEditor; import jmri.util.table.ButtonRenderer; /** * Table Model for edit of tracks used by operations * - * @author Daniel Boudreau Copyright (C) 2008, 2011 + * @author Daniel Boudreau Copyright (C) 2008, 2011, 2012 * @version $Revision$ */ -public class TrackTableModel extends javax.swing.table.AbstractTableModel implements PropertyChangeListener { +public class TrackTableModel extends AbstractTableModel implements PropertyChangeListener { static ResourceBundle rb = ResourceBundle.getBundle("jmri.jmrit.operations.locations.JmritOperationsLocationsBundle"); @@ -46,8 +46,9 @@ protected static final int ENGINESCOLUMN = 6; protected static final int PICKUPSCOLUMN = 7; protected static final int DROPSCOLUMN = 8; - protected static final int EDITPOOLCOLUMN = 9; - protected static final int EDITCOLUMN = 10; + protected static final int POOLCOLUMN = 9; + protected static final int PLANPICKUPCOLUMN = 10; + protected static final int EDITCOLUMN = 11; protected static final int HIGHESTCOLUMN = EDITCOLUMN+1; @@ -95,10 +96,10 @@ } private void initTable(){ - // Install the button handlers - TableColumnModel tcm = _table.getColumnModel(); - ButtonRenderer buttonRenderer = new ButtonRenderer(); - TableCellEditor buttonEditor = new ButtonEditor(new javax.swing.JButton()); + // Use XTableColumnModel so we can control which columns are visible + XTableColumnModel tcm = new XTableColumnModel(); + _table.setColumnModel(tcm); + _table.createDefaultColumnsFromModel(); // set column preferred widths tcm.getColumn(IDCOLUMN).setPreferredWidth(40); @@ -110,23 +111,29 @@ tcm.getColumn(CARSCOLUMN).setPreferredWidth(60); tcm.getColumn(PICKUPSCOLUMN).setPreferredWidth(Math.max(60, new JLabel(getColumnName(PICKUPSCOLUMN)).getPreferredSize().width+10)); tcm.getColumn(DROPSCOLUMN).setPreferredWidth(Math.max(60, new JLabel(getColumnName(DROPSCOLUMN)).getPreferredSize().width+10)); - tcm.getColumn(EDITPOOLCOLUMN).setPreferredWidth(70); - if (_showPoolColumn){ - tcm.getColumn(EDITCOLUMN).setPreferredWidth(70); - tcm.getColumn(EDITCOLUMN).setCellRenderer(buttonRenderer); - tcm.getColumn(EDITCOLUMN).setCellEditor(buttonEditor); - } else { - tcm.getColumn(EDITPOOLCOLUMN).setCellRenderer(buttonRenderer); - tcm.getColumn(EDITPOOLCOLUMN).setCellEditor(buttonEditor); - } + tcm.getColumn(POOLCOLUMN).setPreferredWidth(70); + tcm.getColumn(PLANPICKUPCOLUMN).setPreferredWidth(70); + tcm.getColumn(EDITCOLUMN).setPreferredWidth(70); + tcm.getColumn(EDITCOLUMN).setCellRenderer(new ButtonRenderer()); + tcm.getColumn(EDITCOLUMN).setCellEditor(new ButtonEditor(new JButton())); + + setColumnsVisible(); } + + protected void setColumnsVisible(){ + XTableColumnModel tcm = (XTableColumnModel) _table.getColumnModel(); + // don't show planned pick ups unless there are some + TableColumn column = tcm.getColumnByModelIndex(PLANPICKUPCOLUMN); + tcm.setColumnVisible(column, _location.hasPlannedPickups()); + // don't show pool column if there aren't any pools + column = tcm.getColumnByModelIndex(POOLCOLUMN); + tcm.setColumnVisible(column, _location.hasPools()); + } public int getRowCount(){ return tracksList.size(); } public int getColumnCount(){ - if (_showPoolColumn) - return HIGHESTCOLUMN; - return HIGHESTCOLUMN-1; // show one less column + return HIGHESTCOLUMN; } public String getColumnName(int col){ @@ -140,10 +147,8 @@ case CARSCOLUMN: return rb.getString("Cars"); case PICKUPSCOLUMN: return rb.getString("Pickup"); case DROPSCOLUMN: return rb.getString("Drop"); - case EDITPOOLCOLUMN: - if(_showPoolColumn) - return rb.getString("Pool"); - return ""; + case POOLCOLUMN: return rb.getString("Pool"); + case PLANPICKUPCOLUMN: return rb.getString("PlanPickUp"); case EDITCOLUMN: return ""; //edit column default: return "unknown"; } @@ -160,10 +165,8 @@ case CARSCOLUMN: return String.class; case PICKUPSCOLUMN: return String.class; case DROPSCOLUMN: return String.class; - case EDITPOOLCOLUMN: - if(_showPoolColumn) - return String.class; - return JButton.class; + case POOLCOLUMN: return String.class; + case PLANPICKUPCOLUMN: return String.class; case EDITCOLUMN: return JButton.class; default: return null; } @@ -171,10 +174,6 @@ public boolean isCellEditable(int row, int col){ switch (col) { - case EDITPOOLCOLUMN: - if(_showPoolColumn) - return false; - return true; case EDITCOLUMN: return true; default: @@ -207,10 +206,11 @@ case CARSCOLUMN: return Integer.toString(track.getNumberCars()); case PICKUPSCOLUMN: return Integer.toString(track.getPickupRS()); case DROPSCOLUMN: return Integer.toString(track.getDropRS()); - case EDITPOOLCOLUMN: - if(_showPoolColumn) - return track.getPoolName(); - return rb.getString("Edit"); + case POOLCOLUMN: return track.getPoolName(); + case PLANPICKUPCOLUMN: + if (track.getIgnoreUsedLengthPercentage() > 0) + return track.getIgnoreUsedLengthPercentage()+"%"; + return ""; case EDITCOLUMN: return rb.getString("Edit"); default: return "unknown "+col; } @@ -218,11 +218,6 @@ public void setValueAt(Object value, int row, int col){ switch (col) { - case EDITPOOLCOLUMN: - if(_showPoolColumn) - break; - editTrack(row); - break; case EDITCOLUMN: editTrack(row); break; default: @@ -255,8 +250,9 @@ fireTableDataChanged(); } if (e.getSource().getClass().equals(Track.class) - && e.getPropertyName().equals(Track.POOL_CHANGED_PROPERTY)){ - updateList(); + && (e.getPropertyName().equals(Track.POOL_CHANGED_PROPERTY)) + || e.getPropertyName().equals(Track.PLANNEDPICKUPS_CHANGED_PROPERTY)){ + setColumnsVisible(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |