private void showSliderMenu() { Point location = new Point(getX(), getY() + getHeight()); SwingUtilities.convertPointToScreen(location, InputVolumeControlButton.this.getParent()); if (isFullScreen()) { location.setLocation( location.getX(), location.getY() - sliderMenu.getPreferredSize().getHeight() - getHeight()); } sliderMenu.setLocation(location); sliderMenu.addPopupMenuListener( new PopupMenuListener() { public void popupMenuWillBecomeVisible(PopupMenuEvent ev) { sliderMenuIsVisible = true; } public void popupMenuWillBecomeInvisible(PopupMenuEvent ev) { sliderMenuIsVisible = false; } public void popupMenuCanceled(PopupMenuEvent ev) {} }); sliderMenu.setVisible(!sliderMenu.isVisible()); }
/** * Initializes a new <tt>MuteButton</tt> instance which is to mute the audio stream to a specific * <tt>Call</tt>. * * @param call the <tt>Call</tt> to be associated with the new instance and whose audio stream is * to be muted upon performing its action * @param iconImageID the icon image * @param pressedIconImageID the <tt>ImageID</tt> of the image to be used as the icon in the * pressed button state of the new instance * @param selected <tt>true</tt> if the new toggle button is to be initially selected; otherwise, * <tt>false</tt> * @param inSettingsPanel <tt>true</tt> when the button is used in a menu, to use different * background. */ public InputVolumeControlButton( Call call, ImageID iconImageID, ImageID pressedIconImageID, boolean inSettingsPanel, boolean selected) { super( call, inSettingsPanel, selected, iconImageID, pressedIconImageID, "service.gui.MUTE_BUTTON_TOOL_TIP"); this.mute = selected; volumeControl = getVolumeControl(); // Creates the menu that would contain the volume control component. sliderMenu = new VolumeControlSlider(volumeControl, JSlider.VERTICAL).getPopupMenu(); sliderMenu.setInvoker(this); addMouseListener( new MouseAdapter() { TimerTask timerTask; @Override public void mousePressed(MouseEvent mouseevent) { Timer timer = new Timer(); timerTask = new TimerTask() { @Override public void run() { showSliderMenu(); } }; timer.schedule(timerTask, 1000); } @Override public void mouseReleased(MouseEvent mouseevent) { if (!sliderMenuIsVisible) { if (timerTask != null) { timerTask.cancel(); } } else { setSelected(!isSelected()); } } }); }