Пример #1
0
 void doExitCommand() {
   File fp = new File(dataFile);
   boolean delete = fp.delete();
   pid.destroy();
   doResetCommand();
   setVisible(false);
 }
  protected void _showDialog_() {
    String strMethod = "_showDialog_()";

    String[] strsTypeFileShkCur = _getTypeFileShkCur();

    if (strsTypeFileShkCur == null)
      MySystem.s_printOutExit(this, strMethod, "nil strsTypeFileShkCur");

    String strFileDesc = _getDescFileShkCur();

    if (strFileDesc == null) MySystem.s_printOutExit(this, strMethod, "nil strFileDesc");

    // ----

    File fle = null;

    String strButtonTextOk = "Save file";

    fle =
        S_FileChooserUI.s_getSaveFile(
            super._frmParent_,
            strButtonTextOk,
            strsTypeFileShkCur,
            strFileDesc,
            com.google.code.p.keytooliui.ktl.io.S_FileExtensionUI.f_s_strDirNameDefaultShk);

    if (fle == null) {
      // cancelled
      return;
    }

    if (!_assignValues(fle))
      MySystem.s_printOutExit(this, strMethod, "failed, fle.getName()=" + fle.getName());
  }
Пример #3
0
      public WFile readFile(String strPath) {
        File objFile = new File(strPath);
        HashMap hmConts = new HashMap();
        setHM(strPath, hmConts);

        return new WFile(objFile.lastModified(), hmConts);
      }
Пример #4
0
  public CryoBay reconnectServer(ORB o, ReconnectThread rct) {

    BufferedReader reader;
    File file;
    ORB orb;
    org.omg.CORBA.Object obj;

    orb = o;

    obj = null;
    cryoB = null;

    try {
      // instantiate ModuleAccessor
      file = new File("/vnmr/acqqueue/cryoBay.CORBAref");
      if (file.exists()) {
        reader = new BufferedReader(new FileReader(file));
        obj = orb.string_to_object(reader.readLine());
      }

      if (obj != null) {
        cryoB = CryoBayHelper.narrow(obj);
      }

      if (cryoB != null) {
        if (!(cryoB._non_existent())) {
          // System.out.println("reconnected!!!!");
          rct.reconnected = true;
        }
      }
    } catch (Exception e) {
      // System.out.println("Got error: " + e);
    }
    return cryoB;
  }
 public boolean accept(File pathname) {
   if (pathname.isDirectory()) return true;
   else {
     if (pathname.getName().indexOf(".scl") != -1) return true;
     else return false;
   }
 }
Пример #6
0
  /**
   * A little method that checks the file path to see if it exists, and modifies it with the
   * imageSuffix if it doesn't have one specified by the user. Asks the user if it's OK to overwrite
   * if the file exists.
   *
   * @param filePath absolute file path to check.
   * @param imageSuffix suffix to append to filePath if it doesn't already have one. This word
   *     should not contain a starting '.'.
   * @return null if name is no good, a String to use if good.
   */
  protected String checkFileName(String filePath, String imageSuffix) {

    String fileName = filePath.substring(filePath.lastIndexOf(File.separator));
    String newFilePath;

    if (fileName.indexOf('.') == -1) {
      newFilePath = filePath + "." + imageSuffix;
    } else {
      // else leave it alone, user specified suffix
      newFilePath = filePath;
    }

    File file = new File(newFilePath);
    if (file.exists()) {
      // Check to see if it is alright to overwrite.
      int choice =
          JOptionPane.showConfirmDialog(
              null,
              "The file " + newFilePath + " exists, replace?",
              "Confirm File Replacement",
              JOptionPane.YES_NO_OPTION);
      if (choice != JOptionPane.YES_OPTION) {
        newFilePath = null;
      }
    }

    return newFilePath;
  }
Пример #7
0
 @Override
 public boolean importData(JComponent comp, Transferable t) {
   DataFlavor htmlFlavor = DataFlavor.stringFlavor;
   if (canImport(comp, t.getTransferDataFlavors())) {
     try {
       String transferString = (String) t.getTransferData(htmlFlavor);
       EditorPane targetTextPane = (EditorPane) comp;
       for (Map.Entry<String, String> entry : _copiedImgs.entrySet()) {
         String imgName = entry.getKey();
         String imgPath = entry.getValue();
         File destFile = targetTextPane.copyFileToBundle(imgPath);
         String newName = destFile.getName();
         if (!newName.equals(imgName)) {
           String ptnImgName = "\"" + imgName + "\"";
           newName = "\"" + newName + "\"";
           transferString = transferString.replaceAll(ptnImgName, newName);
           Debug.info(ptnImgName + " exists. Rename it to " + newName);
         }
       }
       targetTextPane.insertString(transferString);
     } catch (Exception e) {
       Debug.error(me + "importData: Problem pasting text\n%s", e.getMessage());
     }
     return true;
   }
   return false;
 }
Пример #8
0
 /**
  * The ActionListener implementation
  *
  * @param event the event.
  */
 public void actionPerformed(ActionEvent event) {
   String searchText = textField.getText().trim();
   if (searchText.equals("") && !saveAs.isSelected() && (fileLength > 10000000)) {
     textPane.setText("Blank search text is not allowed for large IdTables.");
   } else {
     File outputFile = null;
     if (saveAs.isSelected()) {
       outputFile = chooser.getSelectedFile();
       if (outputFile != null) {
         String name = outputFile.getName();
         int k = name.lastIndexOf(".");
         if (k != -1) name = name.substring(0, k);
         name += ".txt";
         File parent = outputFile.getAbsoluteFile().getParentFile();
         outputFile = new File(parent, name);
         chooser.setSelectedFile(outputFile);
       }
       if (chooser.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) System.exit(0);
       outputFile = chooser.getSelectedFile();
     }
     textPane.setText("");
     Searcher searcher = new Searcher(searchText, event.getSource().equals(searchPHI), outputFile);
     searcher.start();
   }
 }
Пример #9
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());
    }
Пример #10
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;
   }
 }
Пример #11
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();
    }
  }
 private void cleanUp(File f) {
   if (!f.delete()) {
     showError("trouble deleting " + f.getName());
   } else {
     // do something here?
   }
 }
Пример #13
0
  private void onTransferFileClicked() {

    if (transferingFile) return;

    int returnVal = fileChooser.showOpenDialog(this);

    if (returnVal == JFileChooser.APPROVE_OPTION) {
      File file = fileChooser.getSelectedFile();

      showInfoMessage("Se selecciono el archivo " + file.getName());

      try {

        lineCount = getFileLineCount(file);

        fileReader = new FileReader(file);

        linesTransfered = 0;
        headerSent = false;
        lineCountSent = false;
        transferingFile = true;

        transmitMessage("$save");

      } catch (IOException e) {
        e.printStackTrace();
      }

    } else {
      showInfoMessage("Se cancelo la transferencia de archivo");
    }
  }
Пример #14
0
 @Override
 public void actionPerformed(ActionEvent e) {
   if (td.getTabCount() > 0) {
     JFileChooser f = new JFileChooser();
     f.setFileFilter(new MyFileFilter());
     int choose = f.showSaveDialog(getContentPane());
     if (choose == JFileChooser.APPROVE_OPTION) {
       BufferedWriter brw = null;
       try {
         File file = f.getSelectedFile();
         brw = new BufferedWriter(new FileWriter(file));
         int i = td.getSelectedIndex();
         TextDocument ta = (TextDocument) td.getComponentAt(i);
         ta.write(brw);
         ta.fileName = file.getName(); // 將檔案名稱更新為存檔的名稱
         td.setTitleAt(td.getSelectedIndex(), ta.fileName);
         ta.file = file;
         ta.save = true; // 設定已儲存
         System.out.println("Save as pass!");
         td.setTitleAt(i, ta.fileName); // 更新標題名稱
       } catch (Exception exc) {
         exc.printStackTrace();
       } finally {
         try {
           brw.close();
         } catch (Exception ecx) {
           ecx.printStackTrace();
         }
       }
     }
   } else {
     JOptionPane.showMessageDialog(null, "沒有檔案可以儲存!");
   }
 }
Пример #15
0
 @Override
 public void actionPerformed(ActionEvent e) {
   JFileChooser f = new JFileChooser();
   f.setFileFilter(new MyFileFilter()); // 設定檔案選擇器
   int choose = f.showOpenDialog(getContentPane()); // 顯示檔案選取
   if (choose == JFileChooser.OPEN_DIALOG) { // 有開啟檔案的話,開始讀檔
     BufferedReader br = null;
     try {
       File file = f.getSelectedFile();
       br = new BufferedReader(new FileReader(file));
       TextDocument ta = new TextDocument(file.getName(), file);
       ta.addKeyListener(new SystemTrackSave());
       ta.read(br, null);
       td.add(ta);
       td.setTitleAt(docCount++, file.getName());
     } catch (Exception exc) {
       exc.printStackTrace();
     } finally {
       try {
         br.close();
       } catch (Exception ecx) {
         ecx.printStackTrace();
       }
     }
   }
 }
Пример #16
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();
 }
Пример #17
0
 private String getCurrentShortFilename() {
   if (_srcBundlePath != null) {
     File f = new File(_srcBundlePath);
     return f.getName();
   }
   return "Untitled";
 }
Пример #18
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());
  }
Пример #19
0
 private void fixConfigSchema() {
   File configFile;
   File ctpDir = new File(directory, "CTP");
   if (ctpDir.exists()) configFile = new File(ctpDir, "config.xml");
   else configFile = new File(directory, "config.xml");
   if (configFile.exists()) {
     try {
       Document doc = getDocument(configFile);
       Element root = doc.getDocumentElement();
       Element server = getFirstNamedChild(root, "Server");
       moveAttributes(server, sslAttrs, "SSL");
       moveAttributes(server, proxyAttrs, "ProxyServer");
       moveAttributes(server, ldapAttrs, "LDAP");
       if (programName.equals("ISN")) fixRSNAROOT(server);
       if (isMIRC(root)) fixFileServiceAnonymizerID(root);
       setFileText(configFile, toString(doc));
     } catch (Exception ex) {
       cp.appendln(Color.red, "\nUnable to convert the config file schema.");
       cp.appendln(Color.black, "");
     }
   } else {
     cp.appendln(Color.red, "\nUnable to find the config file to check the schema.");
     cp.appendln(Color.black, "");
   }
 }
Пример #20
0
    protected void setData(String strChecksum) {
      String strValue = (String) m_cmbPath.getSelectedItem();
      if (strValue == null || strValue.equals("")) return;

      m_cmbChecksum.removeAllItems();

      String strPath = strValue.substring(strValue.lastIndexOf("/") + 1);
      strPath = UtilB.unixPathToWindows(FileUtil.SYS_VNMR + "/p11/checksums/" + strPath);
      strPath = FileUtil.openPath(strPath);
      if (strPath != null) {
        File file = new File(strPath);
        String[] files = file.list();
        int nSize = files.length;
        for (int i = 0; i < nSize; i++) {
          String strfile = files[i];
          m_cmbChecksum.addItem(strfile);
        }

        int nIndex = strChecksum.lastIndexOf("/");
        if (nIndex < 0) nIndex = strChecksum.lastIndexOf(File.separator);
        if (nIndex + 1 < strChecksum.length()) strChecksum = strChecksum.substring(nIndex + 1);

        m_cmbChecksum.setSelectedItem(strChecksum);
      }
    }
Пример #21
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);
      }
    }
  public void actionPerformed(ActionEvent e) {

    // Handle open button action.
    if (e.getSource() == openButton) {
      int returnVal = fc.showOpenDialog(FileChooserDemo.this);

      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        // This is where a real application would open the file.
        log.append("Opening: " + file.getName() + "." + newline);
      } else {
        log.append("Open command cancelled by user." + newline);
      }
      log.setCaretPosition(log.getDocument().getLength());

      // Handle save button action.
    } else if (e.getSource() == saveButton) {
      int returnVal = fc.showSaveDialog(FileChooserDemo.this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        // This is where a real application would save the file.
        log.append("Saving: " + file.getName() + "." + newline);
      } else {
        log.append("Save command cancelled by user." + newline);
      }
      log.setCaretPosition(log.getDocument().getLength());
    }
  }
Пример #23
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();
 }
Пример #24
0
  private void ListSubDirectorySizes(File file) {
    File[] files;
    files =
        file.listFiles(
            new FileFilter() {
              @Override
              public boolean accept(File file) {
                //                if (!file.isDirectory()){
                //                    return false;  //To change body of implemented methods use
                // File | Settings | File Templates.
                //                }else{
                //                    return true;
                //                }
                return true;
              }
            });
    Map<String, Long> dirListing = new HashMap<String, Long>();
    for (File dir : files) {
      DiskUsage diskUsage = new DiskUsage();
      diskUsage.accept(dir);
      //            long size = diskUsage.getSize() / (1024 * 1024);
      long size = diskUsage.getSize();
      dirListing.put(dir.getName(), size);
    }

    ValueComparator bvc = new ValueComparator(dirListing);
    TreeMap<String, Long> sorted_map = new TreeMap<String, Long>(bvc);
    sorted_map.putAll(dirListing);

    PrettyPrint(file, sorted_map);
  }
Пример #25
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;
 }
Пример #26
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();
    }
  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;
  }
Пример #28
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);
   }
 }
Пример #29
0
 public String getSrcBundle() {
   if (_srcBundlePath == null) {
     File tmp = FileManager.createTempDir();
     setSrcBundle(FileManager.slashify(tmp.getAbsolutePath(), true));
     _srcBundleTemp = true;
   }
   return _srcBundlePath;
 }
Пример #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();
    }
  }