Show Broadcasts.java syntax highlighted
/*
* Copyright (c) 2004
* Helsinki Institute of Physics
* see LICENSE file for details
*
* Broadcasts.java
* Created on Sep 12, 2004
*/
package fi.hip.gb.client;
import javax.microedition.lcdui.Form;
/**
* @author Juho Karppinen
*/
public class Broadcasts extends Form {
/** ID of the currenlty selected broadcast message */
//private int selectedBroadcast = -1;
/** ui component for selecting message from the list of broadcast messages */
//private ChoiceGroup cgBroadcast = new ChoiceGroup("0 messages available", Choice.EXCLUSIVE);
/** list of available broadcast messages */
//private Vector broadcasts = new Vector();
public Broadcasts() {
super("Broadcasts");
}
/*
public void commandAction(Command c, Displayable dp) {
String label = c.getLabel();
System.out.println(label);
if (dp == broadcastForm) {
if (c.getCommandType() == Command.BACK) {
showMainForm();
selectedBroadcast = -1;
} else {
selectedBroadcast = cgBroadcast.getSelectedIndex();
if (label.equals("Show") && selectedBroadcast != -1) {
showStatus((Long)broadcasts.elementAt(selectedBroadcast));
} else if (label.equals("Refresh")) {
//showBroadcasts(null);
}
}
}
}
*/
/*
protected static void showBroadcasts(LiteStatus container) {
if(broadcastForm == null) {
broadcastForm = new Form("Messages");
//broadcastForm.addCommand(new Command("Save message", Command.ITEM, 1));
broadcastForm.addCommand(new Command("Back", Command.BACK, 1));
broadcastForm.setCommandListener(MIDui.this);
}
if(container != null) {
broadcastForm.setTitle(container.getName());
int index = cgBroadcast.append(container.getName(), null);
broadcasts.insertElementAt(container.getJobID(), index);
if(container.getStartTime() != null)
broadcastForm.insert(0, new StringItem("Sended: ", container.getStartTime()));
//resultNames.removeAllElements();
//cgResult = new ChoiceGroup("attachments", Choice.EXCLUSIVE);
for(int j=0; j < container.getResults().size(); j++) {
LiteResult res = (LiteResult) container.getResults().elementAt(j);
//broadcastForm.append(new StringItem("Name: ",
// results[j].getFilename()));
broadcastForm.append(new StringItem("Description: ",
res.getDescription()));
if(res.getType() == LiteResult.TEXT_TYPE) {
broadcastForm.append(new StringItem("Message: ", res.readContent()));
} else if(res.getType() == LiteResult.IMAGE_TYPE) {
broadcastForm.append(new ImageItem(res.getName()
+ "\n size: " + res.getSize() + " bytes",
Image.createImage(
res.readBytes(),
0,
res.getSize()),
ImageItem.LAYOUT_LEFT,
"broadcasted image"));
}
//index = cgResult.append(resultNames[i], null);
//resultNames.insertElementAt(resultNames[i], index);
}
//if(resultNames.size() > 0) {
//cgResult.setLabel(cgResult.size() + " results available");
//broadcastForm.append(cgResult);
//}
// stop the automatical updates
}
display.setCurrent(broadcastForm);
}
/**
* Listen broadcast messages
*/
/*
private void broadcasting() {
int refreshRate = configs.getUpdateInterval();
if(refreshRate == -1)
return;
TimerTask timer = new TimerTask() {
public void run() {
try {
// throws exception if not logged in
client.isLogged();
} catch(IOException ioe) {
return;
}
System.out.println("Listing jobs");
String[] jobNames = null;
try {
jobNames = client.getJoblist(true, true);
} catch (Exception e) {
showException("Error while listing jobs", e, mainForm);
return;
}
for (int i = 0; i < jobNames.length; i++) {
// parse ID and name
int indexOf = jobNames[i].indexOf('#');
Long jobID = new Long(Long.parseLong(jobNames[i].substring(0, indexOf)));
String jobname = jobNames[i].substring(indexOf+1);
// dont's reuse old messages
if(broadcasts.contains(jobID))
continue;
System.out.println("Found new broadcast: " + jobname);
LiteStatus status = null;
try {
status = client.getStatus(jobID);
status.setName(jobname);
} catch (Exception e) {
System.out.println(e.getMessage());
cancel();
return;
}
System.out.println("Returned broadcast: " + status.toString());
Vector results = status.getResults();
if(status.isFinished() && results.size() > 0) {
System.out.println("download broadcast results");
String[] names = new String[results.size()];
for(int k=0; k < names.length; k++) {
names[i] = ((LiteResult)results.elementAt(k)).getName();
}
try {
results = client.getResult(jobID, names);
} catch (Exception e) {
showException("Error downloading results", e, mainForm);
}
status.setResults(results);
}
//showBroadcasts(status);
}
}
};
// either list broadcast messages once, or frequently
if(refreshRate > 0)
new Timer().schedule(timer, refreshRate, refreshRate);
else
new Thread(timer).start();
}
*/
}
See more files for this project here