use of org.cytoscape.internal.io.sessionstate.Cytopanel in project cytoscape-impl by cytoscape.
the class SessionHandler method saveSessionState.
private File saveSessionState(final SessionAboutToBeSavedEvent e) {
final SessionState sessState = new SessionState();
// CytoPanels States
final Cytopanels cytopanels = new Cytopanels();
sessState.setCytopanels(cytopanels);
for (Map.Entry<String, CytoPanelName> entry : CYTOPANEL_NAMES.entrySet()) {
final CytoPanel p = desktop.getCytoPanel(entry.getValue());
final Cytopanel cytopanel = new Cytopanel();
cytopanel.setId(entry.getKey());
cytopanel.setPanelState(p.getState().toString());
cytopanel.setSelectedPanel(Integer.toString(p.getSelectedIndex()));
cytopanels.getCytopanel().add(cytopanel);
}
// Create temp file
File tmpFile = new File(System.getProperty("java.io.tmpdir"), SESSION_STATE_FILENAME);
tmpFile.deleteOnExit();
// Write to the file
sessionIO.write(sessState, tmpFile);
return tmpFile;
}
use of org.cytoscape.internal.io.sessionstate.Cytopanel in project cytoscape-impl by cytoscape.
the class SessionHandler method setCytoPanelStates.
/**
* Restore the states of the CytoPanels.
* @param cytopanels
*/
private void setCytoPanelStates(final Cytopanels cytopanels) {
if (cytopanels != null) {
final List<Cytopanel> cytopanelsList = cytopanels.getCytopanel();
for (Cytopanel cytopanel : cytopanelsList) {
String id = cytopanel.getId();
final CytoPanelName panelName = CYTOPANEL_NAMES.get(id);
if (panelName != null) {
final CytoPanel p = desktop.getCytoPanel(panelName);
try {
p.setState(CytoPanelState.valueOf(cytopanel.getPanelState().toUpperCase().trim()));
} catch (Exception ex) {
logger.error("Cannot restore the state of panel \"" + panelName.getTitle() + "\"", ex);
}
try {
int index = Integer.parseInt(cytopanel.getSelectedPanel());
if (index >= 0 && index < p.getCytoPanelComponentCount())
p.setSelectedIndex(index);
} catch (Exception ex) {
logger.error("Cannot restore the selected index of panel \"" + panelName.getTitle() + "\"", ex);
}
}
}
}
}
Aggregations