public void actionPerformed(ActionEvent of) {

      try {
        JFileChooser ChooseFile = new JFileChooser();
        ChooseFile.setCurrentDirectory(new java.io.File("."));
        ChooseFile.setSize(200, 200);
        ChooseFile.setVisible(true);
        ChooseFile.setDialogTitle("Choose the file/folder you want to play");

        int returnValue = ChooseFile.showOpenDialog(null);
        if (returnValue == JFileChooser.APPROVE_OPTION) {
          File selectedFile = ChooseFile.getSelectedFile();
          FileName = selectedFile.getName();
          playlistInfo.setText("Now we got something: " + FileName);
          playlistInfo.setForeground(Color.BLUE);
        }

        PathToFile = ChooseFile.getSelectedFile().getPath();

      } catch (Exception e) {
        System.out.println("Choose song");
        playlistInfo.setText("Choose File, Idiot!");
        playlistInfo.setForeground(Color.RED);
      }
    }
  public void load() {
    JFileChooser jfilechooser = new JFileChooser();
    int returnOption = jfilechooser.showOpenDialog(jFrameMain);

    if (returnOption == JFileChooser.APPROVE_OPTION) {
      try {
        Equation equation = controllerIO.load(jfilechooser.getSelectedFile());
        controllerEquation.setEquation(equation);
        controllerEquation.solveEquation();
        changeView(PANEL.RESULT);
      } catch (ClassNotFoundException e) {
        JOptionPane.showMessageDialog(
            jFrameMain,
            "Didn't found \"Equation.class\".",
            e.getClass().getSimpleName(),
            JOptionPane.ERROR_MESSAGE);
        e.printStackTrace();
      } catch (IOException e) {
        JOptionPane.showMessageDialog(
            jFrameMain,
            "Error while loading file : " + jfilechooser.getSelectedFile().getAbsolutePath(),
            e.getClass().getSimpleName(),
            JOptionPane.ERROR_MESSAGE);
        e.printStackTrace();
      }
    }
  }
Exemple #3
0
  /**
   * Starts file chooser.
   *
   * @param dir whether it needs dir or file
   */
  protected void startFileChooser(
      final Widget paramWi, final String directory, final boolean dirOnly) {
    final Host host = getFirstConnectedHost();
    if (host == null) {
      Tools.appError("Connection to host lost.");
      return;
    }
    final VMSHardwareInfo thisClass = this;
    final JFileChooser fc =
        new JFileChooser(getLinuxDir(directory, host), getFileSystemView(host, directory)) {
          /** Serial version UID. */
          private static final long serialVersionUID = 1L;

          @Override
          public final void setCurrentDirectory(final File dir) {
            super.setCurrentDirectory(new LinuxFile(thisClass, host, dir.toString(), "d", 0, 0));
          }
        };
    fc.setBackground(ClusterBrowser.STATUS_BACKGROUND);
    fc.setDialogType(JFileChooser.CUSTOM_DIALOG);
    if (dirOnly) {
      fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    }
    fc.setDialogTitle(Tools.getString("VMSDiskInfo.FileChooserTitle") + host.getName());
    //        fc.setApproveButtonText(Tools.getString("VMSDiskInfo.Approve"));
    fc.setApproveButtonToolTipText(Tools.getString("VMSDiskInfo.Approve.ToolTip"));
    fc.putClientProperty("FileChooser.useShellFolder", Boolean.FALSE);
    final int ret =
        fc.showDialog(Tools.getGUIData().getMainFrame(), Tools.getString("VMSDiskInfo.Approve"));
    linuxFileCache.clear();
    if (ret == JFileChooser.APPROVE_OPTION && fc.getSelectedFile() != null) {
      final String name = fc.getSelectedFile().getAbsolutePath();
      paramWi.setValue(name);
    }
  }
Exemple #4
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();
   }
 }
  private void GuardarProyectoActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_GuardarProyectoActionPerformed
    // TODO add your handling code here:
    JFileChooser selectorTAC = new JFileChooser();
    javax.swing.filechooser.FileFilter filtro = new FileNameExtensionFilter("Proyecto (.c)", "c");
    selectorTAC.setFileFilter(filtro);
    selectorTAC.setFileSelectionMode(JFileChooser.FILES_ONLY);
    selectorTAC.showOpenDialog(this);
    if (selectorTAC.getSelectedFile() != null) {
      try {
        File fileTAC = selectorTAC.getSelectedFile();
        Scanner3D sTAC = new Scanner3D(new FileReader(fileTAC));
        Parser3D pTAC = new Parser3D();
        pTAC.setScanner(sTAC);

        try {
          pTAC.parse();
          pTAC.g.ConectarNodos();
          int a = 10;
          pTAC.g.NombrePrograma = selectorTAC.getSelectedFile().getName();
          this.prueba = pTAC.g;
          this.LCargar.add(pTAC.g);
          // pTAC.g.BuscarEtiqueta("RobotdeEjemplo_main_").Ejecutar(pTAC.g,null);

          a = 1 + 1;

        } catch (Exception ex) {
          Logger.getLogger(Interfaz.class.getName()).log(Level.SEVERE, null, ex);
        }

      } catch (FileNotFoundException ex) {
        Logger.getLogger(Interfaz.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  } // GEN-LAST:event_GuardarProyectoActionPerformed
 /* (non-Javadoc)
  * @see javax.swing.SwingWorker#done()
  */
 @Override
 protected void done() {
   progress.disposeProgress(); // After file creation, close the progress bar
   // Show successful save dialog
   JOptionPane.showMessageDialog(
       frame,
       chooser.getSelectedFile().getName()
           + " was successfully saved in "
           + chooser.getSelectedFile().getPath());
   // Prompt user is they'd like to open the created file
   String ObjButtons[] = {"Yes", "No"};
   int PromptResult =
       JOptionPane.showOptionDialog(
           null,
           "Do you want to open this file?",
           "Open created file",
           JOptionPane.DEFAULT_OPTION,
           JOptionPane.QUESTION_MESSAGE,
           null,
           ObjButtons,
           ObjButtons[1]);
   if (PromptResult == JOptionPane.YES_OPTION) {
     Video.setVideoName(chooser.getSelectedFile().getAbsolutePath() + ".avi");
     mediaPlayer.playMedia(Video.getVideoName()); // If yes, set this as selected video
     label.setCurrentVideo(); // Update video label
   }
 }
Exemple #7
0
  // Inicio Funcion Abrir
  void abrir() {
    int iResp;
    String strTexto = null;
    Vector<String> alLinea = null;
    Archivo leerArchivo = null;
    try {
      JFileChooser fileChooser = new JFileChooser();
      fileChooser.setFileFilter(filter);
      fileChooser.setDialogTitle("Abrir Archivo");
      iResp = fileChooser.showOpenDialog(fileChooser);
      if (iResp == JFileChooser.OPEN_DIALOG) {

        leerArchivo = new Archivo();
        alLinea = leerArchivo.LeeArchivo(fileChooser.getSelectedFile().toString());
        RutaOpen = fileChooser.getSelectedFile().toString();
        if (alLinea.size() > 0) {
          textArea.setText("");
          for (int iIndice = 0; iIndice < alLinea.size(); iIndice++) {
            strTexto = (String) alLinea.get(iIndice);
            textArea.append(strTexto + "\n");
          }
        }
      }
    } catch (NumberFormatException ex) {
      System.out.println(ex.getMessage());
    }
  }
Exemple #8
0
 private void cmdLoadActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_cmdLoadActionPerformed
   // Confirm save before open another file
   if (this.isContentChanged()) {
     int ans =
         JOptionPane.showConfirmDialog(
             this,
             "The contents of "
                 + CurrentFileName
                 + " has been modified. Would you like to save the changes first?",
             "Confirm saving ...",
             JOptionPane.YES_NO_OPTION);
     if (ans == JOptionPane.YES_OPTION) {
       saveFileContent(this.CurrentFileName, rsTextArea.getText());
     }
   }
   // Select a file to open
   if (FC.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
     CurrentFileName = FC.getSelectedFile().getPath();
     String name = FC.getSelectedFile().getName();
     // Open idf/imf file
     rsTextArea.setText(getFileContent(CurrentFileName));
     setContentChanged(false);
     this.Title = name;
     notifyContentChange(false);
   }
 } // GEN-LAST:event_cmdLoadActionPerformed
  @Override
  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == openButton) {
      int returnVal = fc.showOpenDialog(MainFunction.this);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        try {
          // Convert PDF file to text
          textField.setText("Parsing PDF file");
          PreprocessPDF preproc = new PreprocessPDF(file);
          String text = preproc.pdf2text();

          // Perform NLP analysis of the text file
          textField.setText("Analyzing text file");
          AnalyzeNLP analysis = new AnalyzeNLP();
          text = analysis.cleanupText(text);

          // Upload text file to web server
          WebserverUpload upload = new WebserverUpload(user, passw);
          String filename = fc.getSelectedFile().getName().replace("pdf", "html");
          textField.setText("Sending file to the server");
          upload.post2web(text, filename);
          textField.setText("Done");
        } catch (IOException e1) {
          textField.setText("Failed to parse PDF file: " + e1.getMessage());
        }
      }
    }
  }
Exemple #10
0
 public Zipper<Map<Integer, MZipper<RoiContainer>>> exec(
     Zipper<Map<Integer, MZipper<RoiContainer>>> z, int frame) {
   JFileChooser fc = new JFileChooser();
   int returnVal = fc.showOpenDialog(WindowManager.getCurrentWindow().getCanvas());
   Map<Integer, MZipper<RoiContainer>> newRois;
   if (returnVal == JFileChooser.APPROVE_OPTION) {
     try {
       FileInputStream f = new FileInputStream(fc.getSelectedFile().getCanonicalPath());
       MroiLisp parser = new MroiLisp(f);
       parser.ReInit(f);
       newRois = parser.roiFile();
       //				z.rights.clear();
       //				z.rights.add(newRois);
       //				z = z.right();
       //				return z;
       return z.insertAndStep(newRois);
     } catch (IOException e) {
       IJ.error("Couldn't open from " + fc.getSelectedFile().getName() + ": " + e.getMessage());
     } catch (mroi.ParseException e) {
       IJ.error("Failed in parsing: " + e.getMessage());
     } catch (Exception e) {
       IJ.error("Malformed input file: " + e.getMessage());
     }
   }
   return z;
 }
 /** Exports the Last Deployment to an html file Called by the GuiMain in an action event */
 public void exportLastDeployment(ArrayList<DeployedVirtualMachine> deployed, Component parent) {
   if (deployed.size() != 0) {
     FileSystemView fsv = FileSystemView.getFileSystemView();
     JFileChooser chooser = new JFileChooser(fsv.getRoots()[0]);
     chooser.addChoosableFileFilter(new ReportGeneratorFileFilter());
     chooser.setSelectedFile(new File("report.html"));
     int choice = chooser.showSaveDialog(parent);
     if (choice == JFileChooser.APPROVE_OPTION) {
       try {
         LOG.write("Creating report...");
         new ReportGenerator().makeReport(chooser.getSelectedFile(), deployed, this);
         LOG.write("Report saved at " + chooser.getSelectedFile().getAbsolutePath());
       } catch (Exception e) {
         LOG.write("Error in generating the report");
         LOG.printStackTrace(e);
       }
     }
   } else {
     JOptionPane.showMessageDialog(
         main,
         "No deployment data exists.  \nUse the Deployment Wizard to start a "
             + "new deployment before creating a deployment report.",
         "Could not create report",
         JOptionPane.ERROR_MESSAGE);
   }
 }
Exemple #12
0
  public File chooseFile() {
    final JFileChooser chooser = new JFileChooser("Choose file");
    chooser.setDialogType(JFileChooser.OPEN_DIALOG);
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

    chooser.setFileFilter(getFileFilter());

    path = Preference.pref.get(preferenceKey, path);
    chooser.setCurrentDirectory(new File(path));
    chooser.addPropertyChangeListener(
        new PropertyChangeListener() {
          @Override
          public void propertyChange(PropertyChangeEvent e) {
            if (e.getPropertyName().equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)
                || e.getPropertyName().equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY)) {
              e.getNewValue();
            }
          }
        });

    chooser.setVisible(true);

    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
      path = chooser.getSelectedFile().getParent();
      Preference.pref.put(preferenceKey, path);
      return chooser.getSelectedFile();
    } else {
      return null;
    }
  }
  /** Descripción de Método */
  private void loadFile() {
    log.info("");

    JFileChooser chooser = new JFileChooser();

    chooser.setDialogType(JFileChooser.OPEN_DIALOG);
    chooser.setDialogTitle(Msg.getMsg(Env.getCtx(), "AttachmentNew"));

    int returnVal = chooser.showOpenDialog(this);

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

    //

    String fileName = chooser.getSelectedFile().getName();

    log.config(fileName);

    File file = chooser.getSelectedFile();

    if (m_attachment.addEntry(file)) {
      cbContent.addItem(fileName);
      cbContent.setSelectedIndex(cbContent.getItemCount() - 1);
      m_change = true;
    }
  } // getFileName
Exemple #14
0
 private static void play() {
   if (tmp == 3) {
     String fileName = "";
     File file;
     File kilcliDir =
         new File(
             System.getProperty("user.dir")
                 + System.getProperty("file.separator")
                 + "logs"
                 + System.getProperty("file.separator"));
     JFileChooser chooser = new JFileChooser();
     // Note: source for ExampleFileFilter can be found in FileChooserDemo,
     // under the demo/jfc directory in the Java 2 SDK, Standard Edition.
     ExampleFileFilter filter = new ExampleFileFilter();
     filter.addExtension("txt");
     filter.setDescription("KilCli Log Files");
     chooser.setCurrentDirectory(kilcliDir);
     chooser.setFileFilter(filter);
     int returnVal = chooser.showOpenDialog(null);
     if (returnVal == JFileChooser.APPROVE_OPTION) {
       fileName = chooser.getSelectedFile().getName();
       file = chooser.getSelectedFile();
       new LogViewingThread(fileName, file, 0).start();
     } else {
       quit(null);
     }
   } else if (tmp == 4) {
     System.exit(0);
   } else {
     mainFrame = new KilCli(tmp, laf, theme, themeString);
     mainFrame.initialize();
   }
 }
  private void EliminarArchivoActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_EliminarArchivoActionPerformed
    // TODO add your handling code here:
    JFileChooser selectorTAC = new JFileChooser();
    javax.swing.filechooser.FileFilter filtro = new FileNameExtensionFilter("Proyecto (.c)", "c");
    selectorTAC.setFileFilter(filtro);
    selectorTAC.setFileSelectionMode(JFileChooser.FILES_ONLY);
    selectorTAC.showOpenDialog(this);
    if (selectorTAC.getSelectedFile() != null) {
      try {
        File fileTAC = selectorTAC.getSelectedFile();
        Scanner3D sTAC = new Scanner3D(new FileReader(fileTAC));
        Parser3D pTAC = new Parser3D();
        pTAC.setScanner(sTAC);

        try {
          pTAC.parse();
          pTAC.g.ConectarNodos();
          int a = 10;
          pTAC.g.NombrePrograma = selectorTAC.getSelectedFile().getName();
          pTAC.g.OptimizarSB();
          pTAC.g.EscribirArchivo(
              selectorTAC.getSelectedFile().getCanonicalPath(), pTAC.g.RegenerarTAC());

          a = 1 + 1;

        } catch (Exception ex) {
          Logger.getLogger(Interfaz.class.getName()).log(Level.SEVERE, null, ex);
        }

      } catch (FileNotFoundException ex) {
        Logger.getLogger(Interfaz.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  } // GEN-LAST:event_EliminarArchivoActionPerformed
  private String chooseFileName(boolean ownXmlFormat, FileFilter filefilter) {
    String fileName = null;

    // filechooser must be recreated to avoid a bug where getSelectedFile() was null (if a file is
    // saved more than one time by doubleclicking on an existing file)
    reloadSaveFileChooser();

    setAvailableFileFilters(ownXmlFormat);
    saveFileChooser.setFileFilter(filefilter);

    int returnVal = saveFileChooser.showSaveDialog(Main.getInstance().getGUI());
    if (returnVal == JFileChooser.APPROVE_OPTION) {

      File selectedFileWithExt =
          new File(
              saveFileChooser.getSelectedFile().getName()
                  + "."
                  + fileextensions.get(saveFileChooser.getFileFilter()));
      // We must check for the file with and without extension (saving without adding the extension
      // automatically adds the selected extension)
      if (saveFileChooser.getSelectedFile().exists() || selectedFileWithExt.exists()) {
        int overwriteQuestionResult =
            JOptionPane.showConfirmDialog(
                Main.getInstance().getGUI(),
                "File already exists! Overwrite?",
                "Overwrite File",
                JOptionPane.YES_NO_OPTION);
        if (overwriteQuestionResult == JOptionPane.NO_OPTION)
          return chooseFileName(ownXmlFormat, filefilter);
      }
      fileName = saveFileChooser.getSelectedFile().getAbsolutePath();
    }
    return fileName;
  }
  void importB_actionPerformed(ActionEvent e) {
    // Fix until Sun's JVM supports more locales...
    UIManager.put("FileChooser.lookInLabelText", Local.getString("Look in:"));
    UIManager.put("FileChooser.upFolderToolTipText", Local.getString("Up One Level"));
    UIManager.put("FileChooser.newFolderToolTipText", Local.getString("Create New Folder"));
    UIManager.put("FileChooser.listViewButtonToolTipText", Local.getString("List"));
    UIManager.put("FileChooser.detailsViewButtonToolTipText", Local.getString("Details"));
    UIManager.put("FileChooser.fileNameLabelText", Local.getString("File Name:"));
    UIManager.put("FileChooser.filesOfTypeLabelText", Local.getString("Files of Type:"));
    UIManager.put("FileChooser.openButtonText", Local.getString("Open"));
    UIManager.put("FileChooser.openButtonToolTipText", Local.getString("Open selected file"));
    UIManager.put("FileChooser.cancelButtonText", Local.getString("Cancel"));
    UIManager.put("FileChooser.cancelButtonToolTipText", Local.getString("Cancel"));

    JFileChooser chooser = new JFileChooser();
    chooser.setFileHidingEnabled(false);
    chooser.setDialogTitle(Local.getString("Insert file"));
    chooser.setAcceptAllFileFilterUsed(false);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.addChoosableFileFilter(new AllFilesFilter(AllFilesFilter.HTML));
    chooser.setPreferredSize(new Dimension(550, 375));
    String lastSel = (String) Context.get("LAST_SELECTED_IMPORT_FILE");
    if (lastSel != null) chooser.setCurrentDirectory(new java.io.File(lastSel));
    if (chooser.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) return;

    Context.put("LAST_SELECTED_IMPORT_FILE", chooser.getSelectedFile().getPath());

    File f = chooser.getSelectedFile();
    new HTMLFileImport(f, editor);
  }
  /**
   * This method allows the user to choose a input video file to get images from. It makes sure that
   * only video files are chosen and that they are valid. The user cannot get images from the video
   * if the file is not valid.
   */
  private void chooseVideoPressed() {

    JFileChooser fileChooser = new JFileChooser();

    fileChooser.setCurrentDirectory(new java.io.File("."));

    fileChooser.setDialogTitle("Choose Video File");

    fileChooser.addChoosableFileFilter(SwingFileFilterFactory.newVideoFileFilter());

    // Allows files to be chosen only. Make sure they are video files in the extract part
    // fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

    // put filter to ensure that only video files are chosen.
    fileChooser.setFileFilter(SwingFileFilterFactory.newVideoFileFilter());
    fileChooser.setAcceptAllFileFilterUsed(false);
    int returnValue = fileChooser.showOpenDialog(Images.this);

    if (returnValue == JFileChooser.APPROVE_OPTION) {
      selectedFile = fileChooser.getSelectedFile();
      showVideo.setText("Video chosen: " + selectedFile.getName());
      InvalidCheck i = new InvalidCheck();
      boolean isValidMedia = i.invalidCheck(fileChooser.getSelectedFile().getAbsolutePath());
      // make sure that file is a valid media file.
      if (!isValidMedia) {
        JOptionPane.showMessageDialog(
            Images.this, "You have specified an invalid file.", "Error", JOptionPane.ERROR_MESSAGE);
        makeImages.setEnabled(false);
        return;
      } else {
        makeImages.setEnabled(true);
      }
    }
  }
 private void AbrirProyectoActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_AbrirProyectoActionPerformed
   // TODO add your handling code here:
   JFileChooser CargarProy = new JFileChooser();
   String leerl = "", filecomplete = "";
   javax.swing.filechooser.FileFilter filtro =
       new FileNameExtensionFilter("Proyecto (.java)", "java");
   CargarProy.setFileFilter(filtro);
   CargarProy.setFileSelectionMode(JFileChooser.FILES_ONLY);
   CargarProy.showOpenDialog(this);
   if (CargarProy.getSelectedFile() != null) {
     Errores.InicializarTablaDeErrores();
     Proyecto = CargarProy.getSelectedFile();
     try {
       FileReader fr = new FileReader(Proyecto);
       BufferedReader br = new BufferedReader(fr);
       while ((leerl = br.readLine()) != null) {
         filecomplete = filecomplete + "\n" + leerl;
       }
     } catch (IOException ex) {
       Logger.getLogger(Interfaz.class.getName()).log(Level.SEVERE, null, ex);
     }
     TextArea a = new TextArea();
     a.setEditable(true);
     a.setText(filecomplete);
     a.setEnabled(true);
     archivos.add(Proyecto);
     TAREAS.add(a);
     this.jTP.add(a);
     this.Guardados = true;
   } // GEN-LAST:event_AbrirProyectoActionPerformed
 }
  public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();
    String cmd = e.getActionCommand();

    if (cmd.equals("Ok")) {
      isConverted = convert();

      if (isConverted) {
        dispose();
      }
    } else if (cmd.equals("Cancel")) {
      isConverted = false;
      convertedFile = null;
      dispose();
    } else if (cmd.equals("Browse source file")) {
      JFileChooser fchooser = new JFileChooser(currentDir);
      if (isConvertedFromImage) fchooser.setFileFilter(DefaultFileFilter.getImageFileFilter());

      int returnVal = fchooser.showOpenDialog(this);

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

      File choosedFile = fchooser.getSelectedFile();
      if (choosedFile == null) {
        return;
      }

      String fname = choosedFile.getAbsolutePath();

      if (fname == null) {
        return;
      }

      currentDir = choosedFile.getParent();
      srcFileField.setText(fname);
      dstFileField.setText(fname + toFileExtension);
    } else if (cmd.equals("Browse target file")) {
      JFileChooser fchooser = new JFileChooser();
      int returnVal = fchooser.showOpenDialog(this);

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

      File choosedFile = fchooser.getSelectedFile();
      if (choosedFile == null) {
        return;
      }

      String fname = choosedFile.getAbsolutePath();

      if (fname == null) {
        return;
      }

      dstFileField.setText(fname);
    }
  }
  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());
    }
  }
  public void propertyChange(PropertyChangeEvent e) {
    String prop = e.getPropertyName();

    if (JFileChooser.DIRECTORY_CHANGED_PROPERTY.equals(prop)) fc.setSelectedFile(new File(name));
    else if (JFileChooser.SELECTED_FILE_CHANGED_PROPERTY.equals(prop)
        && !fc.getSelectedFile().isDirectory()) name = fc.getSelectedFile().getName();
  }
 // called when the load script button is pressed.
 private void scriptPressed() {
   int returnVal = fileChooser.showDialog(this, "Load Script");
   if (returnVal == JFileChooser.APPROVE_OPTION) {
     notifyControllerListeners(
         ControllerEvent.SCRIPT_CHANGE, fileChooser.getSelectedFile().getAbsoluteFile());
     scriptComponent.setContents(fileChooser.getSelectedFile().getAbsolutePath());
   }
 }
  private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
    // HBaseTableManager tblmngr = HbaseManagerTableGetter.getTblManager();
    byte[][] colFamilys;
    HashMap<String, String[][]> tableDataList;
    List<byte[]> rowKeyList = new ArrayList<byte[]>();

    final JFileChooser fc = new JFileChooser();

    fc.showSaveDialog(this);
    ObjectOutputStream writeObjectFile = null;
    try {
      // JOptionPane.
      fc.getSelectedFile().getName();
      writeObjectFile = new ObjectOutputStream(new FileOutputStream(fc.getSelectedFile()));

    } catch (IOException ex) {
      Logger.getLogger(HbaseDataBackupRestoreDialog.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
      for (int i = 0; i < listSelectedTables.getModel().getSize(); i++) {
        String tblName =
            (String) listSelectedTables.getModel().getElementAt(i); // (String)listSelectedTables.
        listSelectedTables.setSelectedValue(tblName, true);
        Logger.getLogger(HbaseDataBackupRestoreDialog.class.getName())
            .log(Level.INFO, "Table name: " + tblName);
        HBaseTableStructure tableStructure = new HBaseTableStructure();
        tableStructure.createWriteTableStructure(tblName);

        colFamilys = tableStructure.getAllColoumnFamilies();

        ResultScanner resultScan =
            HbaseManagerTableGetter.getAllFamilyList("0", "zz", colFamilys, tblName);

        tableDataList = getObjectList(resultScan, colFamilys, rowKeyList);

        // HbaseTbleObject ob;

        HbaseTableObject hbTable = new HbaseTableObject();
        HBaseTableData tableData = new HBaseTableData();

        tableData.setDbDataList(tableDataList);
        tableData.setRowKeylist(rowKeyList);

        hbTable.setTableData(tableData);
        hbTable.setTableStructure(tableStructure);

        writeObjectFile.writeObject(hbTable);
        listSelectedTables.setSelectedValue(tblName, false);
      } // write hbTable to file, object stream;
    } catch (IOException ex) {
      Logger.getLogger(HbaseDataBackupRestoreDialog.class.getName()).log(Level.SEVERE, null, ex);
      try {
        writeObjectFile.close();
      } catch (IOException ex1) {
        Logger.getLogger(HbaseDataBackupRestoreDialog.class.getName()).log(Level.SEVERE, null, ex1);
      }
    }
  }
Exemple #25
0
  public static void runSaveLogDialog(Container parent) {
    JFileChooser chooser = new JFileChooser();
    FileNameExtensionFilter filter = new FileNameExtensionFilter("Log Files", "log");
    chooser.setFileFilter(filter);
    int returnVal = chooser.showSaveDialog(parent);
    if (returnVal == JFileChooser.APPROVE_OPTION) {

      // Define the new files to be saved.
      File logFile = new File(getTmpLogPath());
      File saveFile = new File(chooser.getSelectedFile().getPath() + ".log");

      if (!logFile.exists()) {
        JOptionPane.showMessageDialog(parent, "There is nothing to save yet.");
        return;
      }

      // Check to see if we will overwrite the file
      if (saveFile.exists()) {
        int overwrite =
            JOptionPane.showConfirmDialog(null, "File already exists, do you want to overwrite?");
        if (overwrite == JOptionPane.CANCEL_OPTION
            || overwrite == JOptionPane.CLOSED_OPTION
            || overwrite == JOptionPane.NO_OPTION) {
          return;
        }
      }

      // Initialize the file readers and writers
      FileReader in = null;
      FileWriter out = null;

      // Try to open each file
      try {
        int c;
        // Make sure everything has been flushed out of the buffer
        // and has been written to the temporary file.
        Logger logger = Logger.getInstance();
        logger.flushLogFile();

        in = new FileReader(logFile);
        out = new FileWriter(saveFile);

        // Write each line of the first file to the file chosen.
        while ((c = in.read()) != -1) {
          out.write(c);
        }

        // Close both files.
        in.close();
        out.close();

      } catch (FileNotFoundException e1) {
        showError("Log file could not be saved at " + chooser.getSelectedFile().getPath());
      } catch (IOException e1) {
        showError("Log file could not be saved due to an IO error.");
      }
    }
  }
Exemple #26
0
 private void jMenuItem2ActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jMenuItem2ActionPerformed
   JFileChooser chooser = new JFileChooser(txtCHEMIN);
   chooser.setDialogType(JFileChooser.SAVE_DIALOG);
   chooser.showOpenDialog(this);
   if (chooser.getSelectedFile() != null) {
     pc.sauvegarderModele(chooser.getSelectedFile());
   }
 } // GEN-LAST:event_jMenuItem2ActionPerformed
  /** Sauvegarde la carte en cours dans le fichier sélectionné */
  public void save() {
    if (fileChooser.getSelectedFile() == null) {
      return;
    }

    String name = fileChooser.getSelectedFile().getName();
    EngineZildo.getMapManagement().getCurrentMap().setName(name);
    masterFrame.getManager().saveAs(name);
  }
  private void abrirFicheroExpediente() {
    JFileChooser fc = crearDialogoFichero();
    fc.showOpenDialog(this);

    if (fc.getSelectedFile() != null) {

      obtenerExpediente(fc.getSelectedFile().getAbsolutePath());
    }
  }
Exemple #29
0
 public MainForm() {
   alfa.setValue(1);
   beta.setValue(1);
   gamma.setValue(1);
   loadDatabase.addActionListener(
       e -> {
         fileChooser.setCurrentDirectory(new File(database.getText()));
         int returnVal = fileChooser.showOpenDialog(panel1);
         if (returnVal == JFileChooser.APPROVE_OPTION) {
           File file = fileChooser.getSelectedFile();
           database.setText(file.getPath());
         }
       });
   loadKeyword.addActionListener(
       e -> {
         fileChooser.setCurrentDirectory(new File(keywords.getText()));
         int returnVal = fileChooser.showOpenDialog(panel1);
         if (returnVal == JFileChooser.APPROVE_OPTION) {
           File file = fileChooser.getSelectedFile();
           keywords.setText(file.getPath());
         }
       });
   search.addActionListener(
       e -> {
         isKeywordsEnabled = keywordsEnabled.getSelectedIndex() != 0;
         DatabaseCollection.clear();
         if (isKeywordsEnabled) {
           new KeywordParser(keywords.getText()).parse();
         }
         new DocumentParser(database.getText()).parse();
         Method method1 = Method.valueOf((String) MainForm.this.method.getSelectedItem());
         Document query1 = new Document(MainForm.this.query.getText(), "", false);
         showResults(method1, query1);
       });
   oznacz.addActionListener(
       e -> {
         for (Result result : results.getSelectedValuesList()) {
           result.setMarkedAsGood(!result.isMarkedAsGood());
         }
         results.repaint();
       });
   newQuestion.addActionListener(
       e -> {
         ResultModel model = (ResultModel) results.getModel();
         Document query1 = model.getQuery();
         calculateRelevance(
             model.getResultList(),
             query1,
             (Integer) alfa.getValue(),
             (Integer) beta.getValue(),
             (Integer) gamma.getValue());
         queryHelp.setText(query1.getQueryText());
         Method method1 = Method.valueOf((String) MainForm.this.method.getSelectedItem());
         showResults(method1, query1);
       });
 }
  public static void main(String[] args) {
    ManageStudentBalances studBalances = null;
    JFileChooser fileChooser = new JFileChooser();

    JOptionPane.showMessageDialog(null, "choose data file");
    fileChooser.showOpenDialog(null);
    String randomFile = fileChooser.getSelectedFile().getPath();
    JOptionPane.showMessageDialog(null, "choose index file");
    fileChooser.showOpenDialog(null);
    String indexFile = fileChooser.getSelectedFile().getPath();
    try {
      studBalances = new ManageStudentBalances(indexFile, randomFile);
    } catch (Exception e) {
      if (e instanceof FileNotFoundException) {
        System.out.println("cant locate data files");
        System.exit(1);
      } else {
        if (e instanceof IOException) {
          System.out.println("Cant read index file");
          System.exit(1);
        }
      }
    }

    try {
      // process student 1
      System.out.println("Student 1 balance: " + studBalances.getStudentBalance(1));
      studBalances.addToStudentBalance(1, 100.00);
      System.out.println("Student 1 balance after added 100 " + studBalances.getStudentBalance(1));
      // process student 3
      System.out.println("Student 3 balance: " + studBalances.getStudentBalance(3));
      studBalances.addToStudentBalance(3, 300.00);
      System.out.println("Student 3 balance after added 300 " + studBalances.getStudentBalance(3));

      // process student 2
      System.out.println("Student 2 balance: " + studBalances.getStudentBalance(2));
      studBalances.payStudentBalance(2, 200.00);
      System.out.println("Student 2 balance after paid 200 " + studBalances.getStudentBalance(2));
      // close the files
      studBalances.shutdown(indexFile);

    } catch (Exception e) {
      if (e instanceof NotFoundException) {
        System.out.println("couldnt find student data");
      } else {
        if (e instanceof IOException) {
          System.out.println("couldnt read data properly");
        } else {
          if (e instanceof FileNotFoundException) {
            System.out.println("couldnt find data or index file");
          }
        }
      }
    }
  }