コード例 #1
0
 /** Update all the store-able properties to their current values */
 public void updateProperties() {
   // Kept up-to-date with event listeners
   // Manager.actorDetails.visible
   // Manager.groupTable.autoResize
   propertyBag.setProperty(
       "Manager.splitHorizontal.dividerLocation",
       String.valueOf(jSplitPaneHorizontal.getDividerLocation()));
   propertyBag.setProperty(
       "Manager.splitVertical.dividerLocation",
       String.valueOf(jSplitPaneVertical.getDividerLocation()));
   propertyBag.setProperty("Manager.location.x", String.valueOf(getLocation().x));
   propertyBag.setProperty("Manager.location.y", String.valueOf(getLocation().y));
   propertyBag.setProperty("Manager.size.width", String.valueOf(getSize().width));
   propertyBag.setProperty("Manager.size.height", String.valueOf(getSize().height));
   propertyBag.setProperty(
       "Manager.groupFileChooser.defaultLocation",
       groupFileChooser.getCurrentDirectory().getPath());
   propertyBag.setProperty(
       "Manager.gcaFileChooser.defaultLocation", gcaFileChooser.getCurrentDirectory().getPath());
   // Optional properties
   if (saveAsFile != null) {
     propertyBag.setProperty("Manager.currentLoadedFile", saveAsFile.getAbsolutePath());
   } else {
     propertyBag.remove("Manager.currentLoadedFile");
   }
   groupTable.updateProperties(); // Update properties for the table
 }
コード例 #2
0
 @Override
 public void actionPerformed(ActionEvent e) {
   JFileChooser chooser = new JFileChooser();
   if (optionsPane != null) {
     chooser.setCurrentDirectory(new File(Settings.getSettings().getInstallPath()));
     chooser.setDialogTitle(choosertitle);
     chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
     chooser.setAcceptAllFileFilterUsed(false);
     if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
       Logger.logInfo("getCurrentDirectory(): " + chooser.getCurrentDirectory());
       Logger.logInfo("getSelectedFile() : " + chooser.getSelectedFile());
       optionsPane.setInstallFolderText(chooser.getSelectedFile().getPath());
     } else {
       Logger.logWarn("No Selection.");
     }
   } else if (editMPD != null) {
     if (!Settings.getSettings().getLastAddPath().isEmpty()) {
       chooser.setCurrentDirectory(new File(Settings.getSettings().getLastAddPath()));
     }
     chooser.setDialogTitle("Please select the mod to install");
     chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
     chooser.setAcceptAllFileFilterUsed(true);
     if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
       File destination = new File(editMPD.folder, chooser.getSelectedFile().getName());
       if (!destination.exists()) {
         try {
           FileUtils.copyFile(chooser.getSelectedFile(), destination);
           Settings.getSettings().setLastAddPath(chooser.getSelectedFile().getPath());
           LaunchFrame.getInstance().saveSettings();
         } catch (IOException e1) {
           Logger.logError(e1.getMessage());
         }
         editMPD.updateLists();
       } else {
         ErrorUtils.tossError("File already exists, cannot add mod!");
       }
     } else {
       Logger.logWarn("No Selection.");
     }
   } else {
     chooser.setCurrentDirectory(new File(Settings.getSettings().getInstallPath()));
     chooser.setDialogTitle(choosertitle);
     chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
     chooser.setAcceptAllFileFilterUsed(false);
     if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
       Logger.logInfo("getCurrentDirectory(): " + chooser.getCurrentDirectory());
       Logger.logInfo("getSelectedFile() : " + chooser.getSelectedFile());
       installDialog.setInstallFolderText(chooser.getSelectedFile().getPath());
     } else {
       Logger.logWarn("No Selection.");
     }
   }
 }
コード例 #3
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());
   }
 }
コード例 #4
0
  private void findPresentation() {
    JFileChooser fileChooser = new JFileChooser();
    if (lastDirectory_ != null) fileChooser.setCurrentDirectory(lastDirectory_);
    // if (imc.lecturnity.converter.ConverterWizard.USE_CUSTOM_COLORS)
    if (USE_CUSTOM_COLORS) fileChooser.setBackground(Wizard.BG_COLOR);
    LecturnityFileFilter lff = new LecturnityFileFilter();
    fileChooser.addChoosableFileFilter(lff);
    LpdFileFilter lpf = new LpdFileFilter();
    fileChooser.addChoosableFileFilter(lpf);
    EPresentationFileFilter eff = new EPresentationFileFilter();
    fileChooser.addChoosableFileFilter(eff);
    AofFileFilter aff = new AofFileFilter();
    fileChooser.addChoosableFileFilter(aff);
    fileChooser.addChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
    fileChooser.setFileFilter(lff);

    Dimension fcSize = fileChooser.getPreferredSize();
    fileChooser.setPreferredSize(new Dimension(fcSize.width + 100, fcSize.height + 50));

    int action = fileChooser.showOpenDialog(this);

    lastDirectory_ = fileChooser.getCurrentDirectory();

    if (action == fileChooser.APPROVE_OPTION) {
      File selectedFile = fileChooser.getSelectedFile();
      presentationFileField_.setText(selectedFile.getAbsolutePath());
    }
  }
コード例 #5
0
  @SuppressWarnings("null")
  @Test
  public void RememberLastSaveLocationFileChooserIsNull() throws Exception {
    String assertPath = "C:\\";
    Field fileChooser = fileHandler.getClass().getDeclaredField("saveFileChooser");

    fileChooser.setAccessible(true);
    // fileChooser.set(fileHandler, null);

    Constants.last_saved_path = assertPath;
    Main.getInstance().setCurrentDiagramHandler(handler);
    Object obj = null;
    Method[] meths = fileHandler.getClass().getDeclaredMethods();
    for (Method method : meths) {
      if (method.getName().equals("reloadSaveFileChooser")) {
        method.setAccessible(true);
        obj = method.invoke(fileHandler, new Boolean(false));
      }
    }
    Assert.assertNotNull("The FileChooser is null!", obj);
    if (obj != null) {
      JFileChooser jfc = (JFileChooser) obj;
      File file = jfc.getCurrentDirectory();
      Assert.assertEquals("The path is not the last saved path!", assertPath, file.getPath());
    }
  }
コード例 #6
0
ファイル: RateIndicatorBFTab.java プロジェクト: plemey/SPREAD
    public void actionPerformed(ActionEvent ev) {

      try {

        String[] logFiles = new String[] {"log"};

        JFileChooser chooser = new JFileChooser();
        chooser.setDialogTitle("Opening log file...");
        chooser.setMultiSelectionEnabled(false);
        chooser.addChoosableFileFilter(new SimpleFileFilter(logFiles, "Log files (*.log)"));
        chooser.setCurrentDirectory(workingDirectory);

        chooser.showOpenDialog(Utils.getActiveFrame());
        File file = chooser.getSelectedFile();
        logFilename = file.getAbsolutePath();
        System.out.println("Opened " + logFilename + "\n");

        File tmpDir = chooser.getCurrentDirectory();

        if (tmpDir != null) {
          workingDirectory = tmpDir;
        }

      } catch (Exception e) {
        System.err.println("Could not Open! \n");
      }
    }
コード例 #7
0
  @Override
  public void actionPerformed(final ActionEvent e) {

    final Preferences pref = Preferences.userNodeForPackage(RunJavaScriptAction.class);

    JFileChooser chooser = new JFileChooser(pref.get(JAVASCRIPT_DIR, null));

    if (chooser.showOpenDialog(UIApplication.getFrame()) == JFileChooser.APPROVE_OPTION) {
      pref.put(JAVASCRIPT_DIR, chooser.getCurrentDirectory().getAbsolutePath());

      final String file = chooser.getSelectedFile().getAbsolutePath();

      EventQueue.invokeLater(
          new Runnable() {

            @Override
            public void run() {

              try (FileReader reader = new FileReader(file)) {
                new ScriptEngineManager().getEngineByName("JavaScript").eval(reader);
              } catch (IOException | ScriptException e) {
                Logger.getLogger(RunJavaScriptAction.class.getName())
                    .log(Level.SEVERE, e.toString(), e);
              }
            }
          });
    }
  }
コード例 #8
0
  /** Handles the saving of a drawing to a file. */
  private void doSave() {
    JFileChooser chooser = new JFileChooser(getClass().getResource("").getFile());
    chooser.setDialogTitle("Save Graphic");
    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
    FileFilter filter =
        new FileFilter() {
          @Override
          public String getDescription() {
            return "JDraw Graphic (*.draw)";
          }

          @Override
          public boolean accept(File f) {
            return f.getName().endsWith(".draw");
          }
        };
    chooser.setFileFilter(filter);
    int res = chooser.showOpenDialog(this);

    if (res == JFileChooser.APPROVE_OPTION) {
      // save graphic
      File file = chooser.getSelectedFile();
      if (chooser.getFileFilter() == filter && !filter.accept(file)) {
        file = new File(chooser.getCurrentDirectory(), file.getName() + ".draw");
      }
      System.out.println("save current graphic to file " + file.getName());
    }
  }
コード例 #9
0
ファイル: TreePanel.java プロジェクト: whdc/ieo-beast
  public void doImport() {

    try {

      JFileChooser chooser = new JFileChooser();
      chooser.setDialogTitle("Select input tree file...");
      chooser.setMultiSelectionEnabled(false);
      chooser.setCurrentDirectory(frame.getWorkingDirectory());

      int returnValue = chooser.showOpenDialog(Utils.getActiveFrame());

      if (returnValue == JFileChooser.APPROVE_OPTION) {

        File file = chooser.getSelectedFile();

        if (file != null) {

          //					dataList.treeFilesList.add(file);
          treeFileNameText.setText(file.getName());

          importFromFile(file);

          File tmpDir = chooser.getCurrentDirectory();
          if (tmpDir != null) {
            frame.setWorkingDirectory(tmpDir);
          }
        } // END: file opened check
      } // END: dialog cancelled check

    } catch (IOException e) {
      e.printStackTrace();
    } catch (ImportException e) {
      e.printStackTrace();
    } // END: try-catch block
  } // END: doImport
コード例 #10
0
ファイル: JImageEditor.java プロジェクト: ralexsander/nordpos
  public void doLoad() {
    JFileChooser fc = new JFileChooser(m_fCurrentDirectory);

    fc.addChoosableFileFilter(
        new ExtensionsFilter(
            LocalRes.getIntString("label.imagefiles"), "png", "gif", "jpg", "jpeg", "bmp"));

    if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
      try {
        BufferedImage img = ImageIO.read(fc.getSelectedFile());
        if (img != null) {
          // compruebo que no exceda el tamano maximo.
          if (m_maxsize != null
              && (img.getHeight() > m_maxsize.height || img.getWidth() > m_maxsize.width)) {
            if (JOptionPane.showConfirmDialog(
                    this,
                    LocalRes.getIntString("message.resizeimage"),
                    LocalRes.getIntString("title.editor"),
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE)
                == JOptionPane.YES_OPTION) {
              // Redimensionamos la imagen para que se ajuste
              img = resizeImage(img);
            }
          }
          setImage(img);
          m_fCurrentDirectory = fc.getCurrentDirectory();
        }
      } catch (IOException eIO) {
      }
    }
  }
  private void loadFile() {
    JFileChooser fileChooser = new JFileChooser();

    FileNameExtensionFilter filter =
        new FileNameExtensionFilter("HTML Files (*.htm, *.html)", "htm", "html");
    fileChooser.addChoosableFileFilter(filter);
    fileChooser.addChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
    fileChooser.setFileFilter(filter);

    if (internalBalloon.getBalloonContentPath().isSetLastUsedMode()) {
      fileChooser.setCurrentDirectory(
          new File(internalBalloon.getBalloonContentPath().getLastUsedPath()));
    } else {
      fileChooser.setCurrentDirectory(
          new File(internalBalloon.getBalloonContentPath().getStandardPath()));
    }
    int result = fileChooser.showSaveDialog(getTopLevelAncestor());
    if (result == JFileChooser.CANCEL_OPTION) return;
    try {
      String exportString = fileChooser.getSelectedFile().toString();
      browseText.setText(exportString);
      internalBalloon
          .getBalloonContentPath()
          .setLastUsedPath(fileChooser.getCurrentDirectory().getAbsolutePath());
      internalBalloon.getBalloonContentPath().setPathMode(PathMode.LASTUSED);
    } catch (Exception e) {
      //
    }
  }
コード例 #12
0
ファイル: MainWindow.java プロジェクト: Hiperzone/University
  /**
   * Accionado quando se faz clique no botao para extrair um ficheiro.
   *
   * <p>Permite extrair o conteudo de um ficheiro selecionado pelo utilizador. A extracção só será
   * possivel caso o objecto selecionado seja um ficheiro.
   *
   * <p>É lançado uma excepção caso a extracção falhe.
   *
   * @param evt
   */
  private void jMenuItem6ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jMenuItem6ActionPerformed
    try {
      // verificar a seleccão
      int row = jTable1.getSelectedRow();
      Object obj = jTable1.getModel().getValueAt(row, 0);
      if (obj instanceof RFPFileHeader) {
        final JFileChooser fc = new JFileChooser();
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int returnVal = fc.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
          File dir = fc.getCurrentDirectory();
          File dest = fc.getSelectedFile();

          if ((int) (((RFPFileHeader) obj).getFlags() & RFPBinaryFile.RFP_COMPRESSED)
              == RFPBinaryFile.RFP_COMPRESSED) {
            rfpFile.decompressFile(((RFPFileHeader) obj).getFilenameId(), dest.getPath());

          } else {
            rfpFile.extractFile(((RFPFileHeader) obj).getFilenameId(), dest.getPath());
          }
        }
      } else {
        JOptionPane.showMessageDialog(
            null,
            "Impossivel extrair ficheiro.",
            "Extração de Ficheiro",
            JOptionPane.ERROR_MESSAGE);
      }
    } catch (Exception ex) {
      JOptionPane.showMessageDialog(
          null, "Impossivel extrair ficheiro.", "Extração de Ficheiro", JOptionPane.ERROR_MESSAGE);
    }
  } // GEN-LAST:event_jMenuItem6ActionPerformed
コード例 #13
0
ファイル: MainWindow.java プロジェクト: Hiperzone/University
  /**
   * Accionado quando se faz clique no botao para extrair uma directoria do ficheiro RFP.
   *
   * <p>Permite extrair uma directoria do ficheiro RFP na pasta de destino escolhida pelo
   * utilizador.
   *
   * <p>Se o objecto selecionado for uma directoria, irá então ser extraido o conteúdo dessa mesma
   * directoria.
   *
   * <p>É lançado uma excepção caso seja impossivel extrair os conteúdos da directoria selecionada.
   *
   * @param evt
   */
  private void jMenuItem11ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jMenuItem11ActionPerformed
    try {
      // verificar a seleccão
      int row = jTable1.getSelectedRow();
      Object obj = jTable1.getModel().getValueAt(row, 0);
      if (obj instanceof RFPDirectoryHeader) {
        final JFileChooser fc = new JFileChooser();
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int returnVal = fc.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
          File dir = fc.getCurrentDirectory();
          File dest = fc.getSelectedFile();
          rfpFile.extractAll(((RFPDirectoryHeader) obj).getId(), dest.getPath());
        }
      } else {
        JOptionPane.showMessageDialog(
            null,
            "Impossível extrair directoria.",
            "Extrair Directoria",
            JOptionPane.ERROR_MESSAGE);
      }

    } catch (Exception ex) {
      JOptionPane.showMessageDialog(
          null, "Impossível extrair directoria.", "Extrair Directoria", JOptionPane.ERROR_MESSAGE);
    }
  } // GEN-LAST:event_jMenuItem11ActionPerformed
コード例 #14
0
ファイル: MainWindow.java プロジェクト: Hiperzone/University
  /**
   * Accionado quando se faz clique no botao para criar um ficheiro RFP.
   *
   * <p>Cria um novo ficheiro RFP. Pergunta ao utilizador o caminho onde será guardado o ficheiro.
   * Fecha o ficheiro RFP actual caso exista e faz um reset ao conteudo da tabela, mostrando de
   * seguida o conteudo do novo ficheiro RFP.
   *
   * <p>É lançado uma excepção caso seja impossivel criar o ficheiro na directoria de destino.
   *
   * @param evt
   */
  private void jMenuItem14ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jMenuItem14ActionPerformed
    try {
      final JFileChooser fc = new JFileChooser();
      int returnVal = fc.showSaveDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File dir = fc.getCurrentDirectory();
        File file = fc.getSelectedFile();

        if (rfpFile != null && !rfpFile.isClosed()) rfpFile.closeRFP();
        this.resetTable();
        this.resetVariables();

        rfpFile = new RFPBinaryFile(file.getName(), dir.getPath());
        rfpFile.openRFP();
        rfpFile.generateEmptyFile();
        rfpFile.readContents();
        nativePath = dir.getPath();
        this.showRFPContents();
      }
    } catch (Exception ex) {
      JOptionPane.showMessageDialog(
          null, "Impossivel criar ficheiro rfp.", "Novo Ficheiro RFP", JOptionPane.ERROR_MESSAGE);
    }
  } // GEN-LAST:event_jMenuItem14ActionPerformed
コード例 #15
0
ファイル: MainWindow.java プロジェクト: Hiperzone/University
  /**
   * Accionado quando se faz clique no botao para abrir um ficheiro RFP Permite selecionar um
   * ficheiro rfp escolhido pelo utilizador. Fecha o ficheiro actual caso este exista e faz um reset
   * ao conteu do actual da tabela, mostrando de seguida os novos conteudos do ficheiro escolhido.
   *
   * <p>É lançado uma excepção caso seja feito um duplo clique sem selecção.
   *
   * @param evt
   */
  private void jMenuItem2ActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jMenuItem2ActionPerformed

    try {
      final JFileChooser fc = new JFileChooser();
      RFPFileFilter filter = new RFPFileFilter();
      fc.addChoosableFileFilter(filter);
      int returnVal = fc.showOpenDialog(this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        File dir = fc.getCurrentDirectory();
        // fechar o ficheiro actual
        if (rfpFile != null && !rfpFile.isClosed()) rfpFile.closeRFP();

        resetTable();
        resetVariables();
        rfpFile = new RFPBinaryFile(file.getName(), dir.getPath());
        rfpFile.openRFP();
        rfpFile.readContents();
        nativePath = dir.getPath();
        showRFPContents();
      }
    } catch (Exception e) {
      JOptionPane.showMessageDialog(
          null,
          "Impossivel abrir o ficheiro rfp.",
          "Abrir Ficheiro RFP",
          JOptionPane.ERROR_MESSAGE);
    }
  } // GEN-LAST:event_jMenuItem2ActionPerformed
コード例 #16
0
  protected void cmdBrowse() {
    final Preferences prefs = this.getPreferences();
    final String sLastDir =
        (prefs == null)
            ? null
            : prefs.node(PREFS_NODE_COLLECTABLEFILECHOOSER).get(PREFS_KEY_LAST_DIRECTORY, null);
    final JFileChooser filechooser = new JFileChooser(sLastDir);

    configureFileSelection(filechooser);

    final int iBtn = filechooser.showOpenDialog(getJComponent());
    if (iBtn == JFileChooser.APPROVE_OPTION) {
      final java.io.File file = filechooser.getSelectedFile();
      if (file != null) {
        if (prefs != null) {
          prefs
              .node(PREFS_NODE_COLLECTABLEFILECHOOSER)
              .put(PREFS_KEY_LAST_DIRECTORY, filechooser.getCurrentDirectory().getAbsolutePath());
        }
        final String sFileName = file.getAbsolutePath();
        final CollectableValueField clctf = new CollectableValueField(sFileName);
        this.setField(clctf);
      }
    }
  }
コード例 #17
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();
    }
コード例 #18
0
ファイル: OpenTexts.java プロジェクト: miurahr/tmpotter
  private void onTranslation() {
    final JFileChooser fc = new JFileChooser();
    fc.setCurrentDirectory(filePath);

    fc.setMultiSelectionEnabled(false);
    final int returnVal = fc.showOpenDialog(panel);
    filePath = fc.getCurrentDirectory();

    if (returnVal == JFileChooser.APPROVE_OPTION) {
      translationFilePath = fc.getSelectedFile();

      if (fc.getName(translationFilePath).endsWith(".txt")) {
        if (translationFilePath.exists()) {
          translationDoc = fc.getName(translationFilePath);
          fieldTranslation.setText(translationFilePath.getPath());
        } else {
          JOptionPane.showMessageDialog(
              panel,
              getString("MSG.ERROR.FILE_NOTFOUND"),
              getString("MSG.ERROR"),
              JOptionPane.ERROR_MESSAGE);

          fieldTranslation.setText("");
        }
      }
      //  ToDo: remember filename by preferences
    }
  }
コード例 #19
0
 private void openFile() {
   // opens a single file chooser (can select multiple), does not traverse folders.
   this.copyList = new ArrayList();
   final JFileChooser fc = new JFileChooser(currentPath);
   fc.setMultiSelectionEnabled(true);
   fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
   FileNameExtensionFilter filterhtml = new FileNameExtensionFilter("HTML File (.html)", "html");
   fc.addChoosableFileFilter(filterhtml);
   fc.setFileFilter(filterhtml);
   int result = fc.showOpenDialog(FrontEnd.this);
   dir = fc.getCurrentDirectory();
   dirImp = dir.toString();
   switch (result) {
     case JFileChooser.APPROVE_OPTION:
       for (File file1 : fc.getSelectedFiles()) {
         fileImp = file1.toString();
         boolean exists = false;
         for (int i = 0; i < table.getRowCount(); i++) {
           dir = fc.getCurrentDirectory();
           dirImp = dir.toString();
           String copyC = dtm.getValueAt(i, 0).toString();
           if (duplC.isSelected()) {
             if (fileImp.endsWith(copyC)) {
               exists = true;
               break;
             }
           }
         }
         if (!exists) {
           addRow();
           dtm.setValueAt(fileImp.substring(67), curRow, 0);
           dtm.setValueAt(dirImp.substring(67), curRow, 1);
           curRow++;
           if (headC == 1) {
             if (fileImp.substring(67).endsWith(dirImp.substring(67) + ".html")) {
               curRow--;
               dtm.removeRow(curRow);
             }
           }
         }
       }
     case JFileChooser.CANCEL_OPTION:
       break;
   }
 }
コード例 #20
0
  public SelectorDeArchivos(OPERACION operacion) {
    _archivo = null;
    JFileChooser selector = new JFileChooser();
    int opcion;
    if (operacion == OPERACION.CARGA) {
      selector.setFileFilter(new FiltroArchivos());
      opcion = selector.showOpenDialog(new JFrame());
    } else opcion = selector.showSaveDialog(new JFrame());

    if (opcion == JFileChooser.APPROVE_OPTION)
      _archivo =
          selector.getCurrentDirectory().toString() + "/" + selector.getSelectedFile().getName();
  }
コード例 #21
0
 public void actionPerformed(ActionEvent e) {
   int x = jfc.showSaveDialog(null);
   // int x=jfc.showOpenDialog(null);
   if (x == JFileChooser.APPROVE_OPTION) {
     File f = jfc.getSelectedFile();
     System.out.println(f.getPath());
     System.out.println(jfc.getName(f));
     File f1 = jfc.getCurrentDirectory();
     System.out.println(jfc.getName(f1));
   }
   if (x == JFileChooser.CANCEL_OPTION) {
     System.out.println("cancle");
   }
 }
コード例 #22
0
  /** Validates content of file cache. */
  public void validateFileCache() {
    File currentDirectory = filechooser.getCurrentDirectory();
    if (currentDirectory == null) {
      return;
    }
    if (filesLoader != null) {
      filesLoader.loadThread.interrupt();
      filesLoader.cancelRunnables();
    }

    setBusy(true, ++fetchID);

    filesLoader = new FilesLoader(currentDirectory, fetchID);
  }
コード例 #23
0
ファイル: MainWindow.java プロジェクト: Hiperzone/University
 /**
  * Accionado quando se faz clique no botao para adicionar um ficheiro ao ficheiro RFP. Permite
  * adicionar um ficheiro escolhido pelo utilizador..
  *
  * <p>É lançado uma excepção caso seja impossivel adicionar o ficheiro.
  *
  * @param evt
  */
 private void jMenuItem4ActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jMenuItem4ActionPerformed
   try {
     final JFileChooser fc = new JFileChooser();
     int returnVal = fc.showOpenDialog(this);
     if (returnVal == JFileChooser.APPROVE_OPTION) {
       File file = fc.getSelectedFile();
       File dir = fc.getCurrentDirectory();
       rfpFile.addFile(file.getName(), dir.getPath(), RFPBinaryFile.RFP_NO_FLAG);
       showRFPContents();
     }
   } catch (Exception e) {
     JOptionPane.showMessageDialog(
         null, "Impossível adicionar ficheiro.", "Adicionar Ficheiro", JOptionPane.ERROR_MESSAGE);
   }
 } // GEN-LAST:event_jMenuItem4ActionPerformed
コード例 #24
0
  private void btnLoadXmlActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnLoadXmlActionPerformed

    JFileChooser chooser = new JFileChooser();
    chooser.setFileFilter(
        new FileFilter() {
          @Override
          public boolean accept(File f) {
            if (f.isDirectory()) return true;
            return f.getPath().toLowerCase().endsWith(".xml") && f.canRead() && f.canWrite();
          }

          @Override
          public String getDescription() {
            return "XML file";
          }
        });
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    if (currentDir != null) chooser.setCurrentDirectory(currentDir);

    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
      currentDir = chooser.getCurrentDirectory();

      FileInputStream fileInputStream = null;
      try {
        fileInputStream = new FileInputStream(chooser.getSelectedFile());
        String contents = Common.streamToString(fileInputStream);
        txtXml.setSyntaxEditingStyle("text/xml");
        txtXml.setText(contents);
        txtXml.setEditable(true);
      } catch (Exception ex) {
        txtXml.setSyntaxEditingStyle("text/text");
        txtXml.setText(Common.traceToString(ex));
        txtXml.setEditable(false);
      } finally {
        if (fileInputStream != null) {
          try {
            fileInputStream.close();
          } catch (Exception ex) {
          }
        }
      }

      //            setXmlTextIsDirty( true );
    }
  } // GEN-LAST:event_btnLoadXmlActionPerformed
コード例 #25
0
ファイル: Save.java プロジェクト: petosa/Synthesizer
  // When called, opens a file chooser
  public static void start() {

    FileNameExtensionFilter filter = new FileNameExtensionFilter("Synth File", ".synth");
    JFileChooser saveFile = new JFileChooser();

    // Set file chooser properties
    saveFile.setDialogTitle("Save");
    saveFile.setApproveButtonText("Save");
    saveFile.setSelectedFile(new File(filename));
    saveFile.setFileFilter(filter);

    // If valid choice is made, run fileWrite with this file
    if (saveFile.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
      filename = saveFile.getSelectedFile().getName();
      fileWrite(saveFile.getCurrentDirectory().toString());
    }
  }
コード例 #26
0
ファイル: SwingEngine.java プロジェクト: cinquin/pathvisio
 public int show() {
   if (useFileDialog) {
     fileDialog.setVisible(true);
     if (fileDialog.getDirectory() == null) {
       return JFileChooser.CANCEL_OPTION;
     } else {
       PreferenceManager.getCurrent()
           .setFile(dirPreference, new File(fileDialog.getDirectory()));
       return JFileChooser.APPROVE_OPTION;
     }
   }
   int status = jfc.showDialog(getApplicationPanel(), taskName);
   if (status == JFileChooser.APPROVE_OPTION) {
     PreferenceManager.getCurrent().setFile(dirPreference, jfc.getCurrentDirectory());
   }
   return status;
 }
コード例 #27
0
  @Override
  public void actionPerformed(ActionEvent arg0) {
    int rv;
    jfc.setCurrentDirectory(defaultDir.val);
    if (isOpen) rv = jfc.showOpenDialog(parent);
    else rv = jfc.showSaveDialog(parent);

    if (rv == JFileChooser.APPROVE_OPTION) {
      File f = jfc.getSelectedFile();

      try {
        textbox.setText(f.getCanonicalPath());
      } catch (IOException e) {
        textbox.setText(f.getAbsolutePath());
      }
    }

    defaultDir.val = jfc.getCurrentDirectory();
  }
コード例 #28
0
ファイル: SwingComponentUtils.java プロジェクト: piopawlu/ols
  /**
   * Checks whether the given window is either a FileDialog, or contains a JFileChooser component.
   * If so, its current directory is restored from the given properties.
   *
   * @param aNamespace the name space to use;
   * @param aProperties the properties to get the directory from;
   * @param aWindow the window to check for.
   */
  private static void saveFileDialogState(final Preferences aProperties, final Window aWindow) {
    final String propKey = "lastDirectory";

    if (aWindow instanceof FileDialog) {
      final String dir = ((FileDialog) aWindow).getDirectory();
      if (dir != null) {
        aProperties.put(propKey, dir);
      }
    } else if (aWindow instanceof JDialog) {
      final Container contentPane = ((JDialog) aWindow).getContentPane();
      final JFileChooser fileChooser =
          (JFileChooser) findComponent(contentPane, JFileChooser.class);
      if (fileChooser != null) {
        final File dir = fileChooser.getCurrentDirectory();
        if (dir != null) {
          aProperties.put(propKey, dir.getAbsolutePath());
        }
      }
    }
  }
コード例 #29
0
    private void LoadExternalPressed() {

      JFileChooser chooser = new JFileChooser();
      chooser.setFileFilter(
          new javax.swing.filechooser.FileFilter() {
            public String getDescription() {
              return "Class files";
            }

            public boolean accept(File f) {
              return f.getName().endsWith(".class") || f.isDirectory();
            }
          });

      chooser.showOpenDialog(this);

      File chosen = chooser.getSelectedFile();
      File chosenDir = chooser.getCurrentDirectory();

      // System.out.println("Loading class " + chosen.getAbsolutePath());
      // Load file
      FileClass fc = null;
      try {
        URL url = chosenDir.toURI().toURL();
        URL[] urls = new URL[] {url};
        ClassLoader cl = new URLClassLoader(urls);
        Class<?> cls = cl.loadClass(chosen.getName().replace(".class", ""));
        ArrayList<Class<?>> interfaces = getAllInterfaces(cls);
        for (Class<?> c : interfaces) {
          if (c.equals(mytype) && !Modifier.isAbstract(cls.getModifiers())) {
            fc = new FileClass(chosen, cls);
            break;
          }
        }
      } catch (Exception ex) {
        System.err.println("Error loading class file: " + chosen.getAbsolutePath());
      }
      if (fc != null) {
        LoadClass(fc, false);
      }
    }
コード例 #30
0
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() == create) {
     boolean flag = false;
     for (JCheckBox cur : checks) if (cur.isSelected()) flag = true;
     if (flag) {
       File path = chooser.getCurrentDirectory();
       ArrayList<String> cath_selected = new ArrayList<String>();
       for (JCheckBox cur : checks)
         if (cur.isSelected())
           if (cur.getText().compareTo("выбрать все...") != 0) cath_selected.add(cur.getText());
       String mode = new String();
       if (semester_combo.getSelectedItem().toString().compareTo("летний") == 0) mode = "summer";
       else mode = "winter";
       Dispatcher.createEducAssignment(cath_selected, path, mode);
       this.dispose();
     } else
       JOptionPane.showMessageDialog(
           null, "ƒл¤ формировани¤ учебных поручений необходимо определить кафедры.");
   }
   if (e.getSource() == cancel) this.dispose();
 }