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

    r315 r1102  
    22
    33import java.awt.Dimension;
     4import java.awt.Graphics2D;
    45import java.awt.GridBagConstraints;
    56import java.awt.GridBagLayout;
    6 import java.awt.Rectangle;
    77import java.awt.event.ActionEvent;
    88import java.awt.event.ActionListener;
    9 import java.awt.event.ComponentEvent;
    10 import java.awt.event.ComponentListener;
    119import java.util.LinkedList;
    1210
    1311import javax.swing.JButton;
    1412import javax.swing.JLabel;
    15 import javax.swing.SwingUtilities;
     13import javax.swing.JPanel;
    1614
    1715import org.apollo.audio.SampledTrackModel;
     
    2220import org.apollo.util.TrackModelHandler;
    2321import org.apollo.util.TrackModelLoadManager;
     22import org.expeditee.core.bounds.AxisAlignedBoxBounds;
     23import org.expeditee.gio.EcosystemManager;
     24import org.expeditee.gio.InputManager.WindowEventListener;
     25import org.expeditee.gio.InputManager.WindowEventType;
     26import org.expeditee.gio.swing.SwingConversions;
     27import org.expeditee.gio.swing.SwingMiscManager;
    2428import org.expeditee.gui.Browser;
    25 import org.expeditee.gui.FrameGraphics;
    26 import org.expeditee.gui.MessageBay;
     29import org.expeditee.gui.DisplayController;
    2730import org.expeditee.gui.Popup;
    2831import org.expeditee.gui.PopupManager;
     32import org.expeditee.gui.PopupManager.ExpandShrinkAnimator;
    2933
    3034/**
     
    4044       
    4145        /** All epxanded tracks ... either in all in view or all selected ... to be viewed */
    42         private LinkedList<ExpandedTrackPopup> expandedTracks = new LinkedList<ExpandedTrackPopup> (); // SHARED Model data
     46        private LinkedList<ExpandedTrackPopup> expandedTracks = new LinkedList<ExpandedTrackPopup>(); // SHARED Model data
    4347
    4448        private MultiTrackExpansionPopup trackSelectionPopup = new MultiTrackExpansionPopup();
    4549       
    4650        private static ExpandedTrackManager instance = new ExpandedTrackManager();
    47         private ExpandedTrackManager() {
    48                
     51       
     52        private ExpandedTrackManager()
     53        {
    4954                // Keep view centered to browser size
    50                 SwingUtilities.invokeLater(new Runnable() {
    51                         public void run() {
    52 
    53                                 // Keep expanded view centered to the browser window
    54                                 if (Browser._theBrowser != null) {
    55                                         Browser._theBrowser.addComponentListener(new ComponentListener() {
    56 
    57                                                 public void componentHidden(ComponentEvent e) {
    58                                                 }
    59 
    60                                                 public void componentMoved(ComponentEvent e) {
    61                                                 }
    62 
    63                                                 public void componentResized(ComponentEvent e) {
    64                                                        
    65                                                         if (PopupManager.getInstance().isShowing(trackSelectionPopup)) {
    66                                                                 // User currently selecting..
    67                                                                 trackSelectionPopup.setLocation(
    68                                                                                 (Browser._theBrowser.getWidth() / 2) - (trackSelectionPopup.getWidth() / 2), 0);
    69                                                                
    70                                                         } else { // expanded views might be showing
    71                                                                
    72                                                                 // Fails with Maximizing of window on some systems... swing
    73                                                                 // bug!! really anoying
    74                                                                 updateLayout();
    75        
    76                                                         }
    77        
    78                                                 }
    79 
    80                                                 public void componentShown(ComponentEvent e) {
    81                                                 }
    82                                                
    83                                         });
     55                EcosystemManager.getInputManager().addWindowEventListener(new WindowEventListener()
     56                {
     57                        @Override
     58                        public void onWindowEvent(WindowEventType type)
     59                        {
     60                                if (type != WindowEventType.WINDOW_RESIZED) return;
     61                                if (PopupManager.getInstance().isShowing(trackSelectionPopup)) {
     62                                        // User currently selecting..
     63                                        trackSelectionPopup.setLocation((EcosystemManager.getGraphicsManager().getWindowSize().getWidth() - trackSelectionPopup.getFullBounds().getWidth()) / 2, 0);
     64                                       
     65                                } else { // expanded views might be showing
     66                                       
     67                                        // Fails with maximising of window on some systems... swing
     68                                        // bug!! really annoying
     69                                        updateLayout();
     70
    8471                                }
    85                                
    86                         }
     72                        }
     73                       
    8774                });
    8875               
    89                 // Registewr for (indirectly) handling track models
     76                // Register for (indirectly) handling track models
    9077                TrackModelLoadManager.getInstance().addTrackModelHandler(this);
    9178
     79                PopupManager.getInstance().add(trackSelectionPopup);
    9280        }
    9381       
     
    162150         *              If trackModel or trackMix or trackSourceFrameName or localFilename is null.
    163151         */
    164         public boolean addTrackToSelection(
    165                         SampledTrackModel track,
    166                         String trackSourceFrameName,
    167                         Rectangle animationSource,
    168                         TrackMixSubject mix) {
    169                
     152        public boolean addTrackToSelection(SampledTrackModel track, String trackSourceFrameName, AxisAlignedBoxBounds animationSource, TrackMixSubject mix)
     153        {
    170154                assert(track != null);
    171155                assert(Browser._theBrowser != null);
     
    174158                synchronized(expandedTracks) {
    175159       
    176                         if (expandedTracks.size() < MAX_EXPANDED_TRACK_SIZE
    177                                         && !isTrackInExpansionSelection(track)) {
     160                        if (expandedTracks.size() < MAX_EXPANDED_TRACK_SIZE && !isTrackInExpansionSelection(track)) {
    178161                               
    179162                                ExpandedTrackPopup.giveToExpandedTrackManager(
     
    183166                                                0,
    184167                                                track.getFrameCount()); /** @see #receiveExpandedTrackPopup */
    185        
    186                                 Rectangle trackSelectionPopupBounds = null;
    187168                               
    188169                                // Ensure that the trackSelectionPopup is not already showing / animated to show
    189170                                if (!PopupManager.getInstance().isShowing(trackSelectionPopup)) {
    190171                                       
    191                                         trackSelectionPopupBounds = new Rectangle(
    192                                                         (Browser._theBrowser.getWidth() / 2 ) - (trackSelectionPopup.getWidth() / 2),
    193                                                         0,
    194                                                         trackSelectionPopup.getWidth(),
    195                                                         trackSelectionPopup.getHeight());
     172                                        trackSelectionPopup.setLocation((DisplayController.getFramePaintArea().getWidth() - trackSelectionPopup.getFullBounds().getWidth()) / 2, 0);
    196173                                       
    197174                                        // Creep from above
    198                                         PopupManager.getInstance().showPopup(
    199                                                         trackSelectionPopup,
    200                                                         trackSelectionPopupBounds.getLocation(),
    201                                                         null,
    202                                                         PopupManager.getInstance().new ExpandShrinkAnimator(
    203                                                                         trackSelectionPopupBounds,
    204                                                                         null));
    205                                        
    206                                 } else {
    207                                         trackSelectionPopup.repaint();
     175                                        trackSelectionPopup.show();
    208176                                }
    209177                               
    210178                                // Animate a fake popup expanding into the trackSelectionPopup from the given source if not null
    211179                                if (animationSource != null) {
    212                                        
    213                                         PopupManager.getInstance().doPureAnimation(PopupManager.getInstance().new ExpandShrinkAnimator(
    214                                                         animationSource, null),
    215                                                         (trackSelectionPopupBounds == null) ?
    216                                                                         trackSelectionPopup.getBounds() : trackSelectionPopupBounds);
     180                                        ((ExpandShrinkAnimator) trackSelectionPopup.getAnimator()).setInitialBounds(animationSource);
    217181                                }
    218182                               
     
    253217         *
    254218         */
    255         public void expandSingleTrack(
    256                         SampledTrackModel track,
    257                         Rectangle animationSource,
    258                         TrackMixSubject mix,
    259                         String trackSourceFrameName,
    260                         int frameStart,
    261                         int frameLength) {
     219        public void expandSingleTrack(SampledTrackModel track, AxisAlignedBoxBounds animationSource, TrackMixSubject mix, String trackSourceFrameName, int frameStart, int frameLength)
     220        {
    262221                assert(animationSource != null);
    263222                assert(track != null);
     
    265224                synchronized(expandedTracks) {
    266225                        // Hide all expandedTracks that are currently showing
    267                         while (!expandedTracks.isEmpty())
    268                                 PopupManager.getInstance().hidePopup(expandedTracks.getFirst());
     226                        for (ExpandedTrackPopup expandedTrack : expandedTracks) {
     227                                expandedTrack.hide();
     228                        }
    269229                }
    270230
     
    315275        }
    316276       
    317         private void cancelSelection() {
    318                
     277        private void cancelSelection()
     278        {
    319279                hideTrackSelectionPopup();
    320280               
    321281                // Remove from selection
    322                 LinkedList<? extends ExpandedTrackPopup> old = (LinkedList<? extends ExpandedTrackPopup>)expandedTracks.clone();
     282                LinkedList<? extends ExpandedTrackPopup> old = (LinkedList<? extends ExpandedTrackPopup>) expandedTracks.clone();
    323283               
    324284                synchronized(expandedTracks) {
     
    341301         *              A tracks ExpandedTrackPopup if one exists.
    342302         */
    343         private ExpandedTrackPopup getExpandedTrackPopup(SampledTrackModel track) {
     303        private ExpandedTrackPopup getExpandedTrackPopup(SampledTrackModel track)
     304        {
    344305                assert(track != null);
    345306               
     
    362323         *              True if the track is expanded - or is selected to be expanded..
    363324         */
    364         public boolean isTrackInExpansionSelection(SampledTrackModel track) {
     325        public boolean isTrackInExpansionSelection(SampledTrackModel track)
     326        {
    365327                assert(track != null);
    366328                return getExpandedTrackPopup(track) != null;
     
    371333         *                      True if at least 1 expanded track is showing - or is selected to show.
    372334         */
    373         public boolean doesExpandedTrackExist() {
     335        public boolean doesExpandedTrackExist()
     336        {
    374337                synchronized(expandedTracks) {
    375338                        return expandedTracks.size() > 0;
     
    377340        }
    378341       
    379         public boolean isAnyExpandedTrackVisible() {
     342        public boolean isAnyExpandedTrackVisible()
     343        {
    380344                for (ExpandedTrackPopup xtp : expandedTracks) {
    381345                        if (PopupManager.getInstance().isShowing(xtp)) return true;
     
    389353         *
    390354         */
    391         public void showSelection() {
     355        public void showSelection()
     356        {
    392357                expandTracks(null);
    393358        }
    394359       
    395360        /**
    396          * Returns immediatly if there are no tracks selected. Only expands if the popup is not already expanded.
     361         * Returns immediately if there are no tracks selected. Only expands if the popup is not already expanded.
    397362         *
    398363         * @param directAnimSource
     
    401366         *              a widget).
    402367         */
    403         private void expandTracks(Rectangle directAnimSource) {
    404 
     368        private void expandTracks(AxisAlignedBoxBounds directAnimSource)
     369        {
    405370                synchronized(expandedTracks) {
    406371                       
     
    418383                        for (ExpandedTrackPopup xtp : expandedTracks) {
    419384       
    420                                 // Note: returns immediatly if already showing
    421                                 PopupManager.getInstance().showPopup(
    422                                                 xtp,
    423                                                 xtp.getLocation(),
    424                                                 null,
    425                                                 PopupManager.getInstance().new ExpandShrinkAnimator(
    426                                                                 directAnimSource,
    427                                                                 null));
     385                                // Note: returns immediately if already showing
     386                                ((ExpandShrinkAnimator) xtp.getAnimator()).setInitialBounds(directAnimSource);
     387                                xtp.show();
    428388                       
    429389                        }
     
    435395        }
    436396       
    437         private void hideTrackSelectionPopup() {
    438                 PopupManager.getInstance().hidePopup(
    439                                 trackSelectionPopup, PopupManager.getInstance().new ExpandShrinkAnimator(
    440                                                 new Rectangle((Browser._theBrowser.getWidth() / 2 ) - (trackSelectionPopup.getWidth() / 2),
    441                                                                 0, trackSelectionPopup.getWidth(), trackSelectionPopup.getHeight()), null));
     397        private void hideTrackSelectionPopup()
     398        {
     399                trackSelectionPopup.hide();
    442400        }
    443401       
     
    446404         * current state of the window.
    447405         */
    448         private void updateLayout() {
    449                
    450                 synchronized(expandedTracks) {
    451                                
    452        
     406        private void updateLayout()
     407        {
     408                synchronized(expandedTracks) {
     409
    453410                        if (expandedTracks.isEmpty()) return;
    454411                       
     
    456413                        assert(Browser._theBrowser != null);
    457414               
    458                         int cpWidth = Browser._theBrowser.getContentPane().getWidth();
    459                         int cpHeight = Browser._theBrowser.getContentPane().getHeight();
    460                         if (!FrameGraphics.isAudienceMode()) { // if message bay is showing - the remove the height
    461                                
    462                                 cpHeight -= MessageBay.MESSAGE_BUFFER_HEIGHT;
     415                        int cpWidth = DisplayController.getFramePaintArea().getWidth();
     416                        int cpHeight = DisplayController.getFramePaintArea().getHeight();
     417                        if (!DisplayController.isAudienceMode()) { // if message bay is showing - the remove the height
     418                               
     419                                cpHeight -= DisplayController.getMessageBayPaintArea().getHeight();
    463420                               
    464421                        }
     
    504461         * Global Track model re-use .... can be called from any thread
    505462         */
    506         public SampledTrackModel getSharedSampledTrackModel(String localfilename) {
     463        public SampledTrackModel getSharedSampledTrackModel(String localfilename)
     464        {
    507465                synchronized(expandedTracks) {
    508466                        for (ExpandedTrackPopup xtp : expandedTracks) {
     
    521479         *
    522480         */
    523         private class MultiTrackExpansionPopup extends Popup implements ActionListener {
    524                
     481        private class MultiTrackExpansionPopup extends Popup implements ActionListener
     482        {
     483                private JPanel panel;
    525484                private JButton expandButton;
    526485                private JButton cancelButton;
     
    528487                private JLabel selected2;
    529488                private JLabel selectedMore;
    530 
    531                 private static final long serialVersionUID = 1L;
     489               
    532490                //private final Color BACK_COLOR = SampledTrackGraphViewPort.ZOOM_BACKING_COLOR_NORMAL;
    533491               
    534                 MultiTrackExpansionPopup() {
    535                         super(new GridBagLayout());
    536                         setSize(260, 80);
    537                         super.setAudoHide(false);
    538                        
    539                         expandButton = new JButton(IconRepository.getIcon("expand.png"));
     492                MultiTrackExpansionPopup()
     493                {
     494                        super(new ExpandShrinkAnimator());
     495                       
     496                        panel = new JPanel(new GridBagLayout());
     497                        panel.setSize(260, 80);
     498                       
     499                        expandButton = new JButton();
     500                        SwingMiscManager.setJButtonIcon(expandButton, IconRepository.getIcon("expand.png"));
    540501                        expandButton.addActionListener(this);
    541502                        expandButton.setPreferredSize(new Dimension(40, 40));
    542503                        expandButton.setToolTipText("Expand selection");
    543504                       
    544                         cancelButton = new JButton(IconRepository.getIcon("close.png"));
     505                        cancelButton = new JButton();
     506                        SwingMiscManager.setJButtonIcon(cancelButton, IconRepository.getIcon("close.png"));
    545507                        cancelButton.addActionListener(this);
    546508                        cancelButton.setPreferredSize(new Dimension(40, 40));
     
    563525                        c.gridy = 0;
    564526                        c.fill = GridBagConstraints.CENTER;
    565                         add(expandButton, c);
     527                        panel.add(expandButton, c);
    566528                       
    567529                        c = new GridBagConstraints();
     
    569531                        c.gridy = 0;
    570532                        c.fill = GridBagConstraints.CENTER;
    571                         add(cancelButton, c);
     533                        panel.add(cancelButton, c);
    572534                       
    573535                        c = new GridBagConstraints();
     
    576538                        c.gridwidth = 2;
    577539                        c.fill = GridBagConstraints.CENTER;
    578                         add(selected1, c);
     540                        panel.add(selected1, c);
    579541                       
    580542                        c = new GridBagConstraints();
     
    583545                        c.gridwidth = 2;
    584546                        c.fill = GridBagConstraints.CENTER;
    585                         add(selected2, c);
     547                        panel.add(selected2, c);
    586548                       
    587549                        c = new GridBagConstraints();
     
    591553                        c.gridheight = 2;
    592554                        c.fill = GridBagConstraints.CENTER;
    593                         add(selectedMore, c);
    594 
    595                 }
    596                
    597                 public void onTrackSelectionChanged() {
    598                        
     555                        panel.add(selectedMore, c);
     556                }
     557               
     558                public void setLocation(int x, int y)
     559                {
     560                        panel.setLocation(x, y);
     561                }
     562               
     563                public void onTrackSelectionChanged()
     564                {
    599565                        synchronized(expandedTracks) {
    600566                                       
     
    628594                }
    629595
    630                 public void actionPerformed(ActionEvent e) {
     596                public void actionPerformed(ActionEvent e)
     597                {
    631598                        if (e.getSource() == expandButton) {
    632599                                showSelection();
     
    635602                        }
    636603                }
    637                
    638                
    639 
    640         }
    641        
    642        
     604
     605                @Override
     606                protected void paintInternal()
     607                {
     608                        Graphics2D g = SwingMiscManager.getIfUsingSwingGraphicsManager().getCurrentSurface();
     609                       
     610                        panel.paint(g);
     611                }
     612
     613                @Override
     614                public AxisAlignedBoxBounds getFullBounds()
     615                {
     616                        return SwingConversions.fromSwingRectangle(panel.getBounds());
     617                }
     618
     619                @Override
     620                public void onHide()
     621                {
     622                }
     623
     624                @Override
     625                public void onShow()
     626                {
     627                }
     628        }
    643629}
Note: See TracChangeset for help on using the changeset viewer.