Search in sources :

Example 1 with ThrottleFrame

use of jmri.jmrit.throttle.ThrottleFrame in project JMRI by JMRI.

the class ConsistToolFrame method throttleButtonActionPerformed.

public void throttleButtonActionPerformed(ActionEvent e) {
    if (adrSelector.getAddress() == null) {
        JOptionPane.showMessageDialog(this, Bundle.getMessage("NoConsistSelectedError"));
        return;
    }
    // make sure any new locomotives are added to the consist.
    addLocoButtonActionPerformed(e);
    // Create a throttle object with the
    ThrottleFrame tf = ThrottleFrameManager.instance().createThrottleFrame();
    DccLocoAddress address = adrSelector.getAddress();
    /*
         * get the lead locomotive from the list of locomotives so we can
         * register function button bindings in the throttle.
         */
    Consist tempConsist = ConsistMan.getConsist(address);
    ArrayList<DccLocoAddress> addressList = tempConsist.getConsistList();
    DccLocoAddress locoaddress = addressList.get(0);
    if (address != locoaddress) {
        if (log.isDebugEnabled()) {
            log.debug("Consist Address " + address.toString() + ", Lead Locomoitve  " + locoaddress.toString());
        }
        // the consist address and the lead locomotive address differ,
        // register so the function buttons trigger the lead locomotive
        tf.getAddressPanel().setCurrentAddress(locoaddress);
    }
    // Notify the throttle of the selected consist address
    tf.getAddressPanel().setConsistAddress(address);
    tf.toFront();
}
Also used : Consist(jmri.Consist) ThrottleFrame(jmri.jmrit.throttle.ThrottleFrame) DccLocoAddress(jmri.DccLocoAddress)

Example 2 with ThrottleFrame

use of jmri.jmrit.throttle.ThrottleFrame in project JMRI by JMRI.

the class MemoryIcon method showPopUp.

@Override
public boolean showPopUp(JPopupMenu popup) {
    if (isEditable() && selectable) {
        popup.add(new JSeparator());
        java.util.Iterator<String> iterator = map.keySet().iterator();
        while (iterator.hasNext()) {
            String key = iterator.next();
            //String value = ((NamedIcon)map.get(key)).getName();
            popup.add(new AbstractAction(key) {

                @Override
                public void actionPerformed(ActionEvent e) {
                    String key = e.getActionCommand();
                    setValue(key);
                }
            });
        }
        return true;
    }
    // end of selectable
    if (re != null) {
        popup.add(new AbstractAction(Bundle.getMessage("OpenThrottle")) {

            @Override
            public void actionPerformed(ActionEvent e) {
                ThrottleFrame tf = ThrottleFrameManager.instance().createThrottleFrame();
                tf.toFront();
                tf.getAddressPanel().setRosterEntry(re);
            }
        });
        //don't like the idea of refering specifically to the layout block manager for this, but it has to be done if we are to allow the panel editor to also assign trains to block, when used with a layouteditor
        if ((InstanceManager.getDefault(jmri.SectionManager.class).getSystemNameList().size()) > 0 && jmri.InstanceManager.getDefault(jmri.jmrit.display.layoutEditor.LayoutBlockManager.class).getBlockWithMemoryAssigned(getMemory()) != null) {
            final jmri.jmrit.dispatcher.DispatcherFrame df = jmri.InstanceManager.getNullableDefault(jmri.jmrit.dispatcher.DispatcherFrame.class);
            if (df != null) {
                final jmri.jmrit.dispatcher.ActiveTrain at = df.getActiveTrainForRoster(re);
                if (at != null) {
                    popup.add(new AbstractAction(Bundle.getMessage("MenuTerminateTrain")) {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            df.terminateActiveTrain(at);
                        }
                    });
                    popup.add(new AbstractAction(Bundle.getMessage("MenuAllocateExtra")) {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            //Just brings up the standard allocate extra frame, this could be expanded in the future 
                            //As a point and click operation.
                            df.allocateExtraSection(e, at);
                        }
                    });
                    if (at.getStatus() == jmri.jmrit.dispatcher.ActiveTrain.DONE) {
                        popup.add(new AbstractAction(Bundle.getMessage("MenuRestartTrain")) {

                            @Override
                            public void actionPerformed(ActionEvent e) {
                                at.allocateAFresh();
                            }
                        });
                    }
                } else {
                    popup.add(new AbstractAction(Bundle.getMessage("MenuNewTrain")) {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            if (!df.getNewTrainActive()) {
                                df.getActiveTrainFrame().initiateTrain(e, re, jmri.InstanceManager.getDefault(jmri.jmrit.display.layoutEditor.LayoutBlockManager.class).getBlockWithMemoryAssigned(getMemory()).getBlock());
                                df.setNewTrainActive(true);
                            } else {
                                df.getActiveTrainFrame().showActivateFrame(re);
                            }
                        }
                    });
                }
            }
        }
        return true;
    }
    return false;
}
Also used : ActionEvent(java.awt.event.ActionEvent) JSeparator(javax.swing.JSeparator) ThrottleFrame(jmri.jmrit.throttle.ThrottleFrame) AbstractAction(javax.swing.AbstractAction)

Example 3 with ThrottleFrame

use of jmri.jmrit.throttle.ThrottleFrame in project JMRI by JMRI.

the class RosterFrame method bottomRight.

JPanel bottomRight() {
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    ButtonGroup progMode = new ButtonGroup();
    progMode.add(service);
    progMode.add(ops);
    progMode.add(edit);
    service.setEnabled(false);
    ops.setEnabled(false);
    edit.setEnabled(true);
    firePropertyChange("setprogservice", "setEnabled", false);
    firePropertyChange("setprogops", "setEnabled", false);
    firePropertyChange("setprogedit", "setEnabled", true);
    ops.setOpaque(false);
    service.setOpaque(false);
    edit.setOpaque(false);
    JPanel progModePanel = new JPanel();
    GridLayout buttonLayout = new GridLayout(3, 1, 0, 0);
    progModePanel.setLayout(buttonLayout);
    progModePanel.add(service);
    progModePanel.add(ops);
    progModePanel.add(edit);
    programModeListener = (ActionEvent e) -> {
        updateProgMode();
    };
    service.addActionListener(programModeListener);
    ops.addActionListener(programModeListener);
    edit.addActionListener(programModeListener);
    service.setVisible(false);
    ops.setVisible(false);
    panel.add(progModePanel);
    JPanel buttonHolder = new JPanel(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.weightx = 1.0;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.NORTH;
    c.gridx = 0;
    c.ipady = 20;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.gridy = 0;
    c.insets = new Insets(2, 2, 2, 2);
    buttonHolder.add(prog1Button, c);
    c.weightx = 1;
    c.fill = GridBagConstraints.NONE;
    c.gridx = 0;
    c.gridy = 1;
    c.gridwidth = 1;
    c.ipady = 0;
    buttonHolder.add(rosterMedia, c);
    c.weightx = 1.0;
    c.fill = GridBagConstraints.NONE;
    c.gridx = 1;
    c.gridy = 1;
    c.gridwidth = 1;
    c.ipady = 0;
    buttonHolder.add(throttleLaunch, c);
    //buttonHolder.add(throttleLaunch);
    panel.add(buttonHolder);
    prog1Button.setEnabled(false);
    prog1Button.addActionListener((ActionEvent e) -> {
        if (log.isDebugEnabled()) {
            log.debug("Open programmer pressed");
        }
        startProgrammer(null, re, programmer1);
    });
    /*
         * prog2Button.setEnabled(false); prog2Button.addActionListener( new
         * ActionListener() { public void
         * actionPerformed(java.awt.event.ActionEvent e) { if
         * (log.isDebugEnabled()) log.debug("Open progDebugger pressed");
         * startProgrammer(null, re, programmer2); } });
         */
    /*
         * throttleLabels.setEnabled(false); throttleLabels.addActionListener(
         * new ActionListener() { public void
         * actionPerformed(java.awt.event.ActionEvent e) { if
         * (log.isDebugEnabled()) log.debug("Open progDebugger pressed");
         * editMediaButton(); } });
         */
    rosterMedia.setEnabled(false);
    rosterMedia.addActionListener((ActionEvent e) -> {
        if (log.isDebugEnabled()) {
            log.debug("Open programmer pressed");
        }
        edit.setSelected(true);
        startProgrammer(null, re, "dp3" + File.separator + "MediaPane");
    });
    throttleLaunch.setEnabled(false);
    throttleLaunch.addActionListener((ActionEvent e) -> {
        if (log.isDebugEnabled()) {
            log.debug("Launch Throttle pressed");
        }
        if (!checkIfEntrySelected()) {
            return;
        }
        ThrottleFrame tf = ThrottleFrameManager.instance().createThrottleFrame();
        tf.toFront();
        tf.getAddressPanel().setRosterEntry(re);
    });
    return panel;
}
Also used : JPanel(javax.swing.JPanel) GridLayout(java.awt.GridLayout) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ButtonGroup(javax.swing.ButtonGroup) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) ThrottleFrame(jmri.jmrit.throttle.ThrottleFrame)

Example 4 with ThrottleFrame

use of jmri.jmrit.throttle.ThrottleFrame in project JMRI by JMRI.

the class BlockContentsIcon method showPopUp.

@Override
public boolean showPopUp(JPopupMenu popup) {
    if (isEditable() && selectable) {
        popup.add(new JSeparator());
        java.util.Iterator<String> iterator = map.keySet().iterator();
        while (iterator.hasNext()) {
            String key = iterator.next();
            //String value = ((NamedIcon)map.get(key)).getName();
            popup.add(new AbstractAction(key) {

                @Override
                public void actionPerformed(ActionEvent e) {
                    String key = e.getActionCommand();
                    setValue(key);
                }
            });
        }
        return true;
    }
    // end of selectable
    if (re != null) {
        popup.add(new AbstractAction("Open Throttle") {

            @Override
            public void actionPerformed(ActionEvent e) {
                ThrottleFrame tf = ThrottleFrameManager.instance().createThrottleFrame();
                tf.toFront();
                tf.getAddressPanel().setRosterEntry(re);
            }
        });
        final jmri.jmrit.dispatcher.DispatcherFrame df = jmri.InstanceManager.getNullableDefault(jmri.jmrit.dispatcher.DispatcherFrame.class);
        if (df != null) {
            final jmri.jmrit.dispatcher.ActiveTrain at = df.getActiveTrainForRoster(re);
            if (at != null) {
                popup.add(new AbstractAction(Bundle.getMessage("MenuTerminateTrain")) {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        df.terminateActiveTrain(at);
                    }
                });
                popup.add(new AbstractAction(Bundle.getMessage("MenuAllocateExtra")) {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        //Just brings up the standard allocate extra frame, this could be expanded in the future
                        //As a point and click operation.
                        df.allocateExtraSection(e, at);
                    }
                });
                if (at.getStatus() == jmri.jmrit.dispatcher.ActiveTrain.DONE) {
                    popup.add(new AbstractAction("Restart") {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            at.allocateAFresh();
                        }
                    });
                }
            } else {
                popup.add(new AbstractAction(Bundle.getMessage("MenuNewTrain")) {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        if (!df.getNewTrainActive()) {
                            df.getActiveTrainFrame().initiateTrain(e, re, getBlock());
                            df.setNewTrainActive(true);
                        } else {
                            df.getActiveTrainFrame().showActivateFrame(re);
                        }
                    }
                });
            }
        }
        return true;
    }
    return false;
}
Also used : ActionEvent(java.awt.event.ActionEvent) AbstractAction(javax.swing.AbstractAction) JSeparator(javax.swing.JSeparator) ThrottleFrame(jmri.jmrit.throttle.ThrottleFrame)

Example 5 with ThrottleFrame

use of jmri.jmrit.throttle.ThrottleFrame in project JMRI by JMRI.

the class RosterFrame method showPopup.

protected void showPopup(MouseEvent e) {
    int row = rtable.getTable().rowAtPoint(e.getPoint());
    if (!rtable.getTable().isRowSelected(row)) {
        rtable.getTable().changeSelection(row, 0, false, false);
    }
    JPopupMenu popupMenu = new JPopupMenu();
    JMenuItem menuItem = new JMenuItem(Bundle.getMessage("Program"));
    menuItem.addActionListener((ActionEvent e1) -> {
        startProgrammer(null, re, programmer1);
    });
    if (re == null) {
        menuItem.setEnabled(false);
    }
    popupMenu.add(menuItem);
    ButtonGroup group = new ButtonGroup();
    group.add(contextService);
    group.add(contextOps);
    group.add(contextEdit);
    JMenu progMenu = new JMenu(Bundle.getMessage("ProgrammerType"));
    contextService.addActionListener((ActionEvent e1) -> {
        service.setSelected(true);
        updateProgMode();
    });
    progMenu.add(contextService);
    contextOps.addActionListener((ActionEvent e1) -> {
        ops.setSelected(true);
        updateProgMode();
    });
    progMenu.add(contextOps);
    contextEdit.addActionListener((ActionEvent e1) -> {
        edit.setSelected(true);
        updateProgMode();
    });
    if (service.isSelected()) {
        contextService.setSelected(true);
    } else if (ops.isSelected()) {
        contextOps.setSelected(true);
    } else {
        contextEdit.setSelected(true);
    }
    progMenu.add(contextEdit);
    popupMenu.add(progMenu);
    popupMenu.addSeparator();
    menuItem = new JMenuItem(Bundle.getMessage("LabelsAndMedia"));
    menuItem.addActionListener((ActionEvent e1) -> {
        editMediaButton();
    });
    if (re == null) {
        menuItem.setEnabled(false);
    }
    popupMenu.add(menuItem);
    menuItem = new JMenuItem(Bundle.getMessage("Throttle"));
    menuItem.addActionListener((ActionEvent e1) -> {
        ThrottleFrame tf = ThrottleFrameManager.instance().createThrottleFrame();
        tf.toFront();
        tf.getAddressPanel().getRosterEntrySelector().setSelectedRosterGroup(getSelectedRosterGroup());
        tf.getAddressPanel().setRosterEntry(re);
    });
    if (re == null) {
        menuItem.setEnabled(false);
    }
    popupMenu.add(menuItem);
    popupMenu.addSeparator();
    menuItem = new JMenuItem(Bundle.getMessage("PrintSelection"));
    menuItem.addActionListener((ActionEvent e1) -> {
        printLoco(false);
    });
    if (re == null) {
        menuItem.setEnabled(false);
    }
    popupMenu.add(menuItem);
    menuItem = new JMenuItem(Bundle.getMessage("PreviewSelection"));
    menuItem.addActionListener((ActionEvent e1) -> {
        printLoco(true);
    });
    if (re == null) {
        menuItem.setEnabled(false);
    }
    popupMenu.add(menuItem);
    popupMenu.addSeparator();
    menuItem = new JMenuItem(Bundle.getMessage("Duplicateddd"));
    menuItem.addActionListener((ActionEvent e1) -> {
        copyLoco();
    });
    if (re == null) {
        menuItem.setEnabled(false);
    }
    popupMenu.add(menuItem);
    // NOI18N
    menuItem = new JMenuItem(this.getSelectedRosterGroup() != null ? Bundle.getMessage("DeleteFromGroup") : Bundle.getMessage("DeleteFromRoster"));
    menuItem.addActionListener((ActionEvent e1) -> {
        deleteLoco();
    });
    popupMenu.add(menuItem);
    menuItem.setEnabled(this.getSelectedRosterEntries().length > 0);
    popupMenu.show(e.getComponent(), e.getX(), e.getY());
}
Also used : ButtonGroup(javax.swing.ButtonGroup) ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu) JMenu(javax.swing.JMenu) ThrottleFrame(jmri.jmrit.throttle.ThrottleFrame)

Aggregations

ThrottleFrame (jmri.jmrit.throttle.ThrottleFrame)5 ActionEvent (java.awt.event.ActionEvent)4 AbstractAction (javax.swing.AbstractAction)2 ButtonGroup (javax.swing.ButtonGroup)2 JSeparator (javax.swing.JSeparator)2 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 GridLayout (java.awt.GridLayout)1 Insets (java.awt.Insets)1 BoxLayout (javax.swing.BoxLayout)1 JMenu (javax.swing.JMenu)1 JMenuItem (javax.swing.JMenuItem)1 JPanel (javax.swing.JPanel)1 JPopupMenu (javax.swing.JPopupMenu)1 Consist (jmri.Consist)1 DccLocoAddress (jmri.DccLocoAddress)1