Example usage for java.awt.event MouseWheelEvent getWheelRotation

List of usage examples for java.awt.event MouseWheelEvent getWheelRotation

Introduction

In this page you can find the example usage for java.awt.event MouseWheelEvent getWheelRotation.

Prototype

public int getWheelRotation() 

Source Link

Document

Returns the number of "clicks" the mouse wheel was rotated, as an integer.

Usage

From source file:savant.view.swing.GraphPane.java

/**
 * {@inheritDoc}//w w w  . j  av  a2  s. c o m
 */
@Override
public void mouseWheelMoved(MouseWheelEvent e) {

    int notches = e.getWheelRotation();
    LocationController lc = LocationController.getInstance();

    if (MiscUtils.MAC && e.isMetaDown() || e.isControlDown()) {
        if (notches < 0) {
            lc.shiftRangeLeft();
        } else {
            lc.shiftRangeRight();
        }
    } else {
        if (InterfaceSettings.doesWheelZoom()) {
            if (notches < 0) {
                lc.zoomInOnMouse();
            } else {
                lc.zoomOutFromMouse();
            }
        } else {
            JScrollBar sb = getVerticalScrollBar();
            if (sb.isVisible()) {
                sb.setValue(sb.getValue() + notches * 15);
            }
        }
    }
}

From source file:view.WorkspacePanel.java

/**
 * Creates new form MiddlePanel//from  w ww. ja  va2s .  c  om
 */
public WorkspacePanel() {
    initComponents();
    if (Bundle.getBundle().getCurrentLocale() == null) {
        Bundle.getBundle().setCurrentLocale(Bundle.Locales.English);
    }
    updateText();
    status = Status.READY;
    cl = (CardLayout) this.rightPanel.getLayout();
    topToolbar.setVisible(false);
    bottomToolbar.setVisible(false);
    rightPanel.setVisible(false);
    clSign.setVisible(false);
    rightPanel.setBackground(Color.WHITE);
    lblText.setVisible(false);
    jScrollPane1.setVisible(false);
    btnChangeAppearance.setVisible(false);
    add(jMenuBar1, BorderLayout.NORTH);
    ToolTipManager.sharedInstance().registerComponent(jtValidation);
    jSplitPane1.setDividerSize(0);
    cbVisibleSignature.setSelected(true);
    lblRevision.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
    clearSignatureFields();
    jsImagePanel.addMouseWheelListener(new MouseWheelListener() {

        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (e.isControlDown()) {
                e.consume();
                if (e.getWheelRotation() < 0) {
                    zoomIn();
                } else {
                    zoomOut();
                }
                fixTempSignaturePosition(true);
            }
        }
    });
}

From source file:xtrememp.XtremeMP.java

protected void createPanels() {
    JPanel framePanel = new JPanel(new MigLayout("fill"));

    mainPanel = new JPanel(new CardLayout());
    playlistManager = new PlaylistManager(this);
    visualizationManager = new VisualizationManager(audioPlayer.getDSS());
    if (Settings.getLastView().equals(Utilities.VISUALIZATION_PANEL)) {
        visualizationManager.setDssEnabled(true);
        mainPanel.add(visualizationManager, Utilities.VISUALIZATION_PANEL);
        mainPanel.add(playlistManager, Utilities.PLAYLIST_MANAGER);
        visualizationMenuItem.setSelected(true);
    } else {//  w  ww  .  ja va  2 s  . com
        mainPanel.add(playlistManager, Utilities.PLAYLIST_MANAGER);
        mainPanel.add(visualizationManager, Utilities.VISUALIZATION_PANEL);
        playlistManagerMenuItem.setSelected(true);
    }
    framePanel.add(mainPanel, "grow");

    JPanel southPanel = new JPanel(new MigLayout("fill", "[center]"));
    SubstanceLookAndFeel.setDecorationType(southPanel, DecorationAreaType.TOOLBAR);
    seekSlider = new SeekSlider(this);
    seekSlider.setEnabled(false);
    southPanel.add(seekSlider, "north, gap 4 4 1 0");

    controlPanel = new JPanel(new MigLayout("gap 0, ins 0", "[center]"));
    controlPanel.setOpaque(false);
    stopButton = new StopButton();
    stopButton.setEnabled(false);
    stopButton.addActionListener(this);
    controlPanel.add(stopButton);
    previousButton = new PreviousButton();
    previousButton.setEnabled(false);
    previousButton.addActionListener(this);
    controlPanel.add(previousButton);
    playPauseButton = new PlayPauseButton();
    playPauseButton.addActionListener(this);
    controlPanel.add(playPauseButton, "height pref!");
    nextButton = new NextButton();
    nextButton.setEnabled(false);
    nextButton.addActionListener(this);
    controlPanel.add(nextButton);
    volumeButton = new VolumeButton(Utilities.MIN_GAIN, Utilities.MAX_GAIN, Settings.getGain(),
            Settings.isMuted());
    volumeButton.addMouseWheelListener((MouseWheelEvent e) -> {
        try {
            int volumeValue = volumeSlider.getValue() - 5 * e.getWheelRotation();
            int volumeMin = volumeSlider.getMinimum();
            int volumeMax = volumeSlider.getMaximum();
            if (volumeValue < volumeMin) {
                volumeValue = volumeMin;
            } else if (volumeValue > volumeMax) {
                volumeValue = volumeMax;
            }
            volumeButton.setVolumeIcon(volumeValue);
            volumeSlider.setValue(volumeValue);
            audioPlayer.setGain(volumeValue / 100.0F);
            Settings.setGain(volumeValue);
        } catch (PlayerException ex) {
            logger.debug(ex.getMessage(), ex);
        }
    });
    JPopupMenu volumePopupMenu = volumeButton.getPopupMenu();
    volumeSlider = new JSlider(JSlider.VERTICAL, Utilities.MIN_GAIN, Utilities.MAX_GAIN, Settings.getGain());
    volumeSlider.setMajorTickSpacing(25);
    volumeSlider.setMinorTickSpacing(5);
    volumeSlider.setPaintTicks(true);
    volumeSlider.setPaintLabels(true);
    volumeSlider.addChangeListener((ChangeEvent e) -> {
        if (volumeSlider.getValueIsAdjusting()) {
            try {
                int volumeValue = volumeSlider.getValue();
                volumeButton.setVolumeIcon(volumeValue);
                audioPlayer.setGain(volumeValue / 100.0F);
                Settings.setGain(volumeValue);
            } catch (PlayerException ex) {
                logger.debug(ex.getMessage(), ex);
            }
        }
    });
    volumeSlider.setEnabled(!Settings.isMuted());
    JPanel volumePanel = new JPanel(new MigLayout("fill"));
    JLabel volumeLabel = new JLabel(tr("MainFrame.Menu.Player.Volume"), JLabel.CENTER);
    volumeLabel.setFont(volumeLabel.getFont().deriveFont(Font.BOLD));
    volumePanel.add(volumeLabel, "north");
    volumePanel.add(volumeSlider);
    JCheckBox muteCheckBox = new JCheckBox(tr("MainFrame.Menu.Player.Mute"));
    muteCheckBox.setSelected(Settings.isMuted());
    muteCheckBox.addItemListener((ItemEvent e) -> {
        try {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                volumeSlider.setEnabled(false);
                volumeButton.setVolumeMutedIcon();
                audioPlayer.setMuted(true);
                Settings.setMuted(true);
            } else {
                volumeSlider.setEnabled(true);
                volumeButton.setVolumeIcon(Settings.getGain());
                audioPlayer.setMuted(false);
                Settings.setMuted(false);
            }
        } catch (PlayerException ex) {
            logger.debug(ex.getMessage(), ex);
        }
    });
    volumePanel.add(muteCheckBox, "south");
    volumePopupMenu.add(volumePanel);
    controlPanel.add(volumeButton);
    southPanel.add(controlPanel, "gap 0 0 2 5");

    JPanel statusBar = new JPanel(new MigLayout("ins 2 0 2 0"));
    SubstanceLookAndFeel.setDecorationType(statusBar, DecorationAreaType.FOOTER);
    timeLabel = new JLabel(Utilities.ZERO_TIMER);
    timeLabel.setFont(timeLabel.getFont().deriveFont(Font.BOLD));
    statusBar.add(timeLabel, "gap 6 6 0 0, west");
    statusBar.add(new JSeparator(SwingConstants.VERTICAL), "hmin 16");
    statusLabel = new JLabel();
    statusBar.add(statusLabel, "gap 0 2 0 0, wmin 0, push");
    statusBar.add(new JSeparator(SwingConstants.VERTICAL), "hmin 16");
    playModeLabel = new JLabel();
    playModeLabel.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            Playlist.PlayMode[] playModes = Playlist.PlayMode.values();
            Playlist.PlayMode playMode = playlist.getPlayMode();
            int ordinal = playMode.ordinal();
            playlist.setPlayMode(playModes[(ordinal == playModes.length - 1) ? 0 : ordinal + 1]);
        }
    });
    statusBar.add(playModeLabel, "east, gap 2 2 2 2, width 18!, height 18!");
    southPanel.add(statusBar, "south");
    framePanel.add(southPanel, "south");
    mainFrame.setContentPane(framePanel);
}