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

    r1040 r1102  
    11package org.apollo;
    22
    3 import java.awt.Image;
    4 import java.awt.Toolkit;
    5 import java.awt.event.WindowEvent;
    6 import java.awt.event.WindowListener;
    7 import java.net.URL;
    83import java.util.Collection;
    94import java.util.HashSet;
    105import java.util.Set;
    116
    12 import javax.swing.SwingUtilities;
    137import javax.swing.UIManager;
    148
     
    2923import org.apollo.widgets.FramePlayer;
    3024import org.expeditee.actions.Actions;
     25import org.expeditee.core.BlockingRunnable;
     26import org.expeditee.gio.EcosystemManager;
     27import org.expeditee.gio.EcosystemManager.Ecosystem;
     28import org.expeditee.gio.GraphicsManager;
     29import org.expeditee.gio.InputManager.WindowEventListener;
     30import org.expeditee.gio.InputManager.WindowEventType;
    3131import org.expeditee.gui.Browser;
    3232import org.expeditee.gui.Frame;
    3333import org.expeditee.gui.FrameIO;
    34 import org.expeditee.gui.FrameKeyboardActions;
    35 import org.expeditee.gui.FrameMouseActions;
    3634import org.expeditee.settings.UserSettings;
    37 import org.expeditee.importer.FrameDNDTransferHandler;
    3835import org.expeditee.items.Item;
    3936import org.expeditee.items.Text;
     
    4744public final class ApolloSystem {
    4845       
     46        private static final String APOLLO_ICON = "org/apollo/icons/mainicon.png";
     47       
    4948        // TODO: Create actual frames
    5049        public static final String SYSTEM_FRAMESET_NAME = "apollosystem";
    5150        public static final String HELP_TOP_FRAMENAME = SYSTEM_FRAMESET_NAME + 2;
    5251       
    53 //      TODO: How to get good results: collection (moteef) and querry
     52        // TODO: How to get good results: collection (moteef) and querry
    5453        // TODO: How to omit indexing on tracks
    5554        public static final String HELP_MELODYSEARCH_FRAMENAME = SYSTEM_FRAMESET_NAME + 3;
     
    5857        public static final String SETTINGS_NAME_TIMELINE_LMARGIN = "timelineleftmargin";
    5958       
    60 
    61 
    6259        public static boolean useQualityGraphics = true;
    63        
    64         private ApolloSystem() {
    65         }
    6660
    6761        private static boolean hasInitialized = false;
    6862       
     63        private ApolloSystem()
     64        {
     65        }
     66       
    6967        /**
    7068         * Initializes Apollo mod for expeditee - prepares all subsystems.
    7169         */
    72         public static void initialize() {
    73                
     70        public static void initialize()
     71        {
    7472                if (hasInitialized) return;
    7573
    7674                ApolloSystemLog.println("Initializing...");
    77                
    78                 SwingUtilities.invokeLater(new Runnable() {
    79                         public void run() {
    80                                
    81                                  try {
    82 
    83                                         URL url = ClassLoader.getSystemResource("org/apollo/icons/mainicon.png");
    84                                        
    85                                         if (url != null) {
    86                                                  Image img = Toolkit.getDefaultToolkit().getImage(url);
    87                                                  Browser._theBrowser.setIconImage(img);
    88                                         }
    89                                                
    90        
    91                                          
    92                                  } catch (Exception e) {
    93                                          e.printStackTrace();
    94                                  }
    95                                  
    96                                 // Ensure that resources are released before the application is closed.
    97                                 Browser._theBrowser.addWindowListener(new WindowListener() {
    98                
    99                                         public void windowActivated(WindowEvent e) {
    100                                         }
    101                
    102                                         public void windowClosed(WindowEvent e) {
    103                                         }
    104                
    105                                         public void windowClosing(WindowEvent e) {
    106                                                 ApolloSystem.shutdown();
    107                                         }
    108                
    109                                         public void windowDeactivated(WindowEvent e) {
    110                                         }
    111                
    112                                         public void windowDeiconified(WindowEvent e) {
    113                                         }
    114                
    115                                         public void windowIconified(WindowEvent e) {
    116                                         }
    117                
    118                                         public void windowOpened(WindowEvent e) {
    119                                         }
    120                                
    121                                 });
    122                                
    123                                 Browser._theBrowser.getContentPane().removeKeyListener(FrameKeyboardActions.getInstance());
    124                                 Browser._theBrowser.removeKeyListener(FrameKeyboardActions.getInstance());
    125                                
    126                                 Browser._theBrowser.getContentPane().addKeyListener(new AudioFrameKeyboardActions());
    127                                 Browser._theBrowser.addKeyListener(new AudioFrameKeyboardActions());
    128                                
    129                                 // Filter out some special mouse move cases
    130                                 AudioFrameMouseActions apolloMouseFilter = new AudioFrameMouseActions();
    131                                 Browser._theBrowser.getMouseEventRouter().removeExpediteeMouseMotionListener(
    132                                                 FrameMouseActions.getInstance());
    133                                 Browser._theBrowser.getMouseEventRouter().addExpediteeMouseMotionListener(apolloMouseFilter);
    134                                
    135                                 Browser._theBrowser.getMouseEventRouter().removeExpediteeMouseListener(
    136                                                 FrameMouseActions.getInstance());
    137                                 Browser._theBrowser.getMouseEventRouter().addExpediteeMouseListener(apolloMouseFilter);
     75
     76                // Ensure that resources are released before the application is closed.
     77                EcosystemManager.getInputManager().addWindowEventListener(new WindowEventListener() {
     78                        @Override
     79                        public void onWindowEvent(WindowEventType type)
     80                        {
     81                                if (type != WindowEventType.WINDOW_CLOSED) return;
     82                                ApolloSystem.shutdown();
    13883                        }
    13984                });
     85               
     86                EcosystemManager.getInputManager().registerGestureListener(ApolloGestureActions.getInstance());
     87                EcosystemManager.getInputManager().addInputEventToGestureTranslator(new ApolloKBMGestureTranslator());
    14088               
    14189                // Set title
     
    161109               
    162110                // Setup for importing audio
    163                 FrameDNDTransferHandler.getInstance().addCustomFileImporter(
    164                                 new SampledAudioFileImporter());
     111                EcosystemManager.getDragAndDropManager().addCustomFileImporter(new SampledAudioFileImporter());
    165112
    166113                ApolloSystemLog.println("  Loading actions and agents...");
     
    202149         * When invoked, the apollo setting frame is loaded and parsed... setting apollo-specific settings.
    203150         */
    204         public static void loadSettings() {
    205 
     151        public static void loadSettings()
     152        {
    206153                // Load apollo settings frame from the default profile
    207154                Frame profile = FrameIO.LoadProfile(UserSettings.DEFAULT_PROFILE_NAME);
     
    241188        }
    242189       
    243         private static Mutable.Integer stripNameValueStringInteger(String namevalue) {
     190        private static Mutable.Integer stripNameValueStringInteger(String namevalue)
     191        {
    244192                assert (namevalue != null);
    245193                int valueIndex = namevalue.indexOf(':') + 1;
     
    259207         * Releases all resources currently used by the SampledAudioManager.
    260208         */
    261         public static void shutdown() {
    262                
     209        public static void shutdown()
     210        {
    263211                ApolloSystemLog.println("Saving banks...");
    264212                SoundDesk.getInstance().saveMasterMix();
     
    280228         *              True if has initialized.
    281229         */
    282         public static boolean isInitialized() {
     230        public static boolean isInitialized()
     231        {
    283232                return hasInitialized;
    284233        }
     
    294243         * @param args
    295244         */
    296         public static void main(String[] args) {
    297                
    298                 try {
    299                 UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
    300             }
    301             catch (Exception e) {
    302                e.printStackTrace();
    303                return;
    304             }
     245        public static void main(String[] args)
     246        {
     247                if (Browser.ECOSYSTEM_TYPE == Ecosystem.Swing) {
     248                        try {
     249                        UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
     250                    } catch (Exception e) {
     251                       e.printStackTrace();
     252                       return;
     253                    }
     254                }
     255
     256                // Window icon must be set before initialisation
     257                GraphicsManager.setWindowIcon(APOLLO_ICON);
    305258               
    306259                // Run expeditee
     
    308261               
    309262                // Initialize apollo
    310                 SwingUtilities.invokeLater(new Runnable() {
    311                         public void run() {
     263                EcosystemManager.getMiscManager().runOnGIOThread(new BlockingRunnable() {
     264                        public void execute() {
    312265                                ApolloSystem.initialize();
    313266                        }
Note: See TracChangeset for help on using the changeset viewer.