Search in sources :

Example 41 with ChangeListener

use of javax.swing.event.ChangeListener in project jabref by JabRef.

the class DroppedFileHandler method showLinkMoveCopyRenameDialog.

//
// @return true if user pushed "OK", false otherwise
//
private boolean showLinkMoveCopyRenameDialog(String linkFileName, ExternalFileType fileType, BibEntry entry, BibDatabase database) {
    String dialogTitle = Localization.lang("Link to file %0", linkFileName);
    Optional<Path> dir = panel.getBibDatabaseContext().getFirstExistingFileDir(Globals.prefs.getFileDirectoryPreferences());
    if (!dir.isPresent()) {
        destDirLabel.setText(Localization.lang("File directory is not set or does not exist!"));
        copyRadioButton.setEnabled(false);
        moveRadioButton.setEnabled(false);
        renameToTextBox.setEnabled(false);
        renameCheckBox.setEnabled(false);
        linkInPlace.setSelected(true);
    } else {
        destDirLabel.setText(Localization.lang("File directory is '%0':", dir.get().toString()));
        copyRadioButton.setEnabled(true);
        moveRadioButton.setEnabled(true);
        renameToTextBox.setEnabled(true);
        renameCheckBox.setEnabled(true);
    }
    ChangeListener cl = arg0 -> {
        renameCheckBox.setEnabled(!linkInPlace.isSelected());
        renameToTextBox.setEnabled(!linkInPlace.isSelected());
    };
    linkInPlace.setText(Localization.lang("Leave file in its current directory"));
    copyRadioButton.setText(Localization.lang("Copy file to file directory"));
    moveRadioButton.setText(Localization.lang("Move file to file directory"));
    renameCheckBox.setText(Localization.lang("Rename file to").concat(": "));
    LayoutFormatterPreferences layoutPrefs = Globals.prefs.getLayoutFormatterPreferences(Globals.journalAbbreviationLoader);
    // Determine which name to suggest:
    String targetName = FileUtil.createFileNameFromPattern(database, entry, Globals.prefs.get(JabRefPreferences.IMPORT_FILENAMEPATTERN), layoutPrefs);
    String fileDirPattern = Globals.prefs.get(JabRefPreferences.IMPORT_FILEDIRPATTERN);
    String targetDirName = "";
    if (!fileDirPattern.isEmpty()) {
        targetDirName = FileUtil.createFileNameFromPattern(database, entry, fileDirPattern, layoutPrefs);
    }
    if (targetDirName.isEmpty()) {
        renameToTextBox.setText(targetName.concat(".").concat(fileType.getExtension()));
    } else {
        renameToTextBox.setText(targetDirName.concat("/").concat(targetName.concat(".").concat(fileType.getExtension())));
    }
    linkInPlace.setSelected(frame.prefs().getBoolean(JabRefPreferences.DROPPEDFILEHANDLER_LEAVE));
    copyRadioButton.setSelected(frame.prefs().getBoolean(JabRefPreferences.DROPPEDFILEHANDLER_COPY));
    moveRadioButton.setSelected(frame.prefs().getBoolean(JabRefPreferences.DROPPEDFILEHANDLER_MOVE));
    renameCheckBox.setSelected(frame.prefs().getBoolean(JabRefPreferences.DROPPEDFILEHANDLER_RENAME));
    linkInPlace.addChangeListener(cl);
    cl.stateChanged(new ChangeEvent(linkInPlace));
    try {
        Object[] messages = { Localization.lang("How would you like to link to '%0'?", linkFileName), optionsPanel };
        int reply = JOptionPane.showConfirmDialog(frame, messages, dialogTitle, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (reply == JOptionPane.OK_OPTION) {
            // store user's choice
            frame.prefs().putBoolean(JabRefPreferences.DROPPEDFILEHANDLER_LEAVE, linkInPlace.isSelected());
            frame.prefs().putBoolean(JabRefPreferences.DROPPEDFILEHANDLER_COPY, copyRadioButton.isSelected());
            frame.prefs().putBoolean(JabRefPreferences.DROPPEDFILEHANDLER_MOVE, moveRadioButton.isSelected());
            frame.prefs().putBoolean(JabRefPreferences.DROPPEDFILEHANDLER_RENAME, renameCheckBox.isSelected());
            return true;
        } else {
            return false;
        }
    } finally {
        linkInPlace.removeChangeListener(cl);
    }
}
Also used : Path(java.nio.file.Path) NamedCompound(org.jabref.gui.undo.NamedCompound) JTextField(javax.swing.JTextField) FieldName(org.jabref.model.entry.FieldName) BibDatabase(org.jabref.model.database.BibDatabase) JabRefPreferences(org.jabref.preferences.JabRefPreferences) BasePanel(org.jabref.gui.BasePanel) JabRefFrame(org.jabref.gui.JabRefFrame) Localization(org.jabref.logic.l10n.Localization) ChangeListener(javax.swing.event.ChangeListener) BorderLayout(java.awt.BorderLayout) Path(java.nio.file.Path) BoxLayout(javax.swing.BoxLayout) ExternalFileType(org.jabref.gui.externalfiletype.ExternalFileType) ChangeEvent(javax.swing.event.ChangeEvent) FormBuilder(com.jgoodies.forms.builder.FormBuilder) FileUtil(org.jabref.logic.util.io.FileUtil) Files(java.nio.file.Files) ButtonGroup(javax.swing.ButtonGroup) BibEntry(org.jabref.model.entry.BibEntry) UndoableInsertEntry(org.jabref.gui.undo.UndoableInsertEntry) FileListTableModel(org.jabref.gui.filelist.FileListTableModel) IOException(java.io.IOException) LayoutFormatterPreferences(org.jabref.logic.layout.LayoutFormatterPreferences) JOptionPane(javax.swing.JOptionPane) MainTable(org.jabref.gui.maintable.MainTable) IdGenerator(org.jabref.model.entry.IdGenerator) File(java.io.File) JRadioButton(javax.swing.JRadioButton) Globals(org.jabref.Globals) FileListEntry(org.jabref.gui.filelist.FileListEntry) FileHelper(org.jabref.model.util.FileHelper) List(java.util.List) Paths(java.nio.file.Paths) FormLayout(com.jgoodies.forms.layout.FormLayout) JLabel(javax.swing.JLabel) UndoableFieldChange(org.jabref.gui.undo.UndoableFieldChange) JCheckBox(javax.swing.JCheckBox) Optional(java.util.Optional) XMPUtil(org.jabref.logic.xmp.XMPUtil) Log(org.apache.commons.logging.Log) JTextArea(javax.swing.JTextArea) ExternalFileTypes(org.jabref.gui.externalfiletype.ExternalFileTypes) LogFactory(org.apache.commons.logging.LogFactory) JPanel(javax.swing.JPanel) LayoutFormatterPreferences(org.jabref.logic.layout.LayoutFormatterPreferences) ChangeEvent(javax.swing.event.ChangeEvent) ChangeListener(javax.swing.event.ChangeListener)

Example 42 with ChangeListener

use of javax.swing.event.ChangeListener in project JMRI by JMRI.

the class ControlPanel method initGUI.

/**
     * Create, initialize and place GUI components.
     */
private void initGUI() {
    mainPanel = new JPanel();
    this.setContentPane(mainPanel);
    mainPanel.setLayout(new BorderLayout());
    this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    speedControlPanel = new JPanel();
    speedControlPanel.setLayout(new BoxLayout(speedControlPanel, BoxLayout.X_AXIS));
    speedControlPanel.setOpaque(false);
    mainPanel.add(speedControlPanel, BorderLayout.CENTER);
    sliderPanel = new JPanel();
    sliderPanel.setLayout(new GridBagLayout());
    sliderPanel.setOpaque(false);
    speedSlider = new JSlider(0, intSpeedSteps);
    speedSlider.setOpaque(false);
    speedSlider.setValue(0);
    speedSlider.setFocusable(false);
    // add mouse-wheel support
    speedSlider.addMouseWheelListener(new MouseWheelListener() {

        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (e.getWheelRotation() > 0) {
                for (int i = 0; i < e.getScrollAmount(); i++) {
                    decelerate1();
                }
            } else {
                for (int i = 0; i < e.getScrollAmount(); i++) {
                    accelerate1();
                }
            }
        }
    });
    speedSliderContinuous = new JSlider(-intSpeedSteps, intSpeedSteps);
    speedSliderContinuous.setValue(0);
    speedSliderContinuous.setOpaque(false);
    speedSliderContinuous.setFocusable(false);
    // add mouse-wheel support
    speedSliderContinuous.addMouseWheelListener(new MouseWheelListener() {

        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (e.getWheelRotation() > 0) {
                for (int i = 0; i < e.getScrollAmount(); i++) {
                    decelerate1();
                }
            } else {
                for (int i = 0; i < e.getScrollAmount(); i++) {
                    accelerate1();
                }
            }
        }
    });
    speedSpinner = new JSpinner();
    speedSpinnerModel = new SpinnerNumberModel(0, 0, intSpeedSteps, 1);
    speedSpinner.setModel(speedSpinnerModel);
    speedSpinner.setFocusable(false);
    SpeedStep128Button = new JRadioButton(Bundle.getMessage("Button128SS"));
    SpeedStep28Button = new JRadioButton(Bundle.getMessage("Button28SS"));
    SpeedStep27Button = new JRadioButton(Bundle.getMessage("Button27SS"));
    SpeedStep14Button = new JRadioButton(Bundle.getMessage("Button14SS"));
    forwardButton = new JRadioButton();
    if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
        forwardButton.setBorderPainted(false);
        forwardButton.setContentAreaFilled(false);
        forwardButton.setText(null);
        forwardButton.setIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/up-red.png")));
        forwardButton.setSelectedIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/up-green.png")));
        forwardButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
        forwardButton.setToolTipText(Bundle.getMessage("ButtonForward"));
    } else {
        forwardButton.setText(Bundle.getMessage("ButtonForward"));
    }
    reverseButton = new JRadioButton();
    if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
        reverseButton.setBorderPainted(false);
        reverseButton.setContentAreaFilled(false);
        reverseButton.setText(null);
        reverseButton.setIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/down-red.png")));
        reverseButton.setSelectedIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/down-green.png")));
        reverseButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
        reverseButton.setToolTipText(Bundle.getMessage("ButtonReverse"));
    } else {
        reverseButton.setText(Bundle.getMessage("ButtonReverse"));
    }
    propertiesPopup = new JPopupMenu();
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.anchor = GridBagConstraints.CENTER;
    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridheight = 1;
    constraints.gridwidth = 1;
    constraints.ipadx = 0;
    constraints.ipady = 0;
    Insets insets = new Insets(2, 2, 2, 2);
    constraints.insets = insets;
    constraints.weightx = 1;
    constraints.weighty = 1;
    constraints.gridx = 0;
    constraints.gridy = 0;
    sliderPanel.add(speedSlider, constraints);
    //this.getContentPane().add(sliderPanel,BorderLayout.CENTER);
    speedControlPanel.add(sliderPanel);
    speedSlider.setOrientation(JSlider.VERTICAL);
    speedSlider.setMajorTickSpacing(maxSpeed / 2);
    java.util.Hashtable<Integer, JLabel> labelTable = new java.util.Hashtable<Integer, JLabel>();
    labelTable.put(Integer.valueOf(maxSpeed / 2), new JLabel("50%"));
    labelTable.put(Integer.valueOf(maxSpeed), new JLabel("100%"));
    labelTable.put(Integer.valueOf(0), new JLabel(Bundle.getMessage("LabelStop")));
    speedSlider.setLabelTable(labelTable);
    speedSlider.setPaintTicks(true);
    speedSlider.setPaintLabels(true);
    // remove old actions
    speedSlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            if (!internalAdjust) {
                boolean doIt = false;
                if (!speedSlider.getValueIsAdjusting()) {
                    doIt = true;
                    lastTrackedSliderMovementTime = System.currentTimeMillis() - trackSliderMinInterval;
                } else if (trackSlider && System.currentTimeMillis() - lastTrackedSliderMovementTime >= trackSliderMinInterval) {
                    doIt = true;
                    lastTrackedSliderMovementTime = System.currentTimeMillis();
                }
                if (doIt) {
                    float newSpeed = (speedSlider.getValue() / (intSpeedSteps * 1.0f));
                    if (log.isDebugEnabled()) {
                        log.debug("stateChanged: slider pos: " + speedSlider.getValue() + " speed: " + newSpeed);
                    }
                    if (sliderPanel.isVisible() && throttle != null) {
                        throttle.setSpeedSetting(newSpeed);
                    }
                    if (speedSpinner != null) {
                        speedSpinnerModel.setValue(Integer.valueOf(speedSlider.getValue()));
                    }
                    if (speedSliderContinuous != null) {
                        if (forwardButton.isSelected()) {
                            speedSliderContinuous.setValue(((Integer) speedSlider.getValue()).intValue());
                        } else {
                            speedSliderContinuous.setValue(-((Integer) speedSlider.getValue()).intValue());
                        }
                    }
                }
            }
        }
    });
    speedSliderContinuousPanel = new JPanel();
    speedSliderContinuousPanel.setLayout(new GridBagLayout());
    constraints = new GridBagConstraints();
    constraints.anchor = GridBagConstraints.CENTER;
    constraints.fill = GridBagConstraints.BOTH;
    constraints.gridheight = 1;
    constraints.gridwidth = 1;
    constraints.ipadx = 0;
    constraints.ipady = 0;
    insets = new Insets(2, 2, 2, 2);
    constraints.insets = insets;
    constraints.weightx = 1;
    constraints.weighty = 1;
    constraints.gridx = 0;
    constraints.gridy = 0;
    speedSliderContinuousPanel.add(speedSliderContinuous, constraints);
    //this.getContentPane().add(sliderPanel,BorderLayout.CENTER);
    speedControlPanel.add(speedSliderContinuousPanel);
    speedSliderContinuous.setOrientation(JSlider.VERTICAL);
    speedSliderContinuous.setMajorTickSpacing(maxSpeed / 2);
    labelTable = new java.util.Hashtable<Integer, JLabel>();
    labelTable.put(Integer.valueOf(maxSpeed / 2), new JLabel("50%"));
    labelTable.put(Integer.valueOf(maxSpeed), new JLabel("100%"));
    labelTable.put(Integer.valueOf(0), new JLabel(Bundle.getMessage("LabelStop")));
    labelTable.put(Integer.valueOf(-maxSpeed / 2), new JLabel("-50%"));
    labelTable.put(Integer.valueOf(-maxSpeed), new JLabel("-100%"));
    speedSliderContinuous.setLabelTable(labelTable);
    speedSliderContinuous.setPaintTicks(true);
    speedSliderContinuous.setPaintLabels(true);
    // remove old actions
    speedSliderContinuous.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            if (!internalAdjust) {
                boolean doIt = false;
                if (!speedSliderContinuous.getValueIsAdjusting()) {
                    doIt = true;
                    lastTrackedSliderMovementTime = System.currentTimeMillis() - trackSliderMinInterval;
                } else if (trackSlider && System.currentTimeMillis() - lastTrackedSliderMovementTime >= trackSliderMinInterval) {
                    doIt = true;
                    lastTrackedSliderMovementTime = System.currentTimeMillis();
                }
                if (doIt) {
                    float newSpeed = (java.lang.Math.abs(speedSliderContinuous.getValue()) / (intSpeedSteps * 1.0f));
                    boolean newDir = (speedSliderContinuous.getValue() >= 0);
                    if (log.isDebugEnabled()) {
                        log.debug("stateChanged: slider pos: " + speedSliderContinuous.getValue() + " speed: " + newSpeed + " dir: " + newDir);
                    }
                    if (speedSliderContinuousPanel.isVisible() && throttle != null) {
                        throttle.setSpeedSetting(newSpeed);
                        if ((newSpeed > 0) && (newDir != forwardButton.isSelected())) {
                            throttle.setIsForward(newDir);
                        }
                    }
                    if (speedSpinner != null) {
                        speedSpinnerModel.setValue(Integer.valueOf(java.lang.Math.abs(speedSliderContinuous.getValue())));
                    }
                    if (speedSlider != null) {
                        speedSlider.setValue(Integer.valueOf(java.lang.Math.abs(speedSliderContinuous.getValue())));
                    }
                }
            }
        }
    });
    spinnerPanel = new JPanel();
    spinnerPanel.setLayout(new GridBagLayout());
    spinnerPanel.add(speedSpinner, constraints);
    speedControlPanel.add(spinnerPanel);
    // remove old actions
    speedSpinner.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            if (!internalAdjust) {
                //if (!speedSpinner.getValueIsAdjusting())
                //{
                float newSpeed = ((Integer) speedSpinner.getValue()).floatValue() / (intSpeedSteps * 1.0f);
                if (log.isDebugEnabled()) {
                    log.debug("stateChanged: spinner pos: " + speedSpinner.getValue() + " speed: " + newSpeed);
                }
                if (throttle != null) {
                    if (spinnerPanel.isVisible()) {
                        throttle.setSpeedSetting(newSpeed);
                    }
                    speedSlider.setValue(((Integer) speedSpinner.getValue()).intValue());
                    if (speedSliderContinuous != null) {
                        if (forwardButton.isSelected()) {
                            speedSliderContinuous.setValue(((Integer) speedSpinner.getValue()).intValue());
                        } else {
                            speedSliderContinuous.setValue(-((Integer) speedSpinner.getValue()).intValue());
                        }
                    }
                } else {
                    log.warn("no throttle object in stateChanged, ignoring change of speed to " + newSpeed);
                }
            //}
            }
        }
    });
    ButtonGroup speedStepButtons = new ButtonGroup();
    speedStepButtons.add(SpeedStep128Button);
    speedStepButtons.add(SpeedStep28Button);
    speedStepButtons.add(SpeedStep27Button);
    speedStepButtons.add(SpeedStep14Button);
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridy = 1;
    spinnerPanel.add(SpeedStep128Button, constraints);
    constraints.gridy = 2;
    spinnerPanel.add(SpeedStep28Button, constraints);
    constraints.gridy = 3;
    spinnerPanel.add(SpeedStep27Button, constraints);
    constraints.gridy = 4;
    spinnerPanel.add(SpeedStep14Button, constraints);
    SpeedStep14Button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            setSpeedStepsMode(DccThrottle.SpeedStepMode14);
            throttle.setSpeedStepMode(DccThrottle.SpeedStepMode14);
        }
    });
    SpeedStep27Button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            setSpeedStepsMode(DccThrottle.SpeedStepMode27);
            throttle.setSpeedStepMode(DccThrottle.SpeedStepMode27);
        }
    });
    SpeedStep28Button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            setSpeedStepsMode(DccThrottle.SpeedStepMode28);
            throttle.setSpeedStepMode(DccThrottle.SpeedStepMode28);
        }
    });
    SpeedStep128Button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            setSpeedStepsMode(DccThrottle.SpeedStepMode128);
            throttle.setSpeedStepMode(DccThrottle.SpeedStepMode128);
        }
    });
    buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridBagLayout());
    mainPanel.add(buttonPanel, BorderLayout.SOUTH);
    ButtonGroup directionButtons = new ButtonGroup();
    directionButtons.add(forwardButton);
    directionButtons.add(reverseButton);
    constraints.fill = GridBagConstraints.NONE;
    constraints.gridy = 1;
    if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
        constraints.gridx = 3;
    }
    buttonPanel.add(forwardButton, constraints);
    if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
        constraints.gridx = 1;
    } else {
        constraints.gridy = 2;
    }
    buttonPanel.add(reverseButton, constraints);
    if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
        constraints.gridx = 2;
    }
    forwardButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            throttle.setIsForward(true);
            if (speedSliderContinuous != null) {
                speedSliderContinuous.setValue(java.lang.Math.abs(speedSliderContinuous.getValue()));
            }
        }
    });
    reverseButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            throttle.setIsForward(false);
            if (speedSliderContinuous != null) {
                speedSliderContinuous.setValue(-java.lang.Math.abs(speedSliderContinuous.getValue()));
            }
        }
    });
    stopButton = new JButton();
    if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
        stopButton.setBorderPainted(false);
        stopButton.setContentAreaFilled(false);
        stopButton.setText(null);
        stopButton.setIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/estop.png")));
        stopButton.setPressedIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/estop24.png")));
        stopButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
        stopButton.setToolTipText(Bundle.getMessage("ButtonEStop"));
    } else {
        stopButton.setText(Bundle.getMessage("ButtonEStop"));
    }
    constraints.gridy = 4;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    buttonPanel.add(stopButton, constraints);
    stopButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            stop();
        }
    });
    stopButton.addMouseListener(new MouseListener() {

        @Override
        public void mousePressed(MouseEvent e) {
            stop();
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseClicked(MouseEvent e) {
        }
    });
    idleButton = new JButton();
    if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
        idleButton.setBorderPainted(false);
        idleButton.setContentAreaFilled(false);
        idleButton.setText(null);
        idleButton.setIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/stop.png")));
        idleButton.setPressedIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/stop24.png")));
        idleButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
        idleButton.setToolTipText(Bundle.getMessage("ButtonIdle"));
    } else {
        idleButton.setText(Bundle.getMessage("ButtonIdle"));
    }
    if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
        constraints.gridy = 1;
    } else {
        constraints.gridy = 3;
    }
    buttonPanel.add(idleButton, constraints);
    idleButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            speedSlider.setValue(0);
            if (speedSpinner != null) {
                speedSpinner.setValue(Integer.valueOf(0));
            }
            if (speedSliderContinuous != null) {
                speedSliderContinuous.setValue(Integer.valueOf(0));
            }
            throttle.setSpeedSetting(0);
        }
    });
    addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            changeOrientation();
        }
    });
    JMenuItem propertiesItem = new JMenuItem(Bundle.getMessage("ControlPanelProperties"));
    propertiesItem.addActionListener(this);
    propertiesPopup.add(propertiesItem);
    // Add a mouse listener all components to trigger the popup menu.
    MouseInputAdapter popupListener = new PopupListener(propertiesPopup, this);
    MouseInputAdapterInstaller.installMouseInputAdapterOnAllComponents(popupListener, this);
    // Install the Key bindings on all Components
    KeyListenerInstaller.installKeyListenerOnAllComponents(new ControlPadKeyListener(), this);
    // set by default which speed selection method is on top
    setSpeedController(_displaySlider);
}
Also used : JPanel(javax.swing.JPanel) ImageIcon(javax.swing.ImageIcon) GridBagConstraints(java.awt.GridBagConstraints) JRadioButton(javax.swing.JRadioButton) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) MouseWheelListener(java.awt.event.MouseWheelListener) SpinnerNumberModel(javax.swing.SpinnerNumberModel) MouseListener(java.awt.event.MouseListener) BorderLayout(java.awt.BorderLayout) JSlider(javax.swing.JSlider) ChangeListener(javax.swing.event.ChangeListener) JMenuItem(javax.swing.JMenuItem) ComponentAdapter(java.awt.event.ComponentAdapter) MouseEvent(java.awt.event.MouseEvent) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) JPopupMenu(javax.swing.JPopupMenu) MouseWheelEvent(java.awt.event.MouseWheelEvent) ChangeEvent(javax.swing.event.ChangeEvent) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) JSpinner(javax.swing.JSpinner) ComponentEvent(java.awt.event.ComponentEvent) MouseInputAdapter(javax.swing.event.MouseInputAdapter)

Example 43 with ChangeListener

use of javax.swing.event.ChangeListener in project JMRI by JMRI.

the class DieselPane method initComponents.

@Override
public void initComponents() {
    listenerList = new javax.swing.event.EventListenerList();
    this.setLayout(new GridLayout(2, 0));
    //Setup the throttle slider.
    throttle_slider = new JSlider(JSlider.HORIZONTAL, THROTTLE_MIN, THROTTLE_MAX, THROTTLE_INIT);
    throttle_slider.setMajorTickSpacing(1);
    throttle_slider.setPaintTicks(true);
    throttle_slider.setMinimumSize(new Dimension(400, 0));
    throttle_slider.setSnapToTicks(true);
    throttle_slider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            throttleChange(e);
        }
    });
    this.add(throttle_slider);
    // Setup the start button
    start_button = new JToggleButton();
    start_button.setText("Engine Start");
    start_button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            startButtonChange(e);
        }
    });
    this.add(start_button);
    throttle_slider.setVisible(true);
    start_button.setVisible(true);
    this.setVisible(true);
    this.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
}
Also used : GridLayout(java.awt.GridLayout) ChangeEvent(javax.swing.event.ChangeEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) JToggleButton(javax.swing.JToggleButton) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JSlider(javax.swing.JSlider) ChangeListener(javax.swing.event.ChangeListener) Dimension(java.awt.Dimension)

Example 44 with ChangeListener

use of javax.swing.event.ChangeListener in project JMRI by JMRI.

the class ConfigBaseStationFrame method initGui.

private void initGui() {
    // NOTE: Look at jmri.jmrit.vsdecoder.swing.ManageLocationsFrame
    // for how to add a tab for turnouts and other things.
    this.setTitle(Bundle.getMessage("FieldManageBaseStationFrameTitle"));
    this.buildMenu();
    // Panel for managing sensors
    sensorPanel = new JPanel();
    sensorPanel.setLayout(new GridBagLayout());
    JButton addButton = new JButton(Bundle.getMessage("ButtonAddSensor"));
    addButton.setToolTipText(Bundle.getMessage("ToolTipButtonMSFAdd"));
    // NOI18N
    addButton.setMnemonic(Mnemonics.get("AddButton"));
    addButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            addButtonPressed(e);
        }
    });
    JButton closeButton = new JButton(Bundle.getMessage("ButtonClose"));
    closeButton.setToolTipText(Bundle.getMessage("ToolTipButtonMSFClose"));
    // NOI18N
    closeButton.setMnemonic(Mnemonics.get("CloseButton"));
    closeButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            closeButtonPressed(e);
        }
    });
    JButton saveButton = new JButton(Bundle.getMessage("ButtonSaveSensors"));
    saveButton.setToolTipText(Bundle.getMessage("ToolTipButtonMSFSave"));
    // NOI18N
    saveButton.setMnemonic(Mnemonics.get("SaveButton"));
    saveButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            saveButtonPressed(e);
        }
    });
    JScrollPane sensorScrollPanel = new JScrollPane();
    sensorModel = new SensorTableModel();
    sensorTable = new JTable(sensorModel);
    sensorTable.setFillsViewportHeight(true);
    sensorScrollPanel.getViewport().add(sensorTable);
    sensorTable.setPreferredScrollableViewportSize(new Dimension(520, 200));
    sensorTable.getColumn(Bundle.getMessage("FieldTableDeleteColumn")).setCellRenderer(new ButtonRenderer());
    sensorTable.removeColumn(sensorTable.getColumn("isNew"));
    sensorTable.removeColumn(sensorTable.getColumn("isDirty"));
    sensorTable.removeColumn(sensorTable.getColumn("isDelete"));
    sensorTable.addMouseListener(new java.awt.event.MouseAdapter() {

        @Override
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            handleTableMouseClick(sensorTable, evt);
        }
    });
    sensorTable.setAutoCreateRowSorter(true);
    sensorSorter = new TableRowSorter<>(sensorTable.getModel());
    sensorTable.setRowSorter(sensorSorter);
    List<RowSorter.SortKey> sensorSortKeys = new ArrayList<>();
    //int columnIndexToSort = 1;
    sensorSortKeys.add(new RowSorter.SortKey(sensorTable.getColumn(Bundle.getMessage("FieldTableIndexColumn")).getModelIndex(), SortOrder.ASCENDING));
    sensorSorter.setSortKeys(sensorSortKeys);
    sensorSorter.sort();
    sensorSorter.setSortable(sensorTable.getColumn(Bundle.getMessage("FieldTableDeleteColumn")).getModelIndex(), false);
    JScrollPane turnoutScrollPanel = new JScrollPane();
    turnoutModel = new TurnoutTableModel();
    turnoutTable = new JTable(turnoutModel);
    turnoutTable.setFillsViewportHeight(true);
    turnoutScrollPanel.getViewport().add(turnoutTable);
    turnoutTable.setPreferredScrollableViewportSize(new Dimension(520, 200));
    turnoutTable.getColumn(Bundle.getMessage("FieldTableDeleteColumn")).setCellRenderer(new ButtonRenderer());
    turnoutTable.removeColumn(turnoutTable.getColumn("isNew"));
    turnoutTable.removeColumn(turnoutTable.getColumn("isDirty"));
    turnoutTable.removeColumn(turnoutTable.getColumn("isDelete"));
    turnoutTable.addMouseListener(new java.awt.event.MouseAdapter() {

        @Override
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            handleTableMouseClick(turnoutTable, evt);
        }
    });
    turnoutTable.setAutoCreateRowSorter(true);
    turnoutSorter = new TableRowSorter<>(turnoutTable.getModel());
    turnoutTable.setRowSorter(turnoutSorter);
    List<RowSorter.SortKey> turnoutSortKeys = new ArrayList<>();
    //int columnIndexToSort = 1;
    turnoutSortKeys.add(new RowSorter.SortKey(sensorTable.getColumn(Bundle.getMessage("FieldTableIndexColumn")).getModelIndex(), SortOrder.ASCENDING));
    turnoutSorter.setSortKeys(turnoutSortKeys);
    turnoutSorter.setSortable(sensorTable.getColumn(Bundle.getMessage("FieldTableDeleteColumn")).getModelIndex(), false);
    turnoutSorter.sort();
    JScrollPane outputScrollPanel = new JScrollPane();
    outputModel = new OutputTableModel();
    outputTable = new JTable(outputModel);
    outputTable.setFillsViewportHeight(true);
    outputScrollPanel.getViewport().add(outputTable);
    outputTable.setPreferredScrollableViewportSize(new Dimension(520, 200));
    outputTable.getColumn(Bundle.getMessage("FieldTableDeleteColumn")).setCellRenderer(new ButtonRenderer());
    outputTable.removeColumn(outputTable.getColumn("isNew"));
    outputTable.removeColumn(outputTable.getColumn("isDirty"));
    outputTable.removeColumn(outputTable.getColumn("isDelete"));
    outputTable.addMouseListener(new java.awt.event.MouseAdapter() {

        @Override
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            handleTableMouseClick(outputTable, evt);
        }
    });
    outputTable.setAutoCreateRowSorter(true);
    outputSorter = new TableRowSorter<>(outputTable.getModel());
    outputTable.setRowSorter(outputSorter);
    List<RowSorter.SortKey> outputSortKeys = new ArrayList<>();
    //int columnIndexToSort = 1;
    outputSortKeys.add(new RowSorter.SortKey(sensorTable.getColumn(Bundle.getMessage("FieldTableIndexColumn")).getModelIndex(), SortOrder.ASCENDING));
    outputSorter.setSortKeys(outputSortKeys);
    outputSorter.setSortable(sensorTable.getColumn(Bundle.getMessage("FieldTableDeleteColumn")).getModelIndex(), false);
    outputSorter.sort();
    tabbedPane = new JTabbedPane();
    tabbedPane.addTab(Bundle.getMessage("FieldSensorsTabTitle"), sensorScrollPanel);
    tabbedPane.setToolTipTextAt(0, Bundle.getMessage("ToolTipSensorTab"));
    // NOI18N
    tabbedPane.setMnemonicAt(0, Mnemonics.get("SensorTab"));
    tabbedPane.addTab(Bundle.getMessage("FieldTurnoutsTabTitle"), turnoutScrollPanel);
    tabbedPane.setToolTipTextAt(0, Bundle.getMessage("ToolTipTurnoutTab"));
    // NOI18N
    tabbedPane.setMnemonicAt(0, Mnemonics.get("TurnoutTab"));
    tabbedPane.addTab(Bundle.getMessage("FieldOutputsTabTitle"), outputScrollPanel);
    tabbedPane.setToolTipTextAt(0, Bundle.getMessage("ToolTipOutputTab"));
    // NOI18N
    tabbedPane.setMnemonicAt(0, Mnemonics.get("OutputTab"));
    cTab = CurrentTab.SENSOR;
    tabbedPane.setSelectedIndex(0);
    tabbedPane.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            switch(tabbedPane.getSelectedIndex()) {
                case 2:
                    // Set Add to "Add Output"
                    cTab = CurrentTab.OUTPUT;
                    addButton.setText(Bundle.getMessage("ButtonAddOutput"));
                    saveButton.setText(Bundle.getMessage("ButtonSaveOutputs"));
                    log.debug("Current Tab is: {}", tabbedPane.getSelectedIndex());
                    break;
                case 1:
                    // Set Add to "Add Turnout"
                    cTab = CurrentTab.TURNOUT;
                    addButton.setText(Bundle.getMessage("ButtonAddTurnout"));
                    saveButton.setText(Bundle.getMessage("ButtonSaveTurnouts"));
                    log.debug("Current Tab is: {}", tabbedPane.getSelectedIndex());
                    break;
                case 0:
                default:
                    // Set Add to "Add Sensor"
                    cTab = CurrentTab.SENSOR;
                    addButton.setText(Bundle.getMessage("ButtonAddSensor"));
                    saveButton.setText(Bundle.getMessage("ButtonSaveSensors"));
                    log.debug("Current Tab is: {}", tabbedPane.getSelectedIndex());
            }
        }
    });
    JPanel buttonPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
    JPanel buttonPane2 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    buttonPane.add(addButton);
    buttonPane.add(saveButton);
    buttonPane2.add(closeButton);
    this.getContentPane().setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS));
    this.getContentPane().add(tabbedPane);
    this.getContentPane().add(buttonPane);
    this.getContentPane().add(buttonPane2);
    this.pack();
    this.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JTabbedPane(javax.swing.JTabbedPane) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) ArrayList(java.util.ArrayList) ChangeListener(javax.swing.event.ChangeListener) JScrollPane(javax.swing.JScrollPane) RowSorter(javax.swing.RowSorter) TableRowSorter(javax.swing.table.TableRowSorter) Dimension(java.awt.Dimension) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) JTable(javax.swing.JTable)

Example 45 with ChangeListener

use of javax.swing.event.ChangeListener in project JMRI by JMRI.

the class MemoryIconCoordinateEdit method initSetXY.

@Override
public void initSetXY() {
    oldX = pl.getOriginalX();
    oldY = pl.getOriginalY();
    textX = new javax.swing.JLabel();
    textX.setText("X: " + pl.getOriginalX());
    textX.setVisible(true);
    textY = new javax.swing.JLabel();
    textY.setText("Y: " + pl.getOriginalY());
    textY.setVisible(true);
    SpinnerNumberModel model = new SpinnerNumberModel(0, 0, 10000, 1);
    ChangeListener listener = new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            int x = ((Number) spinX.getValue()).intValue();
            int y = ((Number) spinY.getValue()).intValue();
            pl.setLocation(x, y);
            textX.setText(" X: " + pl.getOriginalX());
            textY.setText(" Y: " + pl.getOriginalY());
        }
    };
    spinX = new javax.swing.JSpinner(model);
    spinX.setValue(Integer.valueOf(pl.getOriginalX()));
    spinX.setToolTipText(Bundle.getMessage("EnterXcoord"));
    spinX.setMaximumSize(new Dimension(spinX.getMaximumSize().width, spinX.getPreferredSize().height));
    spinX.addChangeListener(listener);
    model = new javax.swing.SpinnerNumberModel(0, 0, 10000, 1);
    spinY = new javax.swing.JSpinner(model);
    spinY.setValue(Integer.valueOf(pl.getOriginalY()));
    spinY.setToolTipText(Bundle.getMessage("EnterYcoord"));
    spinY.setMaximumSize(new Dimension(spinY.getMaximumSize().width, spinY.getPreferredSize().height));
    spinY.addChangeListener(listener);
    getContentPane().setLayout(new GridBagLayout());
    addSpinItems(true);
    okButton.addActionListener(new java.awt.event.ActionListener() {

        @Override
        public void actionPerformed(java.awt.event.ActionEvent e) {
            int x = ((Number) spinX.getValue()).intValue();
            int y = ((Number) spinY.getValue()).intValue();
            pl.setLocation(x, y);
            textX.setText(" X: " + pl.getOriginalX());
            textY.setText(" Y: " + pl.getOriginalY());
            dispose();
        }
    });
    okButton.getRootPane().setDefaultButton(okButton);
    cancelButton.addActionListener(new java.awt.event.ActionListener() {

        @Override
        public void actionPerformed(java.awt.event.ActionEvent e) {
            pl.setLocation(oldX, oldY);
            dispose();
        }
    });
    // make large enough to easily move
    setMinimumSize(new Dimension(250, 175));
    pack();
}
Also used : GridBagLayout(java.awt.GridBagLayout) SpinnerNumberModel(javax.swing.SpinnerNumberModel) Dimension(java.awt.Dimension) ActionEvent(java.awt.event.ActionEvent) SpinnerNumberModel(javax.swing.SpinnerNumberModel) ChangeEvent(javax.swing.event.ChangeEvent) ChangeListener(javax.swing.event.ChangeListener)

Aggregations

ChangeListener (javax.swing.event.ChangeListener)472 ChangeEvent (javax.swing.event.ChangeEvent)449 ActionEvent (java.awt.event.ActionEvent)170 ActionListener (java.awt.event.ActionListener)164 Dimension (java.awt.Dimension)160 JPanel (javax.swing.JPanel)136 Point (java.awt.Point)108 JLabel (javax.swing.JLabel)98 JSlider (javax.swing.JSlider)69 JButton (javax.swing.JButton)66 JCheckBox (javax.swing.JCheckBox)55 MouseEvent (java.awt.event.MouseEvent)47 BorderLayout (java.awt.BorderLayout)46 GridBagConstraints (java.awt.GridBagConstraints)42 GridBagLayout (java.awt.GridBagLayout)39 MouseAdapter (java.awt.event.MouseAdapter)39 Insets (java.awt.Insets)37 PropertyChangeListener (java.beans.PropertyChangeListener)35 PropertyChangeEvent (java.beans.PropertyChangeEvent)34 ItemEvent (java.awt.event.ItemEvent)33