private static ImageIcon loadIcon(String name) { return loadIcon(16, name); } private static ImageIcon loadIcon(int size, String name) {
public PopupVolumeButton(BoundedRangeModel model) { /* * Construct the popup for the volume slider */ volumePanel = new JPanel(); volumePanel.setLayout(new BoxLayout(volumePanel, BoxLayout.Y_AXIS)); volumeSlider = new JSlider(model); volumeSlider.addChangeListener(volumeChanged); volumeSlider.setOrientation(SwingConstants.VERTICAL); volumePanel.add(new JLabel(highVolumeIcon)); volumeSlider.setAlignmentX(0.25f); volumePanel.add(volumeSlider); volumePanel.add(new JLabel(lowVolumeIcon)); volumePanel.validate(); setAction(volumeAction); } public PopupVolumeButton(final PlayBin2 playbin) {
public void actionPerformed(ActionEvent e) { JToggleButton b = (JToggleButton) e.getSource(); if (!b.isSelected() && volumePopup != null) { volumePopup.hide(); volumePopup = null; } else { Dimension panelSize = volumePanel.getPreferredSize(); // Right-align it with the volume button, so it pops up just above it Point location = new Point(0 - panelSize.width + getPreferredSize().width, 0 - panelSize.height); SwingUtilities.convertPointToScreen(location, PopupVolumeButton.this); volumePopup = PopupFactory.getSharedInstance().getPopup(PopupVolumeButton.this, volumePanel, location.x, location.y); // Remove the slider value from the top of the slider Object paintValue = UIManager.put("Slider.paintValue", Boolean.FALSE); volumePopup.show(); UIManager.put("Slider.paintValue", paintValue); } } };
add(controls, BorderLayout.SOUTH); controls.add(new PopupVolumeButton(volumeModel)); controls.add(new JButton(rewAction)); controls.add(new JButton(togglePlayAction));