use of org.openstack4j.model.identity.v3.Project in project TrakEM2 by trakem2.
the class FSLoader method deleteStaleFiles.
/**
* Delete stale files under the {@link FSLoader#unuid} folder.
* These include "*.ct" files (for {@link CoordinateTransform})
* and "*.zip" files (for alpha mask images) that are not referenced from any {@link Patch}.
*/
@Override
public boolean deleteStaleFiles(boolean coordinate_transforms, boolean alpha_masks) {
boolean b = true;
final Project project = Project.findProject(this);
if (coordinate_transforms)
b = b && StaleFiles.deleteCoordinateTransforms(project);
if (alpha_masks)
b = b && StaleFiles.deleteAlphaMasks(project);
return b;
}
use of org.openstack4j.model.identity.v3.Project in project TrakEM2 by trakem2.
the class FSLoader method saveAs.
/**
* Meant for programmatic access, such as calls to project.saveAs(path, overwrite) which call exactly this method.
*/
@Override
public String saveAs(final String path, final XMLOptions options) {
if (null == path) {
Utils.log("Cannot save on null path.");
return null;
}
String path2 = path;
String extension = ".xml";
if (// all fine
path2.endsWith(extension)) // all fine
{
} else if (path2.endsWith(".xml.gz"))
extension = ".xml.gz";
else {
// neither matches, add the default ".xml"
path2 += extension;
}
File fxml = new File(path2);
if (!fxml.canWrite()) {
// write to storage folder instead
String path3 = path2;
path2 = getStorageFolder() + fxml.getName();
Utils.logAll("WARNING can't write to " + path3 + "\n --> will write instead to " + path2);
fxml = new File(path2);
}
if (!options.overwriteXMLFile) {
int i = 1;
while (fxml.exists()) {
String parent = fxml.getParent().replace('\\', '/');
if (!parent.endsWith("/"))
parent += "/";
String name = fxml.getName();
name = name.substring(0, name.length() - 4);
path2 = parent + name + "-" + i + extension;
fxml = new File(path2);
i++;
}
}
Project project = Project.findProject(this);
path2 = super.saveAs(project, path2, options);
if (null != path2) {
project_file_path = path2;
Utils.logAll("After saveAs, new xml path is: " + path2);
ControlWindow.updateTitle(project);
touched_mipmaps.clear();
}
return path2;
}
use of org.openstack4j.model.identity.v3.Project in project TrakEM2 by trakem2.
the class Merger method createTable.
private static JTable createTable(final HashSet<ZDisplayable> hs, final String column_title, final Project p1, final Project p2) {
final TwoColumnModel tcm = new TwoColumnModel(hs, column_title);
final JTable table = new JTable(tcm);
table.setDefaultRenderer(table.getColumnClass(0), new DefaultTableCellRenderer() {
private static final long serialVersionUID = 1L;
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
final Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (1 == column && tcm.sent[row]) {
c.setBackground(Color.green);
c.setForeground(Color.white);
} else if (isSelected) {
c.setForeground(table.getSelectionForeground());
c.setBackground(table.getSelectionBackground());
} else {
c.setBackground(Color.white);
c.setForeground(Color.black);
}
return c;
}
});
table.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent me) {
final JTable src = (JTable) me.getSource();
final TwoColumnModel model = (TwoColumnModel) src.getModel();
final int row = src.rowAtPoint(me.getPoint()), col = src.columnAtPoint(me.getPoint());
if (2 == me.getClickCount()) {
Object ob = model.getValueAt(row, col);
if (ob instanceof ZDisplayable) {
ZDisplayable zd = (ZDisplayable) ob;
Display df = Display.getOrCreateFront(zd.getProject());
// also select
df.show(zd.getFirstLayer(), zd, true, false);
}
} else if (me.isPopupTrigger()) {
JPopupMenu popup = new JPopupMenu();
final JMenuItem send = new JMenuItem("Send selection");
popup.add(send);
send.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
ArrayList<ZDisplayable> col = new ArrayList<ZDisplayable>();
for (final int i : src.getSelectedRows()) {
col.add((ZDisplayable) model.getValueAt(i, 0));
}
if (col.isEmpty())
return;
// the other
Project target = col.get(0).getProject() == p1 ? p2 : p1;
LayerSet ls = target.getRootLayerSet();
ArrayList<ZDisplayable> copies = new ArrayList<ZDisplayable>();
for (ZDisplayable zd : col) {
copies.add((ZDisplayable) zd.clone(target, false));
model.sent[row] = true;
}
// 1. To the LayerSet:
ls.addAll(copies);
// 2. To the ProjectTree:
target.getProjectTree().insertSegmentations(copies);
// Update:
model.fireTableDataChanged();
}
});
popup.show(table, me.getX(), me.getY());
}
}
});
return table;
}
use of org.openstack4j.model.identity.v3.Project in project TrakEM2 by trakem2.
the class TemplateTree method mousePressed.
public void mousePressed(MouseEvent me) {
Object source = me.getSource();
if (!source.equals(this) || !project.isInputEnabled()) {
return;
}
/*if (!(me.isPopupTrigger() || me.isControlDown() || MouseEvent.BUTTON2 == me.getButton() || 0 != (me.getModifiers() & Event.META_MASK))) { // the last block is from ij.gui.ImageCanvas, aparently to make the right-click work on windows?
return;
}*/
if (!Utils.isPopupTrigger(me))
return;
int x = me.getX();
int y = me.getY();
// find the node and set it selected
TreePath path = getPathForLocation(x, y);
if (null == path)
return;
setSelectionPath(path);
this.selected_node = (DefaultMutableTreeNode) path.getLastPathComponent();
final TemplateThing tt = (TemplateThing) selected_node.getUserObject();
String type = tt.getType();
//
JPopupMenu popup = new JPopupMenu();
JMenuItem item;
if (!Project.isBasicType(type) && !tt.isNested()) {
JMenu menu = new JMenu("Add new child");
popup.add(menu);
item = new JMenuItem("new...");
item.addActionListener(this);
menu.add(item);
// Add also from other open projects
if (ControlWindow.getProjects().size() > 1) {
menu.addSeparator();
JMenu other = new JMenu("From project...");
menu.add(other);
for (Iterator<Project> itp = ControlWindow.getProjects().iterator(); itp.hasNext(); ) {
final Project pr = (Project) itp.next();
if (root.getProject() == pr)
continue;
item = new JMenuItem(pr.toString());
other.add(item);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
GenericDialog gd = new GenericDialog(pr.toString());
gd.addMessage("Project: " + pr.toString());
final HashMap<String, TemplateThing> hm = pr.getTemplateTree().root.getUniqueTypes(new HashMap<String, TemplateThing>());
final String[] u_types = hm.keySet().toArray(new String[0]);
gd.addChoice("type:", u_types, u_types[0]);
gd.showDialog();
if (gd.wasCanceled())
return;
TemplateThing tt_chosen = hm.get(gd.getNextChoice());
// must solve conflicts!
// Recurse into children: if any type that is not a basic type exists in the target project, ban the operation.
ArrayList al = tt_chosen.collectAllChildren(new ArrayList());
for (Iterator ital = al.iterator(); ital.hasNext(); ) {
TemplateThing child = (TemplateThing) ital.next();
if (root.getProject().typeExists(child.getType()) && !pr.isBasicType(child.getType())) {
Utils.showMessage("Type conflict: cannot add type " + tt_chosen.getType());
return;
}
}
// Else add it, recursive into children
// Target is tt
addCopiesRecursively(tt, tt_chosen);
rebuild(selected_node, true);
}
});
}
}
menu.addSeparator();
String[] ut = tt.getProject().getUniqueTypes();
for (int i = 0; i < ut.length; i++) {
item = new JMenuItem(ut[i]);
item.addActionListener(this);
menu.add(item);
}
}
item = new JMenuItem("Delete...");
item.addActionListener(this);
popup.add(item);
// disable deletion of root.
if (null == selected_node.getParent())
item.setEnabled(false);
if (!Project.isBasicType(type)) {
item = new JMenuItem("Rename...");
item.addActionListener(this);
popup.add(item);
}
popup.addSeparator();
item = new JMenuItem("Export XML template...");
item.addActionListener(this);
popup.add(item);
popup.show(this, x, y);
}
use of org.openstack4j.model.identity.v3.Project in project TrakEM2 by trakem2.
the class TemplateTree method renameType.
/**
* Rename a TemplateThing type from @param old_name to @param new_name.
* If such a new_name already exists, the renaming will not occur and returns false.
*/
public boolean renameType(final String old_name, String new_name) {
// to lower case!
new_name = new_name.toLowerCase();
Project project = root.getProject();
if (new_name.equals(old_name)) {
return true;
} else if (project.typeExists(new_name)) {
Utils.logAll("Type '" + new_name + "' exists already!");
return false;
}
// process name change in all TemplateThing instances that have it
ArrayList<TemplateThing> al = root.collectAllChildren(new ArrayList<TemplateThing>());
al.add(root);
for (final TemplateThing tet : al) {
// Utils.log("\tchecking " + tet.getType() + " " + tet.getId());
if (tet.getType().equals(old_name))
tet.rename(new_name);
}
// and update the ProjectThing objects in the tree and its dependant Displayable objects in the open Displays
project.getRootProjectThing().updateType(new_name, old_name);
// tell the project about it
project.updateTypeName(old_name, new_name);
// repaint both trees (will update the type names)
updateUILater();
project.getProjectTree().updateUILater();
return true;
}
Aggregations