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

    r1057 r1102  
    11package org.apollo.widgets;
    22
    3 import java.awt.Color;
    43import java.awt.Dimension;
    54import java.awt.FontMetrics;
     
    4948import org.apollo.util.ApolloSystemLog;
    5049import org.apollo.util.TrackNameCreator;
    51 import org.expeditee.gui.DisplayIO;
     50import org.expeditee.core.Colour;
     51import org.expeditee.gio.gesture.StandardGestureActions;
     52import org.expeditee.gio.swing.SwingConversions;
     53import org.expeditee.gio.swing.SwingMiscManager;
     54import org.expeditee.gui.DisplayController;
    5255import org.expeditee.gui.Frame;
    53 import org.expeditee.gui.FrameGraphics;
    54 import org.expeditee.gui.FrameMouseActions;
    5556import org.expeditee.items.ItemParentStateChangedEvent;
    5657import org.expeditee.items.Text;
    57 import org.expeditee.items.widgets.InteractiveWidget;
     58import org.expeditee.items.widgets.SwingWidget;
    5859
    5960/**
     
    6364 *
    6465 */
    65 public class SampleRecorder extends InteractiveWidget
    66         implements ActionListener, Observer, MultitrackLoadListener {
     66public class SampleRecorder extends SwingWidget implements ActionListener, Observer, MultitrackLoadListener {
    6767       
    6868        private enum WidgetState {
     
    105105        private final static int MAX_COUNTDOWN_TIME = 60;
    106106       
    107         private static final Color GRAPH_BACKCOLOR = Color.BLACK;
    108         private static final Color GRAPH_WAVECOLOR = Color.GREEN;
     107        private static final Colour GRAPH_BACKCOLOR = Colour.BLACK;
     108        private static final Colour GRAPH_WAVECOLOR = Colour.GREEN;
    109109       
    110110        private final static int RENDER_POINTS_PER_SECOND = 20; // how many points to render each second
     
    112112        private final static String COUNTDOWN_META = "countdown=";
    113113       
    114         public SampleRecorder(Text source, String[] args) {
     114        public SampleRecorder(Text source, String[] args)
     115        {
    115116                this(source, args, false);
    116117        }
    117118       
    118         public SampleRecorder(Text source, String[] args, boolean isTemporary) {
     119        public SampleRecorder(Text source, String[] args, boolean isTemporary)
     120        {
    119121                super(source, new JPanel(new GridBagLayout()),
    120122                                AnimatedSampleGraph.GRAPH_WIDTH + (2 * HORO_SPACING),
     
    132134                // Create gui layout
    133135                recordButton = new JButton();
    134                 recordButton.setIcon(IconRepository.getIcon("record.png"));
     136                SwingMiscManager.setJButtonIcon(recordButton, IconRepository.getIcon("record.png"));
    135137                recordButton.addActionListener(this);
    136138                recordButton.setPreferredSize(new Dimension(AnimatedSampleGraph.GRAPH_WIDTH / 2, BUTTON_HEIGHT));
    137139               
    138140                recordSynchedButton = new JButton();
    139                 recordSynchedButton.setIcon(IconRepository.getIcon("recordplay.png"));
     141                SwingMiscManager.setJButtonIcon(recordSynchedButton, IconRepository.getIcon("recordplay.png"));
    140142                recordSynchedButton.addActionListener(this);
    141143                recordSynchedButton.setPreferredSize(new Dimension(AnimatedSampleGraph.GRAPH_WIDTH / 2, BUTTON_HEIGHT));
    142144
    143145                stopButton = new JButton();
    144                 stopButton.setIcon(IconRepository.getIcon("stop.png"));
     146                SwingMiscManager.setJButtonIcon(stopButton, IconRepository.getIcon("stop.png"));
    145147                stopButton.addActionListener(this);
    146148                stopButton.setPreferredSize(new Dimension(AnimatedSampleGraph.GRAPH_WIDTH, BUTTON_HEIGHT));
     
    303305       
    304306                                sampleGraph.alternateText = Integer.toString(countDown);
    305                                 sampleGraph.alternateTextColor = (countDown > 3) ? Color.WHITE : Color.RED;
     307                                sampleGraph.alternateTextColor = (countDown > 3) ? Colour.WHITE : Colour.RED;
    306308                                sampleGraph.invalidateGraph();
    307                                 FrameGraphics.refresh(true);
     309                                DisplayController.requestRefresh(true);
    308310                               
    309311                                countdownThread = new CountDownTimer(countDown);
     
    373375                                         Frame targetFrame = getParentFrame();
    374376                                         if (targetFrame == null) {
    375                                                  targetFrame = DisplayIO.getCurrentFrame();
     377                                                 targetFrame = DisplayController.getCurrentFrame();
    376378                                         }
    377379                                         
     
    398400                                         } else {
    399401                                                 
    400                                                  FrameMouseActions.pickup(trackWidget.getItems());
     402                                                 StandardGestureActions.pickup(trackWidget.getItems());
    401403                                                       
    402404                                                // Reset the state
     
    602604                        assert (state == WidgetState.Ready);
    603605                       
    604                         Frame target = DisplayIO.getCurrentFrame();
     606                        Frame target = DisplayController.getCurrentFrame();
    605607                        if (target  == null) return;
    606608
     
    608610                       
    609611                        RecordOverdubLauncher launcher = new RecordOverdubLauncher((Integer)countDownSpinner.getValue());
    610                         launcher.setPosition(FrameMouseActions.MouseX, FrameMouseActions.MouseY);
     612                        launcher.setPosition(DisplayController.getMousePosition());
    611613
    612614                        // Pick it up
    613                         FrameMouseActions.pickup(launcher);
     615                        StandardGestureActions.pickup(launcher);
    614616                       
    615617                }
     
    757759                        setState(WidgetState.LoadingPlayback, "Loading tracks...");
    758760                       
    759                         Frame currentFrame = DisplayIO.getCurrentFrame();
     761                        Frame currentFrame = DisplayController.getCurrentFrame();
    760762                        if (currentFrame == null || currentFrame.getName() == null) {
    761763                               
     
    843845               
    844846                private String alternateText = null;
    845                 private Color alternateTextColor = Color.WHITE;
     847                private Colour alternateTextColor = Colour.WHITE;
    846848
    847849                AnimatedSampleGraph() {
    848850                        imageBuffer = new BufferedImage(GRAPH_WIDTH, GRAPH_HEIGHT, BufferedImage.TYPE_INT_RGB);
    849851                        imageGraphics = (Graphics2D)imageBuffer.getGraphics();
    850                         imageGraphics.setColor(GRAPH_BACKCOLOR);
     852                        imageGraphics.setColor(SwingConversions.toSwingColor(GRAPH_BACKCOLOR));
    851853                        imageGraphics.fillRect(0, 0, GRAPH_WIDTH, GRAPH_HEIGHT);
    852854                        setPreferredSize(new Dimension(GRAPH_WIDTH, GRAPH_HEIGHT));
     
    857859                 */
    858860                public void clear() {
    859                         imageGraphics.setColor(GRAPH_BACKCOLOR);
     861                        imageGraphics.setColor(SwingConversions.toSwingColor(GRAPH_BACKCOLOR));
    860862                        imageGraphics.fillRect(0, 0, GRAPH_WIDTH, GRAPH_HEIGHT);
    861863                        invalidateGraph();
     
    867869                        if (alternateText != null) {
    868870                               
    869                                 g.setColor(Color.BLACK);
     871                                g.setColor(SwingConversions.toSwingColor(Colour.BLACK));
    870872                                g.fillRect(0, 0, getWidth(), getHeight());
    871873                               
    872                                 g.setFont(TrackWidgetCommons.FREESPACE_TRACKNAME_FONT);
    873                                 g.setColor(alternateTextColor);
     874                                g.setFont(SwingMiscManager.getIfUsingSwingFontManager().getInternalFont(TrackWidgetCommons.FREESPACE_TRACKNAME_FONT));
     875                                g.setColor(SwingConversions.toSwingColor(alternateTextColor));
    874876                               
    875877                                // Center track name
    876                                 FontMetrics fm   = g.getFontMetrics(TrackWidgetCommons.FREESPACE_TRACKNAME_FONT);
     878                                FontMetrics fm   = g.getFontMetrics(SwingMiscManager.getIfUsingSwingFontManager().getInternalFont(TrackWidgetCommons.FREESPACE_TRACKNAME_FONT));
    877879                                Rectangle2D rect = fm.getStringBounds(alternateText, g);
    878880                               
     
    907909                       
    908910                        // Render backcolor
    909                         imageGraphics.setColor(GRAPH_BACKCOLOR);
     911                        imageGraphics.setColor(SwingConversions.toSwingColor(GRAPH_BACKCOLOR));
    910912                        imageGraphics.fillRect(GRAPH_WIDTH - pixelWidth, 0, pixelWidth, GRAPH_HEIGHT);
    911913                       
    912914                        // Render wave forms from lastSampleHeight
    913                         imageGraphics.setColor(GRAPH_WAVECOLOR);
     915                        imageGraphics.setColor(SwingConversions.toSwingColor(GRAPH_WAVECOLOR));
    914916                        int currentPixelX = GRAPH_WIDTH - pixelWidth;
    915917
     
    933935                Rectangle dirty = this.getBounds();
    934936                dirty.translate(SampleRecorder.this.getX(), SampleRecorder.this.getY());
    935                 FrameGraphics.invalidateArea(dirty);
    936                 FrameGraphics.refresh(true);
     937                DisplayController.invalidateArea(SwingConversions.fromSwingRectangle(dirty));
     938                DisplayController.requestRefresh(true);
    937939               
    938940                }
     
    979981                                                        sampleGraph.alternateText = Integer.toString(currentCountdown);
    980982                                                        sampleGraph.alternateTextColor = (currentCountdown > 3) ?
    981                                                                                 Color.WHITE : Color.RED;
     983                                                                                Colour.WHITE : Colour.RED;
    982984                                                        sampleGraph.invalidateGraph();
    983                                                         FrameGraphics.refresh(true);
     985                                                        DisplayController.requestRefresh(true);
    984986                                                }
    985987                                        });
Note: See TracChangeset for help on using the changeset viewer.