コード例 #1
0
  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());
    }
  }
コード例 #2
0
ファイル: Ssys3.java プロジェクト: scyptnex/computing
 /**
  * public char[] jetPass(){ JPasswordField psf = new JPasswordField(); psf.grabFocus(); int opt =
  * JOptionPane.showConfirmDialog(frm, psf, "Password", JOptionPane.PLAIN_MESSAGE); if(opt ==
  * JOptionPane.OK_OPTION) return psf.getPassword(); return null; }
  *
  * <p>public String jetString(String msg, String ttl){ return JOptionPane.showInputDialog(frm,
  * msg, ttl, JOptionPane.QUESTION_MESSAGE); }*
  */
 public static String jobString(String job) {
   if (job.charAt(0) == IMPORT_FLAG) {
     String[] brk = job.split(",", 4); // 4 parts to an import string
     File inf = new File(brk[1]);
     return "import " + inf.getName();
   } else {
     String[] brk = job.split(",", 3); // 3 parts to export string
     File plf = new File(brk[2]);
     return "export " + plf.getName();
   }
 }
コード例 #3
0
ファイル: Ssys3.java プロジェクト: scyptnex/computing
 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;
 }
コード例 #4
0
ファイル: GalaxyViewer.java プロジェクト: runholen/stars
  public GalaxyViewer(Settings settings, boolean animatorFrame) throws Exception {
    super("Stars GalaxyViewer");
    this.settings = settings;
    this.animatorFrame = animatorFrame;
    if (settings.gameName.equals("")) throw new Exception("GameName not defined in settings.");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    File dir = new File(settings.directory);
    File map = new File(dir, settings.getGameName() + ".MAP");
    if (map.exists() == false) {
      File f = new File(dir.getParentFile(), settings.getGameName() + ".MAP");
      if (f.exists()) map = f;
      else {
        String error = "Could not find " + map.getAbsolutePath() + "\n";
        error += "Export this file from Stars! (Only needs to be done one time pr game)";
        throw new Exception(error);
      }
    }
    Vector<File> mFiles = new Vector<File>();
    Vector<File> hFiles = new Vector<File>();
    for (File f : dir.listFiles()) {
      if (f.getName().toUpperCase().endsWith("MAP")) continue;
      if (f.getName().toUpperCase().endsWith("HST")) continue;
      if (f.getName().toUpperCase().startsWith(settings.getGameName() + ".M")) mFiles.addElement(f);
      else if (f.getName().toUpperCase().startsWith(settings.getGameName() + ".H"))
        hFiles.addElement(f);
    }
    if (mFiles.size() == 0) throw new Exception("No M-files found matching game name.");
    if (hFiles.size() == 0) throw new Exception("No H-files found matching game name.");
    parseMapFile(map);
    Vector<File> files = new Vector<File>();
    files.addAll(mFiles);
    files.addAll(hFiles);
    p = new Parser(files);
    calculateColors();

    // UI:
    JPanel cp = (JPanel) getContentPane();
    cp.setLayout(new BorderLayout());
    cp.add(universe, BorderLayout.CENTER);
    JPanel south = createPanel(0, hw, new JLabel("Search: "), search, names, zoom, colorize);
    search.setPreferredSize(new Dimension(100, -1));
    cp.add(south, BorderLayout.SOUTH);
    hw.addActionListener(this);
    names.addActionListener(this);
    zoom.addChangeListener(this);
    search.addKeyListener(this);
    colorize.addActionListener(this);
    setSize(800, 600);
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    setLocation((screen.width - getWidth()) / 2, (screen.height - getHeight()) / 2);
    setVisible(animatorFrame == false);
    if (animatorFrame) names.setSelected(false);
  }
コード例 #5
0
ファイル: TabView.java プロジェクト: linvald/JarFileAnalyser
  /* (non-Javadoc)
   * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
   */
  public void actionPerformed(ActionEvent e) {
    Object o = e.getSource();
    if (o instanceof JMenuItem) {
      JMenuItem sender = (JMenuItem) o;
      String name = sender.getText();
      if (name.equals("close")) {
        tabbedPane.removeTabAt(tabbedPane.getSelectedIndex());
      } else if (name.equals("save")) {
        int index = tabbedPane.getSelectedIndex();
        Component c = tabbedPane.getComponent(index);
        Point p = c.getLocation();
        Component t = tabbedPane.getComponentAt(new Point(p.x + 20, p.y + 30));
        if (t instanceof TextView) {
          TextView text = (TextView) t;
          // String code = text.getText();
          // save the code
          // saveTab(code);
        }
        if (t instanceof HTMLTextView) {
          HTMLTextView text = (HTMLTextView) t;
          fileChooser.setSelectedFile(new File(text.node.getName()));
          int returnVal = fileChooser.showSaveDialog(this);

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

            // save the code
            String fileType =
                f.getName().substring(f.getName().lastIndexOf("."), f.getName().length());
            if (fileType.indexOf("htm") != -1) {
              // save as html
              String code = text.getText();
              saveTab(code, f);
            } else if (fileType.indexOf("java") != -1) {
              // save as java
              String code = text.getUnModyfiedContent();
              saveTab(code, f);
            } else if (text.node.fileType.indexOf(FileTypes.MANIFEST) != -1
                || text.node.fileType.indexOf(FileTypes.MANIFEST2) != -1) {
              String code = text.getUnModyfiedContent();
              saveTab(code, f);
              System.out.println("Saved manifest");
            } else {
              System.out.println("FILETYPE UNKNOWN:" + text.node.fileType);
            }
          }
        }
      } else if (name.equals("close all")) {
        tabbedPane.removeAll();
      }
    }
  }
コード例 #6
0
  private void load(File file) throws Exception {
    if (file.getName().toLowerCase().endsWith(".svg")) {
      SketchDocument doc = importSVG(file);
      if (doc.isPresentation()) {
        context.getMain().setupNewDoc(new PresoModeHelper(context.getMain()), doc);
      } else {
        context.getMain().setupNewDoc(new VectorModeHelper(context.getMain()), doc);
      }
      return;
    }

    StandardDialog.showError(
        "Could not open file " + file.getName() + ".\nUnknown format. Sorry. :(");
  }
コード例 #7
0
ファイル: FileWindow.java プロジェクト: paomoca/SO-2015
    public void actionPerformed(ActionEvent ae) {

      if (ae.getActionCommand().equals("clear")) {
        scriptArea.setText("");
      } else if (ae.getActionCommand().equals("save")) {
        // fc.setCurrentDirectory(new File("/Users/jc/Documents/LOGO"));
        int bandera = fileChooser.showSaveDialog(myWindow);
        if (bandera == JFileChooser.APPROVE_OPTION) {
          String cadena1 = scriptArea.getText();
          String cadena2 = cadena1.replace("\r", "\n");
          System.out.println(cadena1);
          try {
            BufferedWriter script =
                new BufferedWriter(new FileWriter(fileChooser.getSelectedFile() + ".txt"));
            script.write(cadena2);
            script.close();
          } catch (Exception ex) {
            ex.printStackTrace();
          }
          File file = fileChooser.getSelectedFile();
          JOptionPane.showMessageDialog(myWindow, "File: " + file.getName() + " Saved.\n");
        }
        scriptArea.setCaretPosition(scriptArea.getDocument().getLength());
      } else if (ae.getActionCommand().equals("quit")) {
        myWindow.setVisible(false);
      } else if (ae.getActionCommand().equals("load")) {
        // String arreglo[] = new String[100];
        // int i = 0;
        // fc.setCurrentDirectory(new File("/Users/jc/Documents/LOGO"));
        int bandera = fileChooser.showOpenDialog(myWindow);
        if (bandera == JFileChooser.APPROVE_OPTION) {
          try {
            BufferedReader script =
                new BufferedReader(new FileReader(fileChooser.getSelectedFile()));
            scriptArea.read(script, null);
            script.close();
            scriptArea.requestFocus();
          } catch (Exception ex) {
            ex.printStackTrace();
          }
          File file = fileChooser.getSelectedFile();
          myWindow.setTitle(file.getName());
          JOptionPane.showMessageDialog(myWindow, file.getName() + ": File loaded.\n");
          scriptArea.setCaretPosition(scriptArea.getDocument().getLength());
        }
      } else if (ae.getActionCommand().equals("run")) {
        System.out.println("LEL");
      }
    }
コード例 #8
0
 public boolean accept(File pathname) {
   if (pathname.isDirectory()) return true;
   else {
     if (pathname.getName().indexOf(".scl") != -1) return true;
     else return false;
   }
 }
コード例 #9
0
 private String getCurrentShortFilename() {
   if (_srcBundlePath != null) {
     File f = new File(_srcBundlePath);
     return f.getName();
   }
   return "Untitled";
 }
コード例 #10
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;
 }
コード例 #11
0
  @SuppressWarnings({"HardCodedStringLiteral"})
  @Nullable
  public static String getPropertyFromLaxFile(
      @NotNull final File file, @NotNull final String propertyName) {
    if (file.getName().endsWith(".properties")) {
      try {
        PropertyResourceBundle bundle;
        InputStream fis = new BufferedInputStream(new FileInputStream(file));
        try {
          bundle = new PropertyResourceBundle(fis);
        } finally {
          fis.close();
        }
        if (bundle.containsKey(propertyName)) {
          return bundle.getString(propertyName);
        }
        return null;
      } catch (IOException e) {
        return null;
      }
    }

    final String fileContent = getContent(file);

    // try to find custom config path
    final String propertyValue = findProperty(propertyName, fileContent);
    if (!StringUtil.isEmpty(propertyValue)) {
      return propertyValue;
    }

    return null;
  }
コード例 #12
0
ファイル: Controller.java プロジェクト: andrnil/marenor
 public int showConfirmFileOverwriteDialog(File outFile) {
   return JOptionPane.showConfirmDialog(
       this.getFrame(),
       "Replace existing file\n" + outFile.getName() + "?",
       "Overwrite Existing File?",
       JOptionPane.YES_NO_CANCEL_OPTION);
 }
コード例 #13
0
  /**
   * When the user has to specify file names, he can use wildcards (*, ?). This methods handles the
   * usage of these wildcards.
   *
   * @param path The path were to search
   * @param s Wilcards
   * @param sort Set to true will sort file names
   * @return An array of String which contains all files matching <code>s</code> in current
   *     directory.
   */
  public static String[] getWildCardMatches(String path, String s, boolean sort) {
    if (s == null) return null;

    String files[];
    String filesThatMatch[];
    String args = new String(s.trim());
    ArrayList filesThatMatchVector = new ArrayList();

    if (path == null) path = getUserDirectory();

    files = (new File(path)).list();
    if (files == null) return null;

    for (int i = 0; i < files.length; i++) {
      if (match(args, files[i])) {
        File temp = new File(getUserDirectory(), files[i]);
        filesThatMatchVector.add(new String(temp.getName()));
      }
    }

    Object[] o = filesThatMatchVector.toArray();
    filesThatMatch = new String[o.length];
    for (int i = 0; i < o.length; i++) filesThatMatch[i] = o[i].toString();
    o = null;
    filesThatMatchVector = null;

    if (sort) Arrays.sort(filesThatMatch);

    return filesThatMatch;
  }
コード例 #14
0
ファイル: InterpreterFrame.java プロジェクト: DavePearce/jkit
  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;
  }
コード例 #15
0
 public void actionPerformed(ActionEvent ae) {
   String cmd = ae.getActionCommand();
   if (JOkCancelPanel.OK.equals(cmd)) {
     // update evaluator
     evaluator.name = tfName.getText();
     evaluator.type = (byte) cbType.getSelectedIndex();
     evaluator.ignoreDiagonals = cbDiagonals.isSelected();
     evaluator.investments = (byte) cbInvestment.getSelectedIndex();
     evaluator.orgFile = orgFile;
     setVisible(false);
   } else if (JOkCancelPanel.CANCEL.equals(cmd)) {
     // don't update evaluator
     setVisible(false);
   } else if (CMD_CHOOSE_FILE.equals(cmd)) {
     // get a file dialog
     JFrame f = new JFrame();
     JFileChooser jfc = Application.getFileChooser();
     int res = jfc.showOpenDialog(f);
     Application.setWorkingDirectory(jfc.getCurrentDirectory());
     if (res == JFileChooser.CANCEL_OPTION) {
       return;
     }
     orgFile = jfc.getSelectedFile();
     lOrgFileName.setText("File: " + orgFile.getName());
   }
 }
コード例 #16
0
  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());
  }
コード例 #17
0
ファイル: HomeWindow.java プロジェクト: ivandivito/gepetto
  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");
    }
  }
コード例 #18
0
ファイル: MainFrame.java プロジェクト: gaurav/taxref
  /**
   * 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)");
  }
コード例 #19
0
ファイル: Ssys3.java プロジェクト: scyptnex/computing
 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());
 }
コード例 #20
0
ファイル: Decipher.java プロジェクト: johnperry/MIRC1
 /**
  * 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();
   }
 }
コード例 #21
0
ファイル: DirectorySize.java プロジェクト: snasrallah/Java
  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);
  }
コード例 #22
0
ファイル: Notepad.java プロジェクト: ArcherSys/ArcherSysRuby
    @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);
      }
    }
コード例 #23
0
 public Boolean isHidden(File f) {
   String name = f.getName();
   if (name != null && name.charAt(0) == '.') {
     return Boolean.TRUE;
   } else {
     return Boolean.FALSE;
   }
 }
コード例 #24
0
 public static SketchDocument importSVG(File file) throws Exception {
   SketchDocument sdoc = importSVG(new FileInputStream(file));
   // sdoc.setFile(file);
   sdoc.setTitle(file.getName() + "");
   sdoc.setCurrentPage(0);
   sdoc.setDirty(false);
   return sdoc;
 }
コード例 #25
0
 private String getFileExt(File f) {
   String name = f.getName();
   int pos = name.lastIndexOf('.');
   if (pos > 0) {
     return name.substring(pos);
   }
   return "";
 }
コード例 #26
0
  /**
   * Returns the string, showing information for the given file.
   *
   * @param file the file
   * @return the name of the given file
   */
  protected String getFileLabel(File file) {
    String fileName = file.getName();
    long fileSize = file.length();

    ByteFormat format = new ByteFormat();
    String text = format.format(fileSize);

    return fileName + " (" + text + ")";
  }
コード例 #27
0
 public boolean accept(File f) {
   if (f == null) {
     return false;
   }
   if (f.isDirectory()) {
     return true;
   }
   return pattern.matcher(f.getName()).matches();
 }
コード例 #28
0
ファイル: MOCCOStandalone.java プロジェクト: openea/eva2
 /**
  * This method saves the current MOCOData into a serialized file
  *
  * @param saveAs The name of the outputfile
  */
 public void saveObject(String saveAs) {
   File sFile = new File(saveAs);
   try {
     ObjectOutputStream oo =
         new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(sFile)));
     oo.writeObject(this.state);
     oo.close();
   } catch (Exception ex) {
     if (this.mainFrame != null) {
       JOptionPane.showMessageDialog(
           this.mainFrame,
           "Couldn't write to file: " + sFile.getName() + "\n" + ex.getMessage(),
           "Save object",
           JOptionPane.ERROR_MESSAGE);
     } else {
       System.out.println("Couldn't write to file: " + sFile.getName() + "\n" + ex.getMessage());
     }
   }
 }
コード例 #29
0
ファイル: InterpreterFrame.java プロジェクト: DavePearce/jkit
 private String physReadTextFile(File file) {
   // physically read text file
   try {
     BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
     StringBuffer tmp = new StringBuffer();
     while (input.ready()) {
       tmp.append(input.readLine());
       tmp.append("\n");
     }
     return tmp.toString();
   } catch (FileNotFoundException e) {
     // not sure how this can happen
     showErrorDialog("Unable to load \"" + file.getName() + "\" (file not found)");
   } catch (IOException e) {
     // This happens if e.g. file already exists and
     // we do not have write permissions
     showErrorDialog("Unable to load \"" + file.getName() + "\" (I/O error)");
   }
   return new String("");
 }
コード例 #30
0
ファイル: MainWindow.java プロジェクト: jason17055/tournament
 void refresh() {
   if (currentFile != null) {
     String fileName = currentFile.getName();
     if (fileName.endsWith("." + EXTENSION)) {
       fileName = fileName.substring(0, fileName.length() - 1 - EXTENSION.length());
     }
     setTitle(MessageFormat.format(strings.getString("main.caption_named_file"), fileName));
   } else {
     setTitle(strings.getString("main.caption_unnamed_file"));
   }
 }