Beispiel #1
1
  // -------------------------------actionOpenMap----------------------------
  private void actionOpenMap() {
    JFileChooser oFC = new JFileChooser(DEFAULT_MAP_DIRECTORY);
    int nReturn = oFC.showOpenDialog(frame);

    if (nReturn == JFileChooser.APPROVE_OPTION) {
      try {
        oMap.loadMap(oFC.getSelectedFile());
      } catch (Exception e) {
      }
    }
  }
 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());
   }
 }
 private void setupFileChooser() {
   fileChooser = new JFileChooser();
   fileChooser.setDialogTitle("Select directory to output ISArchive to...");
   fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
   fileChooser.setApproveButtonText("Output to selected directory");
   fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
 }
Beispiel #4
0
  void onOpenFileClicked() {
    if (!maybeSave()) {
      return;
    }

    try {
      JFileChooser fc = new JFileChooser();
      FileNameExtensionFilter filter1 =
          new FileNameExtensionFilter(strings.getString("filetype." + EXTENSION), EXTENSION);
      fc.setFileFilter(filter1);

      int rv = fc.showOpenDialog(this);
      if (rv == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();

        Tournament t = new Tournament();
        t.loadFile(file);

        setTournament(file, t);
      }
    } catch (Exception e) {
      JOptionPane.showMessageDialog(
          this, e, strings.getString("main.error_caption"), JOptionPane.ERROR_MESSAGE);
    }
  }
 /**
  * Saves the current chart as an image in png format. The user can select the filename, and is
  * asked to confirm the overwrite of an existing file.
  */
 public void saveImage() {
   JFileChooser fc = new JFileChooser();
   if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
     File f = fc.getSelectedFile();
     if (f.exists()) {
       int ok =
           JOptionPane.showConfirmDialog(
               this,
               KstatResources.getString("SAVEAS.OVERWRITE.TEXT") + " " + f.toString(),
               KstatResources.getString("SAVEAS.CONFIRM.TEXT"),
               JOptionPane.YES_NO_OPTION);
       if (ok != JOptionPane.YES_OPTION) {
         return;
       }
     }
     BufferedImage bi = kbc.getChart().createBufferedImage(500, 300);
     try {
       ImageIO.write(bi, "png", f);
       /*
        * According to the API docs this should throw an IOException
        * on error, but this doesn't seem to be the case. As a result
        * it's necessary to catch exceptions more generally. Even this
        * doesn't work properly, but at least we manage to convey the
        * message to the user that the write failed, even if the
        * error itself isn't handled.
        */
     } catch (Exception ioe) {
       JOptionPane.showMessageDialog(
           this,
           ioe.toString(),
           KstatResources.getString("SAVEAS.ERROR.TEXT"),
           JOptionPane.ERROR_MESSAGE);
     }
   }
 }
 public void initGame() {
   String cfgname = null;
   if (isApplet()) {
     cfgname = getParameter("configfile");
   } else {
     JFileChooser chooser = new JFileChooser();
     chooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
     chooser.setDialogTitle("Choose a config file");
     int returnVal = chooser.showOpenDialog(this);
     if (returnVal == JFileChooser.APPROVE_OPTION) {
       cfgname = chooser.getSelectedFile().getAbsolutePath();
     } else {
       System.exit(0);
     }
     // XXX read this as resource!
     // cfgname = "mygeneratedgame.appconfig";
   }
   gamecfg = new AppConfig("Game parameters", this, cfgname);
   gamecfg.loadFromFile();
   gamecfg.defineFields("gp_", "", "", "");
   gamecfg.saveToObject();
   initMotionPars();
   // unpause and copy settingswhen config window is closed
   gamecfg.setListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           start();
           requestGameFocus();
           initMotionPars();
         }
       });
   defineMedia("simplegeneratedgame.tbl");
   setFrameRate(35, 1);
 }
 protected void uninstallDefaults(JFileChooser fc) {
   uninstallIcons(fc);
   uninstallStrings(fc);
   if (fc.getTransferHandler() instanceof UIResource) {
     fc.setTransferHandler(null);
   }
 }
Beispiel #8
0
    @Override
    public void actionPerformed(ActionEvent e) {
      Frame frame = getFrame();
      JFileChooser chooser = new JFileChooser();
      int ret = chooser.showOpenDialog(frame);

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

      File f = chooser.getSelectedFile();
      if (f.isFile() && f.canRead()) {
        Document oldDoc = getEditor().getDocument();
        if (oldDoc != null) {
          oldDoc.removeUndoableEditListener(undoHandler);
        }
        if (elementTreePanel != null) {
          elementTreePanel.setEditor(null);
        }
        getEditor().setDocument(new PlainDocument());
        frame.setTitle(f.getName());
        Thread loader = new FileLoader(f, editor.getDocument());
        loader.start();
      } else {
        JOptionPane.showMessageDialog(
            getFrame(),
            "Could not open file: " + f,
            "Error opening file",
            JOptionPane.ERROR_MESSAGE);
      }
    }
  private void changeDirectory(File dir) {
    JFileChooser fc = getFileChooser();
    // Traverse shortcuts on Windows
    if (dir != null && FilePane.usesShellFolder(fc)) {
      try {
        ShellFolder shellFolder = ShellFolder.getShellFolder(dir);

        if (shellFolder.isLink()) {
          File linkedTo = shellFolder.getLinkLocation();

          // If linkedTo is null we try to use dir
          if (linkedTo != null) {
            if (fc.isTraversable(linkedTo)) {
              dir = linkedTo;
            } else {
              return;
            }
          } else {
            dir = shellFolder;
          }
        }
      } catch (FileNotFoundException ex) {
        return;
      }
    }
    fc.setCurrentDirectory(dir);
    if (fc.getFileSelectionMode() == JFileChooser.FILES_AND_DIRECTORIES
        && fc.getFileSystemView().isFileSystem(dir)) {

      setFileName(dir.getAbsolutePath());
    }
  }
 public void actionPerformed(ActionEvent e) {
   saveOld();
   if (dialog.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
     readInFile(dialog.getSelectedFile().getAbsolutePath());
   }
   SaveAs.setEnabled(true);
 }
 private void selFolder() {
   // selects a single folder, then makes table uneditable other than launch, sel res folder and
   // cancel, gui table different, just shows folder
   final JFileChooser fc = new JFileChooser(currentPath);
   fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
   int result = fc.showOpenDialog(FrontEnd.this);
   dir = fc.getSelectedFile();
   switch (result) {
     case JFileChooser.APPROVE_OPTION:
       dirImp = dir.toString();
       dtm.getDataVector().removeAllElements();
       dtm.fireTableDataChanged();
       curRow = 0;
       addRow();
       dtm.setValueAt(
           "You have chosen the folder '" + dirImp.substring(67) + "' and all of its subfolders.",
           0,
           0);
       dtm.setValueAt(dirImp.substring(67), 0, 1);
       if (table.getRowCount() > 0) {
         openF.setEnabled(false);
         openFo.setEnabled(false);
         selFo.setEnabled(false);
         canF.setEnabled(true);
       }
       selFoFl = 1;
     case JFileChooser.CANCEL_OPTION:
       break;
   }
 }
Beispiel #12
0
  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;
  }
  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());
    }
  }
Beispiel #14
0
 @Override
 public void actionPerformed(ActionEvent e) {
   if (td.getTabCount() > 0) {
     JFileChooser f = new JFileChooser();
     f.setFileFilter(new MyFileFilter());
     int choose = f.showSaveDialog(getContentPane());
     if (choose == JFileChooser.APPROVE_OPTION) {
       BufferedWriter brw = null;
       try {
         File file = f.getSelectedFile();
         brw = new BufferedWriter(new FileWriter(file));
         int i = td.getSelectedIndex();
         TextDocument ta = (TextDocument) td.getComponentAt(i);
         ta.write(brw);
         ta.fileName = file.getName(); // 將檔案名稱更新為存檔的名稱
         td.setTitleAt(td.getSelectedIndex(), ta.fileName);
         ta.file = file;
         ta.save = true; // 設定已儲存
         System.out.println("Save as pass!");
         td.setTitleAt(i, ta.fileName); // 更新標題名稱
       } catch (Exception exc) {
         exc.printStackTrace();
       } finally {
         try {
           brw.close();
         } catch (Exception ecx) {
           ecx.printStackTrace();
         }
       }
     }
   } else {
     JOptionPane.showMessageDialog(null, "沒有檔案可以儲存!");
   }
 }
Beispiel #15
0
  private void onTransferFileClicked() {

    if (transferingFile) return;

    int returnVal = fileChooser.showOpenDialog(this);

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

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

      try {

        lineCount = getFileLineCount(file);

        fileReader = new FileReader(file);

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

        transmitMessage("$save");

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

    } else {
      showInfoMessage("Se cancelo la transferencia de archivo");
    }
  }
Beispiel #16
0
 @Override
 public void actionPerformed(ActionEvent e) {
   JFileChooser f = new JFileChooser();
   f.setFileFilter(new MyFileFilter()); // 設定檔案選擇器
   int choose = f.showOpenDialog(getContentPane()); // 顯示檔案選取
   if (choose == JFileChooser.OPEN_DIALOG) { // 有開啟檔案的話,開始讀檔
     BufferedReader br = null;
     try {
       File file = f.getSelectedFile();
       br = new BufferedReader(new FileReader(file));
       TextDocument ta = new TextDocument(file.getName(), file);
       ta.addKeyListener(new SystemTrackSave());
       ta.read(br, null);
       td.add(ta);
       td.setTitleAt(docCount++, file.getName());
     } catch (Exception exc) {
       exc.printStackTrace();
     } finally {
       try {
         br.close();
       } catch (Exception ecx) {
         ecx.printStackTrace();
       }
     }
   }
 }
Beispiel #17
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();
   }
 }
Beispiel #18
0
  // Add a test case to testBox and tests array.
  private void addTest() {

    // Set up the frame for the file chooser.
    final JFrame appframe = new JFrame("Select Application");
    appframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    Container contentPane = appframe.getContentPane();
    JFileChooser fileChooser = new JFileChooser(".");

    // Only let you select directories and add chooser to pane.
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    contentPane.add(fileChooser, BorderLayout.CENTER);

    // Make a new action listener for the file chooser.
    ActionListener actionListener =
        new ActionListener() {

          public void actionPerformed(ActionEvent actionEvent) {

            // Get the information to check if the file chosen is valid.
            JFileChooser theFileChooser = (JFileChooser) actionEvent.getSource();
            String command = actionEvent.getActionCommand();

            // If the user cancels selecting a program.
            if (command.equals(JFileChooser.CANCEL_SELECTION)) {
              appframe.setVisible(false);
              appframe.dispose();
              return;
            }

            // If the file chosen is valid.
            if (command.equals(JFileChooser.APPROVE_SELECTION)) {
              // Retrieve the selected file and ask for the main class name.
              File f = theFileChooser.getSelectedFile();

              // Obtain the file URL.
              String fileURL = null;
              fileURL = f.getAbsolutePath();

              // Add a checkbox to the testing check pane.
              JCheckBox newTest = new JCheckBox(fileURL, true);
              testBox.setEditable(true);
              testBox.add(newTest);
              testBox.repaint();
              testBox.setEditable(false);
              // Add the test to the list of tests.
              tests.add(newTest);

              // Make the file chooser disappear.
              appframe.setVisible(false);
              appframe.dispose();
            }
          }
        };

    // Add the action listener created above to file chooser, display it.
    fileChooser.addActionListener(actionListener);
    appframe.pack();
    appframe.setVisible(true);
  }
Beispiel #19
0
 private void openFile() {
   JFileChooser chooser;
   int status;
   chooser = new JFileChooser();
   status = chooser.showOpenDialog(null);
   if (status == JFileChooser.APPROVE_OPTION) readSource(chooser.getSelectedFile());
   else JOptionPane.showMessageDialog(null, "Open File dialog canceled");
 } // openFile
Beispiel #20
0
 public void saveAs(ActionEvent e) {
   int returnVal = fc.showSaveDialog(this);
   if (returnVal != JFileChooser.APPROVE_OPTION) {
     return;
   }
   file = fc.getSelectedFile();
   save(e);
 }
Beispiel #21
0
 public void doIt(Project project) {
   JFileChooser fileChooser = project.getOpenChooser();
   if (fileChooser.showOpenDialog(project.getComponent()) == JFileChooser.APPROVE_OPTION) {
     openFile(project, fileChooser);
   } else {
     project.setEnabled(true);
   }
 }
 protected void uninstallListeners(JFileChooser fc) {
   if (propertyChangeListener != null) {
     fc.removePropertyChangeListener(propertyChangeListener);
   }
   fc.removePropertyChangeListener(getModel());
   SwingUtilities.replaceUIInputMap(fc, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null);
   SwingUtilities.replaceUIActionMap(fc, null);
 }
 // 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());
   }
 }
Beispiel #24
0
  public void actionPerformed(ActionEvent e) {
    Object sender = e.getSource();
    /*
       if (sender == addButton)
       {
          if (project != null)
          {
            if (dirChooser != null)
            {
              dirChooser.setDialogTitle( "add a file" ) ;
              dirChooser.setFileSelectionMode( JFileChooser.FILES_ONLY) ;
              if ( dirChooser.showOpenDialog( this ) == JFileChooser.APPROVE_OPTION )
              {
                addFile( dirChooser.getSelectedFile() ) ;
              }
            }
            else System.out.println( "no chooser" ) ;
          }
          else System.out.println( "no project" ) ;
       }
       else if (sender == removeButton)
       {
         int row = table.getSelectedRow() ;

         if (project != null)
         {
           TProjectData data = project.getProjectData() ;
           TProjectFileList list = data.getAvailableLangs() ;

           TLanguageFile file = list.getData(row) ;

           list.removeLanguageVersion(file) ;

           if (list.getSize() < 1)
           {
             removeButton.setEnabled(false);
           }

           model.fireTableDataChanged();
         }

       }
       else if (sender == rescanButton)
       {

       }
       else
    */
    if (sender == this.baseButton) {
      //      dirChooser.setProjectFileFilter( (String) typeCombo.getSelectedItem() );
      dirChooser.setDialogTitle("select a base file");
      dirChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
      if (dirChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        setBaseFile(dirChooser.getSelectedFile());
        rescan();
      }
    }
  }
    public void actionPerformed(ActionEvent a) {
      QuizCard card = new QuizCard(question.getText(), answer.getText());
      cardList.add(card);
      clearCard();

      JFileChooser fileSave = new JFileChooser();
      fileSave.showSaveDialog(frame);
      saveFile(fileSave.getSelectedFile());
    }
Beispiel #26
0
 private void saveAs() {
   if (saveFC == null) {
     saveFC = new SaveDataFileChooser();
   }
   int ret = saveFC.showSaveDialog(this);
   if (ret == JFileChooser.APPROVE_OPTION) {
     saveDataToFile(saveFC.getSelectedFile());
   }
 }
      public void actionPerformed(ActionEvent evt) {
        File directory = new File(field.getText());
        JFileChooser chooser = new JFileChooser(directory.getParent());
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setSelectedFile(directory);

        if (chooser.showOpenDialog(SwingInstall.this) == JFileChooser.APPROVE_OPTION)
          field.setText(chooser.getSelectedFile().getPath());
      }
Beispiel #28
0
  public Path dateiAuswählen() {
    JFileChooser fc1 = new JFileChooser();

    fc1.setDialogTitle("SyncOrdner auswählen");
    fc1.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    if (fc1.showSaveDialog(this) == JFileChooser.APPROVE_OPTION)
      return fc1.getSelectedFile().toPath();
    else return null;
  }
Beispiel #29
0
 public void loadPuzzle(ActionEvent e) throws NoSuchMethodException {
   int returnVal = fc.showOpenDialog(this);
   if (returnVal != JFileChooser.APPROVE_OPTION) {
     return;
   }
   file = fc.getSelectedFile();
   Map m = new HashMap();
   m.put("file", file);
   mgr.switchScreens(m);
 }
    public void showOpenDialog() {
      JFileChooser fc = new JFileChooser(Configuration.getUserHomeDirectory());
      fc.addChoosableFileFilter(new VPFFileFilter());

      int retVal = fc.showOpenDialog(this);
      if (retVal != JFileChooser.APPROVE_OPTION) return;

      File file = fc.getSelectedFile();
      this.addVPFLayer(file);
    }