Search in sources :

Example 46 with JDialog

use of javax.swing.JDialog in project JMRI by JMRI.

the class TurnoutIconWindowTest method testLayoutEditor.

@SuppressWarnings("unchecked")
public void testLayoutEditor() throws Exception {
    if (GraphicsEnvironment.isHeadless()) {
        // can't Assume in TestCase
        return;
    }
    jmri.jmrit.display.layoutEditor.LayoutEditor panel = new jmri.jmrit.display.layoutEditor.LayoutEditor("TurnoutIconWindowTest.testLayoutEditor");
    JComponent jf = panel.getTargetPanel();
    TurnoutIcon icon = new TurnoutIcon(panel);
    icon.setDisplayLevel(Editor.TURNOUTS);
    Turnout sn = jmri.InstanceManager.turnoutManagerInstance().provideTurnout("IT1");
    icon.setTurnout("IT1");
    icon.setIcon("TurnoutStateClosed", new NamedIcon("resources/icons/smallschematics/tracksegments/os-lefthand-east-closed.gif", "resources/icons/smallschematics/tracksegments/os-lefthand-east-closed.gif"));
    icon.setIcon("TurnoutStateThrown", new NamedIcon("resources/icons/smallschematics/tracksegments/os-lefthand-east-thrown.gif", "resources/icons/smallschematics/tracksegments/os-lefthand-east-thrown.gif"));
    icon.setIcon("BeanStateInconsistent", new NamedIcon("resources/icons/smallschematics/tracksegments/os-lefthand-east-error.gif", "resources/icons/smallschematics/tracksegments/os-lefthand-east-error.gif"));
    icon.setIcon("BeanStateUnknown", new NamedIcon("resources/icons/smallschematics/tracksegments/os-lefthand-east-unknown.gif", "resources/icons/smallschematics/tracksegments/os-lefthand-east-unknown.gif"));
    panel.putItem(icon);
    panel.setVisible(true);
    Assert.assertEquals("initial state", Turnout.UNKNOWN, sn.getState());
    // Click icon change state to Active
    java.awt.Point location = new java.awt.Point(icon.getLocation().x + icon.getSize().width / 2, icon.getLocation().y + icon.getSize().height / 2);
    getHelper().enterClickAndLeave(new MouseEventData(this, // component
    jf, // number clicks
    1, // modifiers
    EventDataConstants.DEFAULT_MOUSE_MODIFIERS, // isPopUpTrigger
    false, // sleeptime
    10, // position
    EventDataConstants.CUSTOM, location));
    Assert.assertEquals("state after one click", Turnout.CLOSED, sn.getState());
    // Click icon change state to inactive
    getHelper().enterClickAndLeave(new MouseEventData(this, icon));
    Assert.assertEquals("state after two clicks", Turnout.THROWN, sn.getState());
    // if OK to here, close window
    TestHelper.disposeWindow(panel.getTargetFrame(), this);
    // that pops dialog, find and press Delete
    List<JDialog> dialogList = new DialogFinder(null).findAll(panel.getTargetFrame());
    JDialog d = dialogList.get(0);
    // Find the button that deletes the panel
    AbstractButtonFinder bf = new AbstractButtonFinder("Delete Panel");
    JButton button = (JButton) bf.find(d, 0);
    Assert.assertNotNull(button);
    // Click button to delete panel and close window
    getHelper().enterClickAndLeave(new MouseEventData(this, button));
    // that pops dialog, find and press Yes - Delete
    dialogList = new DialogFinder(null).findAll(panel.getTargetFrame());
    d = dialogList.get(0);
    // Find the button that deletes the panel
    bf = new AbstractButtonFinder("Yes - Dele");
    button = (JButton) bf.find(d, 0);
    Assert.assertNotNull(button);
    // Click button to delete panel and close window
    getHelper().enterClickAndLeave(new MouseEventData(this, button));
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) JComponent(javax.swing.JComponent) JButton(javax.swing.JButton) MouseEventData(junit.extensions.jfcunit.eventdata.MouseEventData) DialogFinder(junit.extensions.jfcunit.finder.DialogFinder) AbstractButtonFinder(junit.extensions.jfcunit.finder.AbstractButtonFinder) Turnout(jmri.Turnout) JDialog(javax.swing.JDialog)

Example 47 with JDialog

use of javax.swing.JDialog in project JMRI by JMRI.

the class SensorIconWindowTest method testPanelEditor.

// DialogFinder not parameterized
@SuppressWarnings("unchecked")
public void testPanelEditor() throws Exception {
    if (GraphicsEnvironment.isHeadless()) {
        // can't Assume in TestCase
        return;
    }
    jmri.jmrit.display.panelEditor.PanelEditor panel = new jmri.jmrit.display.panelEditor.PanelEditor("SensorIconWindowTest.testPanelEditor");
    JComponent jf = panel.getTargetPanel();
    SensorIcon icon = new SensorIcon(panel);
    panel.putItem(icon);
    Sensor sn = jmri.InstanceManager.sensorManagerInstance().provideSensor("IS1");
    icon.setSensor("IS1");
    icon.setIcon("BeanStateUnknown", new NamedIcon("resources/icons/smallschematics/tracksegments/circuit-error.gif", "resources/icons/smallschematics/tracksegments/circuit-error.gif"));
    //daboudreau added this for Win7
    icon.setDisplayLevel(Editor.SENSORS);
    panel.setVisible(true);
    //jf.setVisible(true);
    Assert.assertEquals("initial state", Sensor.UNKNOWN, sn.getState());
    // Click icon change state to Active
    java.awt.Point location = new java.awt.Point(icon.getLocation().x + icon.getSize().width / 2, icon.getLocation().y + icon.getSize().height / 2);
    getHelper().enterClickAndLeave(new MouseEventData(this, // component
    jf, // number clicks
    1, // modifiers
    EventDataConstants.DEFAULT_MOUSE_MODIFIERS, // isPopUpTrigger
    false, // sleeptime
    10, // position
    EventDataConstants.CUSTOM, location));
    Assert.assertEquals("state after one click", Sensor.INACTIVE, sn.getState());
    // Click icon change state to inactive
    getHelper().enterClickAndLeave(new MouseEventData(this, icon));
    Assert.assertEquals("state after two clicks", Sensor.ACTIVE, sn.getState());
    // if OK to here, close window
    TestHelper.disposeWindow(panel.getTargetFrame(), this);
    // that pops dialog, find and press Delete
    List<JDialog> dialogList = new DialogFinder(null).findAll(panel.getTargetFrame());
    JDialog d = dialogList.get(0);
    // Find the button that deletes the panel
    AbstractButtonFinder bf = new AbstractButtonFinder("Delete Panel");
    JButton button = (JButton) bf.find(d, 0);
    Assert.assertNotNull(button);
    // Click button to delete panel and close window
    getHelper().enterClickAndLeave(new MouseEventData(this, button));
    // that pops dialog, find and press Yes - Delete
    dialogList = new DialogFinder(null).findAll(panel.getTargetFrame());
    d = dialogList.get(0);
    // Find the button that deletes the panel
    bf = new AbstractButtonFinder("Yes - Dele");
    button = (JButton) bf.find(d, 0);
    Assert.assertNotNull(button);
    // Click button to delete panel and close window
    getHelper().enterClickAndLeave(new MouseEventData(this, button));
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) JComponent(javax.swing.JComponent) JButton(javax.swing.JButton) MouseEventData(junit.extensions.jfcunit.eventdata.MouseEventData) DialogFinder(junit.extensions.jfcunit.finder.DialogFinder) AbstractButtonFinder(junit.extensions.jfcunit.finder.AbstractButtonFinder) JDialog(javax.swing.JDialog) Sensor(jmri.Sensor)

Example 48 with JDialog

use of javax.swing.JDialog in project JMRI by JMRI.

the class SensorIconWindowTest method testLayoutEditor.

// DialogFinder not parameterized
@SuppressWarnings("unchecked")
public void testLayoutEditor() throws Exception {
    if (GraphicsEnvironment.isHeadless()) {
        // can't Assume in TestCase
        return;
    }
    jmri.jmrit.display.layoutEditor.LayoutEditor panel = new jmri.jmrit.display.layoutEditor.LayoutEditor("SensorIconWindowTest.testLayoutEditor");
    JComponent jf = panel.getTargetPanel();
    SensorIcon icon = new SensorIcon(panel);
    panel.putItem(icon);
    Sensor sn = jmri.InstanceManager.sensorManagerInstance().provideSensor("IS1");
    icon.setSensor("IS1");
    icon.setIcon("BeanStateUnknown", new NamedIcon("resources/icons/smallschematics/tracksegments/circuit-error.gif", "resources/icons/smallschematics/tracksegments/circuit-error.gif"));
    //daboudreau added this for Win7
    icon.setDisplayLevel(Editor.SENSORS);
    panel.setVisible(true);
    //jf.setVisible(true);
    Assert.assertEquals("initial state", Sensor.UNKNOWN, sn.getState());
    // Click icon change state to Active
    java.awt.Point location = new java.awt.Point(icon.getLocation().x + icon.getSize().width / 2, icon.getLocation().y + icon.getSize().height / 2);
    getHelper().enterClickAndLeave(new MouseEventData(this, // component
    jf, // number clicks
    1, // modifiers
    EventDataConstants.DEFAULT_MOUSE_MODIFIERS, // isPopUpTrigger
    false, // sleeptime
    10, // position
    EventDataConstants.CUSTOM, location));
    Assert.assertEquals("state after one click", Sensor.INACTIVE, sn.getState());
    // Click icon change state to inactive
    getHelper().enterClickAndLeave(new MouseEventData(this, icon));
    Assert.assertEquals("state after two clicks", Sensor.ACTIVE, sn.getState());
    // if OK to here, close window
    TestHelper.disposeWindow(panel.getTargetFrame(), this);
    // that pops dialog, find and press Delete
    List<JDialog> dialogList = new DialogFinder(null).findAll(panel.getTargetFrame());
    JDialog d = dialogList.get(0);
    // Find the button that deletes the panel
    AbstractButtonFinder bf = new AbstractButtonFinder("Delete Panel");
    JButton button = (JButton) bf.find(d, 0);
    Assert.assertNotNull(button);
    // Click button to delete panel and close window
    getHelper().enterClickAndLeave(new MouseEventData(this, button));
    // that pops dialog, find and press Yes - Delete
    dialogList = new DialogFinder(null).findAll(panel.getTargetFrame());
    d = dialogList.get(0);
    // Find the button that deletes the panel
    bf = new AbstractButtonFinder("Yes - Dele");
    button = (JButton) bf.find(d, 0);
    Assert.assertNotNull(button);
    // Click button to delete panel and close window
    getHelper().enterClickAndLeave(new MouseEventData(this, button));
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) JComponent(javax.swing.JComponent) JButton(javax.swing.JButton) MouseEventData(junit.extensions.jfcunit.eventdata.MouseEventData) DialogFinder(junit.extensions.jfcunit.finder.DialogFinder) AbstractButtonFinder(junit.extensions.jfcunit.finder.AbstractButtonFinder) JDialog(javax.swing.JDialog) Sensor(jmri.Sensor)

Example 49 with JDialog

use of javax.swing.JDialog in project JMRI by JMRI.

the class RouteEditTableModel method setComment.

private void setComment(RouteLocation rl) {
    // Create comment panel
    final JDialog dialog = new JDialog();
    dialog.setLayout(new BorderLayout());
    dialog.setTitle(Bundle.getMessage("Comment") + " " + rl.getName());
    final JTextArea commentTextArea = new JTextArea(5, 100);
    JScrollPane commentScroller = new JScrollPane(commentTextArea);
    dialog.add(commentScroller, BorderLayout.CENTER);
    commentTextArea.setText(rl.getComment());
    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new FlowLayout(FlowLayout.CENTER));
    dialog.add(buttonPane, BorderLayout.SOUTH);
    JButton okayButton = new JButton(Bundle.getMessage("ButtonOK"));
    okayButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            rl.setComment(commentTextArea.getText());
            dialog.dispose();
            return;
        }
    });
    buttonPane.add(okayButton);
    JButton cancelButton = new JButton(Bundle.getMessage("ButtonCancel"));
    cancelButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            dialog.dispose();
            return;
        }
    });
    buttonPane.add(cancelButton);
    dialog.setModal(true);
    dialog.pack();
    dialog.setVisible(true);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) FlowLayout(java.awt.FlowLayout) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JDialog(javax.swing.JDialog)

Example 50 with JDialog

use of javax.swing.JDialog in project JMRI by JMRI.

the class EcosLocoAddressManager method checkLocoList.

/* This is used after an event update form the ecos informing us of a change in the 
     * loco list, we have to determine if it is an addition or delete.
     * We should only ever do either a remove or an add in one go, if we are adding the loco
     * to the roster otherwise this causes a problem with the roster list.
     */
void checkLocoList(String[] ecoslines) {
    log.info("Checking loco list");
    String loco;
    for (int i = 0; i < ecoslines.length; i++) {
        loco = ecoslines[i];
        loco = loco.replaceAll("[\\n\\r]", "");
        if (getByEcosObject(loco) == null) {
            log.debug("We are to add loco " + loco + " to the Ecos Loco List");
            EcosMessage mout = new EcosMessage("get(" + loco + ", addr, name, protocol)");
            tc.sendEcosMessage(mout, this);
        }
    }
    String[] jmrilist = getEcosObjectArray();
    boolean nomatch = true;
    for (int i = 0; i < jmrilist.length; i++) {
        nomatch = true;
        for (int k = 0; k < ecoslines.length; k++) {
            loco = ecoslines[k];
            loco = loco.replaceAll("[\\n\\r]", "");
            if (loco.equals(jmrilist[i])) {
                nomatch = false;
                break;
            }
        }
        if (nomatch) {
            //System.out.println("We do not have a match, therefore this should be deleted from the Ecos loco Manager " + jmrilist[i]);
            log.debug("Loco not found so need to remove from register");
            if (getByEcosObject(jmrilist[i]).getRosterId() != null) {
                final String rosterid = getByEcosObject(jmrilist[i]).getRosterId();
                final Roster _roster = Roster.getDefault();
                final RosterEntry re = _roster.entryFromTitle(rosterid);
                re.deleteAttribute(p.getRosterAttribute());
                re.writeFile(null, null, null);
                Roster.getDefault().writeRoster();
                if (p.getRemoveLocoFromJMRI() == EcosPreferences.YES) {
                    _roster.removeEntry(re);
                    Roster.getDefault().writeRoster();
                } else if (p.getRemoveLocoFromJMRI() == EcosPreferences.ASK) {
                    try {
                        final JDialog dialog = new JDialog();
                        dialog.setTitle("Remove Roster Entry From JMRI?");
                        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(rosterid + " has been removed from the Ecos do you want to remove it from 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) {
                                if (remember.isSelected()) {
                                    p.setRemoveLocoFromJMRI(EcosPreferences.ASK);
                                }
                                dialog.dispose();
                            }
                        });
                        yesButton.addActionListener(new ActionListener() {

                            @Override
                            public void actionPerformed(ActionEvent e) {
                                if (remember.isSelected()) {
                                    p.setRemoveLocoFromJMRI(EcosPreferences.YES);
                                }
                                setLocoToRoster();
                                _roster.removeEntry(re);
                                Roster.getDefault().writeRoster();
                                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);
                    } catch (HeadlessException he) {
                    // silently ignore inability to display dialog
                    }
                }
            }
            //Even if we do not delete the loco from the roster, we need to remove it from the ecos list.
            deregister(getByEcosObject(jmrilist[i]));
        }
    }
}
Also used : JPanel(javax.swing.JPanel) HeadlessException(java.awt.HeadlessException) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) JCheckBox(javax.swing.JCheckBox) Roster(jmri.jmrit.roster.Roster) EcosLocoToRoster(jmri.jmrix.ecos.utilities.EcosLocoToRoster) ActionListener(java.awt.event.ActionListener) RosterEntry(jmri.jmrit.roster.RosterEntry) JDialog(javax.swing.JDialog)

Aggregations

JDialog (javax.swing.JDialog)181 JButton (javax.swing.JButton)70 JPanel (javax.swing.JPanel)61 ActionEvent (java.awt.event.ActionEvent)51 ActionListener (java.awt.event.ActionListener)39 JLabel (javax.swing.JLabel)39 JOptionPane (javax.swing.JOptionPane)34 BorderLayout (java.awt.BorderLayout)30 Dimension (java.awt.Dimension)27 JScrollPane (javax.swing.JScrollPane)27 JFrame (javax.swing.JFrame)23 BoxLayout (javax.swing.BoxLayout)21 FlowLayout (java.awt.FlowLayout)19 JCheckBox (javax.swing.JCheckBox)15 AbstractAction (javax.swing.AbstractAction)14 WindowEvent (java.awt.event.WindowEvent)13 JComponent (javax.swing.JComponent)12 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)11 WindowAdapter (java.awt.event.WindowAdapter)11 IOException (java.io.IOException)10