use of jmri.Section in project JMRI by JMRI.
the class SectionTableAction method deleteSectionPressed.
/**
* Special processing when user requests deletion of a Section Standard
* BeanTable processing results in misleading information
*/
private void deleteSectionPressed(String sName) {
final Section s = jmri.InstanceManager.getDefault(jmri.SectionManager.class).getBySystemName(sName);
String fullName = sName;
String uname = s.getUserName();
if (uname != null && uname.length() > 0) {
fullName = fullName + "(" + uname + ")";
}
ArrayList<Transit> affectedTransits = jmri.InstanceManager.getDefault(jmri.TransitManager.class).getListUsingSection(s);
final JDialog dialog = new JDialog();
String msg = "";
dialog.setTitle(Bundle.getMessage("WarningTitle"));
dialog.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
dialog.getContentPane().setLayout(new BoxLayout(dialog.getContentPane(), BoxLayout.Y_AXIS));
JPanel p1 = new JPanel();
p1.setLayout(new FlowLayout());
if (affectedTransits.size() > 0) {
// special warning if Section is used in Transits
JLabel iLabel = new JLabel(java.text.MessageFormat.format(rbx.getString("Message17"), fullName));
p1.add(iLabel);
dialog.add(p1);
for (int i = 0; i < affectedTransits.size(); i++) {
Transit aTransit = affectedTransits.get(i);
String tFullName = aTransit.getSystemName();
uname = aTransit.getUserName();
if (uname != null && uname.length() > 0) {
tFullName = tFullName + "(" + uname + ")";
}
p1 = new JPanel();
p1.setLayout(new FlowLayout());
iLabel = new JLabel(" " + tFullName);
p1.add(iLabel);
dialog.add(p1);
}
dialog.add(p1);
JPanel p3 = new JPanel();
p3.setLayout(new FlowLayout());
JLabel question = new JLabel(rbx.getString("Message18"));
JPanel p4 = new JPanel();
p4.setLayout(new FlowLayout());
question = new JLabel(rbx.getString("Message18a"));
p4.add(question);
dialog.add(p4);
} else {
msg = java.text.MessageFormat.format(rbx.getString("Message19"), fullName);
JLabel question = new JLabel(msg);
p1.add(question);
dialog.add(p1);
}
JPanel p6 = new JPanel();
p6.setLayout(new FlowLayout());
JLabel quest = new JLabel(rbx.getString("Message20"));
p6.add(quest);
dialog.add(p6);
JButton yesButton = new JButton(rbx.getString("YesDeleteIt"));
JButton noButton = new JButton(rbx.getString("NoCancel"));
JPanel button = new JPanel();
button.add(yesButton);
button.add(noButton);
dialog.add(button);
noButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// user cancelled delete request
dialog.dispose();
}
});
yesButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
jmri.InstanceManager.getDefault(jmri.SectionManager.class).deregister(s);
s.dispose();
dialog.dispose();
}
});
dialog.pack();
dialog.setModal(true);
dialog.setVisible(true);
}
use of jmri.Section in project JMRI by JMRI.
the class DispatcherFrame method addExtraRequested.
private void addExtraRequested(ActionEvent e) {
int index = extraBox.getSelectedIndex();
if ((atSelectedIndex < 0) || (index < 0)) {
cancelExtraRequested(e);
return;
}
ActiveTrain at = activeTrainsList.get(atSelectedIndex);
Transit t = at.getTransit();
Section s = extraBoxList.get(index);
//Section ns = null;
AllocationRequest ar = null;
boolean requested = false;
if (t.containsSection(s)) {
if (s == at.getNextSectionToAllocate()) {
// this is a request that the next section in the transit be allocated
allocateNextRequested(atSelectedIndex);
return;
} else {
// requesting allocation of a section in the Transit, but not the next Section
int seq = -99;
ArrayList<Integer> seqList = t.getSeqListBySection(s);
if (seqList.size() > 0) {
seq = seqList.get(0);
}
if (seqList.size() > 1) {
// this section is in the Transit multiple times
int test = at.getNextSectionSeqNumber() - 1;
int diff = java.lang.Math.abs(seq - test);
for (int i = 1; i < seqList.size(); i++) {
if (diff > java.lang.Math.abs(test - seqList.get(i))) {
seq = seqList.get(i);
diff = java.lang.Math.abs(seq - test);
}
}
}
requested = requestAllocation(at, s, at.getAllocationDirectionFromSectionAndSeq(s, seq), seq, true, extraFrame);
ar = findAllocationRequestInQueue(s, seq, at.getAllocationDirectionFromSectionAndSeq(s, seq), at);
}
} else {
// requesting allocation of a section outside of the Transit, direction set arbitrary
requested = requestAllocation(at, s, Section.FORWARD, -99, true, extraFrame);
ar = findAllocationRequestInQueue(s, -99, Section.FORWARD, at);
}
// if allocation request is OK, allocate the Section, if not already allocated
if (requested && (ar != null)) {
allocateSection(ar, null);
}
if (extraFrame != null) {
extraFrame.setVisible(false);
// prevent listing in the Window menu.
extraFrame.dispose();
extraFrame = null;
}
}
use of jmri.Section in project JMRI by JMRI.
the class DispatcherFrame method initializeExtraComboBox.
private void initializeExtraComboBox() {
extraBox.removeAllItems();
extraBoxList.clear();
if (atSelectedIndex < 0) {
return;
}
ActiveTrain at = activeTrainsList.get(atSelectedIndex);
//Transit t = at.getTransit();
ArrayList<AllocatedSection> allocatedSectionList = at.getAllocatedSectionList();
ArrayList<String> allSections = (ArrayList<String>) InstanceManager.getDefault(jmri.SectionManager.class).getSystemNameList();
for (int j = 0; j < allSections.size(); j++) {
Section s = InstanceManager.getDefault(jmri.SectionManager.class).getSection(allSections.get(j));
if (s.getState() == Section.FREE) {
// not already allocated, check connectivity to this train's allocated sections
boolean connected = false;
for (int k = 0; k < allocatedSectionList.size(); k++) {
if (connected(s, allocatedSectionList.get(k).getSection())) {
connected = true;
}
}
if (connected) {
// add to the combo box, not allocated and connected to allocated
extraBoxList.add(s);
extraBox.addItem(getSectionName(s));
}
}
}
if (extraBoxList.size() > 0) {
extraBox.setSelectedIndex(0);
}
}
use of jmri.Section in project JMRI by JMRI.
the class DispatcherFrame method requestNextAllocation.
// submit an AllocationRequest for the next Section of an ActiveTrain
private void requestNextAllocation(ActiveTrain at) {
// set up an Allocation Request
Section next = at.getNextSectionToAllocate();
if (next == null) {
return;
}
int seqNext = at.getNextSectionSeqNumber();
int dirNext = at.getAllocationDirectionFromSectionAndSeq(next, seqNext);
requestAllocation(at, next, dirNext, seqNext, true, dispatcherFrame);
}
use of jmri.Section in project JMRI by JMRI.
the class DispatcherFrame method allocateNextRequested.
// allocate the next section for an ActiveTrain at dispatcher's request
void allocateNextRequested(int index) {
// set up an Allocation Request
ActiveTrain at = activeTrainsList.get(index);
Section next = at.getNextSectionToAllocate();
if (next == null) {
return;
}
int seqNext = at.getNextSectionSeqNumber();
int dirNext = at.getAllocationDirectionFromSectionAndSeq(next, seqNext);
if (requestAllocation(at, next, dirNext, seqNext, true, dispatcherFrame)) {
AllocationRequest ar = findAllocationRequestInQueue(next, seqNext, dirNext, at);
if (ar == null) {
return;
}
// attempt to allocate
allocateSection(ar, null);
}
}
Aggregations