Search in sources :

Example 16 with JOptionPane

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);
    }
}
Also used : JPanel(javax.swing.JPanel) JComboBox(javax.swing.JComboBox) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) JOptionPane(javax.swing.JOptionPane) JDialog(javax.swing.JDialog)

Example 17 with JOptionPane

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);
}
Also used : ComponentFinder(junit.extensions.jfcunit.finder.ComponentFinder) JOptionPane(javax.swing.JOptionPane)

Example 18 with JOptionPane

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);
}
Also used : JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) JOptionPane(javax.swing.JOptionPane)

Example 19 with JOptionPane

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;
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) ItemEvent(java.awt.event.ItemEvent) GridBagLayout(java.awt.GridBagLayout) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) FocusEvent(java.awt.event.FocusEvent) JOptionPane(javax.swing.JOptionPane) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) ItemListener(java.awt.event.ItemListener) FocusListener(java.awt.event.FocusListener) JDialog(javax.swing.JDialog)

Aggregations

JOptionPane (javax.swing.JOptionPane)19 JDialog (javax.swing.JDialog)12 JLabel (javax.swing.JLabel)10 JButton (javax.swing.JButton)6 JPanel (javax.swing.JPanel)6 JTextField (javax.swing.JTextField)5 JComboBox (javax.swing.JComboBox)4 Component (java.awt.Component)3 Dimension (java.awt.Dimension)3 BoxLayout (javax.swing.BoxLayout)3 JCheckBox (javax.swing.JCheckBox)3 BorderLayout (java.awt.BorderLayout)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 ArrayList (java.util.ArrayList)2 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)2 JColorChooser (javax.swing.JColorChooser)2 JFrame (javax.swing.JFrame)2 JScrollPane (javax.swing.JScrollPane)2 JTable (javax.swing.JTable)2