use of org.cytoscape.io.util.RecentlyOpenedTracker in project cytoscape-impl by cytoscape.
the class RecentSessionManager method updateMenuItems.
private void updateMenuItems() {
// Unregister services
for (final OpenRecentSessionAction currentItem : currentMenuItems) serviceRegistrar.unregisterAllServices(currentItem);
currentMenuItems.clear();
final RecentlyOpenedTracker tracker = serviceRegistrar.getService(RecentlyOpenedTracker.class);
final List<URL> urls = tracker.getRecentlyOpenedURLs();
float gravity = 0.0f;
for (final URL url : urls) {
File file = null;
try {
URI uri = url.toURI();
file = new File(uri);
} catch (Exception e) {
logger.error("Invalid recent file URL.", e);
continue;
}
final OpenRecentSessionAction action = new OpenRecentSessionAction(gravity++, file);
serviceRegistrar.registerService(action, CyAction.class, new Properties());
currentMenuItems.add(action);
}
clearMenuAction.updateEnableState();
}
use of org.cytoscape.io.util.RecentlyOpenedTracker in project cytoscape-impl by cytoscape.
the class StarterPanel method maybeOpenSession.
private void maybeOpenSession(final File file) {
if (file.exists()) {
Util.maybeOpenSession(file, StarterPanel.this.getTopLevelAncestor(), serviceRegistrar);
} else {
JOptionPane.showMessageDialog(StarterPanel.this.getTopLevelAncestor(), "Session file not found:\n" + file.getAbsolutePath(), "File not Found", JOptionPane.WARNING_MESSAGE);
final RecentlyOpenedTracker fileTracker = serviceRegistrar.getService(RecentlyOpenedTracker.class);
try {
fileTracker.remove(file.toURI().toURL());
} catch (Exception e) {
logger.error("Error removing session file from RecentlyOpenedTracker.", e);
}
}
}
use of org.cytoscape.io.util.RecentlyOpenedTracker in project cytoscape-impl by cytoscape.
the class StarterPanel method getRecentFiles.
/**
* Returns a list of the most recently opened session files.
*/
private List<FileInfo> getRecentFiles() {
final List<FileInfo> files = new ArrayList<>();
final RecentlyOpenedTracker fileTracker = serviceRegistrar.getService(RecentlyOpenedTracker.class);
final List<URL> recentFiles = fileTracker.getRecentlyOpenedURLs();
int fileCount = Math.min(recentFiles.size(), MAX_FILES);
for (int i = 0; i < fileCount; i++) {
final URL url = recentFiles.get(i);
File file = null;
try {
URI uri = url.toURI();
file = new File(uri);
} catch (Exception e) {
logger.error("Invalid file URL.", e);
continue;
}
if (file.exists() && file.canRead()) {
FileInfo fi = new FileInfo(file, file.getName(), file.getAbsolutePath());
files.add(fi);
} else {
fileCount = Math.min(recentFiles.size(), fileCount + 1);
}
}
return files;
}
Aggregations