private static int getBuildNumber(File installDirectory) {
    installDirectory = installDirectory.getAbsoluteFile();

    File buildTxt = new File(installDirectory, BUILD_NUMBER_FILE);
    if ((!buildTxt.exists()) || (buildTxt.isDirectory())) {
      buildTxt = new File(new File(installDirectory, BIN_FOLDER), BUILD_NUMBER_FILE);
    }

    if (buildTxt.exists() && !buildTxt.isDirectory()) {
      int buildNumber = -1;
      String buildNumberText = getContent(buildTxt);
      if (buildNumberText != null) {
        try {
          if (buildNumberText.length() > 1) {
            buildNumberText = buildNumberText.trim();
            buildNumber = Integer.parseInt(buildNumberText);
          }
        } catch (Exception e) {
          // OK
        }
      }
      return buildNumber;
    }

    return -1;
  }
    public void valueChanged(ListSelectionEvent evt) {
      if (!evt.getValueIsAdjusting()) {
        JFileChooser chooser = getFileChooser();
        FileSystemView fsv = chooser.getFileSystemView();
        JList list = (JList) evt.getSource();

        int fsm = chooser.getFileSelectionMode();
        boolean useSetDirectory = usesSingleFilePane && (fsm == JFileChooser.FILES_ONLY);

        if (chooser.isMultiSelectionEnabled()) {
          File[] files = null;
          Object[] objects = list.getSelectedValues();
          if (objects != null) {
            if (objects.length == 1
                && ((File) objects[0]).isDirectory()
                && chooser.isTraversable(((File) objects[0]))
                && (useSetDirectory || !fsv.isFileSystem(((File) objects[0])))) {
              setDirectorySelected(true);
              setDirectory(((File) objects[0]));
            } else {
              ArrayList<File> fList = new ArrayList<File>(objects.length);
              for (Object object : objects) {
                File f = (File) object;
                boolean isDir = f.isDirectory();
                if ((chooser.isFileSelectionEnabled() && !isDir)
                    || (chooser.isDirectorySelectionEnabled() && fsv.isFileSystem(f) && isDir)) {
                  fList.add(f);
                }
              }
              if (fList.size() > 0) {
                files = fList.toArray(new File[fList.size()]);
              }
              setDirectorySelected(false);
            }
          }
          chooser.setSelectedFiles(files);
        } else {
          File file = (File) list.getSelectedValue();
          if (file != null
              && file.isDirectory()
              && chooser.isTraversable(file)
              && (useSetDirectory || !fsv.isFileSystem(file))) {

            setDirectorySelected(true);
            setDirectory(file);
            if (usesSingleFilePane) {
              chooser.setSelectedFile(null);
            }
          } else {
            setDirectorySelected(false);
            if (file != null) {
              chooser.setSelectedFile(file);
            }
          }
        }
      }
    }
  private void setupHomeDir(String homeString) {
    if (homeString == null) {
      homeString = sysProps.getProperty("swingri.home");
    }

    if (homeString != null) {
      dataDir = new File(homeString);
    } else {
      userHome = new File(sysProps.getProperty("user.home"));
      String dataDirStr = props.getString("application.datadir", DEFAULT_HOME_DIR);
      dataDir = new File(userHome, dataDirStr);
    }

    if (!dataDir.isDirectory()) {
      String path = dataDir.getAbsolutePath();
      boolean create;
      if (props.hasUserRejectedCreatingLocalDataDir()) {
        create = false;
      } else if (getBoolean("application.showLocalStorageDialogs", true)) {
        create =
            Resources.showConfirmDialog(
                null,
                messageBundle,
                "fontManager.properties.title",
                "manager.properties.createNewDirectory",
                path);
        if (!create) props.setUserRejectedCreatingLocalDataDir();
      } else {
        // Always create local-storage directory if show user prompt dialog setting is false.
        create = true;
      }

      if (!create) {
        dataDir = null;
      } else {
        dataDir.mkdirs();
        if (!dataDir.isDirectory()) {
          // check to make sure that dialog should be shown on the error.
          if (getBoolean("application.showLocalStorageDialogs", true)) {
            Resources.showMessageDialog(
                null,
                JOptionPane.ERROR_MESSAGE,
                messageBundle,
                "fontManager.properties.title",
                "manager.properties.failedCreation",
                dataDir.getAbsolutePath());
          }
          dataDir = null;
        }
      }
    }
  }
  /** Initialize the panel UI component values from the current site profile settings. */
  public void updatePanel() {
    {
      File dir = pApp.getHomeDirectory();

      if (dir == null) {
        String home = System.getProperty("user.home");
        if (home != null) {
          File hdir = new File(home);
          if ((hdir != null) && hdir.isDirectory()) dir = hdir.getParentFile();
        }
      }

      if (dir == null) dir = new File("/home");

      pHomeDirComp.setDir(dir);
    }

    {
      File dir = pApp.getTemporaryDirectory();
      if (dir == null) dir = new File("/var/tmp");
      pTempDirComp.setDir(dir);
    }

    {
      File dir = pApp.getUnixJavaHome();
      if (dir == null) dir = new File(pApp.getJavaHome());
      pJavaHomeDirComp.setDir(dir);
    }

    pJavadocDirComp.setDir(pApp.getUnixLocalJavadocDirectory());
    pExtraJavaLibsComp.setJars(pApp.getUnixLocalJavaLibraries());
  }
  protected void getImages() {
    File directory = new File(this.saveDirectory);

    // BufferedImage img = null;

    images = new ArrayList<String>();
    if (directory.exists() && directory.isDirectory()) {
      // File[] files = directory.listFiles();
      String[] files = directory.list();

      for (int i = 0; i < files.length; i++) {
        // System.out.println(files[i]);
        // try {
        // if(files[i].getName().startsWith("cam"))
        if (files[i].startsWith("cam")) {
          // Windows spesific
          images.add(this.saveDirectory + "\\" + files[i]);
          /*
          img = ImageIO.read(files[i]);
          images.add(img);*/
        }
        // } catch (IOException e) {
        //	System.err.println("Failed on reading image. IOException.");
        // }
      }
    }

    System.out.println("Total image count = " + images.size());
    gotImages = true;
  }
Example #6
0
  protected void addExternalFactories(String folder, ClassLoader classLoader) {
    File[] factoryFiles = new File(folder).listFiles();
    if (factoryFiles != null) {
      for (File factoryFile : factoryFiles) {
        if (factoryFile.isDirectory()) {
          addExternalListeners(factoryFile.getAbsolutePath(), classLoader);
          continue;
        }

        if (!factoryFile.getName().toLowerCase().endsWith("-factories.xml")) {
          continue;
        }

        try {
          log.info("Adding factories from [" + factoryFile.getAbsolutePath() + "]");

          getFactoryRegistry().addConfig(new FileInputStream(factoryFile), classLoader);
          // We break the general rule that you shouldn't catch Throwable, because we don't want
          // extensions to crash SoapUI
        } catch (Throwable e) {
          SoapUI.logError(e, "Couldn't load factories in " + factoryFile.getAbsolutePath());
        }
      }
    }
  }
 public boolean accept(File pathname) {
   if (pathname.isDirectory()) return true;
   else {
     if (pathname.getName().indexOf(".scl") != -1) return true;
     else return false;
   }
 }
Example #8
0
 /**
  * The FileEvent listener.
  *
  * @param event the event.
  */
 public void fileEventOccurred(FileEvent event) {
   File file = event.getFile();
   if (file != null) {
     String dirPath;
     if (file.isDirectory()) dirPath = file.getAbsolutePath();
     else dirPath = file.getParentFile().getAbsolutePath();
     properties.setProperty("directory", dirPath);
   } else properties.remove("directory");
 }
Example #9
0
 public void startFile(String logfile) {
   File parent = new File(logfile).getParentFile();
   if (!parent.isDirectory() && !parent.mkdirs()) {
     logger.warning("Could not create log folder: " + parent);
   }
   Handler fileHandler = new RotatingFileHandler(logfile);
   fileHandler.setFormatter(new DateOutputFormatter(FILE_DATE));
   logger.addHandler(fileHandler);
 }
Example #10
0
 protected void fileNew() {
   if (currentFile != null) {
     if (!currentFile.isDirectory()) {
       currentFile = currentFile.getParentFile();
     }
   }
   graph.clear();
   gp.update(gp.getGraphics());
 }
 public boolean accept(File f) {
   if (f == null) {
     return false;
   }
   if (f.isDirectory()) {
     return true;
   }
   return pattern.matcher(f.getName()).matches();
 }
Example #12
0
 public boolean accept(File f) {
   if (f.isDirectory()) {
     return true;
   }
   String fn = f.getName();
   if (fn.toLowerCase().endsWith(".java") || fn.toLowerCase().endsWith(".txt")) {
     return true;
   }
   return false;
 }
 public String getTypeDescription(File f) {
   String type = getFileChooser().getFileSystemView().getSystemTypeDescription(f);
   if (type == null) {
     if (f.isDirectory()) {
       type = directoryDescriptionText;
     } else {
       type = fileDescriptionText;
     }
   }
   return type;
 }
Example #14
0
 protected void fileSave() {
   if (currentFile == null) {
     fileSaveAs();
   } else {
     if (currentFile.isDirectory()) {
       fileSaveAs();
     } else {
       graph.saveAll(currentFile);
       gp.update(gp.getGraphics());
     }
   }
 }
Example #15
0
  /** Returns false if Exception is thrown. */
  private boolean setDirectory() {
    String pathStr = dirTF.getText().trim();
    if (pathStr.equals("")) pathStr = System.getProperty("user.dir");
    try {
      File dirPath = new File(pathStr);
      if (!dirPath.isDirectory()) {
        if (!dirPath.exists()) {
          if (recursiveCheckBox.isSelected())
            throw new NotDirectoryException(dirPath.getAbsolutePath());
          else throw new NotFileException(dirPath.getAbsolutePath());
        } else {
          convertSet.setFile(dirPath);
          convertSet.setDestinationPath(dirPath.getParentFile());
        }
      } else {
        // Set the descriptors
        setMatchingFileNames();

        FlexFilter flexFilter = new FlexFilter();
        flexFilter.addDescriptors(descriptors);
        flexFilter.setFilesOnly(!recursiveCheckBox.isSelected());

        convertSet.setSourcePath(dirPath, flexFilter);
        convertSet.setDestinationPath(dirPath);
      }
    } catch (NotDirectoryException e1) {
      final String caption = ResourceHandler.getMessage("notdirectory_dialog.caption1");

      MessageFormat formatter;
      String info_msg;
      if (pathStr.equals("")) {
        info_msg = ResourceHandler.getMessage("notdirectory_dialog.info5");
      } else {
        formatter = new MessageFormat(ResourceHandler.getMessage("notdirectory_dialog.info0"));
        info_msg = formatter.format(new Object[] {pathStr});
      }
      final String info = info_msg;

      JOptionPane.showMessageDialog(this, info, caption, JOptionPane.ERROR_MESSAGE);
      return false;
    } catch (NotFileException e2) {
      final String caption = ResourceHandler.getMessage("notdirectory_dialog.caption0");

      MessageFormat formatter =
          new MessageFormat(ResourceHandler.getMessage("notdirectory_dialog.info1"));
      final String info = formatter.format(new Object[] {pathStr});

      JOptionPane.showMessageDialog(this, info, caption, JOptionPane.ERROR_MESSAGE);
      return false;
    }

    return true; // no exception thrown
  }
Example #16
0
  public static double getFolderSize(File directory) {

    double length = 0;

    for (File f : directory.listFiles()) {
      if (!f.isDirectory()) length += f.length();
      else length += getFolderSize(f);
    }

    double size = (length / 1024.0) / 1024.0;

    return size;
  }
  private boolean _assignValues(File fle) {
    String strMethod = "_assignValues(fle)";

    if (fle == null) {
      MySystem.s_printOutError(this, strMethod, "nil fle");
      return false;
    }

    if (!fle.exists()) {
      MySystem.s_printOutWarning(
          this, strMethod, "! fle.exists(), fle.getAbsolutePath()=" + fle.getAbsolutePath());

      String strBody = fle.getAbsolutePath();
      strBody += ":\nDirectory not found.";

      OPAbstract.s_showDialogWarning(super._frmParent_, strBody);

      return true;
    }

    if (!fle.isDirectory()) // statement should never be reached!!!
    {
      MySystem.s_printOutWarning(
          this, strMethod, "! fle.isDirectory(), fle.getAbsolutePath()=" + fle.getAbsolutePath());

      String strBody = fle.getAbsolutePath();
      strBody += ":\n  not a directory.";

      OPAbstract.s_showDialogWarning(super._frmParent_, strBody);

      return true;
    }

    if (super._tfdCurSelection_ == null) {
      MySystem.s_printOutError(this, strMethod, "nil super._tfdCurSelection_");
      return false;
    }

    super._tfdCurSelection_.setText(fle.getAbsolutePath());
    super._setSelectedValue_(true);

    if (!_enableButtonsSelectionDone_()) {
      MySystem.s_printOutError(this, strMethod, "failed");
      return false;
    }

    // --
    // ending
    return true;
  }
  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));
      }
    }
  }
Example #19
0
 public static boolean deleteAll(File file) {
   boolean b = true;
   if ((file != null) && file.exists()) {
     if (file.isDirectory()) {
       try {
         File[] files = file.listFiles();
         for (File f : files) b &= deleteAll(f);
       } catch (Exception e) {
         return false;
       }
     }
     b &= file.delete();
   }
   return b;
 }
Example #20
0
    @Override
    public boolean accept(File file) {
      if (file.isDirectory()) {
        return true;
      }

      String name = file.getName().toLowerCase();
      for (int i = 0; i < extensions.length; ++i) {
        if (name.endsWith(extensions[i])) {
          return true;
        }
      }

      return false;
    }
Example #21
0
  public static void main(String[] args) {
    // read arguments and respond correctly
    File in;
    File out;
    String tileDirectory;
    if (args.length == 0 || args.length > 2) {
      in = null;
      out = null;
      tileDirectory = "";
      System.err.println("Incorrect number of arguments. Required: Filename (tileset path)");
      System.exit(0);
    } else if (args.length == 1) { // load old file
      in = new File(args[0]);
      out = in;
      Scanner s = null;
      try {
        s = new Scanner(in);
      } catch (FileNotFoundException e) {
        System.out.println("Could not find input file.");
        System.exit(0);
      }
      tileDirectory = s.nextLine();
    } else {
      in = null;
      out = new File(args[0]);
      tileDirectory = args[1];
      try {
        File f = new File(tileDirectory);
        if (!f.isDirectory()) {
          throw new IOException("Tileset does not exist");
        }
      } catch (IOException e) {
        System.err.println(e);
        System.out.println("This error is likely thanks to an invalid tileset path");
        System.exit(0);
      }
    }

    MapBuilder test = new MapBuilder("Map Editor", in, out, tileDirectory);

    // Build GUI
    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            test.CreateAndDisplayGUI();
          }
        });
  }
Example #22
0
 protected void fileSaveSimple() {
   JFileChooser chooser = null;
   if (currentFile == null) {
     chooser = new JFileChooser(startDirectory);
   } else {
     chooser = new JFileChooser(currentFile);
     if (!currentFile.isDirectory()) {
       chooser.setSelectedFile(currentFile);
     }
   }
   int returnVal = chooser.showSaveDialog(gw);
   if (returnVal == JFileChooser.APPROVE_OPTION) {
     currentFile = chooser.getSelectedFile();
     graph.saveSimple(currentFile);
   }
 }
Example #23
0
  /**
   * 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);
  }
Example #24
0
  private void browseAction() {
    if (selectedPath == null) {
      selectedPath = System.getenv("ROPE_SOURCES_DIR");
      if (selectedPath != null) {
        File dir = new File(selectedPath);
        if (!dir.exists() || !dir.isDirectory()) {
          String message =
              String.format(
                  "The sources path set in environment variable ROPE_SOURCES_DIR is not avaliable.\n%s",
                  selectedPath);
          JOptionPane.showMessageDialog(null, message, "ROPE", JOptionPane.WARNING_MESSAGE);
          selectedPath = null;
        } else {
          System.out.println("Source folder path set from ROPE_SOURCES_DIR: " + selectedPath);
        }
      }
      if (selectedPath == null) {
        selectedPath = System.getProperty("user.dir");

        System.out.println("Source folder path set to current directory: " + selectedPath);
      }
    }

    Vector<RopeFileFilter> filters = new Vector<RopeFileFilter>();
    filters.add(
        new RopeFileFilter(
            new String[] {".a", ".asm", ".aut", ".s"}, "Assembly files (*.a *.asm *.aut *.s)"));
    filters.add(new RopeFileFilter(new String[] {".m", ".mac"}, "Macro files (*.m *.mac)"));
    filters.add(new RopeFileFilter(new String[] {".lst"}, "List files (*.lst)"));
    filters.add(new RopeFileFilter(new String[] {".txt"}, "Text files (*.txt)"));

    RopeFileChooser chooser = new RopeFileChooser(selectedPath, null, filters);
    chooser.setDialogTitle("Source document selection");
    chooser.setFileFilter(filters.firstElement());
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

    File file = chooser.open(this, fileText);
    if (file != null) {
      if (loadSourceFile(file)) {
        mainFrame.showExecWindow(baseName);
      }
    }
  }
Example #25
0
 private void listFiles(String basePath, String path, String extension, Vector<String> vector) {
   File folder = new File(path);
   String[] list = folder.list();
   if (list != null) {
     for (String item : list) {
       if (item.charAt(0) == '.') continue;
       File file = new File(path, item);
       String newPath = file.getAbsolutePath();
       if (newPath.startsWith(basePath)) {
         newPath = newPath.substring(basePath.length());
       }
       if (extension == null || item.toLowerCase().endsWith(extension)) {
         vector.add(newPath);
       }
       if (file.isDirectory()) {
         listFiles(basePath, file.getAbsolutePath(), extension, vector);
       }
     }
   }
 }
Example #26
0
 /**
  * Load the file names of all files in the given directory.
  *
  * @param dirName Directory (folder) name.
  * @param suffix File suffix of interest.
  * @return The names of files found.
  */
 private String[] findFiles(String dirName, String suffix) {
   File dir = new File(dirName);
   if (dir.isDirectory()) {
     String[] allFiles = dir.list();
     if (suffix == null) {
       return allFiles;
     } else {
       List<String> selected = new ArrayList<String>();
       for (String filename : allFiles) {
         if (filename.endsWith(suffix)) {
           selected.add(filename);
         }
       }
       return selected.toArray(new String[selected.size()]);
     }
   } else {
     System.out.println("Error: " + dirName + " must be a directory");
     return null;
   }
 }
    public Icon getIcon(File f) {
      Icon icon = getCachedIcon(f);
      if (icon != null) {
        return icon;
      }
      icon = fileIcon;
      if (f != null) {
        FileSystemView fsv = getFileChooser().getFileSystemView();

        if (fsv.isFloppyDrive(f)) {
          icon = floppyDriveIcon;
        } else if (fsv.isDrive(f)) {
          icon = hardDriveIcon;
        } else if (fsv.isComputerNode(f)) {
          icon = computerIcon;
        } else if (f.isDirectory()) {
          icon = directoryIcon;
        }
      }
      cacheIcon(f, icon);
      return icon;
    }
Example #28
0
  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);
    }
  }
Example #29
0
 boolean tryDir(String d) {
   ClassLoader L = getClass().getClassLoader();
   File p = new File(d, PACKAGE);
   System.out.println("Try " + p);
   if (!p.exists() || !p.isDirectory()) return false;
   for (File f : p.listFiles()) {
     String s = f.getName();
     if (!s.endsWith(".class")) continue;
     String name = s.substring(0, s.length() - 6);
     try {
       Class<?> c = L.loadClass(PACKAGE + "." + name);
       if (!Animator.class.isAssignableFrom(c)) continue;
       Animator a = (Animator) c.newInstance();
       a.container().setPreferredSize(DIM);
       map.put(name, a);
       System.out.println("  " + name);
       // ClassNotFoundException InstantiationException IllegalAccessException
     } catch (Exception e) {
       continue;
     }
   }
   return map.size() > 0;
 }
Example #30
-1
  private void saveItem() {

    File f = new File("config.txt");

    if (f.exists() && !f.isDirectory()) {

      try (PrintWriter out =
          new PrintWriter(new BufferedWriter(new FileWriter("config.txt", true)))) {
        if (!searchName.getText().equals("") && !item.getText().equals("")) {

          out.println(
              searchName.getText()
                  + ","
                  + "http://www.reddit.com/r/hardwareswap/search?q="
                  + item.getText()
                  + "&sort=new&restrict_sr=on");
          addItem();

        } else {

          results.setText("Please provide all info for Search Name and Item");
        }

      } catch (IOException e1) {
        results.append("Error saving to file.");
      }

    } else {
      Main.checkFiles();
    }
  }