📄 .#ui.java.1.8.2.2
字号:
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() {
LOG.debug("Setting current Media Renderer");
try {
// XXX Seems quite weird this code. This MAY cause the
// MediaServer to update its list of servers, and then
// the selected index here is WRONG. But since we
// currently KNOW that this will not happen, because
// we will only update the list on explicit refresh
// requests by the user.
MediaRenderer mr = new MediaRenderer();
LOG.debug("meRenderers.currentIndex = " +
meRenderers.getCurrentIndex());
mr = mr.getMediaRenderer(meRenderers.getCurrentIndex());
oneppSettings.setCurrentMediaRenderer(mr);
} catch (IOException ioe) {
System.out.println("IOException while changing media renderer");
ioe.printStackTrace();
} catch (NoSuchElementException nsee) {
System.out.println("NoSuchElementException while changing media renderer");
nsee.printStackTrace();
}
}
private void setCurrentMediaServer() {
try {
// XXX Seems quite weird this code. This MAY cause the
// MediaServer to update its list of servers, and then
// the selected index here is WRONG. But since we
// currently KNOW that this will not happen, because
// we will only update the list on explicit refresh
// requests by the user.
MediaServer ms = new MediaServer();
oneppSettings.setCurrentMediaServer(
ms.getMediaServer(meServers.getCurrentIndex()));
} catch (IOException ioe) {
System.out.println("IOException while changing media server");
ioe.printStackTrace();
} catch (NoSuchElementException nsee) {
System.out.println("NoSuchElementException while changing media server");
nsee.printStackTrace();
}
}
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 = LOG.getLogCanvas();
lc.setPreviousScreen(disp.getCurrent());
disp.setCurrent(lc);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -