Ignore:
Timestamp:
05/10/18 16:04:51 (6 years ago)
Author:
davidb
Message:

Reworking of the code-base to separate logic from graphics. This version of Expeditee now supports a JFX graphics as an alternative to SWING

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/apollo/gui/PlaybackControlPopup.java

    r315 r1102  
    22
    33import java.awt.Dimension;
     4import java.awt.Graphics2D;
    45import java.awt.GridBagConstraints;
    56import java.awt.GridBagLayout;
     
    89import java.awt.event.ActionListener;
    910
    10 import javax.swing.Icon;
    1111import javax.swing.JButton;
     12import javax.swing.JPanel;
    1213import javax.swing.JSlider;
    1314import javax.swing.JToggleButton;
     
    1617
    1718import org.apollo.io.IconRepository;
     19import org.expeditee.core.Image;
     20import org.expeditee.core.bounds.AxisAlignedBoxBounds;
     21import org.expeditee.gio.swing.SwingConversions;
     22import org.expeditee.gio.swing.SwingMiscManager;
    1823import org.expeditee.gui.Popup;
     24import org.expeditee.gui.PopupManager.ExpandShrinkAnimator;
    1925
    2026/**
     
    2531 *
    2632 */
    27 public abstract class PlaybackControlPopup extends Popup implements ActionListener {
    28 
     33public abstract class PlaybackControlPopup extends Popup implements ActionListener
     34{
     35        public JPanel panel;
    2936        public JButton playPauseButton;
    3037        public JButton stopButton;
     
    3946        private static final int BUTTON_SIZE = 40;
    4047       
    41         protected PlaybackControlPopup() {
    42                 super(new GridBagLayout());
     48        protected PlaybackControlPopup()
     49        {
     50                super(new ExpandShrinkAnimator());
     51               
     52                panel = new JPanel(new GridBagLayout());
    4353               
    4454                playPauseButton = new JButton();
    4555                playPauseButton.setActionCommand("playpause");
    4656                playPauseButton.addActionListener(this);
    47                 playPauseButton.setIcon(IconRepository.getIcon("play.png"));
     57                SwingMiscManager.setJButtonIcon(playPauseButton, IconRepository.getIcon("play.png"));
    4858                playPauseButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
    4959                playPauseButton.setToolTipText("Play selection / Pause");
     
    5363                stopButton.addActionListener(this);
    5464                stopButton.setActionCommand("stop");
    55                 stopButton.setIcon(IconRepository.getIcon("stop.png"));
     65                SwingMiscManager.setJButtonIcon(stopButton, IconRepository.getIcon("stop.png"));
    5666                stopButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
    5767                stopButton.setToolTipText("Stop playback");
     
    6070                rewindButton.addActionListener(this);
    6171                rewindButton.setActionCommand("rewind");
    62                 rewindButton.setIcon(IconRepository.getIcon("rewind.png"));
     72                SwingMiscManager.setJButtonIcon(rewindButton, IconRepository.getIcon("rewind.png"));
    6373                rewindButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
    6474                rewindButton.setToolTipText("Rewind to start");
     
    6676                // Icon changes
    6777                muteButton = new JToggleButton();
    68                 muteButton.setSelectedIcon(IconRepository.getIcon("volmute.png"));
     78                SwingMiscManager.setJButtonSelectedIcon(muteButton, IconRepository.getIcon("volmute.png"));
    6979                muteButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
    7080                muteButton.setToolTipText("Toggle mute");
     
    7888               
    7989                soloButton = new JToggleButton();
    80                 soloButton.setIcon(IconRepository.getIcon("solo.png"));
    81                 soloButton.setSelectedIcon(IconRepository.getIcon("soloon.png"));
     90                SwingMiscManager.setJButtonIcon(soloButton, IconRepository.getIcon("solo.png"));
     91                SwingMiscManager.setJButtonSelectedIcon(soloButton, IconRepository.getIcon("soloon.png"));
    8292                soloButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
    8393                soloButton.setToolTipText("Toggle solo");
     
    115125                c.gridy = 0;
    116126                c.fill = GridBagConstraints.BOTH;
    117                 add(playPauseButton, c);
     127                panel.add(playPauseButton, c);
    118128               
    119129                c = new GridBagConstraints();
     
    121131                c.gridy = 0;
    122132                c.fill = GridBagConstraints.BOTH;
    123                 add(stopButton, c);
     133                panel.add(stopButton, c);
    124134               
    125135                c = new GridBagConstraints();
     
    127137                c.gridy = 0;
    128138                c.fill = GridBagConstraints.BOTH;
    129                 add(rewindButton, c);
     139                panel.add(rewindButton, c);
    130140               
    131141                c = new GridBagConstraints();
     
    133143                c.gridy = 0;
    134144                c.fill = GridBagConstraints.BOTH;
    135                 add(soloButton, c);
     145                panel.add(soloButton, c);
    136146               
    137147                c = new GridBagConstraints();
     
    139149                c.gridy = 0;
    140150                c.fill = GridBagConstraints.BOTH;
    141                 add(muteButton, c);
     151                panel.add(muteButton, c);
    142152               
    143153                c = new GridBagConstraints();
     
    146156                c.fill = GridBagConstraints.BOTH;
    147157                c.insets = new Insets(0,VOLUME_SPACING,0,VOLUME_SPACING);
    148                 add(volumeSlider, c);
     158                panel.add(volumeSlider, c);
    149159               
    150160                c = new GridBagConstraints();
     
    152162                c.gridy = 0;
    153163                c.fill = GridBagConstraints.BOTH;
    154                 add(miscButton, c);
     164                panel.add(miscButton, c);
    155165               
    156166//
     
    201211//              this.setSize(BUTTON_SIZE * 4, BUTTON_SIZE * 2);
    202212               
    203                 this.setSize(BUTTON_SIZE * 8, BUTTON_SIZE);
    204                
    205                 this.doLayout();
     213                panel.setSize(BUTTON_SIZE * 8, BUTTON_SIZE);
     214               
     215                panel.doLayout();
    206216               
    207217        }
     
    213223        private void updateButtonGUI() {
    214224               
    215                 Icon newIcon = null;
     225                Image newIcon = null;
    216226                if (volumeSlider.getValue() <= 25)
    217227                                newIcon = IconRepository.getIcon("vol25.png");
     
    223233                                newIcon = IconRepository.getIcon("vol100.png");
    224234               
    225                 muteButton.setIcon(newIcon);
    226         }
    227 
    228 
     235                SwingMiscManager.setJButtonIcon(muteButton, newIcon);
     236        }
     237       
     238        @Override
     239        protected void paintInternal()
     240        {
     241                Graphics2D g = SwingMiscManager.getIfUsingSwingGraphicsManager().getCurrentSurface();
     242                AxisAlignedBoxBounds bounds = getBounds();
     243               
     244                g.translate(bounds.getMinX(), bounds.getMinY());
     245                panel.paint(g);
     246                g.translate(-bounds.getMinX(), -bounds.getMinY());
     247        }
     248
     249        @Override
     250        public AxisAlignedBoxBounds getFullBounds()
     251        {
     252                return SwingConversions.fromSwingRectangle(panel.getBounds());
     253        }
     254       
    229255        public abstract void actionPerformed(ActionEvent e);
    230256       
Note: See TracChangeset for help on using the changeset viewer.