// 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; }
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()); }
PageSmoother(String pdf) throws IOException { File file = new File(pdf); ndone = 0; RandomAccessFile raf = new RandomAccessFile(file, "r"); FileChannel channel = raf.getChannel(); ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size()); pdffile = new PDFFile(buf); page1 = new CountDownLatch(1); raf.close(); tmpdir = File.createTempFile("pagesmoother", ""); tmpdir.delete(); tmpdir.mkdir(); }
private void setupLock() { if (dataDir == null) { lockDir = null; } else { File dir = new File(dataDir, LOCK_FILE); if (!dir.mkdir()) { dir.delete(); if (!dir.mkdir()) { dir = null; if (getBoolean("application.showLocalStorageDialogs", true)) { Resources.showMessageDialog( null, JOptionPane.ERROR_MESSAGE, messageBundle, "fontManager.properties.title", "manager.properties.session.nolock", LOCK_FILE); } } } lockDir = dir; } }
/** * Create/Replace a Directory * * @param Direct the Directory in which the new Directory is made */ public void createDirectory(String Direct) { File dir = new File(Direct + File_Direct + "\\"); if (dir.isDirectory()) { // Check if this directory already exists if (JOptionPane.showConfirmDialog( null, "This directory already exists, do you wish to replace it?", "Replace", 0) != 0) { return; } // Delete directory DeleteDirect(Direct + File_Direct + "\\"); } // Replace/Create directory dir.mkdir(); Msgs.Type("Directory created", Display); }
public SeatInfo() { File file = new File(".", "data"); file.mkdir(); File f = new File(file, "SeatInfo.txt"); try { raf = new RandomAccessFile(f, "rw"); if (raf.length() == 0) { raf.setLength(31 * 4 * FLIGHT_PER_DAY); for (int i = 0; i < 31 * FLIGHT_PER_DAY; i++) raf.writeInt(0); } } catch (Exception e) { e.printStackTrace(); } }
/** Get the default folder */ public File getDefaultFolder() { final File recentFolder = _folderTracker.getMostRecentFile(); if (recentFolder != null && recentFolder.exists()) { if (_subfolderName != null) { final File defaultFolder = new File(recentFolder, _subfolderName); if (!defaultFolder.exists()) { defaultFolder.mkdir(); } return defaultFolder; } else { return recentFolder; } } return null; }
public String getJLMPropertiesDir() { String jlmPropertiesDir = null; String value = Game.getProperty("jlm.configuration.file.path"); if (value != null) { String paths[] = value.split(","); for (String localPath : paths) { localPath = localPath.replace("$HOME$", System.getProperty("user.home")); File localPropertiesFileParentDirectory = new File(localPath); File localPropertiesFileDirectory = new File(localPath, Game.getLocalPropertiesSubdirectory()); if (!localPropertiesFileParentDirectory.exists()) { continue; } else if (localPropertiesFileDirectory.exists() || localPropertiesFileDirectory.mkdir()) { jlmPropertiesDir = localPropertiesFileParentDirectory.getPath(); break; } else { Logger.log( "Game:storeProperties", "cannot create local properties store directory (" + localPropertiesFileDirectory + ")"); } } } else { JOptionPane.showConfirmDialog( null, "No path provided in the property file (or property file not found)\n" + "You may want to export your session with the menu 'Session/Export session'\n" + "to save your work manually.\n\n" + "Quit without saving?", "Cannot save your changes. Quit without saving?", JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE); return null; } return jlmPropertiesDir; }
public static void copyFolder(File src, File dest, JLabel updatelbl, JLabel updatelbl2) throws IOException { if (src.isDirectory()) { if (!dest.exists()) { dest.mkdir(); updatelbl.setText("Directory copied from " + src + " to " + dest); } String files[] = src.list(); for (String file : files) { File srcFile = new File(src, file); File destFile = new File(dest, file); // recursive copy copyFolder(srcFile, destFile, updatelbl, updatelbl2); } } else { InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dest); byte[] buffer = new byte[1024]; int length; while ((length = in.read(buffer)) > 0) { out.write(buffer, 0, length); } in.close(); out.close(); updatelbl.setText("File copied from " + src); updatelbl2.setText(" to " + dest); } }
/* * 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"); }
@Override public void run() { this.cardIndex = 0; File base = new File(Constants.IO.imageBaseDir); if (!base.exists()) { base.mkdir(); } Connection.ProxyType configProxyType = Connection.ProxyType.valueByText( PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_TYPE, "None")); Proxy.Type type = Proxy.Type.DIRECT; switch (configProxyType) { case HTTP: type = Proxy.Type.HTTP; break; case SOCKS: type = Proxy.Type.SOCKS; break; case NONE: default: p = Proxy.NO_PROXY; break; } if (type != Proxy.Type.DIRECT) { try { String address = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_ADDRESS, ""); Integer port = Integer.parseInt( PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_PORT, "80")); p = new Proxy(type, new InetSocketAddress(address, port)); } catch (Exception ex) { throw new RuntimeException("Gui_DownloadPictures : error 1 - " + ex); } } if (p != null) { HashSet<String> ignoreUrls = SettingsManager.getIntance().getIgnoreUrls(); ArrayList<CardDownloadData> cardsToDownload = this.checkBox.isSelected() ? type2cards : cards; update(0, cardsToDownload.size()); for (int i = 0; i < cardsToDownload.size() && !cancel; i++) { try { CardDownloadData card = cardsToDownload.get(i); log.info("Downloading card: " + card.getName() + " (" + card.getSet() + ")"); String url; if (ignoreUrls.contains(card.getSet()) || card.isToken()) { if (card.getCollectorId() != 0) { continue; } url = cardImageSource.generateTokenUrl(card); } else { url = cardImageSource.generateURL(card); } if (url != null) { Logger.getLogger(this.getClass()).info(url); Runnable task = new DownloadTask(card, new URL(url), cardsToDownload.size()); executor.execute(task); } else { synchronized (sync) { update(cardIndex + 1, cardsToDownload.size()); } } } catch (Exception ex) { log.error(ex, ex); } } executor.shutdown(); while (!executor.isTerminated()) { try { Thread.sleep(1000); } catch (InterruptedException ie) { } } } try { TVFS.umount(); } catch (FsSyncException e) { e.printStackTrace(); JOptionPane.showMessageDialog( null, "Couldn't unmount zip files", "Error", JOptionPane.ERROR_MESSAGE); } finally { System.gc(); } closeButton.setText("Close"); }
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á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; }