use of jmri.jmrit.operations.locations.Pool in project JMRI by JMRI.
the class PoolTrackFrame method updatePoolStatus.
private void updatePoolStatus() {
// This shows the details of the current member tracks in the Pool.
poolStatus.removeAll();
addItemLeft(poolStatus, name, 0, 0);
addItem(poolStatus, minimum, 1, 0);
addItem(poolStatus, length, 2, 0);
String poolName = "";
if (_track.getPool() != null) {
Pool pool = _track.getPool();
poolName = pool.getName();
List<Track> tracks = pool.getTracks();
int totalMinLength = 0;
int totalLength = 0;
for (int i = 0; i < tracks.size(); i++) {
Track track = tracks.get(i);
JLabel name = new JLabel();
name.setText(track.getName());
JLabel minimum = new JLabel();
minimum.setText(Integer.toString(track.getMinimumLength()));
totalMinLength = totalMinLength + track.getMinimumLength();
JLabel length = new JLabel();
length.setText(Integer.toString(track.getLength()));
totalLength = totalLength + track.getLength();
addItemLeft(poolStatus, name, 0, i + 1);
addItem(poolStatus, minimum, 1, i + 1);
addItem(poolStatus, length, 2, i + 1);
}
// Summary
JLabel total = new JLabel(Bundle.getMessage("Totals"));
addItem(poolStatus, total, 0, tracks.size() + 1);
JLabel totalMin = new JLabel();
totalMin.setText(Integer.toString(totalMinLength));
addItem(poolStatus, totalMin, 1, tracks.size() + 1);
JLabel totalLen = new JLabel();
totalLen.setText(Integer.toString(totalLength));
addItem(poolStatus, totalLen, 2, tracks.size() + 1);
}
poolStatus.setBorder(BorderFactory.createTitledBorder(MessageFormat.format(Bundle.getMessage("PoolTracks"), new Object[] { poolName })));
poolStatus.repaint();
poolStatus.revalidate();
// kill JMRI window size
setPreferredSize(null);
pack();
}
use of jmri.jmrit.operations.locations.Pool in project JMRI by JMRI.
the class PoolTrackGuiTest method testSelectPoolAndSaveTrack.
@Test
public void testSelectPoolAndSaveTrack() throws Exception {
if (GraphicsEnvironment.isHeadless()) {
// can't use Assume in TestCase subclasses
return;
}
// This should change the pool track property of the Track under test.
Location l = new Location("LOC1", "Location One");
l.addPool("Pool 1");
Pool desiredPool = l.addPool("Pool 2");
l.addPool("Pool 3");
Assert.assertEquals("Pool count", 3, l.getPoolsByNameList().size());
Track t = new Track("ID1", "TestTrack1", "Siding", l);
Assert.assertEquals("Initial Track Pool", null, t.getPool());
PoolTrackFrame f = new PoolTrackFrame(t);
f.setTitle("Test Pool Track Select Pool and Save Frame");
f.initComponents();
f.comboBoxPools.setSelectedItem(desiredPool);
Assert.assertEquals("ComboBox selection", desiredPool, f.comboBoxPools.getSelectedItem());
// Now click the Save button and the Track should be updated with the selected Pool
enterClickAndLeave(f.saveButton);
Assert.assertEquals("Updated Track Pool", desiredPool, t.getPool());
f.setVisible(true);
// close window
f.dispose();
}