@Override public void actionPerformed(ActionEvent e) { Frame frame = getFrame(); JFileChooser chooser = new JFileChooser(); int ret = chooser.showOpenDialog(frame); if (ret != JFileChooser.APPROVE_OPTION) { return; } File f = chooser.getSelectedFile(); if (f.isFile() && f.canRead()) { Document oldDoc = getEditor().getDocument(); if (oldDoc != null) { oldDoc.removeUndoableEditListener(undoHandler); } if (elementTreePanel != null) { elementTreePanel.setEditor(null); } getEditor().setDocument(new PlainDocument()); frame.setTitle(f.getName()); Thread loader = new FileLoader(f, editor.getDocument()); loader.start(); } else { JOptionPane.showMessageDialog( getFrame(), "Could not open file: " + f, "Error opening file", JOptionPane.ERROR_MESSAGE); } }
/** * Create/Replace a File * * @param Direct the Directory in which the File is made * @param Txt the Text to be written in the file */ public void createFile(String Direct, String Txt) { File f = new File(Direct + File_Name); if (f.isFile()) { // Check if this file already exists if (JOptionPane.showConfirmDialog( null, "This file already exists, do you wish to replace it?", "Replace", 0) != 0) { return; } // Delete file f.delete(); } try { // Replace/Create file f.createNewFile(); // If file preference set to "File with displayed text", write text to file if (Txt != null) { WriteFile(f, Txt); } Msgs.Type("File created", Display); } catch (Exception e) { Msgs.Type("Unable to create this file", Display); } }
/** * Enqueue a direct GET if not already enqueued, or already downloaded to download dir. * * @return true if item was enqueued */ public boolean maybeEnqueueDirectGet( final FrostDownloadItem dlItem, final long expectedFileSize) { if (!isDirectTransferInProgress(dlItem)) { final File targetFile = new File(dlItem.getDownloadFilename()); if (!targetFile.isFile() || targetFile.length() != expectedFileSize) { directTransferQueue.appendItemToQueue(dlItem); return true; } } return false; }
void addChildren(DefaultMutableTreeNode parent, File parentDirFile) { for (File file : parentDirFile.listFiles()) { String[] namesplitStrings = file.toString().split("\\\\"); String filename = namesplitStrings[namesplitStrings.length - 1]; if (file.isDirectory()) { DefaultMutableTreeNode child = new DefaultMutableTreeNode(filename); addChildren(child, file); parent.add(child); } else if (file.isFile()) { parent.add(new DefaultMutableTreeNode(filename)); } } }
public boolean load(File file) { this.file = file; if (file != null && file.isFile()) { try { errStr = null; audioInputStream = AudioSystem.getAudioInputStream(file); fileName = file.getName(); format = audioInputStream.getFormat(); } catch (Exception ex) { reportStatus(ex.toString()); return false; } } else { reportStatus("Audio file required."); return false; } numChannels = format.getChannels(); sampleRate = (double) format.getSampleRate(); sampleBitSize = format.getSampleSizeInBits(); long frameLength = audioInputStream.getFrameLength(); long milliseconds = (long) ((frameLength * 1000) / audioInputStream.getFormat().getFrameRate()); double audioFileDuration = milliseconds / 1000.0; if (audioFileDuration > MAX_AUDIO_DURATION) duration = MAX_AUDIO_DURATION; else duration = audioFileDuration; frameLength = (int) Math.floor((duration / audioFileDuration) * (double) frameLength); try { audioBytes = new byte[(int) frameLength * format.getFrameSize()]; audioInputStream.read(audioBytes); } catch (Exception ex) { reportStatus(ex.toString()); return false; } getAudioData(); return true; }
private void cleanup(File directory) { // Clean up from old installations, removing or renaming files. // Note that directory is the parent of the CTP directory // unless the original installation was done by Bill Weadock's // all-in-one installer for Windows. // Get a file pointing to the CTP directory. // This might be the current directory, or // it might be the CTP child. File dir; if (directory.getName().equals("RSNA")) dir = directory; else dir = new File(directory, "CTP"); // If CTP.jar exists in this directory, it is a really // old CTP main file - not used anymore File ctp = new File(dir, "CTP.jar"); if (ctp.exists()) ctp.delete(); // These are old names for the Launcher.jar file File launcher = new File(dir, "CTP-launcher.jar"); if (launcher.exists()) launcher.delete(); launcher = new File(dir, "TFS-launcher.jar"); if (launcher.exists()) launcher.delete(); // Delete the obsolete CTP-runner.jar file File runner = new File(dir, "CTP-runner.jar"); if (runner.exists()) runner.delete(); // Delete the obsolete MIRC-copier.jar file File copier = new File(dir, "MIRC-copier.jar"); if (copier.exists()) copier.delete(); // Rename the old versions of the properties files File oldprops = new File(dir, "CTP-startup.properties"); File newprops = new File(dir, "CTP-launcher.properties"); File correctprops = new File(dir, "Launcher.properties"); if (oldprops.exists()) { if (newprops.exists() || correctprops.exists()) oldprops.delete(); else oldprops.renameTo(correctprops); } if (newprops.exists()) { if (correctprops.exists()) newprops.delete(); else newprops.renameTo(correctprops); } // Get rid of obsolete startup and shutdown programs File startup = new File(dir, "CTP-startup.jar"); if (startup.exists()) startup.delete(); File shutdown = new File(dir, "CTP-shutdown.jar"); if (shutdown.exists()) shutdown.delete(); // Get rid of the obsolete linux directory File linux = new File(dir, "linux"); if (linux.exists()) { startup = new File(linux, "CTP-startup.jar"); if (startup.exists()) startup.delete(); shutdown = new File(linux, "CTP-shutdown.jar"); if (shutdown.exists()) shutdown.delete(); linux.delete(); } // clean up the libraries directory File libraries = new File(dir, "libraries"); if (libraries.exists()) { // remove obsolete versions of the slf4j libraries // and the dcm4che-imageio libraries File[] files = libraries.listFiles(); for (File file : files) { if (file.isFile()) { String name = file.getName(); if (name.startsWith("slf4j-") || name.startsWith("dcm4che-imageio-rle")) { file.delete(); } } } // remove the email subdirectory File email = new File(libraries, "email"); deleteAll(email); // remove the xml subdirectory File xml = new File(libraries, "xml"); deleteAll(xml); // remove the sftp subdirectory File sftp = new File(libraries, "sftp"); deleteAll(xml); // move edtftpj.jar to the ftp directory File edtftpj = new File(libraries, "edtftpj.jar"); if (edtftpj.exists()) { File ftp = new File(libraries, "ftp"); ftp.mkdirs(); File ftpedtftpj = new File(ftp, "edtftpj.jar"); edtftpj.renameTo(ftpedtftpj); } } // remove the obsolete xml library under dir File xml = new File(dir, "xml"); deleteAll(xml); // remove the dicom profiles so any // obsolete files will disappear File profiles = new File(dir, "profiles"); File dicom = new File(profiles, "dicom"); deleteAll(dicom); dicom.mkdirs(); // Remove the index.html file so it will be rebuilt from // example-index.html when the system next starts. File root = new File(dir, "ROOT"); if (root.exists()) { File index = new File(root, "index.html"); index.delete(); } }
public boolean accept(File file) { if (file.isFile()) size += file.length(); else file.listFiles(this); return false; }