Search in sources :

Example 1 with CytoPanelName

use of org.cytoscape.application.swing.CytoPanelName 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;
}
Also used : SessionState(org.cytoscape.internal.io.sessionstate.SessionState) CytoPanelName(org.cytoscape.application.swing.CytoPanelName) Cytopanels(org.cytoscape.internal.io.sessionstate.Cytopanels) CytoPanel(org.cytoscape.application.swing.CytoPanel) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) File(java.io.File) Cytopanel(org.cytoscape.internal.io.sessionstate.Cytopanel)

Example 2 with CytoPanelName

use of org.cytoscape.application.swing.CytoPanelName 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);
                }
            }
        }
    }
}
Also used : CytoPanelName(org.cytoscape.application.swing.CytoPanelName) CytoPanel(org.cytoscape.application.swing.CytoPanel) Cytopanel(org.cytoscape.internal.io.sessionstate.Cytopanel)

Aggregations

CytoPanel (org.cytoscape.application.swing.CytoPanel)2 CytoPanelName (org.cytoscape.application.swing.CytoPanelName)2 Cytopanel (org.cytoscape.internal.io.sessionstate.Cytopanel)2 File (java.io.File)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Cytopanels (org.cytoscape.internal.io.sessionstate.Cytopanels)1 SessionState (org.cytoscape.internal.io.sessionstate.SessionState)1