use of javax.swing.JOptionPane in project JMRI by JMRI.
the class TurnoutTableAction method setDefaultSpeeds.
/**
* Show a pane to configure closed and thrown turnout speed defaults.
*
* @param _who parent JFrame to center the pane on
*/
protected void setDefaultSpeeds(JFrame _who) {
JComboBox<String> thrownCombo = new JComboBox<String>(speedListThrown);
JComboBox<String> closedCombo = new JComboBox<String>(speedListClosed);
thrownCombo.setEditable(true);
closedCombo.setEditable(true);
JPanel thrown = new JPanel();
thrown.add(new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("ThrownSpeed"))));
thrown.add(thrownCombo);
JPanel closed = new JPanel();
closed.add(new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("ClosedSpeed"))));
closed.add(closedCombo);
thrownCombo.removeItem(defaultThrownSpeedText);
closedCombo.removeItem(defaultClosedSpeedText);
thrownCombo.setSelectedItem(turnManager.getDefaultThrownSpeed());
closedCombo.setSelectedItem(turnManager.getDefaultClosedSpeed());
// block of options above row of buttons; gleaned from Maintenance.makeDialog()
// can be accessed by Jemmy in GUI test
String title = Bundle.getMessage("TurnoutGlobalSpeedMessageTitle");
// build JPanel for comboboxes
JPanel speedspanel = new JPanel();
speedspanel.setLayout(new BoxLayout(speedspanel, BoxLayout.PAGE_AXIS));
speedspanel.add(new JLabel(Bundle.getMessage("TurnoutGlobalSpeedMessage")));
//default LEFT_ALIGNMENT
thrown.setAlignmentX(Component.LEFT_ALIGNMENT);
speedspanel.add(thrown);
closed.setAlignmentX(Component.LEFT_ALIGNMENT);
speedspanel.add(closed);
JOptionPane pane = new JOptionPane(speedspanel, JOptionPane.INFORMATION_MESSAGE, 0, null, new Object[] { Bundle.getMessage("ButtonOK"), Bundle.getMessage("ButtonCancel") });
//pane.setxxx(value); // Configure more?
JDialog dialog = pane.createDialog(_who, title);
dialog.pack();
dialog.show();
if (pane.getValue() == null) {
// pane close button was clicked, check before assigning to retval
return;
}
Object retval = pane.getValue();
log.debug("Retval = {}", retval.toString());
// only 2 buttons to choose from, OK = button 2
if (retval != Bundle.getMessage("ButtonOK")) {
// Cancel button clicked
return;
}
String closedValue = (String) closedCombo.getSelectedItem();
String thrownValue = (String) thrownCombo.getSelectedItem();
// We will allow the turnout manager to handle checking whether the values have changed
try {
turnManager.setDefaultThrownSpeed(thrownValue);
} catch (jmri.JmriException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage() + "\n" + thrownValue);
}
try {
turnManager.setDefaultClosedSpeed(closedValue);
} catch (jmri.JmriException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage() + "\n" + closedValue);
}
}
use of javax.swing.JOptionPane in project JMRI by JMRI.
the class NXFrameTest method confirmJOptionPane.
// For types from DialogFinder().findAll(..)
@SuppressWarnings("unchecked")
private void confirmJOptionPane(java.awt.Container frame, String title, String message, String buttonLabel) {
ComponentFinder finder = new ComponentFinder(JOptionPane.class);
JOptionPane pane;
if (frame == null) {
pane = (JOptionPane) finder.find();
Assert.assertNotNull(title + " JOptionPane not found", pane);
} else {
List<JOptionPane> list = finder.findAll(frame);
Assert.assertNotNull(title + " JOptionPane not found", list);
Assert.assertTrue(title + " JOptionPane not found", list.size() == 1);
// java.util.Iterator iter = list.iterator();
pane = list.get(0);
}
if (message != null) {
Assert.assertEquals(title + " JOptionPane message", message, pane.getMessage());
}
pressButton(pane, buttonLabel);
}
use of javax.swing.JOptionPane in project aima-java by aimacode.
the class GuiBase method initMessageBox.
/**
* Initializes the dialog for the message box.
*/
public static void initMessageBox() {
MESSAGE_BOX = new JOptionPane().createDialog("MCL");
final JPanel panel = new JPanel();
panel.setBounds(5, 5, 345, 95);
MESSAGE_LABEL = new JLabel("", JLabel.CENTER);
Dimension dimension = new Dimension(350, 100);
panel.setLayout(new BorderLayout());
panel.add(MESSAGE_LABEL, BorderLayout.CENTER);
MESSAGE_OK_BUTTON = new JButton("OK");
MESSAGE_OK_BUTTON.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
MESSAGE_BOX.setVisible(false);
}
});
panel.add(MESSAGE_OK_BUTTON, BorderLayout.SOUTH);
MESSAGE_BOX.add(panel);
MESSAGE_BOX.setContentPane(panel);
MESSAGE_BOX.setMinimumSize(dimension);
MESSAGE_BOX.setResizable(false);
MESSAGE_BOX.setAlwaysOnTop(true);
MESSAGE_BOX.pack();
MESSAGE_BOX.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
MESSAGE_BOX.setModalityType(JDialog.ModalityType.MODELESS);
}
use of javax.swing.JOptionPane in project ceylon-compiler by ceylon.
the class SelectToolTask method createPane.
JOptionPane createPane(final Properties props) {
JPanel body = new JPanel(new GridBagLayout());
GridBagConstraints lc = new GridBagConstraints();
lc.insets.right = 10;
lc.insets.bottom = 3;
GridBagConstraints fc = new GridBagConstraints();
fc.anchor = GridBagConstraints.WEST;
fc.gridx = 1;
fc.gridwidth = GridBagConstraints.REMAINDER;
fc.insets.bottom = 3;
JLabel toolLabel = new JLabel("Tool:");
body.add(toolLabel, lc);
String[] toolChoices = { "apt", "javac", "javadoc", "javah", "javap" };
if (true || toolProperty == null) {
// include empty value in setup mode
List<String> l = new ArrayList<String>(Arrays.asList(toolChoices));
l.add(0, "");
toolChoices = l.toArray(new String[l.size()]);
}
toolChoice = new JComboBox(toolChoices);
if (toolName != null)
toolChoice.setSelectedItem(toolName);
toolChoice.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
String tn = (String) e.getItem();
argsField.setText(getDefaultArgsForTool(props, tn));
if (toolProperty != null)
okButton.setEnabled(!tn.equals(""));
}
});
body.add(toolChoice, fc);
argsField = new JTextField(getDefaultArgsForTool(props, toolName), 40);
if (toolProperty == null || argsProperty != null) {
JLabel argsLabel = new JLabel("Args:");
body.add(argsLabel, lc);
body.add(argsField, fc);
argsField.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
}
public void focusLost(FocusEvent e) {
String toolName = (String) toolChoice.getSelectedItem();
if (toolName.length() > 0)
props.put(toolName + ".args", argsField.getText());
}
});
}
defaultCheck = new JCheckBox("Set as default");
if (toolProperty == null)
defaultCheck.setSelected(true);
else
body.add(defaultCheck, fc);
final JOptionPane p = new JOptionPane(body);
okButton = new JButton("OK");
okButton.setEnabled(toolProperty == null || (toolName != null && !toolName.equals("")));
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JDialog d = (JDialog) SwingUtilities.getAncestorOfClass(JDialog.class, p);
d.setVisible(false);
}
});
p.setOptions(new Object[] { okButton });
return p;
}
Aggregations