Search in sources :

Example 1 with MouseWheelEvent

use of java.awt.event.MouseWheelEvent in project graphhopper by graphhopper.

the class MiniGraphUI method visualize.

public void visualize() {
    try {
        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                int frameHeight = 800;
                int frameWidth = 1200;
                JFrame frame = new JFrame("GraphHopper UI - Small&Ugly ;)");
                frame.setLayout(new BorderLayout());
                frame.add(mainPanel, BorderLayout.CENTER);
                frame.add(infoPanel, BorderLayout.NORTH);
                infoPanel.setPreferredSize(new Dimension(300, 100));
                // scale
                mainPanel.addMouseWheelListener(new MouseWheelListener() {

                    @Override
                    public void mouseWheelMoved(MouseWheelEvent e) {
                        mg.scale(e.getX(), e.getY(), e.getWheelRotation() < 0);
                        repaintRoads();
                    }
                });
                // listener to investigate findID behavior
                //                    MouseAdapter ml = new MouseAdapter() {
                //
                //                        @Override public void mouseClicked(MouseEvent e) {
                //                            findIDLat = mg.getLat(e.getY());
                //                            findIDLon = mg.getLon(e.getX());
                //                            findIdLayer.repaint();
                //                            mainPanel.repaint();
                //                        }
                //
                //                        @Override public void mouseMoved(MouseEvent e) {
                //                            updateLatLon(e);
                //                        }
                //
                //                        @Override public void mousePressed(MouseEvent e) {
                //                            updateLatLon(e);
                //                        }
                //                    };
                MouseAdapter ml = new MouseAdapter() {

                    // for routing:
                    double fromLat, fromLon;

                    boolean fromDone = false;

                    boolean dragging = false;

                    @Override
                    public void mouseClicked(MouseEvent e) {
                        if (!fromDone) {
                            fromLat = mg.getLat(e.getY());
                            fromLon = mg.getLon(e.getX());
                        } else {
                            double toLat = mg.getLat(e.getY());
                            double toLon = mg.getLon(e.getX());
                            StopWatch sw = new StopWatch().start();
                            logger.info("start searching from " + fromLat + "," + fromLon + " to " + toLat + "," + toLon);
                            // get from and to node id
                            fromRes = index.findClosest(fromLat, fromLon, EdgeFilter.ALL_EDGES);
                            toRes = index.findClosest(toLat, toLon, EdgeFilter.ALL_EDGES);
                            logger.info("found ids " + fromRes + " -> " + toRes + " in " + sw.stop().getSeconds() + "s");
                            repaintPaths();
                        }
                        fromDone = !fromDone;
                    }

                    @Override
                    public void mouseDragged(MouseEvent e) {
                        dragging = true;
                        fastPaint = true;
                        update(e);
                        updateLatLon(e);
                    }

                    @Override
                    public void mouseReleased(MouseEvent e) {
                        if (dragging) {
                            // update only if mouse release comes from dragging! (at the moment equal to fastPaint)
                            dragging = false;
                            fastPaint = false;
                            update(e);
                        }
                    }

                    public void update(MouseEvent e) {
                        mg.setNewOffset(e.getX() - currentPosX, e.getY() - currentPosY);
                        repaintRoads();
                    }

                    @Override
                    public void mouseMoved(MouseEvent e) {
                        updateLatLon(e);
                    }

                    @Override
                    public void mousePressed(MouseEvent e) {
                        updateLatLon(e);
                    }
                };
                mainPanel.addMouseListener(ml);
                mainPanel.addMouseMotionListener(ml);
                // just for fun
                //                    mainPanel.getInputMap().put(KeyStroke.getKeyStroke("DELETE"), "removedNodes");
                //                    mainPanel.getActionMap().put("removedNodes", new AbstractAction() {
                //                        @Override public void actionPerformed(ActionEvent e) {
                //                            int counter = 0;
                //                            for (CoordTrig<Long> coord : quadTreeNodes) {
                //                                int ret = quadTree.remove(coord.lat, coord.lon);
                //                                if (ret < 1) {
                ////                                    logger.info("cannot remove " + coord + " " + ret);
                ////                                    ret = quadTree.remove(coord.getLatitude(), coord.getLongitude());
                //                                } else
                //                                    counter += ret;
                //                            }
                //                            logger.info("Removed " + counter + " of " + quadTreeNodes.size() + " nodes");
                //                        }
                //                    });
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setSize(frameWidth + 10, frameHeight + 30);
                frame.setVisible(true);
            }
        });
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) MouseWheelListener(java.awt.event.MouseWheelListener) MouseWheelEvent(java.awt.event.MouseWheelEvent)

Example 2 with MouseWheelEvent

use of java.awt.event.MouseWheelEvent in project jdk8u_jdk by JetBrains.

the class bug7170657 method main.

public static void main(final String[] args) {
    final int mask = InputEvent.META_DOWN_MASK | InputEvent.CTRL_MASK;
    Frame f = new Frame();
    MouseEvent mwe = new MouseWheelEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true, 1, 1, 1);
    MouseEvent mdme = new MenuDragMouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true, null, null);
    MouseEvent me = new MouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true, MouseEvent.NOBUTTON);
    test(f, mwe);
    test(f, mdme);
    test(f, me);
    if (FAILED) {
        throw new RuntimeException("Wrong mouse event");
    }
}
Also used : Frame(java.awt.Frame) MenuDragMouseEvent(javax.swing.event.MenuDragMouseEvent) MouseEvent(java.awt.event.MouseEvent) MouseWheelEvent(java.awt.event.MouseWheelEvent) MenuDragMouseEvent(javax.swing.event.MenuDragMouseEvent)

Example 3 with MouseWheelEvent

use of java.awt.event.MouseWheelEvent 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 4 with MouseWheelEvent

use of java.awt.event.MouseWheelEvent in project OpenNotebook by jaltekruse.

the class StringAdjustmentPanel method addPanelContent.

@Override
public void addPanelContent() {
    // to prevent the panel from looking too small, estimate the amount of lines needed to
    // show all of the text
    int numLines = 0;
    if (getGraphics() != null) {
        // one of these panels is constructed in the background to initialize some resources
        // at that time there is no graphics object to reference to measure text 
        numLines = getGraphics().getFontMetrics().stringWidth(mAtt.getValue()) / 120;
    } else {
        numLines = mAtt.getValue().length() / 20;
    }
    if (numLines < 2) {
        numLines = 2;
    }
    textArea = new JTextArea(numLines, 12);
    textArea.setEditable(true);
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    textArea.setText(mAtt.getValue());
    textArea.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent arg0) {
        }

        @Override
        public void focusLost(FocusEvent arg0) {
            applyPanelValueToObject();
        }
    });
    // need to decide if having this panel set with the enter key is worth
    // not being able to include line breaks
    textArea.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent ev) {
            if (ev.getKeyCode() == KeyEvent.VK_ENTER) {
                applyPanelValueToObject();
                enterJustPressed = true;
            }
        }

        @Override
        public void keyReleased(KeyEvent arg0) {
            if (arg0.getKeyCode() == KeyEvent.VK_ENTER && enterJustPressed) {
                // had issue with hitting enter to confirm dialog, dialog disappeared but enter key release event
                // was still received here if an object was selected, hence the boolean set in the keypressed
                // method and checked here
                String s = textArea.getText();
                int caretPos = textArea.getCaretPosition() - 1;
                s = s.substring(0, textArea.getCaretPosition() - 1) + s.substring(textArea.getCaretPosition());
                textArea.setText(s);
                textArea.setCaretPosition(caretPos);
                enterJustPressed = false;
            }
        }

        @Override
        public void keyTyped(KeyEvent arg0) {
        }
    });
    setLayout(new GridBagLayout());
    GridBagConstraints con = new GridBagConstraints();
    con.fill = GridBagConstraints.HORIZONTAL;
    con.weightx = .5;
    con.gridx = 0;
    con.gridwidth = 1;
    con.gridy = 0;
    con.insets = new Insets(2, 5, 0, 5);
    add(new JLabel(mAtt.getName()), con);
    JButton keyboard = new JButton(ObjectPropertiesFrame.SMALL_KEYBOARD_IMAGE);
    keyboard.setToolTipText("Show On-Screen Keyboard");
    keyboard.setMargin(new Insets(3, 3, 3, 3));
    keyboard.setFocusable(false);
    con.insets = new Insets(2, 2, 2, 2);
    con.gridx = 1;
    con.weightx = .1;
    con.weighty = .1;
    con.gridheight = 1;
    add(keyboard, con);
    keyboard.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            notebookPanel.getCurrentDocViewer().setOnScreenKeyBoardVisible(true);
        }
    });
    JButton applyChanges = new JButton("Apply");
    applyChanges.setToolTipText("Value can also be applied by hitting Enter");
    applyChanges.setMargin(new Insets(5, 3, 5, 3));
    applyChanges.setFocusable(false);
    con.gridx = 2;
    con.weightx = .1;
    con.weighty = .1;
    con.gridheight = 1;
    add(applyChanges, con);
    applyChanges.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            applyPanelValueToObject();
        }
    });
    con.fill = GridBagConstraints.BOTH;
    con.weightx = 1;
    con.weighty = 1;
    con.gridwidth = 3;
    con.gridy = 1;
    con.gridx = 0;
    con.gridheight = 3;
    scrollPane = new JScrollPane(textArea);
    scrollPane.setWheelScrollingEnabled(false);
    con.insets = new Insets(0, 5, 2, 0);
    add(scrollPane, con);
    scrollPane.addMouseWheelListener(new MouseWheelListener() {

        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            Point componentPoint = SwingUtilities.convertPoint(scrollPane, e.getPoint(), parentPanel);
            parentPanel.dispatchEvent(new MouseWheelEvent(parentPanel, e.getID(), e.getWhen(), e.getModifiers(), componentPoint.x, componentPoint.y, e.getClickCount(), e.isPopupTrigger(), e.getScrollType(), e.getScrollAmount(), e.getWheelRotation()));
        }
    });
}
Also used : JScrollPane(javax.swing.JScrollPane) GridBagConstraints(java.awt.GridBagConstraints) JTextArea(javax.swing.JTextArea) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) MouseWheelListener(java.awt.event.MouseWheelListener) Point(java.awt.Point) FocusEvent(java.awt.event.FocusEvent) Point(java.awt.Point) KeyEvent(java.awt.event.KeyEvent) ActionListener(java.awt.event.ActionListener) MouseWheelEvent(java.awt.event.MouseWheelEvent) KeyListener(java.awt.event.KeyListener) FocusListener(java.awt.event.FocusListener)

Example 5 with MouseWheelEvent

use of java.awt.event.MouseWheelEvent in project intellij-community by JetBrains.

the class ConsoleViewImpl method initConsoleEditor.

private void initConsoleEditor() {
    myEditor = createConsoleEditor();
    registerConsoleEditorActions();
    myEditor.getScrollPane().setBorder(null);
    MouseAdapter mouseListener = new MouseAdapter() {

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

        @Override
        public void mouseDragged(MouseEvent e) {
            updateStickToEndState(false);
        }

        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            updateStickToEndState(false);
        }
    };
    myEditor.getScrollPane().addMouseWheelListener(mouseListener);
    myEditor.getScrollPane().getVerticalScrollBar().addMouseListener(mouseListener);
    myEditor.getScrollPane().getVerticalScrollBar().addMouseMotionListener(mouseListener);
    myHyperlinks = new EditorHyperlinkSupport(myEditor, myProject);
    myEditor.getScrollingModel().addVisibleAreaListener(e -> {
        Rectangle oldR = e.getOldRectangle();
        if (oldR != null && oldR.height <= 0 && e.getNewRectangle().height > 0 && isStickingToEnd()) {
            scrollToEnd();
        }
    });
}
Also used : EditorMouseEvent(com.intellij.openapi.editor.event.EditorMouseEvent) MouseEvent(java.awt.event.MouseEvent) MouseWheelEvent(java.awt.event.MouseWheelEvent) MouseAdapter(java.awt.event.MouseAdapter)

Aggregations

MouseWheelEvent (java.awt.event.MouseWheelEvent)6 MouseEvent (java.awt.event.MouseEvent)5 MouseWheelListener (java.awt.event.MouseWheelListener)3 GridBagConstraints (java.awt.GridBagConstraints)2 GridBagLayout (java.awt.GridBagLayout)2 Insets (java.awt.Insets)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 MouseAdapter (java.awt.event.MouseAdapter)2 JButton (javax.swing.JButton)2 JLabel (javax.swing.JLabel)2 DarculaLookAndFeelInfo (com.intellij.ide.ui.laf.darcula.DarculaLookAndFeelInfo)1 EditorMouseEvent (com.intellij.openapi.editor.event.EditorMouseEvent)1 BorderLayout (java.awt.BorderLayout)1 Dimension (java.awt.Dimension)1 Frame (java.awt.Frame)1 Point (java.awt.Point)1 ComponentAdapter (java.awt.event.ComponentAdapter)1 ComponentEvent (java.awt.event.ComponentEvent)1 FocusEvent (java.awt.event.FocusEvent)1