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

📄 .#ui.java.1.8.2.3

📁 国外的j2me播放器软件
💻 3
📖 第 1 页 / 共 3 页
字号:
            
                LOG.debug(
                    "Selected server: " + currentMS.getFriendlyName());
                
                ContentDirectoryService cds = 
                    currentMS.getContentDirectoryService();

                MediaContent[] mc = cds.browseContentContainer(
                    0, 
                    ContentDirectoryService.REQUEST_ALL);

                if (mc == null || mc.length == 0) {
                    LOG.debug("mc=0/null - Returning nothing!");
                    return MENUACTION_DO_NOTHING;
                }
                
                for(int i = 0; i < mc.length; i++) {
                    meBrowse.addChild(
                        new MediaContentMenuElement(
                            cds, 
                            mc[i]));
                }

                return MENUACTION_DISPLAY_CHILDREN;
            } catch (IOException ioe) {
                LOG.fatal("IOException while getting the current server");
                LOG.fatal(ioe);
            }
        }
        
        return MENUACTION_DO_NOTHING;
    }

    /**
     * User navigates 'back' or 'left'.
     *
     * @param me MenuElement which is marked/selected by the user, and where 
     *           the action occurs. Notice that for MenuElementComboShift 
     *           the parent of a sub-MenuElement will be me, and not the 
     *           selected sub-element.
     */
    public int menuNavigateBack(MenuElement me) {
        if (me == meSetupBack) {
            return MENUACTION_DO_NOTHING;
        } else if (me == meSetupRepeat) {
            oneppSettings.setRepeatSetting(!oneppSettings.getRepeatSetting());
            System.out.println("Repeat setting: " + oneppSettings.getRepeatSetting());
        } else if (me == meSetupShuffle) {
            oneppSettings.setShuffleSetting(!oneppSettings.getShuffleSetting());
            System.out.println("Shuffle setting: " + oneppSettings.getShuffleSetting());
        } else if (me == meSetupHostingPort) {
            oneppSettings.toggleHostingPortSetting();
        }
	
	
        return MENUACTION_DO_NOTHING;
    }

    /**
     * User activates the marked MenuElement.
     *
     * @param me MenuElement which is marked/selected by the user, and where 
     *           the action occurs. Notice that for MenuElementComboShift 
     *           the parent of a sub-MenuElement will be me, and not the 
     *           selected sub-element.
     */
    public int menuAction(MenuElement me) {
        if (me == meSetupBack) {
            return MENUACTION_DISPLAY_GRANDPARENT;
        } else if (me == meSetupRepeat) {
            oneppSettings.setRepeatSetting(!oneppSettings.getRepeatSetting());
            System.out.println("Repeat setting: " + oneppSettings.getRepeatSetting());
        } else if (me == meSetupHostingPort) {
		if (oneppSettings.getHostingPortSetting() != -1) {
		    // TODO Show some popup screen to input port number
		}
        } else if (me == meServers) {
            if (meServers.getCurrentChild() == meServersRefresh) {
                LOG.debug("Refreshing server menu");
                try {
                    updateMediaServerMenu();
                } catch (IOException ioe) {
                    System.out.println("IOException caught while updating MS list");
                    ioe.printStackTrace();
                } catch (InterruptedException ie) {
                    LOG.fatal("Interrupted while updating MS menu");
                    LOG.fatal(ie);
                } finally {
                    LOG.debug("Finished refreshing MS menu");
                }
            } else {
                setCurrentMediaServer();
            }
            
            return MENUACTION_REPAINT;
        } else if (me == meRenderers) {
            if (meRenderers.getCurrentChild() == meRenderersRefresh) {
                LOG.debug("Refreshing renderer menu");
                try {
                    updateMediaRendererMenu();
                } catch (IOException ioe) {
                    LOG.fatal("IOException caught while updating MS list");
                    LOG.fatal(ioe);
                } catch (InterruptedException ie) {
                    LOG.fatal("Interrupted while updating MS list");
                    LOG.fatal(ie);
                } finally {
                    LOG.debug("Finished refreshing MR menu");
                }
            } else {
                setCurrentMediaRenderer();
            }

            return MENUACTION_REPAINT;
        } else if (me == meExit) {
            m.quit();
        }
        
        return MENUACTION_DO_NOTHING;
    }
	
    private void setCurrentMediaRenderer() {
        oneppSettings.setCurrentMediaRendererIndex(meRenderers.getCurrentIndex());
    }
        
    private void setCurrentMediaServer() {
        oneppSettings.setCurrentMediaServerIndex(meServers.getCurrentIndex());
	}
	
	public void commandAction(Command c, Displayable d) {
        LOG.debug("UI::commandAction (" + c + ", " + d + ")");
        
		if (c == playCommand) {
            LOG.debug("Show playscreen");

            Display disp = Display.getDisplay(m);
            disp.setCurrent(ps);
		} else if (c == homeCommand) {
            oneppMenu.displayMenuRoot();
		} else if (c == showLogCommand) {
            Display disp = Display.getDisplay(m);
            org.apache.log4j.LogCanvas lc = LOG.getLogCanvas();
            lc.setPreviousScreen(disp.getCurrent());
            disp.setCurrent(lc);
        } else {
            LOG.debug("Unknown command");
        }
	}
    
    private class MediaContentMenuElement extends MenuElement 
                                          implements MenuEventListener {
        private MediaContent mc = null;
        private ContentDirectoryService cds = null;
        
        public MediaContentMenuElement(
            ContentDirectoryService cds, MediaContent mc) {
            this.cds = cds;
            this.mc = mc;
        }

        public String toString() {
            return mc.getName();
        }

        public void paint(Graphics g) {
            String text = mc.getName();
            
            if (mc instanceof ContentContainer) {
                text += " ->";
            }
                
            g.drawString(
                text,
                g.getClipX(),
                g.getClipY(),
                Graphics.TOP | Graphics.LEFT);
        }

        public int menuAction(MenuElement me) {
            LOG.debug("menuAction for " + this);
            
            if (mc instanceof ContentContainer) {
                LOG.debug("Navigate to children of: " + mc);
                getContentContainerElements();

                return MENUACTION_DISPLAY_CHILDREN;
            } else if (mc instanceof TrackInformation) {
                playMediaTrack((TrackInformation)mc);
                
                return MENUACTION_DO_NOTHING;
            } else {
                LOG.debug("menuAction for " + this + "- unknown");
                return MENUACTION_DO_NOTHING;
            }
        }
                
        public int menuNavigateBack(MenuElement me) {
            LOG.debug("MenuNavigateBack for " + this);
            //super(me);

            return MENUACTION_DISPLAY_GRANDPARENT;
        }

        public int menuNavigateInto(MenuElement me) {
            LOG.debug("MenuNavigateInto for " + this);

            if (mc instanceof ContentContainer) {
                LOG.debug("Navigate to children of: " + mc);
                getContentContainerElements();
                
                return MENUACTION_DISPLAY_CHILDREN;
            } else if (mc instanceof TrackInformation) {
                playMediaTrack((TrackInformation)mc);
                return MENUACTION_DO_NOTHING;
            } else {
                LOG.debug("menuAction for " + this + "- unknown");
                return MENUACTION_DO_NOTHING;
            }
        }   

        private void getContentContainerElements() {
            try {
                this.removeAllChildren();

                if (cds == null) {
                    LOG.debug("CDS is null");
                    return;
                }

                int objId = mc.getObjectID();
                
                LOG.debug("Browse container " + objId);
                MediaContent[] mcChildren = cds.browseContentContainer(
                    mc.getObjectID(), 
                    15);
                // XXX Should get the number of elements which fits ONE screen height
                LOG.debug("Finished browsing");
                
                if (mcChildren == null) {
                    LOG.debug("mcChildren is null!");
                    return;
                }

                LOG.debug(
                    "Number of child elements found: " + mcChildren.length);

                for(int i = 0; i < mcChildren.length; i++) {
                    LOG.debug(
                        "Child" + i + ": " + mcChildren[i].getName());
                    this.addChild(
                        new MediaContentMenuElement(
                            cds, 
                            mcChildren[i]));
                }
            } catch (IOException ioe) {
                LOG.fatal("IOException getting elements of container");
                LOG.fatal(ioe);
            } catch (ArrayIndexOutOfBoundsException ae) {
                LOG.fatal("ArrayIndex wrong");
                LOG.fatal(ae);
            } catch (Exception e) {
                LOG.fatal("Exception getting elements of container");
                LOG.fatal(e);
            }
        }

        private void playMediaTrack(TrackInformation ti) {
            try {
                LOG.debug("Play media element: " + ti);
                MediaRenderer mr = Settings.getInstance().getCurrentMediaRenderer();
                    
                AVTransportService avts = mr.getAVTransportService();
                
                avts.setAVTransportURI(ti);
                avts.play();

                ps.setTitle(ti.getName());
                ps.setAlbum(ti.getAlbum());
                ps.setArtist(ti.getArtist());
                // XXX Should also "tell" PlayScreen that it is in 'play' mode
                //     One possiblity:
                //     PS subscribes to the events by the current renderer, 
                //     and will therefore get all this information seamlessly by UPnP.
                //     Now it should work even if some other device chooses to change 
                //     the current URI.
            } catch (IOException ioe) {
                LOG.fatal("IOException while starting to play a  song...");
                LOG.fatal(ioe);
            } catch (Exception e) {
                LOG.fatal("Exception while starting to play");
                LOG.fatal(e);
            } finally {
                LOG.debug("Finished start to play :)");
            }
        }
    }
    
    private class StartScreen extends Form implements CommandListener {
        private Gauge progress = null;
        
        public StartScreen(String title) {
            super(title);

            try {
                addCommand(showLogCommand);
                setCommandListener(this);
                
                Image imgLogo = Image.createImage("/aml_noalpha.png");
                ImageItem logo = new ImageItem(
                    "Agder University College",
                    imgLogo,
                    Item.LAYOUT_CENTER | 
                    // (ahaeber) Not supported by J9: Item.LAYOUT_VCENTER | 
                    Item.LAYOUT_NEWLINE_AFTER | 
                    Item.PLAIN,
                    "Agder Mobility Lab");
                append(logo);
                append("ONE Portable Player v1.0.5000");

                progress = new Gauge("Progress", false, 100, 0);
                append(progress);
            } catch (/*IO*/Exception io) {
                LOG.fatal(io);
            }
        }

        public void commandAction(Command c, Displayable d) {
            Display disp = Display.getDisplay(m);
            org.apache.log4j.LogCanvas lc = Logger.getLogCanvas();
            lc.setPreviousScreen(disp.getCurrent());
            disp.setCurrent(lc);
        }
    }
}

⌨️ 快捷键说明

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