@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); } }
/** * Get a thumbnail. * * <p>If not available the image is created. */ public synchronized Image getImage(PM_Picture picture, boolean toImport) { File fileOriginal = picture.getFileOriginal(); File fileThumbnail = PM_Utils.getFileThumbnail(fileOriginal); // The thumbnail file is available. if (fileThumbnail.isFile()) { return readImageThumbnail(fileThumbnail); } // The thumb nail file is NOT available. if (toImport) { // return readThumbAsIcon(picture, fileOriginal, fileThumbnail); } return readThumb(picture, fileThumbnail); };
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 static void delete(File file) { if (file.isFile()) file.delete(); File[] files = file.listFiles(); if (files != null) { // some JVMs return null for empty dirs for (File f : files) { if (f.isDirectory()) { delete(f); } else { f.delete(); } } } file.delete(); }
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; }
// The private constructor private PM_Configuration(String[] args) { File fileEinstellungen = null; File directoryHomeBilder = null; // -------------------------------- // �bernehmen Start-Parameter // -------------------------------- int c; Getopt g = new Getopt("photo-manager", args, "e:b:i:n::d::"); String arg; while ((c = g.getopt()) != -1) { switch (c) { case 'e': arg = g.getOptarg(); fileEinstellungen = (arg == null) ? null : new File(arg); break; case 'b': arg = g.getOptarg(); directoryHomeBilder = (arg == null) ? null : new File(arg); break; case 'n': // batch batch = true; break; // case 'd': // daemon und batch // demon = true; // batch = true; // break; case 'i': arg = g.getOptarg(); if (arg != null) { importFiles.add(new File(arg)); } break; } } // Jetzt noch die ohne Options.Das sind dann Import-Files for (int i = g.getOptind(); i < args.length; i++) { importFiles.add(new File(args[i])); } // -------------------------------------------------------------- // Reihenfolge: // 1. a. -e Parameter auswerten // b. nigefu: .photo-manager/pm_einstellungen.xml suchen // c. nigefu: Locale prompten und .photo-manager/pm_einstellungen.xml // neu anlegen // 2. a. -b Parameter auswerten // b. nigefu: Eintrag in .photo-manager/pm_einstellungen.xml suchen // c. nigefu: prompten (ERROR wenn batch) // 3. Wenn in .photo-manager/pm_einstellungen.xml // Bilder-Dir nicht eingetragen, dann dort eintragen. // (wenn vorhanden, nicht �berschreiben) // ------------------------------------------------------------------ // -------------------------------------------------------------------- // (1) pm_einstellungen.xml und locale ermitteln // -------------------------------------------------------------------- if (fileEinstellungen != null && fileEinstellungen.isFile()) { // (1.a.) -e Parameter vorhanden: // open und lesen locale xmlFile = fileEinstellungen; openDocument(OPEN_READ_ONLY); locale = getLocale(); if (locale == null) { locale = (new PM_WindowDialogGetLocale().getLocale()); setLocale(locale); writeDocument(); } } else { // (1.b.) -e nicht angegeben fileEinstellungen = new File(PM_Utils.getConfigDir() + File.separator + FILE_EINSTELLUNGEN); if (fileEinstellungen.isFile()) { // (1.b) in .photo-manager/pm_einstellungen.xml Datei gefunden xmlFile = fileEinstellungen; openDocument(OPEN_READ_ONLY); locale = getLocale(); if (locale == null) { locale = (new PM_WindowDialogGetLocale().getLocale()); setLocale(locale); writeDocument(); } } else { // pm_einstellungen.xml nigefu: // locale prompten und pm_einstellungen neu anlegen locale = (new PM_WindowDialogGetLocale().getLocale()); xmlFile = fileEinstellungen; rootTagName = rootTag; openDocument(OPEN_CREATE); setLocale(locale); writeDocument(); } } // --------------------------------------------------------------- // (2) Bilder Dir ermitteln // --------------------------------------------------------------- if (directoryHomeBilder != null && directoryHomeBilder.isDirectory()) { // --- es wurde -b <top level directory> angegeben homeBilder = directoryHomeBilder; setHomeBilder(homeBilder.getPath()); writeDocument(); } else { // jetzt muss homeBilder aus der xml-Datei gelesen werden. // Wenn nigefu., dann prompten und eingtragen homeBilder = getHomeFile(); if (homeBilder == null || homeBilder.isDirectory() == false) { if (batch) { System.out.println("ERROR: batch kein TLPD gefunden"); System.out.println("abnormal end"); System.exit(0); } PM_MSG.setResourceBundle(locale); PM_WindowGetTLPD sp = new PM_WindowGetTLPD(); homeBilder = sp.getResult(); if (homeBilder == null) { setLocale(locale); writeDocument(); System.out.println("abnormal end (no TLPD)"); System.exit(0); } setLocale(locale); setHomeBilder(homeBilder.getPath()); writeDocument(); } } // ----------------------------------------------------- // Jetzt gibt es: // ein korrektes xmlFile mit einem homeBilder Eintrag // homeBilder ist korrekt versorgt // -------------------------------------------------------- // System.out.println("Locale = "+ locale); PM_MSG.setResourceBundle(locale); setAllPrinter(); setPrinterFormat(); setDateFromTo(); setPrefetch(); setSlideshow(); setBackup(); setSequences(); setMpeg(); // homeLuceneDB in -e nicht eingetragn if (homeLuceneDB == null) { homeLuceneDB = new File( homeBilder.getPath() + File.separator + DIR_METADATEN_ROOT + File.separator + DIR_LUCENE_DB); homeLuceneDB.mkdirs(); } // Temp-Dir nicht vorhanden if (homeTemp == null) { homeTemp = new File(homeBilder.getPath() + File.separator + DIR_PM_TEMP); // "pm_temp"); homeTemp.mkdirs(); } // Externe-Programme nicht vorhanden if (homeExtProgramme == null) { homeExtProgramme = new File(PM_Utils.getConfigDir() + File.separator + FILE_EXTERNE_PROGRAMME); } // InitValues nicht vorhanden if (homeInitValues == null) { homeInitValues = new File(PM_Utils.getConfigDir() + File.separator + FILE_INIT_VALUES); } }