boolean locked = JSynoptic.gui.getLockedShapes().contains(provider);
for (int i=0; i<actions.length; ++i) {
// Display action in a hirarchical sub menus.
JMenuItem jmi = createMenuItem(this, actions[i], null); //TODO Set icon if provided
//JMenuItem jmi = new JMenuItem(actions[i]);
if (locked || !provider.canDoAction(x,y,o,actions[i],context))
jmi.setEnabled(false);
else
jmi.addActionListener(this);
//add(jmi);
menuItems.put(jmi, actions[i]);
providers.put(jmi, provider);
}
}
}
if (obj instanceof Linkable) {
final Linkable l = (Linkable)obj;
final String link = l.getLink();
if (!isEmpty) addSeparator();
JMenuItem jmi;
boolean followItem = false;
if ((link==null) || (link.equals(""))) {
jmi = new JMenuItem(messageWriter.print0args("AddLink"));
} else {
followItem = true;
jmi = new JMenuItem(messageWriter.print0args("EditLink"));
}
jmi.addActionListener(this);
menuItems.put(jmi, jmi.getText());
add(jmi);
providers.put(jmi, new ContextualActionProvider() {
public String[] getActions(double x, double y, Object o, int context) {return null;}
public boolean canDoAction(double x, double y, Object o, String action, int context) {return true;}
public boolean doAction(double x, double y, Object o, String action, CompoundEdit undoableEdit) {
JFileChooser fc;
if(JSynoptic.gui instanceof JSynopticPanels){
fc =((JSynopticPanels)JSynoptic.gui).getFileChooser();
}else{
fc = new JFileChooser();
}
if (link!=null) fc.setSelectedFile(new File(link));
int res = fc.showDialog(JSynoptic.gui.getOwner(), messageWriter.print0args("SelectLink"));
if (res!=JFileChooser.APPROVE_OPTION) return false;
File f = fc.getSelectedFile();
if ((f==null) || (!f.exists())) {
JSynoptic.setStatus(messageWriter.print1args("CannotSetLinkInvalidFile",f.getName()));
return false;
}
try {
l.setLink(f.getCanonicalPath());
} catch (IOException e) {
l.setLink(f.getAbsolutePath());
}
ActionPopup.this.component.repaint();
return true;
}
});
if (followItem) {
jmi = new JMenuItem(messageWriter.print0args("OpenLink"));
jmi.addActionListener(this);
menuItems.put(jmi, jmi.getText());
add(jmi);
providers.put(jmi, new ContextualActionProvider() {
public String[] getActions(double x, double y, Object o, int context) {return null;}
public boolean canDoAction(double x, double y, Object o, String action, int context) {return true;}