⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 .#ui.java.1.8.2.3

📁 国外的j2me播放器软件
💻 3
📖 第 1 页 / 共 3 页
字号:
package no.auc.one.portableplayer.userinterface;

import no.auc.one.portableplayer.*;
import no.auc.one.portableplayer.communication.mediaserver.*;
import no.auc.one.portableplayer.communication.mediarenderer.*;
import no.auc.one.portableplayer.librarymanager.*;
import no.auc.one.portableplayer.utils.*;

import java.io.IOException;
import javax.microedition.lcdui.*;

import org.apache.log4j.*;

// XXX Really UserInterfaceController.
//     Should control the other user interface elements.
public class UI implements CommandListener, MenuEventListener {

    private static Logger LOG;
    
	//Commands
	private Command homeCommand = null;
	private Command playCommand = null;
    private Command showLogCommand = null;
	
    // Menu & elements
    Menu oneppMenu;
    MenuElement meBrowse;
    MenuElement meSetup;
    MenuElement meSetupBack;
    MenuElementComboShift meSetupRepeat;
    MenuElementComboShift meSetupShuffle;
    MenuElementComboShift meSetupHostingPort;
    MenuElementComboShift meServers;
    MenuElement meServersRefresh;
    MenuElementComboShift meRenderers;
    MenuElement meRenderersRefresh;
    MenuElement meExit;

    StartScreen sc = null;
    PlayScreen ps = null;
    
	Main m = null;
	private static UI ref;
    LibraryMgr lib = LibraryMgr.getInstance();
    Settings oneppSettings = Settings.getInstance();
    
    static MediaServer currentMS = null;
    
	//Constructor
	private UI() {
        LOG = Logger.getLogger("UI");
	}
	
	public static UI getInstance() {
      if (ref == null) {
          // it's ok, we can call this constructor
          ref = new UI();
      }
      return ref;
    }

    public void setOwner(Main m) {
        this.m = m;
    }

    // XXX EVIL method... to be removed later (using Settings instead)
    public Main getOwner() {
        return m;
    }
    
    public void show() throws Exception {
        if (m == null) {
            // XXX Should throw some more appropriate Exception class
            throw new Exception("Main has not been specified");
        }

        LOG.debug("UI::show");
        
        Display d = Display.getDisplay(m);
        Logger.getLogCanvas().setPreviousScreen(oneppMenu);
        d.setCurrent(Logger.getLogCanvas());
        
        showLogCommand = new Command("Show Log", Command.SCREEN, 1);

        
        // Display splash screen...
        LOG.debug("UI::show Creating StartScreen");
        sc = new StartScreen("Starting...");
        if (sc != null) {
            LOG.debug("UI::show StartScreen created");
            d.setCurrent(sc);
            d.flashBacklight(1000);
        } else {
            LOG.fatal("UI::show Startscreen is NULL");
            return;
        }
        
        ps = new PlayScreen("Now Playing", oneppMenu, d);
        initializeMenu();
        
        sc.progress.setValue(100);
        
        d.setCurrent(oneppMenu);
    }
    
    private void initializeMenu() {
        try {
            oneppMenu = new Menu();

		    homeCommand = new Command("Home", Command.BACK, 1);
		    playCommand = new Command("Play Screen", Command.SCREEN, 1);
	        oneppMenu.setCommandListener(this);
        
		    oneppMenu.addCommand(homeCommand);
		    oneppMenu.addCommand(playCommand);
            oneppMenu.addCommand(showLogCommand);

            // XXX Browse needs special treatment...
            //      1) When browsing it should check what the currently 
            //         selected server is.
            //      2) Will always have the 'Back' MenuElement. But when the 
            //         user invokes menuAction for meBrowse then it will 
            //         try to fetch the content for the root of the current 
            //         server.
            //      3) If the current server is null or refresh then do not 
            //         add more elements.
            //      4) The children of meBrowse will be of two kinds:
            //          i)  Normal MenuElement for containers. These will 
            //              use their 'id' for the objectid.
            //          ii) MenuElementMediaContent for all media content.
            //              Will have a MediaContent element associated 
            //              with it. Using something like:
            //                  if (element instanceof MediaContentTrack) {
            //                      playMusic(element);
            //                  } else if (element instanceof MediaContentVideo) {
            //                      showVideo(element);
            //                  } ... etc.
            //  
            meBrowse = new MenuElement("Browse media", this);
            oneppMenu.addRootMenuElement(meBrowse);

            sc.progress.setValue(10);
            
            // Update media server and renderer lists
            // TODO Add servers and renderers to settings too
            meServers = new MenuElementComboShift("Media Server", this);
            meServersRefresh = new MenuElement("Refresh", this);
            meServers.addChild(meServersRefresh);
            //updateMediaServerMenu();
            
            sc.progress.setValue(50);
            
            meRenderers = new MenuElementComboShift("Media Renderer", this);
            meRenderersRefresh = new MenuElement("Refresh", this);
            meRenderers.addChild(meRenderersRefresh);
            //updateMediaRendererMenu();
            
            meSetup = new MenuElement("Settings");
            
            meSetupRepeat = new MenuElementComboShift("Repeat", this);
            if (oneppSettings.getRepeatSetting() == true) {
		    meSetupRepeat.addChild(
		    	new MenuElement[]{
				new MenuElement("On"),
				new MenuElement("Off")});
	    }
	    else {
		    meSetupRepeat.addChild(
		    	new MenuElement[]{
				new MenuElement("Off"),
				new MenuElement("On")});
	    }
	    
            
            meSetupShuffle = new MenuElementComboShift("Shuffle", this);
            if (oneppSettings.getShuffleSetting() == true) {
		    meSetupShuffle.addChild(
		    	new MenuElement[]{
				new MenuElement("On"),
				new MenuElement("Off")});
	    }
	    else {
		    meSetupShuffle.addChild(
		    	new MenuElement[]{
				new MenuElement("Off"),
				new MenuElement("On")});
	    }
	    
	    meSetupHostingPort = new MenuElementComboShift("Hosting port number", this);
            if (oneppSettings.getHostingPortSetting() == -1) {
	        meSetupHostingPort.addChild(
                    new MenuElement[]{
                        new MenuElement("Auto"),
		        new MenuElement("Manual")
		        });
            }
	    else {
	        meSetupHostingPort.addChild(
                    new MenuElement[]{
                        new MenuElement("Manual"),
		        new MenuElement("Auto")
		        });
            }
		   
            meSetupBack = new MenuElement("Back", this);
            
            meSetup.addChild(
                new MenuElement[]{
                    meSetupBack, 
                    meSetupRepeat, 
                    meSetupShuffle,
                    meServers,
                    meRenderers,
		    meSetupHostingPort});
            
            oneppMenu.addRootMenuElement(meSetup);

            meExit = new MenuElement("Exit", this);
            
            oneppMenu.addRootMenuElement(new MenuElement[]{
                meServers,
                meRenderers,
                meExit
            });

            sc.progress.setValue(90);
        } catch (NullPointerException npe) {
            LOG.fatal("NullPointerException");
            LOG.fatal(npe);
        } catch (Exception e) {
            LOG.fatal("Exception occured finding MS or MR.");
            LOG.fatal(e);
        }
    }
	
	public void favouriteMediaServerUpdate(String locationUrl, String UDN) {
		
		LOG.debug("updateMediaServerMenu");
        meServers.removeAllChildren();
        
        FavouriteMediaServerUpdate fmsupdateThread = new FavouriteMediaServerUpdate();
        fmsupdateThread.setLocationUrl(locationUrl);
		fmsupdateThread.setUDN(UDN);
		fmsupdateThread.start();
		
	}
	
	private class FavouriteMediaServerUpdate extends Thread implements CancelAction {
		
		String locationUrl = "";
		String UDN = "";
		
		public void setLocationUrl(String locationUrl) {
			this.locationUrl = locationUrl;
		}
		
		public void setUDN(String UDN) {
			this.UDN = UDN;
		}
		
		public void run () {
			MenuUpdateAlert mua = null;
			try {
				oneppSettings.addMediaServerByLocationUrl(locationUrl);
			}
			catch (/*IO*/Exception e) {
                LOG.fatal(
                    "Exception occured while adding mediaserver by device description");
                LOG.fatal(e);
				e.printStackTrace();
            }
			
            try {
                
				
				MediaServer[] msList = oneppSettings.getMediaServerList();
				System.out.println("msList.length: " + msList.length);
                
				if (msList == null || msList.length == 0) {
					mua = new MenuUpdateAlert(
                    "Finding favourite media servers",
                    (CancelAction)this,
                    this);
					mua.start();
					oneppSettings.addMediaServerByUDN(UDN);
				}
				
				for(int i = 0; i < msList.length; i++) {
                    LOG.debug("MS Name: " + msList[i].getFriendlyName());
					meServers.addChild(new MenuElement(msList[i].getFriendlyName()));
                }
            } catch (/*IO*/Exception e) {
                LOG.fatal(
                    "Exception occured while updating (favourite) media server menu");
                LOG.fatal(e);
				e.printStackTrace();
            } finally {
                LOG.debug("Finished updating media server menu");
                meServers.addChild(meServersRefresh);
                
                Display d = Display.getDisplay(m);
                if (d.getCurrent() == mua) {
                    LOG.debug("Current displayable is MUA");
                    d.setCurrent(mua.getPrevDisplayable());
                } else {
                    LOG.debug("Current displayable is " + d.getCurrent());
                }
            }
			
		}
		
		public void cancel() throws IOException {
			
			if (oneppSettings.isUpdatingMediaServerList()) {
                oneppSettings.cancelUpdateMediaServerList();
            } else {
                throw new IllegalStateException("Currently not discovery going on");
            }
			
		}
		
	}
		
    private void updateMediaServerMenu() throws IOException, InterruptedException {
        LOG.debug("updateMediaServerMenu");
        meServers.removeAllChildren();
        
        MediaServerMenuUpdate msupdateThread = new MediaServerMenuUpdate();
        msupdateThread.start();		
    }
	
	
	
	
    private class MediaServerMenuUpdate extends Thread implements CancelAction {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -