Пример #1
0
    @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);
      }
    }
Пример #2
0
  /** 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());
  }
Пример #3
0
 private byte[] loadClassData(String className) throws IOException {
   Playground.println("Loading class " + className + ".class", warning);
   File f = new File(System.getProperty("user.dir") + "/" + className + ".class");
   byte[] b = new byte[(int) f.length()];
   new FileInputStream(f).read(b);
   return b;
 }
Пример #4
0
  //    public static final String showElementTreeAction = "showElementTree";
  // -------------------------------------------------------------
  public void openFile(String currDirStr, String currFileStr) {

    if (fileDialog == null) {
      fileDialog = new FileDialog(this);
    }
    fileDialog.setMode(FileDialog.LOAD);
    if (!(currDirStr.equals(""))) {
      fileDialog.setDirectory(currDirStr);
    }
    if (!(currFileStr.equals(""))) {
      fileDialog.setFile(currFileStr);
    }
    fileDialog.show();

    String file = fileDialog.getFile(); // cancel pushed
    if (file == null) {
      return;
    }
    String directory = fileDialog.getDirectory();
    File f = new File(directory, file);
    if (f.exists()) {
      Document oldDoc = getEditor().getDocument();
      if (oldDoc != null)
        // oldDoc.removeUndoableEditListener(undoHandler);
        /*
          if (elementTreePanel != null) {
          elementTreePanel.setEditor(null);
          }
        */
        getEditor().setDocument(new PlainDocument());
      fileDialog.setTitle(file);
      Thread loader = new FileLoader(f, editor1.getDocument());
      loader.start();
    }
  }
Пример #5
0
    public void actionPerformed(ActionEvent e) {
      if (readOnly) {
        return;
      }
      JFileChooser fc = getFileChooser();
      File currentDirectory = fc.getCurrentDirectory();

      if (!currentDirectory.exists()) {
        JOptionPane.showMessageDialog(
            fc,
            newFolderParentDoesntExistText,
            newFolderParentDoesntExistTitleText,
            JOptionPane.WARNING_MESSAGE);
        return;
      }

      File newFolder;
      try {
        newFolder = fc.getFileSystemView().createNewFolder(currentDirectory);
        if (fc.isMultiSelectionEnabled()) {
          fc.setSelectedFiles(new File[] {newFolder});
        } else {
          fc.setSelectedFile(newFolder);
        }
      } catch (IOException exc) {
        JOptionPane.showMessageDialog(
            fc,
            newFolderErrorText + newFolderErrorSeparator + exc,
            newFolderErrorText,
            JOptionPane.ERROR_MESSAGE);
        return;
      }

      fc.rescanCurrentDirectory();
    }
Пример #6
0
    public void actionPerformed(ActionEvent e) {
      int index = list.getSelectedIndex();
      if (index == -1) {
        return;
      }
      int returnVal = fc.showOpenDialog(fileBackupProgram.this);

      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        Path directory = file.toPath();

        try {
          destination.setText("Destination Directory: " + directory.toRealPath());
          // destField.setValue(directory.toRealPath());
        } catch (IOException x) {
          printer.printError(x.toString());
        }

        directoryList.getDirectory(index).setDestination(directory);
        startButton.setEnabled(true);
      } else {
        log.append("Open command cancelled by user." + newline);
      }
      log.setCaretPosition(log.getDocument().getLength());
    }
Пример #7
0
 /** Get the default folder URL */
 public URL getDefaultFolderURL() {
   try {
     final File defaultFolder = getDefaultFolder();
     return (defaultFolder != null) ? defaultFolder.toURI().toURL() : null;
   } catch (MalformedURLException exception) {
     throw new RuntimeException("Exception getting the default document URL.", exception);
   }
 }
Пример #8
0
    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);
            }
          }
        }
      }
    }
Пример #9
0
 public boolean accept(File f) {
   if (f == null) {
     return false;
   }
   if (f.isDirectory()) {
     return true;
   }
   return pattern.matcher(f.getName()).matches();
 }
Пример #10
0
  /** Creates new form addonSearch */
  public addonSearch() {
    initComponents();
    ys = new listener();

    try {
      logfileURL = new URL("file:/" + System.getProperty("user.dir") + "/addonsearch.htm");
      log = new File(logfileURL.toURI());
      log.delete();
      log = new File(logfileURL.toURI());
      log_out = new BufferedWriter(new FileWriter(log, true));
      log_out.write("");
      refresh();
    } catch (Exception ex) {
      JOptionPane.showMessageDialog(
          this,
          "Cannot create logfile for chat window."
              + " Try running this program in 'My Documents'.\n"
              + ex,
          "addonsearch",
          JOptionPane.ERROR_MESSAGE);
    }

    File file = null;
    BufferedWriter output;
    try {
      file =
          new File(new URL("file:/" + System.getProperty("user.dir") + "/addonsearch.cfg").toURI());
      if (file.exists()) ys_cfg(file);
      else {
        output = new BufferedWriter(new FileWriter(file));
        jFrame1.setSize(580, 420);
        jFrame1.setVisible(true);
      }
    } catch (Exception ex) {
      if (!ex.toString().equals("java.io.IOException: Stream closed")) System.out.println(ex);
      // JOptionPane.showMessageDialog(this, "Impossible to read the YSChat config file!\n"+ex,
      // "YS_chat", JOptionPane.ERROR_MESSAGE);
    }

    makeLocalDB();

    messOut.addHyperlinkListener(
        new HyperlinkListener() {
          public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
              if (Desktop.isDesktopSupported()) {
                try {
                  Desktop.getDesktop().browse(e.getURL().toURI());
                } catch (Exception ex) {
                  System.out.println(ex.getMessage());
                }
              }
            }
          }
        });
  }
Пример #11
0
 public void paintComponent(Graphics g) {
   if (paint) {
     try {
       Rectangle vis = getVisibleRect();
       File fi = ImageLoader.getFile("images/inventoryback.png");
       BufferedImage bg = ImageIO.read(fi.toURL());
       g.drawImage(bg, vis.x, vis.y, null);
     } catch (Exception e) {
     }
   }
 }
Пример #12
0
  public void setFileName(int row, String name) {
    // avoid moving a File by renaming it !!
    if (name.indexOf("..") < 0 && name.indexOf("/") < 0 && name.indexOf("\\") < 0) {
      File oldFile = getFile(filenames[row]);
      File newFile = new File(oldFile.getParent() + File.separator + name);

      filenames[row] = name;

      oldFile.renameTo(newFile);
    }
  }
Пример #13
0
 private void makeLocalDB() {
   if (!ysDir.isEmpty()) {
     localDB = new ArrayList<String>();
     File aircraftDir = new File(ysDir + "/aircraft");
     String list[] = aircraftDir.list();
     for (String lst : list) {
       if (lst.lastIndexOf(".") != -1)
         if (lst.substring(lst.lastIndexOf(".")).equalsIgnoreCase(".lst"))
           readLST(ysDir + "/aircraft/" + lst);
     }
     ys.localAddons = localDB;
   }
 }
  public void displayPage(JEditorPane pane, String text) {
    try {
      File helpFile = new File((String) locations.get(text));
      String loc = "file:" + helpFile.getAbsolutePath();
      URL page = new URL(loc);

      pane.setPage(page);

    } catch (IOException ioe) {
      JOptionPane.showMessageDialog(null, "Help Topic Unavailable");
      pane.getParent().repaint();
    }
  }
Пример #15
0
    public void actionPerformed(ActionEvent e) {
      Frame frame = getFrame();
      JFileChooser chooser = new JFileChooser();
      int ret = chooser.showSaveDialog(frame);

      if (ret != JFileChooser.APPROVE_OPTION) {
        return;
      }

      File f = chooser.getSelectedFile();
      frame.setTitle(f.getName());
      Thread saver = new FileSaver(f, editor.getDocument());
      saver.start();
    }
Пример #16
0
  public static void stringToFile(String file, String string) {
    try {
      if (file.lastIndexOf('\\') != -1) {
        File par = new File(file.substring(0, file.lastIndexOf('\\')));
        par.mkdirs();
      }

      FileWriter fw = new FileWriter(file);
      fw.write(string);
      fw.flush();
      fw.close();
    } catch (IOException e) {
      System.out.println("Failed to save file.");
    }
  }
Пример #17
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;
    }
Пример #18
0
  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));
      }
    }
  }
Пример #19
0
  private boolean checkForSave() {
    // build warning message
    String message;
    if (file == null) {
      message = "File has been modified.  Save changes?";
    } else {
      message = "File \"" + file.getName() + "\" has been modified.  Save changes?";
    }

    // show confirm dialog
    int r =
        JOptionPane.showConfirmDialog(
            this,
            new JLabel(message),
            "Warning!",
            JOptionPane.YES_NO_CANCEL_OPTION,
            JOptionPane.WARNING_MESSAGE);

    if (r == JOptionPane.YES_OPTION) {
      // Save File
      if (fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
        // write the file
        physWriteTextFile(fileChooser.getSelectedFile(), textView.getText());
      } else {
        // user cancelled save after all
        return false;
      }
    }
    return r != JOptionPane.CANCEL_OPTION;
  }
Пример #20
0
  /**
   * Load a file of a particular type. It's a pretty standard helper function, which uses DarwinCSV
   * and setCurrentCSV(...) to make file loading happen with messaging and whatnot. We can also
   * reset the display: just call loadFile(null).
   *
   * @param file The file to load.
   * @param type The type of file (see DarwinCSV's constants).
   */
  private void loadFile(File file, short type) {
    // If the file was reset, reset the display and keep going.
    if (file == null) {
      mainFrame.setTitle(basicTitle);
      setCurrentCSV(null);
      return;
    }

    // Load up a new DarwinCSV and set current CSV.
    try {
      setCurrentCSV(new DarwinCSV(file, type));

    } catch (IOException ex) {
      MessageBox.messageBox(
          mainFrame,
          "Could not read file '" + file + "'",
          "Unable to read file '" + file + "': " + ex);
    }

    // Set the main frame title, based on the filename and the index.
    mainFrame.setTitle(
        basicTitle
            + ": "
            + file.getName()
            + " ("
            + String.format("%,d", currentCSV.getRowIndex().getRowCount())
            + " rows)");
  }
Пример #21
0
  public JFileChooser createFileChooser() {
    // create a filechooser
    JFileChooser fc = new JFileChooser();
    if (getSwingSet2() != null && getSwingSet2().isDragEnabled()) {
      fc.setDragEnabled(true);
    }

    // set the current directory to be the images directory
    File swingFile = new File("resources/images/About.jpg");
    if (swingFile.exists()) {
      fc.setCurrentDirectory(swingFile);
      fc.setSelectedFile(swingFile);
    }

    return fc;
  }
Пример #22
0
  private void changeDirectory(File dir) {
    JFileChooser fc = getFileChooser();
    // Traverse shortcuts on Windows
    if (dir != null && FilePane.usesShellFolder(fc)) {
      try {
        ShellFolder shellFolder = ShellFolder.getShellFolder(dir);

        if (shellFolder.isLink()) {
          File linkedTo = shellFolder.getLinkLocation();

          // If linkedTo is null we try to use dir
          if (linkedTo != null) {
            if (fc.isTraversable(linkedTo)) {
              dir = linkedTo;
            } else {
              return;
            }
          } else {
            dir = shellFolder;
          }
        }
      } catch (FileNotFoundException ex) {
        return;
      }
    }
    fc.setCurrentDirectory(dir);
    if (fc.getFileSelectionMode() == JFileChooser.FILES_AND_DIRECTORIES
        && fc.getFileSystemView().isFileSystem(dir)) {

      setFileName(dir.getAbsolutePath());
    }
  }
Пример #23
0
  /**
   * Upload files to pre-configured url.
   *
   * @param uploadLocation the location we are uploading to.
   * @param fileName the filename we use for the resulting filename we upload.
   * @param params the optional parameter names.
   * @param values the optional parameter values.
   */
  static void uploadLogs(String uploadLocation, String fileName, String[] params, String[] values) {
    try {
      File tempDir = LoggingUtilsActivator.getFileAccessService().getTemporaryDirectory();
      File newDest = new File(tempDir, fileName);

      File optionalFile = null;

      // if we have some description params
      // save them to file and add it to archive
      if (params != null) {
        optionalFile =
            new File(
                LoggingUtilsActivator.getFileAccessService().getTemporaryDirectory(),
                "description.txt");
        OutputStream out = new FileOutputStream(optionalFile);
        for (int i = 0; i < params.length; i++) {
          out.write((params[i] + " : " + values[i] + "\r\n").getBytes("UTF-8"));
        }
        out.flush();
        out.close();
      }

      newDest = LogsCollector.collectLogs(newDest, optionalFile);

      // don't leave any unneeded information
      if (optionalFile != null) optionalFile.delete();

      if (uploadLocation == null) return;

      if (HttpUtils.postFile(uploadLocation, "logs", newDest) != null) {
        NotificationService notificationService = LoggingUtilsActivator.getNotificationService();

        if (notificationService != null) {
          ResourceManagementService resources = LoggingUtilsActivator.getResourceService();
          String bodyMsgKey = "plugin.loggingutils.ARCHIVE_MESSAGE_OK";

          notificationService.fireNotification(
              LOGFILES_ARCHIVED,
              resources.getI18NString("plugin.loggingutils.ARCHIVE_BUTTON"),
              resources.getI18NString(bodyMsgKey, new String[] {uploadLocation}),
              null);
        }
      }
    } catch (Throwable e) {
      logger.error("Cannot upload file", e);
    }
  }
Пример #24
0
  /** 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;
  }
Пример #25
0
  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;
  }
Пример #26
0
 public Boolean isHidden(File f) {
   String name = f.getName();
   if (name != null && name.charAt(0) == '.') {
     return Boolean.TRUE;
   } else {
     return Boolean.FALSE;
   }
 }
Пример #27
0
  public HtmlPane(String helpFileName) {
    try {
      File f = new File(helpFileName);
      String s = f.getAbsolutePath();
      s = "file:" + s;
      URL url = new URL(s);
      html = new JEditorPane(s);
      html.setEditable(false);
      html.addHyperlinkListener(this);

      JViewport vp = getViewport();
      vp.add(html);
    } catch (MalformedURLException e) {
      System.out.println("Malformed URL: " + e);
    } catch (IOException e) {
      System.out.println("IOException: " + e);
    }
  }
Пример #28
0
 private void load() {
   File file = new File(filename);
   if (file.exists()) {
     try {
       Document doc = XmlUtil.getDocument(file);
       Element root = doc.getDocumentElement();
       Node child = root.getFirstChild();
       while (child != null) {
         if (child.getNodeType() == Node.ELEMENT_NODE) {
           Profile p = new Profile((Element) child);
           table.put(p.name, p);
         }
         child = child.getNextSibling();
       }
     } catch (Exception ignore) {
     }
   }
 }
Пример #29
0
  public void saveAs() {
    Vector<RopeFileFilter> filters = new Vector<RopeFileFilter>();

    if (fileExt.equals("m") || fileExt.equals("mac")) {
      filters.add(new RopeFileFilter(new String[] {".m", ".mac"}, "Macro files (*.m *.mac)"));
      filters.add(
          new RopeFileFilter(
              new String[] {".a", ".asm", ".aut", ".s"}, "Assembly files (*.a *.asm *.aut *.s)"));
    } else {
      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[] {".txt"}, "Text files (*.txt)"));

    RopeFileChooser chooser = new RopeFileChooser(selectedPath, null, filters);
    chooser.setDialogTitle("Save Source File");
    String fileName = String.format("%s.%s", baseName, fileExt);
    chooser.setSelectedFile(new File(selectedPath, fileName));
    JTextField field = chooser.getTextField();
    field.setSelectionStart(0);
    field.setSelectionEnd(baseName.length());
    File file = chooser.save(ROPE.mainFrame);
    if (file != null) {
      selectedPath = file.getParent();

      BufferedWriter writer = null;
      try {
        writer = new BufferedWriter(new FileWriter(file));
        writer.write(sourceArea.getText());
      } catch (IOException ex) {
        ex.printStackTrace();
      } finally {
        try {
          if (writer != null) {
            writer.close();
          }
        } catch (IOException ex) {
          ex.printStackTrace();
        }
      }
    }
  }
Пример #30
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);
      }
    }
  }