use of jmri.jmrix.ecos.EcosLocoAddress in project JMRI by JMRI.
the class AddRosterEntryToEcos method rosterEntryUpdate.
void rosterEntryUpdate() {
if (rosterEntry != null) {
rosterEntry.removeAllItems();
}
for (RosterEntry r : roster.getAllEntries()) {
// Add only those locos to the drop-down list that are in the roster but not in the Ecos
String DccAddress = r.getDccAddress();
EcosLocoAddress EcosAddress = null;
if (DccAddress != null) {
log.debug("DccAddress=" + DccAddress);
EcosAddress = objEcosLocoManager.getByDccAddress(Integer.parseInt(DccAddress));
}
if (EcosAddress == null) {
// It is not possible to create MFX locomotives in the Ecos. They are auto-discovered.
if (r.getProtocol() != jmri.LocoAddress.Protocol.MFX) {
rosterEntry.addItem(r.titleString());
}
}
}
}
use of jmri.jmrix.ecos.EcosLocoAddress in project JMRI by JMRI.
the class EcosLocoToRoster method processQueue.
public void processQueue() {
if (inProcess) {
return;
}
suppressFurtherAdditions = false;
inProcess = true;
Runnable run = new Runnable() {
@Override
public void run() {
while (locoList.size() != 0) {
final EcosLocoAddress tmploco = locoList.get(0);
waitingForComplete = false;
if (p.getAddLocoToJMRI() == EcosPreferences.YES) {
adaptermemo.getLocoAddressManager().setLocoToRoster();
ecosLocoToRoster(tmploco.getEcosObject());
} else if (!suppressFurtherAdditions && tmploco.addToRoster() && (tmploco.getRosterId() == null)) {
class WindowMaker implements Runnable {
EcosLocoAddress ecosObject;
WindowMaker(EcosLocoAddress o) {
ecosObject = o;
}
@Override
public void run() {
final JDialog dialog = new JDialog();
dialog.setTitle("Add Roster Entry From JMRI?");
//dialog.setLocationRelativeTo(null);
dialog.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
JPanel container = new JPanel();
container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));
container.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
JLabel question = new JLabel("Loco " + ecosObject.getEcosDescription() + " has been add to the " + adaptermemo.getUserName());
question.setAlignmentX(Component.CENTER_ALIGNMENT);
container.add(question);
question = new JLabel("Do you want to add it to JMRI?");
question.setAlignmentX(Component.CENTER_ALIGNMENT);
container.add(question);
final JCheckBox remember = new JCheckBox("Remember this setting for next time?");
remember.setFont(remember.getFont().deriveFont(10f));
remember.setAlignmentX(Component.CENTER_ALIGNMENT);
//user preferences do not have the save option, but once complete the following line can be removed
//Need to get the method to save connection configuration.
remember.setVisible(true);
JButton yesButton = new JButton("Yes");
JButton noButton = new JButton("No");
JPanel button = new JPanel();
button.setAlignmentX(Component.CENTER_ALIGNMENT);
button.add(yesButton);
button.add(noButton);
container.add(button);
noButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ecosObject.doNotAddToRoster();
waitingForComplete = true;
if (remember.isSelected()) {
suppressFurtherAdditions = true;
p.setAddLocoToJMRI(EcosPreferences.NO);
}
dialog.dispose();
}
});
yesButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (remember.isSelected()) {
p.setAddLocoToJMRI(EcosPreferences.YES);
}
ecosLocoToRoster(ecosObject.getEcosObject());
dialog.dispose();
}
});
container.add(remember);
container.setAlignmentX(Component.CENTER_ALIGNMENT);
container.setAlignmentY(Component.CENTER_ALIGNMENT);
dialog.getContentPane().add(container);
dialog.pack();
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
int w = dialog.getSize().width;
int h = dialog.getSize().height;
int x = (dim.width - w) / 2;
int y = (dim.height - h) / 2;
// Move the window
dialog.setLocation(x, y);
dialog.setModal(true);
dialog.setVisible(true);
}
}
try {
WindowMaker t = new WindowMaker(tmploco);
javax.swing.SwingUtilities.invokeAndWait(t);
} catch (Exception ex) {
// Thread.currentThread().interrupt();
}
} else {
waitingForComplete = true;
}
Runnable r = new Runnable() {
@Override
public void run() {
try {
while (!waitingForComplete) {
Thread.sleep(500L);
}
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
};
Thread thr = new Thread(r);
thr.start();
thr.setName("Ecos Loco To Roster Inner thread");
try {
thr.join();
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
locoList.remove(0);
}
inProcess = false;
}
};
Thread thread = new Thread(run);
thread.setName("Ecos Loco To Roster");
thread.start();
}
Aggregations