public boolean accept(File pathname) {
   if (pathname.isDirectory()) return true;
   else {
     if (pathname.getName().indexOf(".scl") != -1) return true;
     else return false;
   }
 }
Пример #2
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
  }
Пример #3
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;
    }
Пример #4
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;
 }
Пример #5
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);
      }
    }
  }
Пример #6
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;
   }
 }
Пример #7
0
  public boolean loadSourceFile(File file) {
    boolean result = false;

    selectedPath = file.getParent();

    BufferedReader sourceFile = null;

    String directoryPath = file.getParent();
    String sourceName = file.getName();

    int idx = sourceName.lastIndexOf(".");
    fileExt = idx == -1 ? "" : sourceName.substring(idx + 1);
    baseName = idx == -1 ? sourceName.substring(0) : sourceName.substring(0, idx);
    String basePath = directoryPath + File.separator + baseName;

    DataOptions.directoryPath = directoryPath;

    sourcePath = file.getPath();

    AssemblerOptions.sourcePath = sourcePath;
    AssemblerOptions.listingPath = basePath + ".lst";
    AssemblerOptions.objectPath = basePath + ".cd";

    String var = System.getenv("ROPE_MACROS_DIR");
    if (var != null && !var.isEmpty()) {
      File dir = new File(var);
      if (dir.exists() && dir.isDirectory()) {
        AssemblerOptions.macroPath = var;
      } else {
        AssemblerOptions.macroPath = directoryPath;
      }
    } else {
      AssemblerOptions.macroPath = directoryPath;
    }

    DataOptions.inputPath = AssemblerOptions.objectPath;
    DataOptions.outputPath = basePath + ".out";
    DataOptions.readerPath = null;
    DataOptions.punchPath = basePath + ".pch";
    DataOptions.tape1Path = basePath + ".mt1";
    DataOptions.tape2Path = basePath + ".mt2";
    DataOptions.tape3Path = basePath + ".mt3";
    DataOptions.tape4Path = basePath + ".mt4";
    DataOptions.tape5Path = basePath + ".mt5";
    DataOptions.tape6Path = basePath + ".mt6";

    this.setTitle("EDIT: " + sourceName);
    fileText.setText(sourcePath);

    if (dialog == null) {
      dialog = new AssemblerDialog(mainFrame, "Assembler options");

      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      Dimension dialogSize = dialog.getSize();
      dialog.setLocation(
          (screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2);
    }

    dialog.initialize();

    AssemblerOptions.command = dialog.buildCommand();

    sourceArea.setText(null);

    try {
      sourceFile = new BufferedReader(new FileReader(file));
      String line;

      while ((line = sourceFile.readLine()) != null) {
        sourceArea.append(line + "\n");
      }

      sourceArea.setCaretPosition(0);
      optionsButton.setEnabled(true);
      assembleButton.setEnabled(true);
      saveButton.setEnabled(true);

      setSourceChanged(false);
      undoMgr.discardAllEdits();

      result = true;
    } catch (IOException ex) {
      ex.printStackTrace();
    } finally {
      try {
        if (sourceFile != null) {
          sourceFile.close();
        }
      } catch (IOException ignore) {
      }
    }

    return result;
  }