Search in sources :

Example 1 with CyApplicationConfiguration

use of org.cytoscape.application.CyApplicationConfiguration in project cytoscape-impl by cytoscape.

the class LinkOut method readLocalProperties.

/**
 * Read properties values from linkout.props file included in the
 * linkout.jar file and apply those properties to the base Cytoscape
 * properties. Only apply the properties from the jar file if NO linkout
 * properties already exist. This allows linkout properties to be specified
 * on the command line, edited in the preferences dialog, and to be saved
 * with other properties.
 */
private void readLocalProperties() {
    final CyApplicationConfiguration config = registrar.getService(CyApplicationConfiguration.class);
    final File propertyFile = new File(config.getConfigurationDirectoryLocation(), File.separator + "linkout.props");
    try {
        if (propertyFile.canRead())
            linkoutProps.getProperties().load(new FileInputStream(propertyFile));
    } catch (Exception e) {
        logger.warn("Couldn't load linkout props from \'" + propertyFile.getAbsolutePath() + "\'.", e);
    }
}
Also used : CyApplicationConfiguration(org.cytoscape.application.CyApplicationConfiguration) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with CyApplicationConfiguration

use of org.cytoscape.application.CyApplicationConfiguration in project cytoscape-impl by cytoscape.

the class ConfigDirPropertyWriter method handleEvent.

@Override
public void handleEvent(final CyShutdownEvent event) {
    for (final Map.Entry<CyProperty<?>, Map<?, ?>> keyAndValue : configDirProperties.entrySet()) {
        final String propertyName = (String) keyAndValue.getValue().get("cyPropertyName");
        if (propertyName == null || propertyName.isEmpty())
            continue;
        final String propertyFileName;
        if (propertyName.endsWith(".props"))
            propertyFileName = propertyName;
        else
            propertyFileName = propertyName + ".props";
        final CyApplicationConfiguration config = serviceRegistrar.getService(CyApplicationConfiguration.class);
        final File outputFile = new File(config.getConfigurationDirectoryLocation(), propertyFileName);
        final Properties props = (Properties) keyAndValue.getKey().getProperties();
        try {
            FileOutputStream out = new FileOutputStream(outputFile);
            props.store(out, null);
            out.close();
        } catch (Exception e) {
            logger.error("Error in wring properties file.");
        }
    }
}
Also used : CyProperty(org.cytoscape.property.CyProperty) FileOutputStream(java.io.FileOutputStream) Properties(java.util.Properties) HashMap(java.util.HashMap) Map(java.util.Map) CyApplicationConfiguration(org.cytoscape.application.CyApplicationConfiguration) File(java.io.File)

Example 3 with CyApplicationConfiguration

use of org.cytoscape.application.CyApplicationConfiguration in project cytoscape-impl by cytoscape.

the class Cy3PreferencesPanel method saveStateToConfigDirectory.

// ---------------------------------------------------------------------------------------------------------
public void saveStateToConfigDirectory() {
    copyLocalToGlobalProperties();
    Map<String, Properties> prefs = propertyMap;
    System.out.println("saveStateToConfigDirectory");
    for (String key : prefs.keySet()) {
        if (key.startsWith("layout"))
            continue;
        if (key.startsWith("vizmap"))
            continue;
        final String propertyName = key;
        if (propertyName == null || propertyName.isEmpty())
            continue;
        String propertyFileName = propertyName;
        if (!propertyFileName.endsWith(".props"))
            propertyFileName += ".props";
        final CyApplicationConfiguration config = serviceRegistrar.getService(CyApplicationConfiguration.class);
        final File outputFile = new File(config.getConfigurationDirectoryLocation(), propertyFileName);
        Properties properties = prefs.get(key);
        try {
            FileOutputStream out = new FileOutputStream(outputFile);
            properties.store(out, null);
            out.close();
        } catch (Exception e) {
            System.err.println("Error in writing properties file.");
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) Properties(java.util.Properties) CyApplicationConfiguration(org.cytoscape.application.CyApplicationConfiguration) File(java.io.File)

Example 4 with CyApplicationConfiguration

use of org.cytoscape.application.CyApplicationConfiguration in project cytoscape-impl by cytoscape.

the class CytoscapeToolBar method writeStopList.

private void writeStopList(List<String> list) {
    BufferedWriter writer = null;
    try {
        CyApplicationConfiguration cyApplicationConfiguration = serviceRegistrar.getService(CyApplicationConfiguration.class);
        if (cyApplicationConfiguration == null) {
            System.err.println("cyApplicationConfiguration not found");
            return;
        }
        File configDirectory = cyApplicationConfiguration.getConfigurationDirectoryLocation();
        File configFile = null;
        if (configDirectory.exists())
            configFile = new File(configDirectory.toPath() + "/toolbar.stoplist");
        writer = new BufferedWriter(new FileWriter(configFile));
        for (String line : list) {
            if (line != null)
                writer.write(line + "\n");
        }
    } catch (IOException e) {
        System.err.println("IOException: " + e.getMessage());
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) CyApplicationConfiguration(org.cytoscape.application.CyApplicationConfiguration) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 5 with CyApplicationConfiguration

use of org.cytoscape.application.CyApplicationConfiguration in project cytoscape-impl by cytoscape.

the class CytoscapeToolBar method readStopList.

private void readStopList() {
    stopList.clear();
    final List<String> lines;
    try {
        CyApplicationConfiguration cyApplicationConfiguration = serviceRegistrar.getService(CyApplicationConfiguration.class);
        if (cyApplicationConfiguration == null)
            return;
        File configDirectory = cyApplicationConfiguration.getConfigurationDirectoryLocation();
        File configFile = null;
        if (configDirectory.exists())
            configFile = new File(configDirectory.toPath() + "/toolbar.stoplist");
        lines = Files.readAllLines(configFile.toPath(), Charset.defaultCharset());
    } catch (IOException e) {
        // file not found: there's no customization, just return
        return;
    }
    for (String line : lines) stopList.add(line.trim());
}
Also used : IOException(java.io.IOException) CyApplicationConfiguration(org.cytoscape.application.CyApplicationConfiguration) File(java.io.File)

Aggregations

CyApplicationConfiguration (org.cytoscape.application.CyApplicationConfiguration)12 File (java.io.File)10 IOException (java.io.IOException)4 FileOutputStream (java.io.FileOutputStream)3 Properties (java.util.Properties)3 CyEventHelper (org.cytoscape.event.CyEventHelper)2 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)2 BufferedWriter (java.io.BufferedWriter)1 FileInputStream (java.io.FileInputStream)1 FileWriter (java.io.FileWriter)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AppManagerAction (org.cytoscape.app.internal.action.AppManagerAction)1 CitationsAction (org.cytoscape.app.internal.action.CitationsAction)1 AppManager (org.cytoscape.app.internal.manager.AppManager)1 UpdateManager (org.cytoscape.app.internal.net.UpdateManager)1 WebQuerier (org.cytoscape.app.internal.net.WebQuerier)1 AddAllowOriginHeader (org.cytoscape.app.internal.net.server.AddAllowOriginHeader)1 AppGetResponder (org.cytoscape.app.internal.net.server.AppGetResponder)1 CyHttpd (org.cytoscape.app.internal.net.server.CyHttpd)1