use of javax.swing.JDialog in project JMRI by JMRI.
the class LogixTableAction method deletePressed.
/**
* Respond to the Delete combo selection Logix window.
*
* @param sName system name of bean to be deleted
*/
void deletePressed(String sName) {
if (!checkFlags(sName)) {
return;
}
if (!checkConditionalReferences(sName)) {
return;
}
final Logix x = _logixManager.getBySystemName(sName);
final jmri.UserPreferencesManager p;
p = jmri.InstanceManager.getNullableDefault(jmri.UserPreferencesManager.class);
if (p != null && p.getMultipleChoiceOption(getClassName(), "delete") == 0x02) {
if (x != null) {
_logixManager.deleteLogix(x);
deleteSourceWhereUsed();
}
} else {
final JDialog dialog = new JDialog();
String msg;
dialog.setTitle(rbx.getString("ConfirmTitle"));
dialog.setLocationRelativeTo(null);
dialog.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
JPanel container = new JPanel();
container.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));
msg = java.text.MessageFormat.format(rbx.getString("ConfirmLogixDelete"), sName);
JLabel question = new JLabel(msg);
question.setAlignmentX(Component.CENTER_ALIGNMENT);
container.add(question);
final JCheckBox remember = new JCheckBox(Bundle.getMessage("MessageRememberSetting"));
remember.setFont(remember.getFont().deriveFont(10f));
remember.setAlignmentX(Component.CENTER_ALIGNMENT);
JButton yesButton = new JButton(Bundle.getMessage("ButtonYes"));
JButton noButton = new JButton(Bundle.getMessage("ButtonNo"));
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) {
//there is no point in remebering this the user will never be
//able to delete a bean!
/*if(remember.isSelected()){
setDisplayDeleteMsg(0x01);
}*/
dialog.dispose();
}
});
yesButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (p != null && remember.isSelected()) {
p.setMultipleChoiceOption(getClassName(), "delete", 0x02);
}
if (x != null) {
_logixManager.deleteLogix(x);
deleteSourceWhereUsed();
}
dialog.dispose();
}
});
container.add(remember);
container.setAlignmentX(Component.CENTER_ALIGNMENT);
container.setAlignmentY(Component.CENTER_ALIGNMENT);
dialog.getContentPane().add(container);
dialog.pack();
dialog.setModal(true);
dialog.setVisible(true);
}
/*if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(f, java.text.MessageFormat.format(
rbx.getString("ConfirmLogixDelete"), sName),
rbx.getString("ConfirmTitle"), JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE) )
{
Logix x = _logixManager.getBySystemName(sName);
if (x != null) {
_logixManager.deleteLogix(x);
}
}*/
f.setVisible(true);
}
use of javax.swing.JDialog in project JMRI by JMRI.
the class Maintenance method makeDialog.
/**
* Build and display a dialog box with an OK button and optional 2nd button.
*
* @param component Body of message to put in dialog box
* @param button optional second button to add to pane
* @param parent Frame that asked for this dialog
* @param title text do use as title of the dialog box
*/
static void makeDialog(Component component, Component button, Frame parent, String title) {
JDialog dialog = new JDialog(parent, title, true);
JButton ok = new JButton(Bundle.getMessage("ButtonOK"));
class myListener implements ActionListener {
java.awt.Window _w;
myListener(java.awt.Window w) {
_w = w;
}
@Override
public void actionPerformed(ActionEvent e) {
_w.dispose();
}
}
ok.addActionListener(new myListener(dialog));
ok.setMaximumSize(ok.getPreferredSize());
java.awt.Container contentPane = dialog.getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
contentPane.add(component, BorderLayout.CENTER);
contentPane.add(Box.createVerticalStrut(5));
contentPane.add(Box.createVerticalGlue());
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
panel.add(ok);
if (button != null) {
panel.add(Box.createHorizontalStrut(5));
panel.add(button);
}
contentPane.add(panel, BorderLayout.SOUTH);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setLocationRelativeTo(parent);
dialog.pack();
dialog.setVisible(true);
}
use of javax.swing.JDialog in project JMRI by JMRI.
the class WarrantRoute method pickRoute.
/**
* Callback from RouteFinder - several routes found
*
* @param destNodes the destination blocks
* @param routeTree the routes
*/
protected void pickRoute(List<DefaultMutableTreeNode> destNodes, DefaultTreeModel routeTree) {
if (destNodes.size() == 1) {
showRoute(destNodes.get(0), routeTree);
selectedRoute(_orders);
return;
}
_pickRouteDialog = new JDialog(this, Bundle.getMessage("DialogTitle"), false);
_pickRouteDialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
clearTempWarrant();
}
});
_tempWarrant = null;
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout(5, 5));
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(new JLabel(Bundle.getMessage("NumberRoutes1", destNodes.size())));
panel.add(new JLabel(Bundle.getMessage("NumberRoutes2")));
mainPanel.add(panel, BorderLayout.NORTH);
ButtonGroup buttons = new ButtonGroup();
panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
for (int i = 0; i < destNodes.size(); i++) {
JRadioButton button = new JRadioButton(Bundle.getMessage("RouteSize", i + 1, destNodes.get(i).getLevel() + 1));
button.setActionCommand("" + i);
button.addActionListener((ActionEvent e) -> {
clearTempWarrant();
});
buttons.add(button);
panel.add(button);
}
JScrollPane scrollPane = new JScrollPane(panel);
mainPanel.add(scrollPane, BorderLayout.CENTER);
JButton ok = new JButton(Bundle.getMessage("ButtonSelect"));
ok.addActionListener(new ActionListener() {
ButtonGroup buts;
JDialog dialog;
List<DefaultMutableTreeNode> dNodes;
DefaultTreeModel tree;
@Override
public void actionPerformed(ActionEvent e) {
if (buts.getSelection() != null) {
clearTempWarrant();
int i = Integer.parseInt(buttons.getSelection().getActionCommand());
showRoute(dNodes.get(i), tree);
selectedRoute(_orders);
dialog.dispose();
} else {
showWarning(Bundle.getMessage("SelectRoute"));
}
}
ActionListener init(ButtonGroup bg, JDialog d, List<DefaultMutableTreeNode> dn, DefaultTreeModel t) {
buts = bg;
dialog = d;
dNodes = dn;
tree = t;
return this;
}
}.init(buttons, _pickRouteDialog, destNodes, routeTree));
ok.setMaximumSize(ok.getPreferredSize());
JButton show = new JButton(Bundle.getMessage("ButtonReview"));
show.addActionListener(new ActionListener() {
ButtonGroup buts;
List<DefaultMutableTreeNode> destinationNodes;
DefaultTreeModel tree;
@Override
public void actionPerformed(ActionEvent e) {
if (buts.getSelection() != null) {
clearTempWarrant();
int i = Integer.parseInt(buttons.getSelection().getActionCommand());
showRoute(destinationNodes.get(i), tree);
showTempWarrant(_orders);
} else {
showWarning(Bundle.getMessage("SelectRoute"));
}
}
ActionListener init(ButtonGroup bg, List<DefaultMutableTreeNode> dn, DefaultTreeModel t) {
buts = bg;
destinationNodes = dn;
tree = t;
return this;
}
}.init(buttons, destNodes, routeTree));
show.setMaximumSize(show.getPreferredSize());
panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
panel.add(Box.createHorizontalStrut(STRUT_SIZE));
panel.add(show);
panel.add(Box.createHorizontalStrut(STRUT_SIZE));
panel.add(ok);
panel.add(Box.createHorizontalStrut(STRUT_SIZE));
mainPanel.add(panel, BorderLayout.SOUTH);
panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
panel.add(Box.createHorizontalStrut(STRUT_SIZE));
panel.add(makeRouteTablePanel());
panel.add(Box.createHorizontalStrut(STRUT_SIZE));
panel.add(mainPanel);
panel.add(Box.createHorizontalStrut(STRUT_SIZE));
_pickRouteDialog.getContentPane().add(panel);
_pickRouteDialog.setLocation(getLocation().x - 20, getLocation().y + 150);
_pickRouteDialog.pack();
_pickRouteDialog.setVisible(true);
}
use of javax.swing.JDialog in project JMRI by JMRI.
the class EcosLocoAddressManager method propertyChange.
/**
* The PropertyChangeListener interface in this class is intended to keep
* track of roster entries and sync them up with the Ecos.
*/
@Override
public void propertyChange(java.beans.PropertyChangeEvent e) {
//If we are adding the loco to the roster from the ecos, we don't want to be adding it back to the ecos!
if (getLocoToRoster()) {
return;
}
if (e.getPropertyName().equals("add")) {
_re = (RosterEntry) e.getNewValue();
} else if (e.getPropertyName().equals("saved")) {
if (_re != null) {
if (_re.getAttribute(rosterAttribute) != null) {
_re = null;
return;
}
//if the ecosobject attribute exists this would then indicate that it has already been created on the ecos
if (p.getAddLocoToEcos() == EcosPreferences.ASK) {
final JDialog dialog = new JDialog();
dialog.setTitle("Add Loco to the ECoS?");
//test.setSize(300,130);
dialog.setLocation(300, 200);
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("Do you also want to add " + _re.getId() + " to the " + adaptermemo.getUserName() + "?");
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) {
if (remember.isSelected()) {
p.setAddLocoToEcos(0x01);
}
_re = null;
dialog.dispose();
}
});
yesButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (remember.isSelected()) {
p.setAddLocoToEcos(0x02);
}
RosterToEcos rosterToEcos = new RosterToEcos();
rosterToEcos.createEcosLoco(_re, adaptermemo);
_re = null;
dialog.dispose();
}
});
container.add(remember);
container.setAlignmentX(Component.CENTER_ALIGNMENT);
container.setAlignmentY(Component.CENTER_ALIGNMENT);
dialog.getContentPane().add(container);
dialog.pack();
dialog.setModal(true);
dialog.setVisible(true);
}
if (p.getAddLocoToEcos() == 0x02) {
RosterToEcos rosterToEcos = new RosterToEcos();
rosterToEcos.createEcosLoco(_re, adaptermemo);
_re = null;
}
}
} else if (e.getPropertyName().equals("remove")) {
_re = (RosterEntry) e.getNewValue();
if (_re.getAttribute(rosterAttribute) != null) {
if (p.getRemoveLocoFromEcos() == EcosPreferences.YES) {
RemoveObjectFromEcos removeObjectFromEcos = new RemoveObjectFromEcos();
removeObjectFromEcos.removeObjectFromEcos(_re.getAttribute(p.getRosterAttribute()), tc);
deleteEcosLoco(provideByEcosObject(_re.getAttribute(p.getRosterAttribute())));
} else if (p.getRemoveLocoFromEcos() == EcosPreferences.ASK) {
final JDialog dialog = new JDialog();
dialog.setTitle("Remove Loco From ECoS?");
//test.setSize(300,130);
dialog.setLocation(300, 200);
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("Do you also want to remove this loco from the " + adaptermemo.getUserName());
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) {
if (remember.isSelected()) {
p.setRemoveLocoFromEcos(0x01);
}
provideByEcosObject(_re.getAttribute(p.getRosterAttribute())).setRosterId(null);
dialog.dispose();
}
});
yesButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (remember.isSelected()) {
p.setRemoveLocoFromEcos(0x02);
}
RemoveObjectFromEcos removeObjectFromEcos = new RemoveObjectFromEcos();
removeObjectFromEcos.removeObjectFromEcos(_re.getAttribute(p.getRosterAttribute()), tc);
deleteEcosLoco(provideByEcosObject(_re.getAttribute(p.getRosterAttribute())));
dialog.dispose();
}
});
container.add(remember);
container.setAlignmentX(Component.CENTER_ALIGNMENT);
container.setAlignmentY(Component.CENTER_ALIGNMENT);
dialog.getContentPane().add(container);
dialog.pack();
dialog.setModal(true);
dialog.setVisible(true);
}
}
_re = null;
} else if (e.getPropertyName().equals("throttleAssigned")) {
jmri.DccLocoAddress la = (jmri.DccLocoAddress) e.getNewValue();
EcosLocoAddress ela = getByDccAddress(la.getNumber());
EcosMessage m = new EcosMessage("get(" + ela.getEcosObject() + ", speed)");
tc.sendEcosMessage(m, this);
m = new EcosMessage("get(" + ela.getEcosObject() + ", dir)");
tc.sendEcosMessage(m, this);
}
}
use of javax.swing.JDialog in project JMRI by JMRI.
the class CircuitBuilder method editCircuitDialog.
/**
* Edit existing OBlock Used by edit to set up _editCircuitFrame Sets
* _currentBlock to chosen OBlock or null if none selected
*/
private void editCircuitDialog(String title) {
_dialog = new JDialog(_editor, Bundle.getMessage(title), true);
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout(10, 10));
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
mainPanel.add(Box.createVerticalStrut(STRUT_SIZE));
JPanel p = new JPanel();
p.add(new JLabel(Bundle.getMessage("selectOBlock")));
mainPanel.add(p);
_oblockModel = PickListModel.oBlockPickModelInstance();
JTable table = _oblockModel.makePickTable();
mainPanel.add(new JScrollPane(table));
mainPanel.add(Box.createVerticalStrut(STRUT_SIZE));
mainPanel.add(makeDoneButtonPanel(false));
panel.add(mainPanel);
_dialog.getContentPane().add(panel);
_dialog.setLocation(_editor.getLocation().x + 100, _editor.getLocation().y + 100);
_dialog.pack();
_dialog.setVisible(true);
}
Aggregations