*
* @param menu the menu (JMenu or JPopupMenu) to add items to
* @param url the URL of the image to send
*/
private void _initImageMenu(JComponent menu, final URL url) {
final MainImageDisplay imageDisplay = _imageFrame.getImageDisplayControl().getImageDisplay();
if (menu instanceof JMenu) {
// only include these in the main menu
JMenu jMenu = (JMenu) menu;
jMenu.add(getRegisterAction(true));
jMenu.add(getRegisterAction(false));
jMenu.add(new HubWatchAction(_imageFrame, this));
jMenu.add(getHubStartAction(true));
jMenu.add(getHubStartAction(false));
jMenu.addSeparator();
}
final PlasticTransmitter trans = new PlasticTransmitter(this, MessageId.FITS_LOADIMAGE, "image") {
@Override
protected void transmit(PlasticHubListener hub, URI clientId, ApplicationItem app) throws IOException {
URI[] recipients = app == null
? null
: new URI[]{app.getId()};
transmitImage(hub, clientId, recipients, url);
}
};
JMenu sendMenu = trans.createSendMenu();
sendMenu.setIcon(Resources.getIcon("phone2.gif"));
menu.add(sendMenu);
final JMenuItem broadCastItem = new JMenuItem("Broadcast Image");
broadCastItem.setIcon(Resources.getIcon("broadcast.gif"));
broadCastItem.addActionListener(trans.getBroadcastAction());
menu.add(broadCastItem);
if (url == null) {
broadCastItem.setEnabled(false);
trans.setEnabled(false);
imageDisplay.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent changeEvent) {
ImageChangeEvent e = (ImageChangeEvent) changeEvent;
if (e.isNewImage() && !e.isBefore()) {
boolean enabled = (imageDisplay.getURL() != null || imageDisplay.getFilename() != null);
trans.setEnabled(enabled);
broadCastItem.setEnabled(enabled);
}
}
});