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/widgets/LinkedTrack.java

    r372 r1102  
    11package org.apollo.widgets;
    22
    3 import java.awt.Color;
    4 import java.awt.Font;
    53import java.awt.FontMetrics;
    64import java.awt.GradientPaint;
     
    86import java.awt.Graphics2D;
    97import java.awt.Paint;
    10 import java.awt.Point;
    118import java.awt.Rectangle;
    12 import java.awt.Shape;
    13 import java.awt.Stroke;
    149import java.awt.event.ActionEvent;
    1510import java.awt.event.ActionListener;
     
    1914import java.awt.event.MouseListener;
    2015import java.awt.event.MouseMotionListener;
    21 import java.awt.geom.Area;
    2216import java.awt.geom.Rectangle2D;
    2317import java.util.LinkedList;
     
    2923import javax.swing.SwingUtilities;
    3024
     25import org.apollo.ApolloGestureActions;
     26import org.apollo.ApolloKBMGestureTranslator;
    3127import org.apollo.ApolloSystem;
    32 import org.apollo.AudioFrameKeyboardActions;
    33 import org.apollo.AudioFrameMouseActions;
    3428import org.apollo.audio.ApolloSubjectChangedEvent;
    3529import org.apollo.audio.SampledAudioManager;
     
    6256import org.apollo.util.Mutable;
    6357import org.apollo.util.ODFrameHeirarchyFetcher;
    64 import org.apollo.util.PopupReaper;
    6558import org.apollo.util.StringEx;
    6659import org.apollo.util.ODFrameHeirarchyFetcher.ODFrameReceiver;
     60import org.expeditee.core.Clip;
     61import org.expeditee.core.Colour;
     62import org.expeditee.core.EnforcedClipStack.EnforcedClipKey;
     63import org.expeditee.core.Fill;
     64import org.expeditee.core.Font;
     65import org.expeditee.core.Line;
     66import org.expeditee.core.Point;
     67import org.expeditee.core.Stroke;
     68import org.expeditee.core.TextLayout;
     69import org.expeditee.core.bounds.AxisAlignedBoxBounds;
     70import org.expeditee.gio.EcosystemManager;
     71import org.expeditee.gio.GraphicsManager;
     72import org.expeditee.gio.TextLayoutManager;
     73import org.expeditee.gio.swing.MouseEventRouter;
     74import org.expeditee.gio.swing.SwingConversions;
     75import org.expeditee.gio.swing.SwingMiscManager;
    6776import org.expeditee.gui.Browser;
    68 import org.expeditee.gui.DisplayIO;
     77import org.expeditee.gui.DisplayController;
    6978import org.expeditee.gui.Frame;
    70 import org.expeditee.gui.FrameGraphics;
    7179import org.expeditee.gui.FrameUtils;
    7280import org.expeditee.gui.MessageBay;
    73 import org.expeditee.gui.MouseEventRouter;
    7481import org.expeditee.gui.PopupManager;
    7582import org.expeditee.items.Item;
    7683import org.expeditee.items.ItemParentStateChangedEvent;
    7784import org.expeditee.items.Text;
    78 import org.expeditee.items.widgets.InteractiveWidget;
    7985import org.expeditee.items.widgets.InteractiveWidgetInitialisationFailedException;
    8086import org.expeditee.items.widgets.InteractiveWidgetNotAvailableException;
    81 
    82 public class LinkedTrack extends InteractiveWidget implements ODFrameReceiver, Observer, MultitrackLoadListener, PlaybackClockListener {
     87import org.expeditee.items.widgets.SwingWidget;
     88import org.expeditee.items.widgets.Widget;
     89
     90public class LinkedTrack extends SwingWidget implements ODFrameReceiver, Observer, MultitrackLoadListener, PlaybackClockListener {
    8391       
    8492        private String virtualFilename; // immutable
     
    92100       
    93101        private PlaybackPopup playbackControlPopup = null;
    94 
    95102
    96103        // private SoundDeskPopup soundDeskPopup = null;
     
    116123        private String abortMessage = null;
    117124       
    118         private static final Color FAILED_MESSAGE_COLOR = Color.RED;
     125        private static final Colour FAILED_MESSAGE_COLOR = Colour.RED;
    119126        private static final Font MESSAGE_FONT = TrackWidgetCommons.FREESPACE_TRACKNAME_FONT;
    120         private static final Font HELPER_FONT = new Font("Arial", Font.BOLD, 12);
    121        
    122         private static final Color[] TRACK_COLOR_WHEEL = {
    123                                                         new Color(66, 145, 255),
    124                                                         new Color(255, 163, 33),
    125                                                         new Color(155, 227, 48),
     127        private static final Font HELPER_FONT = new Font("Arial", Font.Style.BOLD, 12);
     128       
     129        private static final Colour[] TRACK_COLOR_WHEEL = {
     130                                                        Colour.FromRGB255(66, 145, 255),
     131                                                        Colour.FromRGB255(255, 163, 33),
     132                                                        Colour.FromRGB255(155, 227, 48)
    126133                                                };
    127         private static final Color TRACK_LOAD_COLOR = Color.BLACK;
    128         private static final Color TRACK_FAIL_COLOR = Color.RED;
    129        
    130         private static final Color SELECTION_COLOR = new Color(0,0,0,100);
     134        private static final Colour TRACK_LOAD_COLOR = Colour.BLACK;
     135        private static final Colour TRACK_FAIL_COLOR = Colour.RED;
     136       
     137        private static final Colour SELECTION_COLOR = Colour.FromRGBA255(0,0,0,100);
    131138
    132139        private static final Stroke TRACK_BORDER = Strokes.SOLID_1;
    133140        private static final Stroke TRACK_SELECTED_BORDER = Strokes.SOLID_2;
    134         private static final Color TRACK_BORDER_COLOR = Color.BLACK;
    135         private static final Color TRACK_SELECTED_BORDER_COLOR = new Color(253, 255, 201);
     141        private static final Colour TRACK_BORDER_COLOR = Colour.BLACK;
     142        private static final Colour TRACK_SELECTED_BORDER_COLOR = Colour.FromRGB255(253, 255, 201);
    136143       
    137144       
     
    154161         * @param args
    155162         */
    156         public LinkedTrack(Text source, String[] args) {
     163        public LinkedTrack(Text source, String[] args)
     164        {
    157165                super(source, new JPanel(),
    158166                                100, -1,
     
    187195                playbackControlPopup = new PlaybackPopup();
    188196               
    189                 nameLabel = new EmulatedTextItem(_swingComponent, new Point(10, 20));
    190                 nameLabel.setBackgroundColor(Color.WHITE);     
     197                nameLabel = new EmulatedTextItem("", new Point(10, 20));
     198                nameLabel.setBackgroundColor(Colour.WHITE);     
    191199               
    192200                String metaName = getStrippedDataString(TrackWidgetCommons.META_NAME_TAG);
     
    210218                        public void keyPressed(KeyEvent e) {
    211219                                if ((state != PLAYING && state != STOPPED) || e.isControlDown()) return;
    212                                 if (nameLabel.onKeyPressed(e, _swingComponent)) {
    213                                         e.consume();
    214                                         return;
    215                                 }
    216220                        }
    217221
     
    219223                                if ((state != PLAYING && state != STOPPED)) return;
    220224                                else if (e.isControlDown()) {
    221                                         if (e.getKeyCode() == KeyEvent.VK_LEFT || e.getKeyCode() == KeyEvent.VK_RIGHT) {
    222                                                 AudioFrameKeyboardActions.adjustInitationTime(LinkedTrack.this, e.getKeyCode() == KeyEvent.VK_LEFT);
    223                                         } else if (e.getKeyCode() == KeyEvent.VK_UP || e.getKeyCode() == KeyEvent.VK_DOWN) {
    224                                                 AudioFrameKeyboardActions.adjustVerticlePosition(LinkedTrack.this, e.getKeyCode() == KeyEvent.VK_UP);
     225                                        if (e.getKeyCode() == KeyEvent.VK_LEFT) {
     226                                                ApolloGestureActions.adjustInitiationTime(LinkedTrack.this, -ApolloKBMGestureTranslator.TRACK_WIDGET_TIMELINE_ADJUSTMENT);
     227                                        } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
     228                                                ApolloGestureActions.adjustInitiationTime(LinkedTrack.this, ApolloKBMGestureTranslator.TRACK_WIDGET_TIMELINE_ADJUSTMENT);
     229                                        } else if (e.getKeyCode() == KeyEvent.VK_UP) {
     230                                                ApolloGestureActions.adjustVerticalPosition(LinkedTrack.this, -ApolloKBMGestureTranslator.TRACK_WIDGET_VERTICAL_ADJUSTMENT);
     231                                        } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
     232                                                ApolloGestureActions.adjustVerticalPosition(LinkedTrack.this, ApolloKBMGestureTranslator.TRACK_WIDGET_VERTICAL_ADJUSTMENT);
    225233                                        }
    226                                 } else if (nameLabel.onKeyReleased(e, _swingComponent)) {
    227                                         e.consume();
    228                                         return;
    229234                                }
    230235                        }
     
    234239                       
    235240                });
    236                
    237241               
    238242                updateBorderColor();
     
    346350                        playbackControlPopup.stopButton.setEnabled(false);
    347351                        playbackControlPopup.playPauseButton.setEnabled(true);
    348                         playbackControlPopup.playPauseButton.setIcon(IconRepository.getIcon("play.png"));
     352                        SwingMiscManager.setJButtonIcon(playbackControlPopup.playPauseButton, IconRepository.getIcon("play.png"));
    349353               
    350354
     
    363367                        playbackControlPopup.rewindButton.setEnabled(false);
    364368                        playbackControlPopup.playPauseButton.setEnabled(true);
    365                         playbackControlPopup.playPauseButton.setIcon(IconRepository.getIcon("pause.png"));
     369                        SwingMiscManager.setJButtonIcon(playbackControlPopup.playPauseButton, IconRepository.getIcon("pause.png"));
    366370
    367371                        setWidgetEdgeThickness(TrackWidgetCommons.PLAYING_TRACK_EDGE_THICKNESS);
     
    408412               
    409413                invalidateSelf();
    410                 FrameGraphics.refresh(true);
     414                DisplayController.requestRefresh(true);
    411415        }
    412416       
     
    528532                        for (Track t : tracks) setTrackState(t, TRACKSTATE_READY);
    529533                        invalidateSelf();
    530                         FrameGraphics.refresh(true);
     534                        DisplayController.requestRefresh(true);
    531535                        break;
    532536                case MultitrackLoadListener.LOAD_FAILED_BAD_GRAPH:
     
    552556                        setTrackState((String) state, TRACKSTATE_READY);
    553557                        invalidateSelf();
    554                         FrameGraphics.refresh(true);
     558                        DisplayController.requestRefresh(true);
    555559                        break;
    556560
     
    611615         */
    612616        @Override
    613         public InteractiveWidget copy()
     617        public Widget copy()
    614618                throws InteractiveWidgetNotAvailableException, InteractiveWidgetInitialisationFailedException {
    615619               
     
    632636                source.setData(data);
    633637               
    634                 return InteractiveWidget.createWidget((Text)source);
     638                return Widget.createWidget((Text)source);
    635639
    636640        }
     
    640644         */
    641645        @Override
    642         protected void onParentStateChanged(int eventType) {
     646        protected void onParentStateChanged(int eventType)
     647        {
    643648                super.onParentStateChanged(eventType);
    644649               
     
    667672                                boolean inferInitTime = true;
    668673       
    669                                 if (AudioFrameMouseActions.isYAxisRestictionOn()) {
     674                                if (ApolloGestureActions.isYAxisRestictionOn()) {
    670675                                        Mutable.Long ms = getInitiationTimeFromMeta();
    671676                                        if (ms != null) {
     
    683688                               
    684689                                // Also must not set initiation time if the frame is simply being displayed
    685                                 inferInitTime &=
    686                                         (AudioFrameMouseActions.isMouseAnchoring() || AudioFrameMouseActions.isMouseStamping());
    687 
     690                                //inferInitTime &= (AudioFrameMouseActions.isMouseAnchoring() || AudioFrameMouseActions.isMouseStamping());
     691                                inferInitTime &= (eventType == ItemParentStateChangedEvent.EVENT_TYPE_ADDED);
     692                               
    688693                                if (inferInitTime) {
    689694                                        initTime = Mutable.createMutableLong(FrameLayoutDaemon.getInstance().getMSAtX(getX(), parent));
     
    731736                        if (MouseEventRouter.getCurrentMouseEvent() != null &&
    732737                                        MouseEventRouter.getCurrentMouseEvent().getButton() == MouseEvent.BUTTON2) {
    733                                 Frame suspended = DisplayIO.getCurrentFrame();
     738                                Frame suspended = DisplayController.getCurrentFrame();
    734739                                if (suspended != null) {
    735740                                        FrameLayoutDaemon.getInstance().suspendLayout(suspended, this);
     
    755760                                public void run() {
    756761                                        invalidateSelf();
    757                                         FrameGraphics.refresh(true);
     762                                        DisplayController.requestRefresh(true);
    758763                                }
    759764                        }); // NOTE TO REPEAT: Pick up a linked track and delete it directly from freespace
     
    946951         */
    947952        @Override
    948         public void paint(Graphics g) {
     953        public void paintSwingWidget(Graphics2D gm) {
    949954               
    950955                if (Browser._theBrowser == null) return;
    951956               
     957                GraphicsManager g = EcosystemManager.getGraphicsManager();
     958               
    952959                // Ensure that load bar or any text doesn't spill over widgets invalidation area
    953                 Area clip = FrameGraphics.getCurrentClip();
    954                
    955                 Shape clipBackUp = g.getClip();
    956                
    957                 Area tmpClip = (clip != null) ? clip :
    958                         new Area(new Rectangle(0, 0,
    959                                         Browser._theBrowser.getContentPane().getWidth(),
    960                                         Browser._theBrowser.getContentPane().getHeight()));
    961                
    962                 tmpClip.intersect(new Area(getBounds()));
    963 
    964                 if (tmpClip.isEmpty()) return;
    965 
    966                 g.setClip(tmpClip);
     960                EnforcedClipKey clipKey = g.pushClip(new Clip(getBounds()));
    967961               
    968962                // Paint backing
    969                 g.setColor(SampledTrackGraphView.DEFAULT_BACKGROUND_COLOR);
    970                 g.fillRect(getX(), getY(), getWidth(), getHeight());
     963                g.drawRectangle(getBounds(), 0.0, new Fill(SwingConversions.fromSwingColor(SampledTrackGraphView.DEFAULT_BACKGROUND_COLOR)), null, null, null);
    971964               
    972965                String centralizedMessage = null;
     966                Colour colour = null;
    973967
    974968                // Render according to the currently widget state
     
    978972
    979973                case FAILED_STATE:
     974                        centralizedMessage = failMessage;
     975                        assert(failMessage != null);
     976                        colour = FAILED_MESSAGE_COLOR;
     977                        break;
    980978                case EMPTY_STATE:
     979                        if (getLink() == null) {
     980                                centralizedMessage = "Click to create";
     981                        } else {
     982                                centralizedMessage = "Nothing to play";
     983                        }
     984                       
     985                        colour = Colour.DARK_GREY;
     986                        break;
    981987                case LOADING_TRACK_GRAPH:
    982                        
    983                         if (state == FAILED_STATE) {
    984                                 centralizedMessage = failMessage;
    985                                 assert(failMessage != null);
    986                                 g.setColor(FAILED_MESSAGE_COLOR);
    987                         } else if (state == LOADING_TRACK_GRAPH){
    988                                 centralizedMessage = "Loading...";
    989                                 g.setColor(Color.DARK_GRAY);
    990                         } else { // empty
    991                                 if (getLink() == null) {
    992                                         centralizedMessage = "Click to create";
    993                                 } else {
    994                                         centralizedMessage = "Nothing to play";
    995                                 }
    996                                
    997                                 g.setColor(Color.DARK_GRAY);
    998                         }
    999 
     988                        centralizedMessage = "Loading...";
     989                        colour = Colour.DARK_GREY;
    1000990                        break;
    1001991                       
     
    1008998
    1009999                        for (Track track : tracks) {
    1010                                 track.paintTrackArea((Graphics2D)g, x, y);
     1000                                track.paintTrackArea(x, y);
    10111001                                if (track.isSelected) {
    10121002                                        selected = track;
    10131003                                } else {
    1014                                         track.paintTrackBorder(g, x, y);
     1004                                        track.paintTrackBorder(x, y);
    10151005                                       
    10161006                                        if (track.area.height > 15) { // don't clutter up busy linked tracks
    1017                                                 drawTrackName(track, g, Color.DARK_GRAY);
     1007                                                drawTrackName(track, Colour.DARK_GREY);
    10181008                                        }
    10191009       
     
    10251015                        // the selected border is drawn last
    10261016                        if (selected != null) {
    1027                                 selected.paintTrackBorder(g, x, y);
    1028                                 drawTrackName(selected, g, Color.BLACK);
     1017                                selected.paintTrackBorder(x, y);
     1018                                drawTrackName(selected, Colour.BLACK);
    10291019                        }
    10301020
     
    10381028                               
    10391029                                centralizedMessage = "Loading dubs...";
    1040                                 g.setColor(Color.BLACK);
     1030                                colour = Colour.BLACK;
    10411031                               
    10421032                        } else {
     
    10451035                                int selLeftX = XatFrame(selectionStart);
    10461036                                if (selectionLength > 1) {
    1047                                         g.setColor(SELECTION_COLOR);
    1048                                         g.fillRect(     getX() + selLeftX,
    1049                                                                 getY(),
    1050                                                                 XatFrame(selectionStart + selectionLength) - selLeftX,
    1051                                                                 getHeight());
     1037                                        colour = SELECTION_COLOR;
     1038                                        AxisAlignedBoxBounds b = new AxisAlignedBoxBounds(      getX() + selLeftX,
     1039                                                        getY(),
     1040                                                        XatFrame(selectionStart + selectionLength) - selLeftX,
     1041                                                        getHeight());
     1042                                        g.drawRectangle(b, 0.0, new Fill(colour), null, null, null);
    10521043                                }
    1053                                
    1054                                 // Draw selection start bar
    1055                                 ((Graphics2D)g).setStroke(SampledTrackGraphView.GRAPH_BAR_STROKE);
    10561044                               
    10571045                                // Note that if the start line is near the edges of the panel it can be concealed - thus
     
    10631051                                        x = getWidth() - 1;
    10641052                                }
    1065                                
    1066                                 g.setColor(Color.RED);
    1067                                 g.drawLine(
     1053                                colour = Colour.RED;
     1054                                Line l = new Line(
    10681055                                                x,
    10691056                                                getY(),
    10701057                                                x,
    10711058                                                getY() + getHeight());
     1059                                g.drawLine(l, colour, SwingConversions.fromSwingStroke(SampledTrackGraphView.GRAPH_BAR_STROKE));
    10721060       
    10731061                               
     
    10761064                                       
    10771065                                        x = XatFrame(currentPlaybackFramePosition) + getX();
    1078                                        
    1079                                         ((Graphics2D)g).setStroke(SampledTrackGraphView.GRAPH_BAR_STROKE);
    1080                                         g.setColor(SampledTrackGraphView.PLAYBACK_BAR_COLOR);
    1081                                         g.drawLine(x, getY(), x, getY() + getHeight());
     1066                                        colour = SwingConversions.fromSwingColor(SampledTrackGraphView.PLAYBACK_BAR_COLOR);
     1067                                        Line l2 = new Line(x, getY(), x, getY() + getHeight());
     1068                                        g.drawLine(l2, colour, SwingConversions.fromSwingStroke(SampledTrackGraphView.GRAPH_BAR_STROKE));
    10821069                               
    10831070                                }
    10841071                       
    10851072                        }
    1086                        
    1087 
    10881073                       
    10891074                        break;
     
    10941079                if (centralizedMessage != null) {
    10951080
    1096                         FontMetrics fm   = g.getFontMetrics(MESSAGE_FONT);
    1097                         Rectangle2D rect = fm.getStringBounds(centralizedMessage, g);
     1081                        TextLayoutManager t = EcosystemManager.getTextLayoutManager();
     1082                       
     1083                        TextLayout layout = t.layoutString(centralizedMessage, MESSAGE_FONT, Point.ORIGIN, null, Integer.MAX_VALUE, 0, true, false).get(0);
     1084                       
     1085                        AxisAlignedBoxBounds layoutBounds = layout.getPixelBounds(0, 0);
    10981086
    10991087                        // Calc centered position
    1100                         int x = getX() + ((getWidth() / 2) - (int)(rect.getWidth() / 2));
    1101                         int y = getY() + ((getHeight() / 2) + (int)(rect.getHeight() / 2) - 4);
     1088                        int x = getX() + ((getWidth() / 2) - (int)(layoutBounds.getWidth() / 2));
     1089                        int y = getY() + ((getHeight() / 2) + (int)(layoutBounds.getHeight() / 2) - 4);
    11021090                       
    11031091                        // Draw text
    1104                         g.setFont(MESSAGE_FONT);
    1105                         g.drawString(centralizedMessage, x, y);
     1092                        g.drawTextLayout(layout, new Point(x, y), colour);
    11061093                       
    11071094                        // Draw add icon if waiting for a link
    11081095                        if (getLink() == null) {
    1109                                 IconRepository.getIcon("goto.png").paintIcon(null,
     1096                                /*IconRepository.getIcon("goto.png").paintIcon(null,
    11101097                                                g,
    11111098                                                x - 34,
    1112                                                 getY() + (getHeight() / 2) - 12);
     1099                                                getY() + (getHeight() / 2) - 12);*/
     1100                                g.drawImage(IconRepository.getIcon("goto.png"), new Point(x - 34, getY() + (getHeight() / 2) - 12));
    11131101                        }
    11141102                               
     
    11161104
    11171105                // Paint name label over everything
    1118                 if (state != NOT_INITIALIZED && state != FAILED_STATE && state != EMPTY_STATE)
    1119                         nameLabel.paint(g);
    1120                
    1121                 g.setClip(clipBackUp);
    1122                
    1123                 super.paintLink((Graphics2D)g);
    1124 
    1125         }
    1126        
    1127         private void drawTrackName(Track track, Graphics g, Color textColor) {
    1128 
     1106                if (state != NOT_INITIALIZED && state != FAILED_STATE && state != EMPTY_STATE) nameLabel.paint();
     1107               
     1108                g.popClip(clipKey);
     1109
     1110        }
     1111       
     1112        private void drawTrackName(Track track, Colour textColor)
     1113        {
     1114                Graphics2D g = SwingMiscManager.getIfUsingSwingGraphicsManager().getCurrentSurface();
     1115               
    11291116                // Draw helper message for user to give meaningful information of what they
    11301117                // are actually highlighting
     
    11331120                helperMessage = helperMessage + " (" + track.getParentFrameName() +  ")";
    11341121               
    1135                 FontMetrics fm   = g.getFontMetrics(HELPER_FONT);
     1122                FontMetrics fm   = g.getFontMetrics(SwingMiscManager.getIfUsingSwingFontManager().getInternalFont(HELPER_FONT));
    11361123                Rectangle2D rect = fm.getStringBounds(helperMessage, g);
    11371124
     
    11491136               
    11501137                // Draw text
    1151                 g.setColor(textColor);
    1152                 g.setFont(HELPER_FONT);
     1138                g.setColor(SwingConversions.toSwingColor(textColor));
     1139                g.setFont(SwingMiscManager.getIfUsingSwingFontManager().getInternalFont(HELPER_FONT));
    11531140                g.drawString(helperMessage, xoff, yoff);
    11541141
     
    11561143       
    11571144        @Override
    1158         protected void paintInFreeSpace(Graphics g) {
    1159 
    1160                 super.paintInFreeSpace(g);
    1161 
    1162                 Shape clipBackUp = g.getClip();
    1163                 Rectangle tmpClip = (clipBackUp != null) ? clipBackUp.getBounds() :
    1164                         new Rectangle(0, 0,
    1165                                         Browser._theBrowser.getContentPane().getWidth(),
    1166                                         Browser._theBrowser.getContentPane().getHeight());
    1167                        
    1168                 g.setClip(tmpClip.intersection(getBounds()));
     1145        protected void paintInFreeSpace()
     1146        {
     1147                super.paintInFreeSpace();
     1148               
     1149                // Draw the name of the track
     1150               
     1151                GraphicsManager g = EcosystemManager.getGraphicsManager();
     1152
     1153                // Ensure that load bar or any text doesn't spill over widgets invalidation area
     1154                EnforcedClipKey clipKey = g.pushClip(new Clip(getBounds()));
    11691155       
    11701156                // Draw the name
     
    11731159                        name = "Unnamed";
    11741160                }
    1175 
    1176                 g.setFont(TrackWidgetCommons.FREESPACE_TRACKNAME_FONT);
    1177                 g.setColor(TrackWidgetCommons.FREESPACE_TRACKNAME_TEXT_COLOR);
    1178                
    1179                 // Center track name
    1180                 FontMetrics fm   = g.getFontMetrics(TrackWidgetCommons.FREESPACE_TRACKNAME_FONT);
    1181                 Rectangle2D rect = fm.getStringBounds(name, g);
    1182                
    1183                 g.drawString(
    1184                                 name,
    1185                                 this.getX() + (int)((getWidth() - rect.getWidth()) / 2),
    1186                                 this.getY() + (int)((getHeight() - rect.getHeight()) / 2) + (int)rect.getHeight()
    1187                                 );
    1188                
    1189                 g.setClip(clipBackUp);
    1190        
    1191 
     1161               
     1162                List<TextLayout> layouts = EcosystemManager.getTextLayoutManager().layoutString(name, TrackWidgetCommons.FREESPACE_TRACKNAME_FONT, getBounds().getTopLeft(), null, getBounds().getWidth(), 0, true, false);
     1163
     1164                // Centre the track name
     1165                int lineYDelta = 0;
     1166                for (TextLayout layout : layouts) {
     1167                        AxisAlignedBoxBounds bounds = layout.getPixelBounds(getBounds().getMinX(), getBounds().getMinY() + lineYDelta);
     1168                        int centreXOffset = (getBounds().getWidth() - bounds.getWidth()) / 2;
     1169                        bounds.translate(centreXOffset, 0);
     1170                        g.drawTextLayout(layout, bounds.getTopLeft(), TrackWidgetCommons.FREESPACE_TRACKNAME_TEXT_COLOR);
     1171                        lineYDelta += bounds.getHeight();
     1172                }
     1173               
     1174                g.popClip(clipKey);
    11921175        }
    11931176
     
    12051188                                x = XatFrame(currentPlaybackFramePosition);
    12061189                               
    1207                                 FrameGraphics.invalidateArea(new Rectangle(
     1190                                DisplayController.invalidateArea(new AxisAlignedBoxBounds(
    12081191                                        x + offsetX,
    12091192                                        offsetY,
     
    12201203                                x = XatFrame(currentPlaybackFramePosition);
    12211204               
    1222                                 FrameGraphics.invalidateArea(new Rectangle(
     1205                                DisplayController.invalidateArea(new AxisAlignedBoxBounds(
    12231206                                                x + offsetX ,
    12241207                                                offsetY,
     
    14621445               
    14631446                // Get border color currently used
    1464                 Color oldC = getSource().getBorderColor();
    1465                
    1466                 Color newC = TrackWidgetCommons.getBorderColor(
     1447                Colour oldC = getSource().getBorderColor();
     1448               
     1449                Colour newC = TrackWidgetCommons.getBorderColor(
    14671450                                SoundDesk.getInstance().isSolo(masterMix.getChannelID()),
    14681451                                                masterMix.isMuted());
     
    15181501         *
    15191502         */
    1520         private class PlaybackPopup extends PlaybackControlPopup {
    1521 
    1522                 private static final long serialVersionUID = 1L;
    1523                
     1503        private class PlaybackPopup extends PlaybackControlPopup
     1504        {
    15241505                public PlaybackPopup() {
    15251506                        miscButton.setActionCommand("goto");
    1526                         miscButton.setIcon(IconRepository.getIcon("goto.png"));
     1507                        SwingMiscManager.setJButtonIcon(miscButton, IconRepository.getIcon("goto.png"));
    15271508                        miscButton.setToolTipText("Goto linked frame");
    15281509                }
    15291510
    15301511                @Override
    1531                 public void onHide() {
    1532                         super.onHide();
     1512                public void onHide()
     1513                {
    15331514                }
    15341515
    15351516                @Override
    1536                 public void onShow() {
    1537                         super.onShow();
     1517                public void onShow()
     1518                {
    15381519                        updateVolume((int)(100 * masterMix.getVolume()));
    15391520                        updateMute(masterMix.isMuted());
    15401521                        updateSolo(SoundDesk.getInstance().isSolo(masterMix.getChannelID()));
    15411522                }
    1542 
    1543                 public void actionPerformed(ActionEvent e) {
    1544                        
     1523               
     1524                public void actionPerformed(ActionEvent e)
     1525                {
    15451526                        if (e.getSource() == miscButton) {
    15461527                               
     
    16701651                                currentPlaybackFramePosition = -1;
    16711652                                setSelection(0, 0); // invalidates
    1672                                 FrameGraphics.refresh(true);
     1653                                DisplayController.requestRefresh(true);
    16731654                               
    16741655                        }
     
    16911672        }
    16921673       
    1693         private class MouseActions implements MouseListener, MouseMotionListener {
    1694 
    1695                 public void mouseClicked(MouseEvent e) {
     1674        private class MouseActions implements MouseListener, MouseMotionListener
     1675        {
     1676                public void mouseClicked(MouseEvent e)
     1677                {
    16961678                        assert(state != EMPTY_STATE);
    16971679                       
     
    17051687                }
    17061688
    1707 
    1708                 public void mouseEntered(MouseEvent e) {
     1689                public void mouseEntered(MouseEvent e)
     1690                {
    17091691                        assert(state != EMPTY_STATE);
    17101692                }
    17111693
    17121694
    1713                 public void mouseExited(MouseEvent e) {
     1695                public void mouseExited(MouseEvent e)
     1696                {
    17141697                        assert(state != EMPTY_STATE);
    1715                        
    1716                 }
    1717 
    1718 
    1719                 public void mousePressed(MouseEvent e) {
    1720                        
     1698                }
     1699
     1700
     1701                public void mousePressed(MouseEvent e)
     1702                {
    17211703                        assert(state != EMPTY_STATE);
    17221704                       
     
    17321714                        setSelection(frameAtX(selectionStartX), 1);
    17331715                       
    1734                         FrameGraphics.refresh(true);
    1735                 }
    1736 
    1737 
    1738                 public void mouseReleased(MouseEvent e) {
    1739                        
    1740 
     1716                        DisplayController.requestRefresh(true);
     1717                }
     1718
     1719
     1720                public void mouseReleased(MouseEvent e)
     1721                {
    17411722                        assert(state != EMPTY_STATE);
    1742                        
    17431723                       
    17441724                        // Was the release a simple click
     
    17651745                                return;
    17661746                        }
    1767 
    1768                        
    1769                 }
    1770                
    1771 
    1772                 public void mouseDragged(MouseEvent e) {
    1773                        
     1747                }
     1748               
     1749
     1750                public void mouseDragged(MouseEvent e)
     1751                {
    17741752                        assert(state != EMPTY_STATE);
    17751753                       
     
    18001778                        }
    18011779                       
    1802                         FrameGraphics.refresh(true);
    1803                 }
    1804 
    1805                 public void mouseMoved(MouseEvent e) {
     1780                        DisplayController.requestRefresh(true);
     1781                }
     1782
     1783                public void mouseMoved(MouseEvent e)
     1784                {
    18061785                        assert(state != EMPTY_STATE);
    18071786                       
    18081787                        if (state != PLAYING && state != STOPPED) return;
    18091788
    1810                         if (nameLabel.onMouseMoved(e, _swingComponent)) {
    1811                                 e.consume();
    1812                                 return;
     1789                        if (nameLabel != null) {
     1790                                nameLabel.gainFocus();
    18131791                        }
    18141792
     
    18221800                               
    18231801                                // Get rid of all popups
    1824                                 PopupManager.getInstance().hideAutohidePopups();
    1825                                
    1826                                 Rectangle animationSource = _swingComponent.getBounds();
     1802                                PopupManager.getInstance().hideAutoHidePopups();
     1803                               
     1804                                AxisAlignedBoxBounds animationSource = SwingConversions.fromSwingRectangle(_swingComponent.getBounds());
    18271805                               
    18281806                                // Determine where popup should show
    18291807                                int x = LinkedTrack.this.getX();
    1830                                 int y = LinkedTrack.this.getY() - playbackControlPopup.getHeight() - 2; // by default show above
     1808                                int y = LinkedTrack.this.getY() - playbackControlPopup.getFullBounds().getHeight() - 2; // by default show above
    18311809                               
    18321810                                // I get sick.dizzy from the popup expanding from the whole thing...
    1833                                 animationSource.height = 1;
    1834                                 animationSource.width = Math.min(animationSource.width, playbackControlPopup.getWidth());
     1811                                animationSource.getSize().height = 1;
     1812                                animationSource.getSize().width = Math.min(animationSource.getWidth(), playbackControlPopup.getFullBounds().getWidth());
    18351813                               
    18361814                                if (y < 0) {
    18371815                                        y = LinkedTrack.this.getY() + LinkedTrack.this.getHeight() + 2;
    1838                                         animationSource.y = y - 2;
     1816                                        animationSource.getTopLeft().y = y - 2;
    18391817                                }
    18401818
    18411819                                // Animate the popup
    1842                                 PopupManager.getInstance().showPopup(
    1843                                                 playbackControlPopup,
    1844                                                 new Point(x, y),
    1845                                                 _swingComponent,
    1846                                                 PopupManager.getInstance().new ExpandShrinkAnimator(
    1847                                                                 animationSource,
    1848                                                                 Color.LIGHT_GRAY));
    1849                                
    1850                                 PopupReaper.getInstance().initPopupLifetime(
    1851                                                 playbackControlPopup,
    1852                                                 PopupManager.getInstance().new ExpandShrinkAnimator(
    1853                                                                 animationSource,
    1854                                                                 Color.LIGHT_GRAY),
    1855                                                                 TrackWidgetCommons.POPUP_LIFETIME);
    1856                                
     1820                                playbackControlPopup.getAutoHideTime().setLifetime(TrackWidgetCommons.POPUP_LIFETIME);
     1821                                PopupManager.getInstance().add(playbackControlPopup);
     1822                                playbackControlPopup.show();
    18571823                        } else {
    1858                                 PopupReaper.getInstance().revivePopup(playbackControlPopup, TrackWidgetCommons.POPUP_LIFETIME);
     1824                                playbackControlPopup.show();
    18591825                        }
    18601826                       
     
    18781844                        if (shouldInvalidate) {
    18791845                                invalidateSelf();
    1880                                 FrameGraphics.refresh(true);
     1846                                DisplayController.requestRefresh(true);
    18811847                        }
    18821848                }
     
    18881854         * @author Brook Novak
    18891855         */
    1890         private class Track {
    1891                
     1856        private class Track
     1857        {
    18921858                private AbsoluteTrackNode absNode; // immutable. Never null
    18931859               
    18941860                private Rectangle area;
    18951861               
    1896                 private Color baseColor;
     1862                private Colour baseColor;
    18971863               
    18981864                boolean isSelected = false;
     
    19001866                private int state = TRACKSTATE_READY;
    19011867               
    1902                 Track(AbsoluteTrackNode absNode) {
     1868                Track(AbsoluteTrackNode absNode)
     1869                {
    19031870                        assert(absNode != null);
    19041871                        this.absNode = absNode;
    19051872                }
    19061873               
    1907                 public String getChannelID() {
     1874                public String getChannelID()
     1875                {
    19081876                        return absNode.getChannelID();
    19091877                }
     
    19291897                }
    19301898               
    1931                 public void paintTrackArea(Graphics2D g, int x, int y) {
     1899                public void paintTrackArea(int x, int y)
     1900                {
     1901                        Graphics2D g = SwingMiscManager.getIfUsingSwingGraphicsManager().getCurrentSurface();
    19321902                       
    19331903                        if (state == TRACKSTATE_LOADING && LinkedTrack.this.state == PLAYBACK_LOADING) {
    1934                                 g.setColor(TRACK_LOAD_COLOR);
     1904                                g.setColor(SwingConversions.toSwingColor(TRACK_LOAD_COLOR));
    19351905                        } else if (state == TRACKSTATE_FAILED) {
    1936                                 g.setColor(TRACK_FAIL_COLOR);
     1906                                g.setColor(SwingConversions.toSwingColor(TRACK_FAIL_COLOR));
    19371907                        } else {
    1938                                 g.setColor(baseColor);
     1908                                g.setColor(SwingConversions.toSwingColor(baseColor));
    19391909                        }
    19401910                       
     
    19431913
    19441914                                GradientPaint gp = new GradientPaint(
    1945                                                 (int) (area.x + x + (area.width / 2)), area.y + y + (int)(area.height * 0.8), baseColor,
    1946                                                 (int) (area.x + x + (area.width / 2)), area.y + y, TRACK_SELECTED_BORDER_COLOR);
     1915                                                (int) (area.x + x + (area.width / 2)), area.y + y + (int)(area.height * 0.8), SwingConversions.toSwingColor(baseColor),
     1916                                                (int) (area.x + x + (area.width / 2)), area.y + y, SwingConversions.toSwingColor(TRACK_SELECTED_BORDER_COLOR));
    19471917                                g.setPaint(gp);
    19481918                        }
    19491919                       
    1950                         // Draw a filled rect - represented a track in the heirarchy
     1920                        // Draw a filled rect - represented a track in the hierarchy
    19511921                        g.fillRect(area.x + x, area.y + y, area.width, area.height);
    19521922                       
     
    19571927                }
    19581928               
    1959                 public void paintTrackBorder(Graphics g, int x, int y) {
     1929                public void paintTrackBorder(int x, int y)
     1930                {
     1931                        Graphics g = SwingMiscManager.getIfUsingSwingGraphicsManager().getCurrentSurface();
    19601932                       
    19611933                        if (isSelected) {
    1962                                 g.setColor(TRACK_SELECTED_BORDER_COLOR);
    1963                                 ((Graphics2D)g).setStroke(TRACK_SELECTED_BORDER);
     1934                                g.setColor(SwingConversions.toSwingColor(TRACK_SELECTED_BORDER_COLOR));
     1935                                ((Graphics2D)g).setStroke(SwingConversions.toSwingStroke(TRACK_SELECTED_BORDER));
    19641936                        } else {
    1965                                 g.setColor(TRACK_BORDER_COLOR);
    1966                                 ((Graphics2D)g).setStroke(TRACK_BORDER); // todo muted colors etc...
     1937                                g.setColor(SwingConversions.toSwingColor(TRACK_BORDER_COLOR));
     1938                                ((Graphics2D)g).setStroke(SwingConversions.toSwingStroke(TRACK_BORDER)); // todo muted colors etc...
    19671939                        }
    19681940                       
     
    19721944        }
    19731945       
     1946        // TODO: Why not? cts16
    19741947        @Override
    19751948        public boolean isWidgetEdgeThicknessAdjustable() {
Note: See TracChangeset for help on using the changeset viewer.