private void onOK() {
    try {
      InputStream in = new FileInputStream(inputFile);
      if (outputFile == null) {
        outputFile = new File(inputFile.getAbsolutePath() + "_");
      }
      OutputStream out = new FileOutputStream(outputFile);

      ANSIUnicodeConverter converter = new ANSIUnicodeConverter();
      converter.setDirection(ANSIUnicodeConverter.ANSI2UNICODE);
      StringBuffer output = new StringBuffer();

      final int BUFFER_SIZE = 1024 * 1024; // 1M
      byte[] buffer = new byte[BUFFER_SIZE];
      int currentPosition = 0;
      while (in.available() != 0) {
        int currentBufferSize = BUFFER_SIZE;
        if (in.available() < BUFFER_SIZE) {
          currentBufferSize = in.available();
        }
        in.read(buffer, currentPosition, currentBufferSize);
        currentBufferSize = currentBufferSize + currentBufferSize;
        converter.setInput(new String(buffer));

        out.write(converter.convert().getBytes());
      }

      in.close();
      out.close();
    } catch (Exception e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }
  }
Beispiel #2
0
 public String saveAsFile(boolean accessingAsFile) throws IOException {
   File file = new SikuliIDEFileChooser(SikuliIDE.getInstance(), accessingAsFile).save();
   if (file == null) {
     return null;
   }
   String bundlePath = FileManager.slashify(file.getAbsolutePath(), false);
   if (!file.getAbsolutePath().endsWith(".sikuli")) {
     bundlePath += ".sikuli";
   }
   if (FileManager.exists(bundlePath)) {
     int res =
         JOptionPane.showConfirmDialog(
             null,
             SikuliIDEI18N._I("msgFileExists", bundlePath),
             SikuliIDEI18N._I("dlgFileExists"),
             JOptionPane.YES_NO_OPTION);
     if (res != JOptionPane.YES_OPTION) {
       return null;
     }
   } else {
     FileManager.mkdir(bundlePath);
   }
   try {
     saveAsBundle(bundlePath, (SikuliIDE.getInstance().getCurrentFileTabTitle()));
     if (Settings.isMac()) {
       if (!Settings.handlesMacBundles) {
         makeBundle(bundlePath, accessingAsFile);
       }
     }
   } catch (IOException iOException) {
   }
   return getCurrentShortFilename();
 }
Beispiel #3
0
 public void loadFile(String filename) {
   filename = FileManager.slashify(filename, false);
   setSrcBundle(filename + "/");
   File script = new File(filename);
   _editingFile = FileManager.getScriptFile(script, null, null);
   if (_editingFile != null) {
     editingType =
         _editingFile
             .getAbsolutePath()
             .substring(_editingFile.getAbsolutePath().lastIndexOf(".") + 1);
     initBeforeLoad(editingType);
     try {
       this.read(
           new BufferedReader(new InputStreamReader(new FileInputStream(_editingFile), "UTF8")),
           null);
     } catch (Exception ex) {
       _editingFile = null;
     }
   }
   if (_editingFile != null) {
     updateDocumentListeners();
     setDirty(false);
     _srcBundleTemp = false;
   } else {
     _srcBundlePath = null;
   }
 }
Beispiel #4
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
  }
 String askForReadFilename() {
   int returnVal = sqlLoadChooser.showOpenDialog(this);
   if (returnVal == JFileChooser.APPROVE_OPTION) {
     File file = sqlLoadChooser.getSelectedFile();
     System.out.println("Selected read file " + file.getAbsolutePath());
     // return file.getName();
     return file.getAbsolutePath();
   } else {
     System.out.println("Open command cancelled by user.");
   }
   return null;
 }
  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;
  }
Beispiel #7
0
 private void writeSrcFile() throws IOException {
   Debug.log(3, "IDE: writeSrcFile: " + _editingFile.getName());
   writeFile(_editingFile.getAbsolutePath());
   if (PreferencesUser.getInstance().getAtSaveMakeHTML()) {
     convertSrcToHtml(getSrcBundle());
   } else {
     String snameDir = new File(_editingFile.getAbsolutePath()).getParentFile().getName();
     String sname = snameDir.replace(".sikuli", "") + ".html";
     (new File(snameDir, sname)).delete();
   }
   if (PreferencesUser.getInstance().getAtSaveCleanBundle()) {
     cleanBundle(getSrcBundle());
   }
   setDirty(false);
 }
Beispiel #8
0
  private void updateLinuxServiceInstaller() {
    try {
      File dir = new File(directory, "CTP");
      if (suppressFirstPathElement) dir = dir.getParentFile();
      Properties props = new Properties();
      String ctpHome = dir.getAbsolutePath();
      cp.appendln(Color.black, "...CTP_HOME: " + ctpHome);
      ctpHome = ctpHome.replaceAll("\\\\", "\\\\\\\\");
      props.put("CTP_HOME", ctpHome);
      File javaHome = new File(System.getProperty("java.home"));
      String javaBin = (new File(javaHome, "bin")).getAbsolutePath();
      cp.appendln(Color.black, "...JAVA_BIN: " + javaBin);
      javaBin = javaBin.replaceAll("\\\\", "\\\\\\\\");
      props.put("JAVA_BIN", javaBin);

      File linux = new File(dir, "linux");
      File install = new File(linux, "ctpService-ubuntu.sh");
      cp.appendln(Color.black, "Linux service installer:");
      cp.appendln(Color.black, "...file: " + install.getAbsolutePath());
      String bat = getFileText(install);
      bat = replace(bat, props); // do the substitutions
      bat = bat.replace("\r", "");
      setFileText(install, bat);

      // If this is an ISN installation, put the script in the correct place.
      String osName = System.getProperty("os.name").toLowerCase();
      if (programName.equals("ISN") && !osName.contains("windows")) {
        install = new File(linux, "ctpService-red.sh");
        cp.appendln(Color.black, "ISN service installer:");
        cp.appendln(Color.black, "...file: " + install.getAbsolutePath());
        bat = getFileText(install);
        bat = replace(bat, props); // do the substitutions
        bat = bat.replace("\r", "");
        File initDir = new File("/etc/init.d");
        File initFile = new File(initDir, "ctpService");
        if (initDir.exists()) {
          setOwnership(initDir, "edge", "edge");
          setFileText(initFile, bat);
          initFile.setReadable(true, false); // everybody can read //Java 1.6
          initFile.setWritable(true); // only the owner can write //Java 1.6
          initFile.setExecutable(true, false); // everybody can execute //Java 1.6
        }
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      System.err.println("Unable to update the Linux service ctpService.sh file");
    }
  }
  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());
    }
  }
Beispiel #10
0
 public void secureDelete() {
   int rw = tblItems.getSelectedRow();
   if (rw == -1) {
     JOptionPane.showMessageDialog(frm, "No item selected", "Error", JOptionPane.ERROR_MESSAGE);
     return;
   }
   int idx = tblItems.convertRowIndexToModel(rw);
   if (JOptionPane.showConfirmDialog(
           frm,
           "Delete " + store.plainName(idx) + "?",
           "Confirm Delete",
           JOptionPane.YES_NO_OPTION)
       != JOptionPane.YES_OPTION) return;
   File del = store.delete(idx);
   store.fireTableDataChanged();
   if (del != null) {
     if (del.delete()) {
       // successful
       needsSave = true;
     } else {
       System.err.println("Delete " + del.getAbsolutePath() + " failed");
     }
   }
   updateStatus();
 }
Beispiel #11
0
 public void totalExport() {
   File expf = new File("export");
   if (expf.exists()) rmrf(expf);
   expf.mkdirs();
   for (int sto = 0; sto < storeLocs.size(); sto++) {
     try {
       String sl =
           storeLocs.get(sto).getAbsolutePath().replaceAll("/", "-").replaceAll("\\\\", "-");
       File estore = new File(expf, sl);
       estore.mkdir();
       File log = new File(estore, LIBRARY_NAME);
       PrintWriter pw = new PrintWriter(log);
       for (int i = 0; i < store.getRowCount(); i++)
         if (store.curStore(i) == sto) {
           File enc = store.locate(i);
           File dec = sec.prepareMainFile(enc, estore, false);
           pw.println(dec.getName());
           pw.println(store.getValueAt(i, Storage.COL_DATE));
           pw.println(store.getValueAt(i, Storage.COL_TAGS));
           synchronized (jobs) {
             jobs.addLast(expJob(enc, dec));
           }
         }
       pw.close();
     } catch (IOException exc) {
       exc.printStackTrace();
       JOptionPane.showMessageDialog(frm, "Exporting Failed");
       return;
     }
   }
   JOptionPane.showMessageDialog(frm, "Exporting to:\n   " + expf.getAbsolutePath());
 }
  private boolean _assignValues(File fle) {
    String strMethod = "_assignValues(fle)";

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

    // --
    // allow overwriting
    // --

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

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

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

    super._btnClearSelection_.setEnabled(true);

    // --
    // ending
    return true;
  }
Beispiel #13
0
 public void save(String s, File f) {
   try {
     int saveNumber = 1;
     File file = new File(f.getAbsolutePath() + "/save.adv");
     while (file.exists()) {
       file = new File(f.getAbsolutePath() + "/save" + saveNumber + ".adv");
       saveNumber++;
     }
     file.createNewFile();
     FileWriter fWriter = new FileWriter(file.getAbsoluteFile());
     BufferedWriter bWriter = new BufferedWriter(fWriter);
     bWriter.write(s);
     bWriter.close();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Beispiel #14
0
 public String getSrcBundle() {
   if (_srcBundlePath == null) {
     File tmp = FileManager.createTempDir();
     setSrcBundle(FileManager.slashify(tmp.getAbsolutePath(), true));
     _srcBundleTemp = true;
   }
   return _srcBundlePath;
 }
Beispiel #15
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");
 }
Beispiel #16
0
  public String exportAsZip() throws IOException, FileNotFoundException {
    File file = new SikuliIDEFileChooser(SikuliIDE.getInstance()).export();
    if (file == null) {
      return null;
    }

    String zipPath = file.getAbsolutePath();
    String srcName = file.getName();
    if (!file.getAbsolutePath().endsWith(".skl")) {
      zipPath += ".skl";
    } else {
      srcName = srcName.substring(0, srcName.lastIndexOf('.'));
    }
    writeFile(getSrcBundle() + srcName + ".py");
    FileManager.zip(getSrcBundle(), zipPath);
    Debug.log(2, "export to executable file: " + zipPath);
    return zipPath;
  }
Beispiel #17
0
 public boolean edtImport(File fi, String date, String tags) {
   if (!fi.exists()) {
     System.err.println("import: file " + fi.getAbsolutePath() + " doesnt exist");
     return false;
   }
   String pname = fi.getName();
   if (store.containsEntry(pname)) {
     System.err.println("import: already have a file named " + pname);
     return false;
   }
   long size = fi.length() / KILOBYTE;
   File save = sec.encryptMainFile(fi, storeLocs.get(0), true);
   if (save == null) {
     System.err.println("import: Encryption failure");
     return false;
   }
   if (checkImports) {
     boolean success = true;
     File checkfi = new File(idx + ".check");
     File checkOut = sec.encryptSpecialFile(save, checkfi, false);
     if (checkOut == null) success = false;
     else {
       String fiHash = sec.digest(fi);
       String outHash = sec.digest(checkOut);
       if (fiHash == null || outHash == null || fiHash.length() < 1 || !fiHash.equals(outHash))
         success = false;
     }
     checkfi.delete();
     if (!success) {
       save.delete();
       if (JOptionPane.showConfirmDialog(
               frm,
               "Confirming "
                   + fi.getName()
                   + "failed\n\n - Would you like to re-import the file?",
               "Import failed",
               JOptionPane.YES_NO_OPTION)
           == JOptionPane.YES_OPTION) {
         String j = impJob(fi, date, tags);
         synchronized (jobs) {
           if (priorityExport) jobs.addLast(j);
           else jobs.addFirst(j);
         }
       }
       return false;
     }
   }
   if (!fi.delete()) {
     System.err.println("import: Couldnt delete old file - continuing");
   }
   store.add(save.getName(), pname, date, size, tags, 0);
   needsSave = true;
   return true;
 }
 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);
       }
     }
   }
 }
Beispiel #19
0
  private void saveDataToFile(File file) {
    try {
      PrintStream out = new PrintStream(new FileOutputStream(file));

      // Print header line
      out.print("Time");
      for (Sequence seq : seqs) {
        out.print("," + seq.name);
      }
      out.println();

      // Print data lines
      if (seqs.size() > 0 && seqs.get(0).size > 0) {
        for (int i = 0; i < seqs.get(0).size; i++) {
          double excelTime = toExcelTime(times.time(i));
          out.print(String.format(Locale.ENGLISH, "%.6f", excelTime));
          for (Sequence seq : seqs) {
            out.print("," + getFormattedValue(seq.value(i), false));
          }
          out.println();
        }
      }

      out.close();
      JOptionPane.showMessageDialog(
          this,
          Resources.format(
              Messages.FILE_CHOOSER_SAVED_FILE, file.getAbsolutePath(), file.length()));
    } catch (IOException ex) {
      String msg = ex.getLocalizedMessage();
      String path = file.getAbsolutePath();
      if (msg.startsWith(path)) {
        msg = msg.substring(path.length()).trim();
      }
      JOptionPane.showMessageDialog(
          this,
          Resources.format(Messages.FILE_CHOOSER_SAVE_FAILED_MESSAGE, path, msg),
          Messages.FILE_CHOOSER_SAVE_FAILED_TITLE,
          JOptionPane.ERROR_MESSAGE);
    }
  }
    @Override
    public void actionPerformed(ActionEvent e) {
      if (fc == null) {
        fc = new IDEFileChooser();
        fc.setFileView(new IDEFileView());
        fc.setAcceptAllFileFilterUsed(false);
        fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fc.setMultiSelectionEnabled(false);
        fc.setDialogTitle(
            messagesBundle.getString("ImageViewerPanelSaveAction.Choose_filename_to_save_4"));

        //$NON-NLS-1$

        // prepare file filters
        IIORegistry theRegistry = IIORegistry.getDefaultInstance();
        Iterator it = theRegistry.getServiceProviders(ImageWriterSpi.class, false);
        while (it.hasNext()) {
          ImageWriterSpi writer = (ImageWriterSpi) it.next();
          if ((imageType == BufferedImage.TYPE_INT_ARGB
                  || imageType == BufferedImage.TYPE_INT_ARGB_PRE)
              && "JPEG".equals(writer.getFormatNames()[0].toUpperCase())) continue;
          ImageWriterSpiFileFilter ff = new ImageWriterSpiFileFilter(writer);
          fc.addChoosableFileFilter(ff);
        }
      }

      if (fc.showSaveDialog(viewerPanel) == JFileChooser.APPROVE_OPTION) {
        File selectedFile = fc.getSelectedFile();

        if (selectedFile != null) {
          String fileName = selectedFile.getAbsolutePath();
          ImageWriterSpiFileFilter ff = (ImageWriterSpiFileFilter) fc.getFileFilter();
          if (!ff.hasCorrectSuffix(fileName)) fileName = ff.addSuffix(fileName);
          selectedFile = new File(fileName);
          if (selectedFile.exists()) {
            String message =
                MessageFormat.format(
                    messagesBundle.getString("ImageViewerPanelSaveAction.Overwrite_question_5"),
                    //$NON-NLS-1$
                    fileName);
            if (JOptionPane.NO_OPTION
                == JOptionPane.showConfirmDialog(
                    viewerPanel,
                    message,
                    messagesBundle.getString("ImageViewerPanelSaveAction.Warning_6"),
                    //$NON-NLS-1$
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.WARNING_MESSAGE)) return;
          }
          writeToFile(selectedFile, ff);
        }
      }
    }
Beispiel #21
0
  /*
   * This function just finds and loads the file
   */
  private boolean loadFile() {
    JFileChooser fc = new JFileChooser();
    fc.setDialogTitle("Load File");

    // Choose only files, not directories
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);

    // Start in current directory
    fc.setCurrentDirectory(new File("."));

    // Set filter for Java source files.
    fc.setFileFilter(fJavaFilter);

    // Now open chooser
    int result = fc.showOpenDialog(this);

    if (result == JFileChooser.CANCEL_OPTION) {
      // return true;
    } else if (result == JFileChooser.APPROVE_OPTION) {

      fFile = fc.getSelectedFile();
      String textFile = fFile.toString();

      if (fileNo.equalsIgnoreCase("LOAD1")) {
        UpLoadFile.filePath1.setText(textFile);
      } else if (fileNo.equalsIgnoreCase("LOAD2")) {
        UpLoadFile.filePath2.setText(textFile);
      } else if (fileNo.equalsIgnoreCase("LOAD3")) {
        VisualizationInput.originalFilePath.setText(textFile);
      } else if (fileNo.equalsIgnoreCase("LOAD4")) {
        VisualizationInput.DWDVecFilePath.setText(textFile);
      } else if (fileNo.equalsIgnoreCase("LOAD5")) {
        VisualizationInput.DWDOutputFilePath.setText(textFile);
      } else if (fileNo.equalsIgnoreCase("LOAD6")) {
        UpLoadMAGEMLFile.filePath1.setText(textFile);
      } else if (fileNo.equalsIgnoreCase("LOAD7")) {
        UpLoadMAGEMLFile.filePath2.setText(textFile);
      }

      // Get the absolute path for the file being opened
      filePath = fFile.getAbsolutePath();

      if (filePath == null) {
        // fTextField.setText (filePath);
        return false;
      }

    } else {
      return false;
    }
    return true;
  } /*End of loadFile*/
Beispiel #22
0
  /** Runs a Solaris installer */
  public static boolean runSolarisInstaller(String installPath, File installFile) {

    /** Build temp. script file */
    File script = null;
    boolean success = false;
    try {
      script = SolarisInstaller.createTempShellScript();

      String[] args = new String[3];
      args[0] = installPath;
      args[1] = script.getAbsolutePath();
      args[2] = installFile.getAbsolutePath();
      String execString = getExecuteString(args);
      success = SolarisInstaller.execute(execString);
    } catch (IOException ioe) {
      Config.trace("Got ioe: " + ioe);
      return false;
    } finally {
      if (script != null) script.delete();
    }
    return success;
  }
 // #718
 // http://code.google.com/p/processing/issues/detail?id=718
 private String[] listFiles(File folder, boolean relative, String extension) {
   String path = folder.getAbsolutePath();
   Vector<String> vector = new Vector<String>();
   if (extension != null) {
     if (!extension.startsWith(".")) {
       extension = "." + extension;
     }
   }
   listFiles(relative ? (path + File.separator) : "", path, extension, vector);
   String outgoing[] = new String[vector.size()];
   vector.copyInto(outgoing);
   return outgoing;
 }
Beispiel #24
0
 public File reparseBefore() {
   Element e = this.getDocument().getDefaultRootElement();
   if (e.getEndOffset() - e.getStartOffset() == 1) {
     return null;
   }
   File temp = FileManager.createTempFile("reparse");
   try {
     writeFile(temp.getAbsolutePath());
     return temp;
   } catch (IOException ex) {
   }
   return null;
 }
Beispiel #25
0
 public File getCurrentFile(boolean shouldSave) {
   if (shouldSave && _editingFile == null && isDirty()) {
     try {
       saveAsFile(Settings.isMac());
     } catch (IOException e) {
       Debug.error(
           me + "getCurrentFile: Problem while trying to save %s\n%s",
           _editingFile.getAbsolutePath(),
           e.getMessage());
     }
   }
   return _editingFile;
 }
  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();
    }
  }
Beispiel #27
0
  private void updateWindowsServiceInstaller() {
    try {
      File dir = new File(directory, "CTP");
      if (suppressFirstPathElement) dir = dir.getParentFile();
      File windows = new File(dir, "windows");
      File install = new File(windows, "install.bat");
      cp.appendln(Color.black, "Windows service installer:");
      cp.appendln(Color.black, "...file: " + install.getAbsolutePath());
      String bat = getFileText(install);
      Properties props = new Properties();
      String home = dir.getAbsolutePath();
      cp.appendln(Color.black, "...home: " + home);
      home = home.replaceAll("\\\\", "\\\\\\\\");
      props.put("home", home);

      bat = replace(bat, props);
      setFileText(install, bat);
    } catch (Exception ex) {
      ex.printStackTrace();
      System.err.println("Unable to update the windows service install.barfile.");
    }
  }
  private void chooseFileFor(JButton chooserBtn) {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.showDialog(this, "Choose a file");
    File file = fileChooser.getSelectedFile();

    if (chooserBtn == btnInput) {
      inputFile = file;
    } else {
      outputFile = file;
    }
    if (file != null) {
      chooserBtn.setText(file.getAbsolutePath());
    }
  }
Beispiel #29
0
    // Writes the program to a source file, compiles it, and runs it.
    private void compileAndRun(String fileName, String code) {
      // Exceptions here can pick and choose what font to use, as needed.
      // Exceptions thrown by the program, that cause the Playground to be unstable, should be in
      // blue.

      println("Deleting old temp files...", progErr);
      new File(fileName + ".java").delete();
      new File(fileName + ".class").delete();

      println("Creating source file...", progErr);
      file = new File(fileName + ".java");

      println("Writing code to source file...", progErr);
      try {
        new FileWriter(file).append(code).close();
      } catch (IOException i) {
        println("Had an IO Exception when trying to write the code. Stack trace:", error);
        i.printStackTrace();
        return; // Exit on error
      }

      println("Compiling code...", progErr);
      // This should only ever be called if the JDK isn't installed. How you'd get here, I don't
      // know.
      if (compiler == null) {
        println("Fatal Error: JDK not installed. Go to java.sun.com and install.", error);
        return;
      }

      // Tries to compile. Success code is 0, so if something goes wrong, do stuff.
      int result =
          compiler.run(
              null,
              null,
              null,
              file
                  .getAbsolutePath()); // Possibly add a new outputstream to parse through the
                                       // compiler errors
      if (result != 0) {
        displayLog();
        println("Failed to compile.", error);
        return; // Return on error
      }

      println("Code compiled with 0 errors.", progErr);

      println("Attempting to run code...", progErr);
      run(fileName);
    }
Beispiel #30
0
 void getTable() {
   if (chooser == null) {
     File userdir = new File(System.getProperty("user.dir"));
     chooser = new JFileChooser(userdir);
   }
   if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
     file = chooser.getSelectedFile();
     fileLength = file.length();
     setTitle(windowTitle + ": " + file.getAbsolutePath());
     int size = Key.getEncryptionKeySize(this, true);
     key = Key.getEncryptionKey(this, true, size);
     if (key == null) key = defaultKey;
     initCipher();
   } else System.exit(0);
 }