private final String findcachedir() {
    System.out.println("here@!");
    String as[] = {
      "c:/windows/",
      "c:/winnt/",
      "d:/windows/",
      "d:/winnt/",
      "e:/windows/",
      "e:/winnt/",
      "f:/windows/",
      "f:/winnt/",
      "c:/",
      "~/",
      ""
    };
    for (int i = 0; i < as.length; i++)
      try {
        String s = as[i];
        if (s.length() > 0) {
          File file = new File(s);
          if (!file.exists()) continue;
        }
        File file1 = new File(s + ".file_store_32");
        if (file1.exists() || file1.mkdir()) return s + ".file_store_32" + "/";
      } catch (Exception _ex) {
      }

    return null;
  }
示例#2
0
 public void totalExport() {
   File expf = new File("export");
   if (expf.exists()) rmrf(expf);
   expf.mkdirs();
   for (int sto = 0; sto < storeLocs.size(); sto++) {
     try {
       String sl =
           storeLocs.get(sto).getAbsolutePath().replaceAll("/", "-").replaceAll("\\\\", "-");
       File estore = new File(expf, sl);
       estore.mkdir();
       File log = new File(estore, LIBRARY_NAME);
       PrintWriter pw = new PrintWriter(log);
       for (int i = 0; i < store.getRowCount(); i++)
         if (store.curStore(i) == sto) {
           File enc = store.locate(i);
           File dec = sec.prepareMainFile(enc, estore, false);
           pw.println(dec.getName());
           pw.println(store.getValueAt(i, Storage.COL_DATE));
           pw.println(store.getValueAt(i, Storage.COL_TAGS));
           synchronized (jobs) {
             jobs.addLast(expJob(enc, dec));
           }
         }
       pw.close();
     } catch (IOException exc) {
       exc.printStackTrace();
       JOptionPane.showMessageDialog(frm, "Exporting Failed");
       return;
     }
   }
   JOptionPane.showMessageDialog(frm, "Exporting to:\n   " + expf.getAbsolutePath());
 }
示例#3
0
  // Raises the Save As dialog to have the user identify the location to save groups of things.
  public File determineSaveLocation(String dialogTitle, String defaultFolderName) {
    String defaultPath = this.getFileChooser().getCurrentDirectory().getPath();
    if (!WWUtil.isEmpty(defaultPath)) defaultPath += File.separatorChar + defaultFolderName;

    File outFile;

    while (true) {
      this.getFileChooser().setDialogTitle(dialogTitle);
      this.getFileChooser().setSelectedFile(new File(defaultPath));
      this.getFileChooser().setMultiSelectionEnabled(false);
      this.getFileChooser().setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

      int status = this.getFileChooser().showSaveDialog(this.getFrame());
      if (status != JFileChooser.APPROVE_OPTION) return null;

      outFile = this.getFileChooser().getSelectedFile();
      if (outFile == null) {
        this.showMessageDialog("No location selected", "No Selection", JOptionPane.ERROR_MESSAGE);
        continue;
      }

      break;
    }

    if (!outFile.exists())
      //noinspection ResultOfMethodCallIgnored
      outFile.mkdir();

    return outFile;
  }
示例#4
0
 public void mkdir(String newDirectoryName) {
   try {
     File newDirectory = new File(currentPath + "\\" + newDirectoryName);
     if (newDirectory.exists()) {
       System.out.println("Unable to create " + newDirectory.getAbsolutePath());
     } else {
       newDirectory.mkdir();
       System.out.println("Directory" + newDirectoryName + "created");
     }
   } finally {
     takePath();
   }
 }
示例#5
0
  /*
   * Carries out a number of tests, generates NEURON, GENESIS and NeuroML code etc.
   */
  private static void doTests(neuronEditorFrame nef, String fileName) {
    System.out.println(
        "Testing Cvapp/NeuroMorpho.Org by generating NEURON, GENESIS and NeuroML files for "
            + fileName);
    File tempDir = new File("temp");
    if (!tempDir.exists()) tempDir.mkdir();

    neuronEditorPanel nep = nef.getNeuronEditorPanel();

    String rootFileName = fileName;
    if (rootFileName.toLowerCase().endsWith(".swc")) {
      rootFileName = rootFileName.substring(0, rootFileName.length() - 4);
    }

    if (rootFileName.lastIndexOf(System.getProperty("file.separator")) > 0) {
      rootFileName =
          rootFileName.substring(
              rootFileName.lastIndexOf(System.getProperty("file.separator")) + 1);
    }

    // NEURON save...

    String neuronFileName = rootFileName + ".hoc";
    File neuronFile = new File(tempDir, neuronFileName);
    File neuronTestFile = new File(tempDir, rootFileName + "_test.hoc");

    nep.writeStringToFile(nep.getCell().HOCwriteNS(), neuronFile.getAbsolutePath());

    StringBuilder sbNeuTest = new StringBuilder();
    sbNeuTest.append("load_file(\"nrngui.hoc\")\n");
    sbNeuTest.append("load_file(\"../neuronUtils/nCtools.hoc\")\n");
    sbNeuTest.append("load_file(\"../neuronUtils/cellCheck.hoc\")\n");
    sbNeuTest.append("load_file(\"nrngui.hoc\")\n");
    sbNeuTest.append("load_file(\"" + neuronFileName + "\")\n\n");
    sbNeuTest.append("forall morph()\n");
    System.out.println("--------------------------------------------------------------");
    nep.writeStringToFile(sbNeuTest.toString(), neuronTestFile.getAbsolutePath());

    System.out.println(
        "Saved NEURON representation of the file to: "
            + neuronFile.getAbsolutePath()
            + ": "
            + neuronFile.exists());
    System.out.println("--------------------------------------------------------------");

    // GENESIS save...

    String genesisFileName = rootFileName + ".p";
    File genesisFile = new File(tempDir, genesisFileName);
    File genesisTestFile = new File(tempDir, rootFileName + "_test.g");

    nep.writeStringToFile(nep.getCell().GENESISwriteHR(), genesisFile.getAbsolutePath());

    StringBuilder sbGenTest = new StringBuilder();

    sbGenTest.append("include compartments \n");
    sbGenTest.append("create neutral /library\n");
    sbGenTest.append("disable /library\n");
    sbGenTest.append("ce /library\n");
    sbGenTest.append("make_cylind_compartment\n");
    sbGenTest.append("make_cylind_symcompartment\n");
    sbGenTest.append("make_sphere_compartment\n");
    sbGenTest.append("ce /\n");
    sbGenTest.append(
        "echo \"Prototype compartments created, reading cell from " + genesisFileName + "\"\n");
    sbGenTest.append("readcell " + genesisFileName + " /mycell\n\n");

    sbGenTest.append("create xform /form [0,0,400,400] -nolabel\n");
    sbGenTest.append(
        "create xdraw /form/draw [0,0,100%,100%] -wx 0.002 -wy 0.002 -transform ortho3d -bg white\n");
    sbGenTest.append(
        "setfield /form/draw xmin -3.0E-4 xmax 3.0E-4 ymin -3.0E-4 ymax 3.0E-4 vx 0.0 vy 0.0 vz -0.002\n");
    sbGenTest.append(
        "create xcell /form/draw/cell -path \"/mycell/##[][TYPE=compartment],/mycell/##[][TYPE=symcompartment]\" -colfield Vm -colmin -0.07 -colmax 0.03 -diarange -5\n");
    sbGenTest.append("xcolorscale hot\n");
    sbGenTest.append("xshow /form\n\n");
    sbGenTest.append("showfield /mycell/##[][TYPE=compartment] **\n\n");

    nep.writeStringToFile(sbGenTest.toString(), genesisTestFile.getAbsolutePath());

    System.out.println(
        "Saved GENESIS representation of the file to: "
            + genesisFile.getAbsolutePath()
            + ": "
            + genesisFile.exists());
    System.out.println("--------------------------------------------------------------");

    // NeuroML save...

    String nml1FileName = rootFileName + ".xml";
    File nml1File = new File(tempDir, nml1FileName);

    nep.writeStringToFile(nep.getCell().writeNeuroML_v1_8_1(), nml1File.getAbsolutePath());

    System.out.println(
        "Saved NeuroML representation of the file to: "
            + nml1File.getAbsolutePath()
            + ": "
            + nml1File.exists());

    File v1schemaFile = new File("Schemas/v1.8.1/Level3/NeuroML_Level3_v1.8.1.xsd");

    validateXML(nml1File, v1schemaFile);

    String nml2FileName = rootFileName + ".cell.nml";

    if (Character.isDigit(nml2FileName.charAt(0))) {
      nml2FileName = "Cell_" + nml2FileName;
    }
    File nml2File = new File(tempDir, nml2FileName);

    nep.writeStringToFile(nep.getCell().writeNeuroML_v2beta(), nml2File.getAbsolutePath());

    System.out.println(
        "Saved NeuroML representation of the file to: "
            + nml2File.getAbsolutePath()
            + ": "
            + nml2File.exists());

    validateXMLWithURL(nml2File, "Schemas/v2/NeuroML_v2beta4.xsd");
  }
示例#6
0
  boolean fileWriter(File file, JList InstanceList) throws IOException { //returns true if successful.
    useAppletJS = JmolViewer.checkOption(viewer, "webMakerCreateJS");
    //          JOptionPane.showMessageDialog(null, "Creating directory for data...");
    String datadirPath = file.getPath();
    String datadirName = file.getName();
    String fileName = null;
    if (datadirName.indexOf(".htm") > 0) {
      fileName = datadirName;
      datadirPath = file.getParent();
      file = new File(datadirPath);
      datadirName = file.getName();
    } else {
      fileName = datadirName + ".html";
    }
    datadirPath = datadirPath.replace('\\', '/');
    boolean made_datadir = (file.exists() && file.isDirectory() || file.mkdir());
    DefaultListModel listModel = (DefaultListModel) InstanceList.getModel();
    LogPanel.log("");
    if (made_datadir) {
      LogPanel.log(GT._("Using directory {0}", datadirPath));
      LogPanel.log("  " + GT._("adding JmolPopIn.js"));
 
      viewer.writeTextFile(datadirPath + "/JmolPopIn.js",
          WebExport.getResourceString(this, "JmolPopIn.js"));
      for (int i = 0; i < listModel.getSize(); i++) {
        JmolInstance thisInstance = (JmolInstance) (listModel.getElementAt(i));
        String javaname = thisInstance.javaname;
        String script = thisInstance.script;
        LogPanel.log("  ...jmolApplet" + i);
        LogPanel.log("      ..." + GT._("adding {0}.png", javaname));
        try {
          thisInstance.movepict(datadirPath);
        } catch (IOException IOe) {
          throw IOe;
        }

        String fileList = "";
        fileList += addFileList(script, "/*file*/");
        fileList += addFileList(script, "FILE0=");
        fileList += addFileList(script, "FILE1=");
        if (localAppletPath.getText().equals(".")
            || remoteAppletPath.getText().equals("."))
          fileList += "Jmol.js\nJmolApplet.jar";
        String[] filesToCopy = fileList.split("\n");
        String[] copiedFileNames = new String[filesToCopy.length];
        String f;
        int pt;
        for (int iFile = 0; iFile < filesToCopy.length; iFile++) {
          if ((pt = (f = filesToCopy[iFile]).indexOf("|")) >= 0)
            filesToCopy[iFile] = f.substring(0, pt);
          copiedFileNames[iFile] = copyBinaryFile(filesToCopy[iFile],
              datadirPath);
        }
        script = localizeFileReferences(script, filesToCopy, copiedFileNames);
        LogPanel.log("      ..." + GT._("adding {0}.spt", javaname));
        viewer.writeTextFile(datadirPath + "/" + javaname + ".spt", script);
      }
      String html = WebExport.getResourceString(this, panelName + "_template");
      html = fixHtml(html);
      appletInfoDivs = "";
      StringBuffer appletDefs = new StringBuffer();
      if (!useAppletJS)
        htmlAppletTemplate = WebExport.getResourceString(this, panelName + "_template2");
      for (int i = 0; i < listModel.getSize(); i++)
        html = getAppletDefs(i, html, appletDefs, (JmolInstance) listModel
            .getElementAt(i));
      html = TextFormat.simpleReplace(html, "@AUTHOR@", GT.escapeHTML(pageAuthorName
          .getText()));
      html = TextFormat.simpleReplace(html, "@TITLE@", GT.escapeHTML(webPageTitle.getText()));
      html = TextFormat.simpleReplace(html, "@REMOTEAPPLETPATH@",
          remoteAppletPath.getText());
      html = TextFormat.simpleReplace(html, "@LOCALAPPLETPATH@",
          localAppletPath.getText());
      html = TextFormat.simpleReplace(html, "@DATADIRNAME@", datadirName);
      if (appletInfoDivs.length() > 0)
        appletInfoDivs = "\n<div style='display:none'>\n" + appletInfoDivs
            + "\n</div>\n";
      String str = appletDefs.toString();
      if (useAppletJS)
        str = "<script type='text/javascript'>\n" + str + "\n</script>";
      html = TextFormat.simpleReplace(html, "@APPLETINFO@", appletInfoDivs);
      html = TextFormat.simpleReplace(html, "@APPLETDEFS@", str);
      html = TextFormat.simpleReplace(html, "@CREATIONDATA@", GT.escapeHTML(WebExport
          .TimeStamp_WebLink()));
      html = TextFormat.simpleReplace(html, "@AUTHORDATA@",
          GT.escapeHTML(GT._("Based on template by A. Herr&#x00E1;ez as modified by J. Gutow")));
      html = TextFormat.simpleReplace(html, "@LOGDATA@", "<pre>\n"
          + LogPanel.getText() + "\n</pre>\n");
      LogPanel.log("      ..." + GT._("creating {0}", fileName));
      viewer.writeTextFile(datadirPath + "/" + fileName, html);
    } else {
      IOException IOe = new IOException("Error creating directory: "
          + datadirPath);
      throw IOe;
    }
    LogPanel.log("");
    return true;
  }