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/ExpandedTrackPopup.java

    r315 r1102  
    22
    33import java.awt.BorderLayout;
    4 import java.awt.Color;
    54import java.awt.Dimension;
    65import java.awt.Event;
    76import java.awt.Font;
    8 import java.awt.Graphics;
     7import java.awt.Graphics2D;
    98import java.awt.GridBagConstraints;
    109import java.awt.GridBagLayout;
    1110import java.awt.Insets;
    1211import java.awt.Point;
    13 import java.awt.Rectangle;
    1412import java.awt.event.ActionEvent;
    1513import java.awt.event.ActionListener;
    16 import java.awt.event.KeyEvent;
    17 import java.awt.event.KeyListener;
    18 import java.awt.event.MouseEvent;
    19 import java.awt.event.MouseListener;
    20 import java.awt.event.MouseMotionListener;
    2114
    2215import javax.sound.sampled.LineUnavailableException;
    23 import javax.swing.Icon;
    2416import javax.swing.JButton;
    2517import javax.swing.JPanel;
     
    4537import org.apollo.util.AudioMath;
    4638import org.apollo.widgets.TrackWidgetCommons;
     39import org.expeditee.core.Colour;
     40import org.expeditee.core.Image;
     41import org.expeditee.core.bounds.AxisAlignedBoxBounds;
     42import org.expeditee.gio.EcosystemManager;
     43import org.expeditee.gio.input.InputEvent;
     44import org.expeditee.gio.input.InputEventListener;
     45import org.expeditee.gio.swing.SwingConversions;
     46import org.expeditee.gio.swing.SwingMiscManager;
    4747import org.expeditee.gui.Browser;
    48 import org.expeditee.gui.FrameGraphics;
     48import org.expeditee.gui.DisplayController;
    4949import org.expeditee.gui.Popup;
    50 import org.expeditee.gui.PopupManager;
    51 
    52 public class ExpandedTrackPopup extends Popup implements ActionListener, Observer {
    53        
    54         private static final long serialVersionUID = 1L;
    55        
     50import org.expeditee.gui.PopupManager.ExpandShrinkAnimator;
     51
     52public class ExpandedTrackPopup extends Popup implements ActionListener, Observer
     53{
    5654        /** The observed subject. Can never be null */
    5755        private SampledTrackModel trackModel; // immutable
     
    6159        private TrackMixSubject trackMix; // immutable
    6260
     61        private JPanel panel;
    6362        private JButton playPauseButton;
    6463        private JButton stopButton;
     
    106105                        String trackSourceFrameName,
    107106                        int frameStart,
    108                         int frameLength) {
    109                 super(new BorderLayout());
     107                        int frameLength)
     108        {
     109                super(new ExpandShrinkAnimator());
    110110                super.setConsumeBackClick(true);
     111               
     112                panel = new JPanel(new BorderLayout());
    111113               
    112114                if (trackModel == null) throw new NullPointerException("trackModel");
     
    121123                playPauseButton = new JButton();
    122124                playPauseButton.addActionListener(this);
    123                 playPauseButton.setIcon(IconRepository.getIcon("play.png"));
     125                SwingMiscManager.setJButtonIcon(playPauseButton, IconRepository.getIcon("play.png"));
    124126                playPauseButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
    125127                playPauseButton.setToolTipText("Play selection / Pause");
     
    128130                stopButton.setEnabled(false);
    129131                stopButton.addActionListener(this);
    130                 stopButton.setIcon(IconRepository.getIcon("stop.png"));
     132                SwingMiscManager.setJButtonIcon(stopButton, IconRepository.getIcon("stop.png"));
    131133                stopButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
    132134                stopButton.setToolTipText("Stop playback");
     
    134136                rewindButton = new JButton();
    135137                rewindButton.addActionListener(this);
    136                 rewindButton.setIcon(IconRepository.getIcon("rewind.png"));
     138                SwingMiscManager.setJButtonIcon(rewindButton, IconRepository.getIcon("rewind.png"));
    137139                rewindButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
    138140                rewindButton.setToolTipText("Rewind to start");
     
    140142                // Icon changes
    141143                muteButton = new JToggleButton();
    142                 muteButton.setSelectedIcon(IconRepository.getIcon("volmute.png"));
     144                SwingMiscManager.setJButtonIcon(muteButton, IconRepository.getIcon("volmute.png"));
    143145                muteButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
    144146                muteButton.setToolTipText("Toggle mute");
     
    153155               
    154156                soloButton = new JToggleButton();
    155                 soloButton.setIcon(IconRepository.getIcon("solo.png"));
    156                 soloButton.setSelectedIcon(IconRepository.getIcon("soloon.png"));
     157                SwingMiscManager.setJButtonIcon(soloButton, IconRepository.getIcon("solo.png"));
     158                SwingMiscManager.setJButtonSelectedIcon(soloButton, IconRepository.getIcon("soloon.png"));
    157159                soloButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
    158160                soloButton.setToolTipText("Toggle solo");
     
    170172                closeButton = new JButton();
    171173                closeButton.addActionListener(this);
    172                 closeButton.setIcon(IconRepository.getIcon("close.png"));
     174                SwingMiscManager.setJButtonIcon(closeButton, IconRepository.getIcon("close.png"));
    173175                closeButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
    174176                closeButton.setToolTipText("Close");
     
    216218                nameLabelParent = new JPanel();
    217219               
    218                 nameLabelParent.addMouseListener(new MouseListener() {
    219 
    220                         public void mouseClicked(MouseEvent e) {
    221                                 if (nameLabel != null) {
    222                                         if (nameLabel.onMouseClicked(e)) {
    223                                                 e.consume();
    224                                                 return;
    225                                         }
    226                                 }
    227                         }
    228 
    229                         public void mouseEntered(MouseEvent e) {
    230                         }
    231 
    232                         public void mouseExited(MouseEvent e) {
    233                         }
    234 
    235                         public void mousePressed(MouseEvent e) {
    236                                 if (nameLabel != null) {
    237                                         if (nameLabel.onMousePressed(e)) {
    238                                                 e.consume();
    239                                         }
    240                                 }
    241                         }
    242 
    243                         public void mouseReleased(MouseEvent e) {
    244                                 if (nameLabel != null) {
    245                                         if (nameLabel.onMouseReleased(e)) {
    246                                                 e.consume();
    247                                         }
    248                                 }
    249                         }
    250                
    251                 });
    252                
    253                 nameLabelParent.addMouseMotionListener(new MouseMotionListener() {
    254 
    255                         public void mouseDragged(MouseEvent e) {
    256                                 if (nameLabel != null) {
    257                                         if (nameLabel.onMouseDragged(e)) {
    258                                                 e.consume();
    259                                         }
    260                                 }
    261                         }
    262 
    263                         public void mouseMoved(MouseEvent e) {
    264                                 if (nameLabel != null) {
    265                                         nameLabel.onMouseMoved(e, nameLabelParent);
    266                                 }
    267                         }
    268 
    269                 });
    270                
    271                 nameLabelParent.addKeyListener(new KeyListener() {
    272 
    273                         public void keyPressed(KeyEvent e) {
    274                                 if (nameLabel != null) {
    275                                         if (nameLabel.onKeyPressed(e, nameLabelParent)) {
    276                                                 e.consume();
    277                                         }
    278                                 }
    279                         }
    280 
    281                         public void keyReleased(KeyEvent e) {
    282                                 if (nameLabel != null) {
    283                                         if (nameLabel.onKeyReleased(e, nameLabelParent)) {
    284                                                 e.consume();
    285                                         }
    286                                 }
    287 
    288                         }
    289 
    290                         public void keyTyped(KeyEvent e) {
    291                         }
    292                        
    293                 });
    294                
    295                 nameLabel = new EmulatedTextItem(nameLabelParent, new Point(10, 25));
    296                 nameLabel.setFontStyle(Font.BOLD);
     220                nameLabel = new EmulatedTextItem(trackModel.getName(), SwingConversions.fromSwingPoint(new Point(10, 25)));
     221                nameLabel.setFontStyle(SwingConversions.fromSwingFontStyle(Font.BOLD));
    297222                nameLabel.setFontSize(16);
    298                 nameLabel.setBackgroundColor(Color.WHITE);     
    299                 nameLabel.setText(trackModel.getName());
     223                nameLabel.setBackgroundColor(Colour.WHITE);
     224                nameLabel.gainFocus();
    300225
    301226                nameLabel.addTextChangeListener(new TextChangeListener() { //  a little bit loopy!
     
    373298                toolBarPanel.add(closeButton, c);
    374299               
    375                 this.add(toolBarPanel, BorderLayout.NORTH);
    376                 this.add(splitPane, BorderLayout.CENTER);
     300                panel.add(toolBarPanel, BorderLayout.NORTH);
     301                panel.add(splitPane, BorderLayout.CENTER);
    377302               
    378303                // Observe track model
     
    430355                ExpandedTrackManager.getInstance().receiveExpandedTrackPopup(xtp);
    431356        }
    432 
     357       
    433358        @Override
    434         public void onShowing() {
    435 
    436         }
    437        
    438         @Override
    439         public void onShow() {
    440                
     359        public void onShow()
     360        {
    441361                if (splitPane.getHeight() < 140) {
    442362                        splitPane.setDividerLocation(splitPane.getHeight() - 30);
     
    456376                // Invalidate full frame for shading
    457377                if (Browser._theBrowser != null) {
    458                         FrameGraphics.refresh(false);
     378                        DisplayController.requestRefresh(false);
    459379                }
    460380        }
    461381
    462382        @Override
    463         public void onHide() {
     383        public void onHide()
     384        {
    464385                ExpandedTrackManager.getInstance().expandedTrackPopupHidden(this);
    465386                releaseMemory(); // get rid of buffer etc..
     
    470391                // Invalidate full frame for shading
    471392                if (Browser._theBrowser != null) {
    472                         FrameGraphics.refresh(false);
     393                        DisplayController.requestRefresh(false);
    473394                }
    474395        }
    475396       
    476        
    477 
    478 
    479397        @Override
    480         public void paint(Graphics g) {
    481                 super.paint(g);
    482                
    483                 g.translate(-getX(), -getY());
    484                 nameLabel.paint(g);
    485                 g.translate(getX(), getY());
    486                
    487         }
    488 
    489         public void actionPerformed(ActionEvent e) {
     398        public void paintInternal()
     399        {
     400                Graphics2D g = SwingMiscManager.getIfUsingSwingGraphicsManager().getCurrentSurface();
     401               
     402                panel.paint(g);
     403               
     404                g.translate(-getFullBounds().getMinX(), -getFullBounds().getMinY());
     405                nameLabel.paint();
     406                g.translate(getFullBounds().getMinX(), getFullBounds().getMinY());
     407        }
     408
     409        public void actionPerformed(ActionEvent e)
     410        {
    490411                if (trackModel == null) return;
    491412               
     
    587508                        // If there are more expanded tracks showing then the ExpandedTrackManager
    588509                        // will automatically re-layout the remaing views.
    589                         PopupManager.getInstance().hidePopup(this,
    590                                         PopupManager.getInstance().new ExpandShrinkAnimator(
    591                                         new Rectangle(0, getY(), 1, getHeight()),
    592                                                         Color.LIGHT_GRAY));
     510                        hide();
    593511                       
    594512                }
     
    660578                        stopButton.setEnabled(true);
    661579                        rewindButton.setEnabled(false);
    662                         playPauseButton.setIcon(IconRepository.getIcon("pause.png"));
     580                        SwingMiscManager.setJButtonIcon(playPauseButton, IconRepository.getIcon("pause.png"));
    663581
    664582                        setBorderThickness(TrackWidgetCommons.PLAYING_TRACK_EDGE_THICKNESS);
     
    670588                        rewindButton.setEnabled(true);
    671589                        stopButton.setEnabled(false);
    672                         playPauseButton.setIcon(IconRepository.getIcon("play.png"));
     590                        SwingMiscManager.setJButtonIcon(playPauseButton, IconRepository.getIcon("play.png"));
    673591                       
    674592                        // Note:
     
    810728               
    811729                // Get border color currently used
    812                 Color oldC = getBorderColor();
    813                
    814                 Color newC = TrackWidgetCommons.getBorderColor(
     730                Colour oldC = getBorderColor();
     731               
     732                Colour newC = TrackWidgetCommons.getBorderColor(
    815733                                SoundDesk.getInstance().isSolo(trackMix.getChannelID()),
    816734                                trackMix.isMuted());
     
    828746        private void updateButtonGUI() {
    829747               
    830                 Icon newIcon = null;
     748                Image newIcon = null;
    831749                if (volumeSlider.getValue() <= 25)
    832750                                newIcon = IconRepository.getIcon("vol25.png");
     
    838756                                newIcon = IconRepository.getIcon("vol100.png");
    839757               
    840                 muteButton.setIcon(newIcon);
     758                SwingMiscManager.setJButtonIcon(muteButton, newIcon);
    841759        }
    842760
     
    846764         *              Never null.
    847765         */
    848         public String getTrackSourceFrameName() {
     766        public String getTrackSourceFrameName()
     767        {
    849768                return trackSourceFrameName;
    850769        }
    851770       
     771        public void setBounds(int x, int y, int width, int height)
     772        {
     773                panel.setBounds(x, y, width, height);
     774        }
     775
     776        @Override
     777        public AxisAlignedBoxBounds getFullBounds()
     778        {
     779                return SwingConversions.fromSwingRectangle(panel.getBounds());
     780        }
     781       
    852782       
    853783}
Note: See TracChangeset for help on using the changeset viewer.