示例#1
0
    public void actionPerformed(ActionEvent event) {
      logger.entering("ImageViewerFrame.FileOpenListener", "actionPerformed", event);
      // set up file chooser
      JFileChooser chooser = new JFileChooser();
      chooser.setCurrentDirectory(new File("."));
      // accept all file ending with .gif
      chooser.setFileFilter(
          new javax.swing.filechooser.FileFilter() {
            public boolean accept(File f) {
              return f.getName().toLowerCase().endsWith(".gif") || f.isDirectory();
            }

            public String getDescription() {
              return "GIF Images";
            }
          });

      int r = chooser.showOpenDialog(ImageViewerFrame.this);
      if (r == JFileChooser.APPROVE_OPTION) {
        String name = chooser.getSelectedFile().getPath();
        logger.log(Level.FINE, "Read file {0}", name);
        label.setIcon(new ImageIcon(name));
      } else logger.fine("File open dialog canceled.");
      logger.exiting("ImageViewerFrame.FileOpenListener", "actionPerformed");
    }
示例#2
0
    /**
     * create a file chooser populated with file filters for the given pathway importers / exporters
     */
    private void createFileFilters(Set<? extends PathwayIO> set) {
      jfc.setAcceptAllFileFilterUsed(false);

      SortedSet<PathwayIO> exporters =
          new TreeSet<PathwayIO>(
              new Comparator<PathwayIO>() {
                public int compare(PathwayIO o1, PathwayIO o2) {
                  return o1.getName().compareTo(o2.getName());
                }
              });
      exporters.addAll(set);

      PathwayFileFilter selectedFilter = null;
      for (PathwayIO exp : exporters) {
        PathwayFileFilter ff = new PathwayFileFilter(exp);
        jfc.addChoosableFileFilter(ff);
        if (exp instanceof GpmlFormat) {
          selectedFilter = ff;
        }
      }
      if (selectedFilter != null) {
        jfc.setFileFilter(selectedFilter);
        fileDialog.setFilenameFilter(selectedFilter);
      }
    }
  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());
    }
  }
示例#4
0
    @Override
    public void actionPerformed(ActionEvent e) {
      Preferences pref = Preferences.userNodeForPackage(FSFrame.class);
      String saveDirName = pref.get(SAVE_DIR, System.getProperty("user.dir"));

      JFileChooser fileChooser = new JFileChooser(saveDirName);
      int result = fileChooser.showSaveDialog(FSFrame.this);
      if (result != JFileChooser.APPROVE_OPTION) {
        return;
      }
      File file = fileChooser.getSelectedFile();
      if (!file.getName().toLowerCase().endsWith(".fsext")) {
        file = new File(file.getAbsolutePath() + ".fsext");
      }
      if (file.exists()) {
        result =
            JOptionPane.showConfirmDialog(
                FSFrame.this, FSResource.getString("file_exists"), "", JOptionPane.YES_NO_OPTION);
        if (result != JOptionPane.YES_OPTION) {
          return;
        }
      }
      pref.put(SAVE_DIR, file.getAbsolutePath());

      FileOutputStream fos = null;
      try {
        fos = new FileOutputStream(file);
        new Parser().write(panel.getModel(), fos);
      } catch (IOException ex) {
        JOptionPane.showMessageDialog(
            FSFrame.this, FSResource.resourceBundle.getString("failed_to_output"));
        ex.printStackTrace();
      }
    }
示例#5
0
  /*
   * This method will open a file that the user chooses,
   * then store the data from the file into a StringBuffer.
   */
  public static StringBuffer openFile() {
    StringBuffer fileContents =
        new StringBuffer(); // Declares the String buffer to hold text in the text file.
    JFileChooser chooser =
        new JFileChooser(); // Declares the JFileChooser object to let the user choose their file.
    FileNameExtensionFilter filter = new FileNameExtensionFilter("TEXT FILES", "txt", "text");

    chooser.setFileFilter(filter); // Adds the fileNameExtensionFilter into the JFileChooser
    chooser.showOpenDialog(null); // Displays an open dialog window.

    File targetFile =
        chooser.getSelectedFile(); // Assigns the chosen file to the variable targetFile.

    try {
      Scanner myScanner =
          new Scanner(
              targetFile); // Declares and instantiates our Scanner object for reading the file.
      while (myScanner.hasNextLine()) { // Our loop will check to ensure there is a line there.
        // This line of code takes the nextLine of text from the file and appends it to our
        // StringBuffer.
        fileContents.append(myScanner.nextLine() + "\r\n");
      }
      myScanner.close(); // Closes our scanner object so that we're not wasting resources.
    } catch (NullPointerException event) {
      System.out.println("We've encountered a NullPointerException");
      event.printStackTrace();
    } catch (FileNotFoundException event) {
      System.out.println("We've encountered a FileNotFoundException");
      event.printStackTrace();
    }

    return new StringBuffer(
        fileContents); // Returns a new StringBuffer item which will contain the text from the file.
  }
示例#6
0
  protected void save(String text) {
    String title = "Save " + textType + " File";
    TextFileFilter fileFilter = getTextFileFilter(textType);
    chooser.setFileFilter(fileFilter);

    if (chooser.showSaveDialog(editor.getFrame()) == JFileChooser.APPROVE_OPTION) {
      String name = chooser.getSelectedFile().toString();
      if (!name.endsWith(fileFilter.getExtension())) {
        name = name + "." + fileFilter.getExtension();
      }
      try {
        editor.getFrame().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        FileOutputStream fos = new FileOutputStream(new File(name));
        fos.write(text.getBytes());
        fos.close();
        JOptionPane.showMessageDialog(
            editor.getFrame(),
            textType + " saved successfully to " + name,
            title,
            JOptionPane.INFORMATION_MESSAGE);
      } catch (Exception ex) {
        Logger.getLogger(FileMenuAction.class.getName()).log(Level.SEVERE, null, ex);
        ExceptionHandler.handleException(ex);
        return;
      } finally {
        editor.getFrame().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
      }
    }
  }
  public ArrayList getWordListFromFile() {
    JFileChooser openFileChooser = new JFileChooser();
    openFileChooser.setDialogTitle("Select a word list file");
    ArrayList allWords = new ArrayList();
    if (openFileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
      BufferedReader infile = null;
      String line;
      try {
        infile = new BufferedReader(new FileReader(openFileChooser.getSelectedFile()));
      } catch (FileNotFoundException e) {
        e.printStackTrace();
      }

      try {
        while ((line = infile.readLine()) != null) {
          String[] lineParts = line.split("\t");
          allWords.add(
              new Word(
                  lineParts[0],
                  Integer.parseInt(lineParts[1]),
                  lineParts[2],
                  Integer.parseInt(lineParts[3])));
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    return allWords;
  }
示例#8
0
  /**
   * Ask use if they would like a dump file, if so, create one.
   *
   * @param pcap Reference to the PcapHandle.
   */
  @Override
  protected boolean beforeStart(Pcap pcap) {
    super.beforeStart(pcap);
    int option = JOptionPane.showConfirmDialog(GrassMarlin.window, "Create a dumpfile?");
    if (option == JOptionPane.OK_OPTION) {
      try {

        String filename = System.currentTimeMillis() + "_dump.pcap";
        File f = new File(Environment.DIR_LIVE_CAPTURE.getPath() + File.separator + filename);

        JFileChooser fc = new JFileChooser();
        fc.setSelectedFile(f);

        int i = fc.showSaveDialog(GrassMarlin.window.getContentPane());

        if (i == JFileChooser.APPROVE_OPTION) {
          dumper = pcap.dumpOpen(fc.getSelectedFile().getCanonicalPath());
        }

      } catch (Exception ex) {
        Logger.getLogger(LivePCAPImport.class.getName())
            .log(Level.SEVERE, "Failed to set dumpfile.", ex);
      }
    } else if (option == JOptionPane.CANCEL_OPTION) {
      return false;
    }
    isUsingDumpFile = dumper != null;
    return true;
  }
示例#9
0
  public ImportSQLDialog() {
    initGUI();
    setPreferredSize(new Dimension(528, 199));
    center(this);

    //		String filename = File.separator;
    String filename =
        File.separator
            + "Dokumente und Einstellungen"
            + File.separator
            + "admin"
            + File.separator
            + "workspace"
            + File.separator
            + "BusinessImpactAnalysis"
            + File.separator
            + "testdata"
            + File.separator
            + "processes";
    File currDir = new File(filename);
    fileChooser.setCurrentDirectory(currDir);
    fileChooser.setFileSelectionMode(JFileChooser.OPEN_DIALOG);

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
  }
示例#10
0
  public void copyHistorial() {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    File desktop = new File(System.getProperty("user.home"), "Desktop");
    fileChooser.setCurrentDirectory(desktop);

    if (fileChooser.showOpenDialog(window) == JFileChooser.APPROVE_OPTION) {
      String path = fileChooser.getSelectedFile().getAbsolutePath();
      Date date = new Date(System.currentTimeMillis());
      SimpleDateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z");
      String dateText = df.format(date);
      String name = "/historial(" + dateText + ").txt";
      PrintWriter writer = null;
      try {
        writer = new PrintWriter(path + name, "UTF-8");
      } catch (FileNotFoundException | UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      for (int i = 0; i < actionList.size(); i++) {
        writer.println(actionList.get(i).toString());
      }
      writer.close();
    } else {
      JOptionPane.showMessageDialog(
          null, "Alert", "Something has gone wrong", JOptionPane.ERROR_MESSAGE);
    }
  }
示例#11
0
  /** Initialize the application. */
  public void initializeApp() {
    // Create and initialize the storage policy
    try {
      DefaultStoragePolicy storage = new DefaultStoragePolicy();
      setStoragePolicy(storage);

      FileFilter ff =
          new FileFilter() {
            public boolean accept(File file) {
              return GUIUtilities.getFileExtension(file).toLowerCase().equals("txt");
            }

            public String getDescription() {
              return "Text files";
            }
          };
      JFileChooser fc;
      fc = storage.getOpenFileChooser();
      fc.addChoosableFileFilter(ff);
      fc.setFileFilter(ff);

      fc = storage.getSaveFileChooser();
      fc.addChoosableFileFilter(ff);
      fc.setFileFilter(ff);
    } catch (SecurityException ex) {
      // FIXME: create a new "NoStoragePolicy"
    }

    setDocumentFactory(new TextDocument.Factory());
  }
示例#12
0
 private void choosePath(JTextField pathField) {
   File current = new File(pathField.getText()).getAbsoluteFile();
   fileChooser.setSelectedFile(current);
   if (fileChooser.showDialog(this, null) == JFileChooser.APPROVE_OPTION) {
     pathField.setText(fileChooser.getSelectedFile().getAbsolutePath());
   }
 }
示例#13
0
 public void actionPerformed(ActionEvent e) {
   FileChooseTableModel model = (FileChooseTableModel) reviewTable.getModel();
   List<FileNameObj> fileNames = model.getFileNameSet();
   JFileChooser fileDialog = new JFileChooser();
   fileDialog.setMultiSelectionEnabled(true);
   int result = fileDialog.showOpenDialog(mainFrame);
   if (result == JFileChooser.APPROVE_OPTION) {
     File[] files = fileDialog.getSelectedFiles();
     for (File file : files) {
       FileNameObj fNameObj = new FileNameObj(file.getAbsolutePath());
       boolean isAdded = false;
       Iterator iter = fileNames.iterator();
       while (iter.hasNext()) {
         if (fNameObj.equals(iter.next())) {
           isAdded = true;
           break;
         }
       }
       if (!isAdded) {
         fileNames.add(fNameObj);
       }
     }
   }
   model.fireTableDataChanged();
 }
  public DefaultSaveDialog(
      JFrame parent,
      Path lastDirectory,
      Path initialFile,
      FileFilter filter,
      String defaultExtension) {
    this.parent = parent;
    this.defaultExtension = defaultExtension;
    fileChooser = new OverwritePromptFileChooser();

    for (javax.swing.filechooser.FileFilter fileFilter : fileChooser.getChoosableFileFilters()) {
      fileChooser.removeChoosableFileFilter(fileFilter);
    }

    if (fileChooser instanceof OverwritePromptFileChooser) {
      ((OverwritePromptFileChooser) fileChooser).setFileFilter(filter, defaultExtension);
    } else {
      fileChooser.setFileFilter(filter);
    }

    if (lastDirectory != null) {
      fileChooser.setCurrentDirectory(lastDirectory.toFile());
    }

    fileChooser.setSelectedFile(initialFile != null ? initialFile.toFile() : null);
  }
示例#15
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;
  }
示例#16
0
  public void onClick(InputEventInfo ev) {
    super.onClick(ev);

    final JFileChooser fc = new JFileChooser();
    fc.setFileFilter(new ImageFileFilter());
    int returnVal =
        fc.showOpenDialog(
            CCanvasController.canvasdb.get(CCanvasController.getCurrentUUID()).getComponent());

    if (returnVal == JFileChooser.APPROVE_OPTION) {
      File file = fc.getSelectedFile();
      Networking.send(
          CImageController.getImageTransferPacket(
              Calico.uuid(),
              CCanvasController.getCurrentUUID(),
              BubbleMenu.lastOpenedPosition.x,
              BubbleMenu.lastOpenedPosition.y,
              file));
    }
    //		if (this.uuid != 0l && new_uuid != 0l &&
    // CGroupController.groupdb.get(new_uuid).getParentUUID() == 0l)
    //		{
    //			CGroupController.move_start(new_uuid);
    //			CGroupController.move_end(new_uuid, ev.getX(), ev.getY());
    //		}
  }
示例#17
0
 @Action()
 public void openProject() {
   final JFileChooser chooser = new JFileChooser();
   chooser.setFileFilter(new ProjectFileFilter());
   final int option = chooser.showOpenDialog(this);
   if (JFileChooser.APPROVE_OPTION != option) {
     return;
   }
   File file = chooser.getSelectedFile();
   ResourceMap resourceMap = context.getResourceMap();
   try {
     file = file.getCanonicalFile();
     logger.info(resourceMap.getString("openProject.info.loading"), file.getName());
     projectService.openProject(file);
     logger.info(resourceMap.getString("openProject.info.loaded"), file.getName());
   } catch (IOException e) {
     logger.error(e, resourceMap.getString("openProject.error.loading"), file.getName());
   }
   try {
     // XXX we should really save connection state in the project file
     //     and restore it after re-opening
     RvConnection.resumeQueue();
   } catch (TibrvException e) {
     logger.error(e, resourceMap.getString("openProject.error.starting"), e.error);
   }
 }
  /** Selects a file to use as target for the report processing. */
  protected void performSelectFile() {
    if (fileChooser == null) {
      fileChooser = new JFileChooser();
      final FilesystemFilter filter =
          new FilesystemFilter(
              CSVDataExportDialog.CSV_FILE_EXTENSION,
              getResources().getString("csvexportdialog.csv-file-description")); // $NON-NLS-1$
      fileChooser.addChoosableFileFilter(filter);
      fileChooser.setMultiSelectionEnabled(false);
    }

    fileChooser.setSelectedFile(new File(getFilename()));
    final int option = fileChooser.showSaveDialog(this);
    if (option == JFileChooser.APPROVE_OPTION) {
      final File selFile = fileChooser.getSelectedFile();
      String selFileName = selFile.getAbsolutePath();

      // Test if ends on csv
      if (StringUtils.endsWithIgnoreCase(selFileName, CSVDataExportDialog.CSV_FILE_EXTENSION)
          == false) {
        selFileName = selFileName + CSVDataExportDialog.CSV_FILE_EXTENSION;
      }
      setFilename(selFileName);
    }
  }
示例#19
0
 @Override
 public void actionPerformed(ActionEvent e) {
   if (e.getActionCommand().equals(CANCELAR)) {
     PPal.get().seleccionarPrimerFactura();
   } else if (e.getActionCommand().equals(CONFIRMAR)) {
     PPal.get().agregarFactura(getNewFactura());
   } else if (e.getActionCommand().equals(CARGAR)) {
     JFileChooser chooser = new JFileChooser();
     FileNameExtensionFilter filter =
         new FileNameExtensionFilter("JPG & GIF Images", "jpg", "gif");
     chooser.setFileFilter(filter);
     int returnVal = chooser.showOpenDialog(this);
     if (returnVal == JFileChooser.APPROVE_OPTION) {
       try {
         txtBono.setText(ManagerQR.readQRCode(chooser.getSelectedFile()));
       } catch (FileNotFoundException e1) {
         // TODO Auto-generated catch block
         e1.printStackTrace();
       } catch (NotFoundException e1) {
         // TODO Auto-generated catch block
         e1.printStackTrace();
       } catch (IOException e1) {
         // TODO Auto-generated catch block
         e1.printStackTrace();
       }
     }
   }
 }
示例#20
0
  {
    //        fileChooser = new JFileChooser(new File("."));
    JFileChooser fc = null;
    try {
      fc = new JFileChooser();
      fc.setFileFilter(
          new javax.swing.filechooser.FileFilter() {
            final Matcher matchLevelFile = Pattern.compile(".*\\.svg[z]?").matcher("");

            public boolean accept(File file) {
              if (file.isDirectory()) return true;

              matchLevelFile.reset(file.getName());
              return matchLevelFile.matches();
            }

            public String getDescription() {
              return "SVG file (*.svg, *.svgz)";
            }
          });
    } catch (AccessControlException ex) {
      // Do not create file chooser if webstart refuses permissions
    }
    fileChooser = fc;
  }
示例#21
0
 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);
 }
示例#22
0
  @Override
  public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand() == locale.btOpen()) {
      final JFileChooser fc = new JFileChooser();
      fc.setFileFilter(
          new FileFilter() {

            @Override
            public String getDescription() {
              return "MATSim config file";
            }

            @Override
            public boolean accept(File f) {
              if (f.isDirectory()) {
                return true;
              }
              if (f.getName().endsWith("xml")) {
                return true;
              }
              return false;
            }
          });

    } else if (e.getActionCommand() == locale.btSave()) {
      if (this.roadClosures.size() > 0) {
        boolean saved = ConfigIO.saveRoadClosures(controller, roadClosures);
        // TODO add confirmation dialog?

      }
    }
  }
    public void actionPerformed(ActionEvent e) {
      System.out.println(e.getActionCommand());

      // handle the event of the "Share" button being clicked
      if (e.getSource().equals(shareButton)) {
        // prompt the user to choose a file to share
        int returnVal = fc.showOpenDialog(this);

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

          // this is where a real application would open the file.
          System.out.println("Sharing: " + file.getName() + ".");
          try {
            // ContentManager.share() will automatically create a
            // ContentAdvertisement for a file and begin sharing it.
            // If more control in the construction of the
            // ContentAdvertisement is needed, there are also
            // overloaded versions of share() that allow the
            // advertised name, content type, and other metadata to
            // in the advertisement to be specified.
            cms.getContentManager().share(file);

            // update the list of shared content
            updateLocalFiles();

          } catch (IOException ex) {
            System.out.println("Share command failed.");
          }
        } else {
          System.out.println("Share command cancelled by user.");
        }
      }
    }
示例#24
0
  /** @param args */
  public static void main(String[] args) {
    JFileChooser chooser = new JFileChooser();
    chooser.showOpenDialog(null);
    File file = chooser.getSelectedFile();
    String indir = file.getAbsolutePath();
    BufferedImage out = null;
    try (BufferedReader br = new BufferedReader(new FileReader(file))) {
      out = new BufferedImage(256, 1, BufferedImage.TYPE_INT_RGB);
      String sCurrentLine;
      int pos = 0;
      while ((sCurrentLine = br.readLine()) != null) {
        String[] values = sCurrentLine.split(" ");
        Color ocol =
            new Color(
                Integer.valueOf(values[0]), Integer.valueOf(values[1]), Integer.valueOf(values[2]));
        out.setRGB(pos, 0, ocol.getRGB());
        pos++;
      }
      File outputimage = new File("C:\\ydkj\\palette", "GENPALETTE.bmp");
      ImageIO.write(out, "bmp", outputimage);

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
示例#25
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();
   }
 }
  protected FileChooserPanel getFileChooserPanel() {
    // LoadFileDataSourceQueryChoosers share the same JFileChooser so that the user's
    // work is not lost when he switches data-source types. Also, the JFileChooser options
    // are set once because setting them is slow (freezes the GUI for a few seconds).
    // [Jon Aquino]
    if (blackboard().get(FILE_CHOOSER_PANEL_KEY) == null) {
      final JFileChooser fileChooser = GUIUtil.createJFileChooserWithExistenceChecking();
      fileChooser.setMultiSelectionEnabled(true);
      fileChooser.setControlButtonsAreShown(false);

      blackboard().put(FILE_CHOOSER_KEY, fileChooser);
      blackboard().put(FILE_CHOOSER_PANEL_KEY, new FileChooserPanel(fileChooser, blackboard()));

      if (PersistentBlackboardPlugIn.get(context).get(FILE_CHOOSER_DIRECTORY_KEY) != null) {
        fileChooser.setCurrentDirectory(
            new File(
                (String) PersistentBlackboardPlugIn.get(context).get(FILE_CHOOSER_DIRECTORY_KEY)));
        ((FileChooserPanel) blackboard().get(FILE_CHOOSER_PANEL_KEY))
            .setSelectedCoordinateSystem(
                (String)
                    PersistentBlackboardPlugIn.get(context)
                        .get(FILE_CHOOSER_COORDINATE_SYSTEM_KEY));
      }

      if (CoordinateSystemSupport.isEnabled(blackboard())) {
        ((FileChooserPanel) blackboard().get(FILE_CHOOSER_PANEL_KEY))
            .setCoordinateSystemComboBoxVisible(true);
      }
    }

    return (FileChooserPanel) blackboard().get(FILE_CHOOSER_PANEL_KEY);
  }
  private void saveStyle() {
    if (_openedDocument == null) return;

    _openedDocument.putContents(_editorPane.getText());

    try {
      if (!_openedDocument.isSaved()) {
        JFileChooser fileChooser = new JFileChooser();
        int result = fileChooser.showSaveDialog(this);
        if (result == JFileChooser.APPROVE_OPTION) {
          File f = fileChooser.getSelectedFile();
          String path = f.getAbsolutePath();

          _openedDocument.saveStyle(path);
          refreshUI();
        }
      } else {
        _openedDocument.saveStyle();
        refreshUI();
      }

    } catch (Exception e) {
      JOptionPane.showMessageDialog(
          this, e.toString(), "Error while saving style", JOptionPane.ERROR_MESSAGE);
    }
  }
  private void openStyle() {
    try {
      JFileChooser fileChooser = new JFileChooser();
      int result = fileChooser.showOpenDialog(this);
      if (result == JFileChooser.APPROVE_OPTION) {
        File f = fileChooser.getSelectedFile();
        if (!f.exists()) throw new Exception("File doesn't exists!");

        String path = f.getAbsolutePath();
        // String path = Constants.ROOT_MAPSFORGE_DIR + "\\styles\\default.xml";

        if (_openedDocument != null) closeStyle();

        refreshUI();

        _openedDocument = StyleDocument.loadStyle(path);
        _editorPane.setText(_openedDocument.getContent());

        refreshUI();
        _editorPane.addCaretListener(_caretListener);
      }

    } catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(
          this, e.toString(), "Error while opening style", JOptionPane.ERROR_MESSAGE);
    }
  }
  private void changeMap() {
    try {
      JFileChooser fileChooser = new JFileChooser();
      int result = fileChooser.showOpenDialog(this);
      if (result == JFileChooser.APPROVE_OPTION) {
        File f = fileChooser.getSelectedFile();
        if (!f.exists()) throw new Exception("File doesn't exists!");

        String path = f.getAbsolutePath();
        // String path = Constants.ROOT_MAPSFORGE_DIR + "\\styles\\default.xml";

        Constants.MAP_FILE = path;

        File fProperties = new File("properties.props");

        Properties props = new Properties();
        props.load(new FileInputStream(fProperties));
        props.put("mapFile", Constants.MAP_FILE);
        props.save(new FileOutputStream(fProperties), "");

        MapFile mf = new MapFile(f);
        double lat = mf.boundingBox().getCenterPoint().latitude;
        double lng = mf.boundingBox().getCenterPoint().longitude;
        _mapView.getModel().mapViewPosition.setCenter(new LatLong(lat, lng));

        refreshUI();
      }
    } catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(
          this, e.toString(), "Error while changing map file", JOptionPane.ERROR_MESSAGE);
    }
  }
示例#30
-1
  @SuppressWarnings("serial")
  public void checkDirectory() {
    File RWDirectory;

    if (firstLoad == "yes") {
      // Allows selecting of Folders.
      JFileChooser chooser =
          new JFileChooser(new File(".")) {

            public void approveSelection() {
              if (getSelectedFile().isFile()) {
                return;
              } else super.approveSelection();
            }
          };

      chooser.setDialogTitle("Choose RimWorld Game Folder");

      int returnVal = chooser.showOpenDialog(null);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        RWDirectory = chooser.getSelectedFile();

        setRWDirectory(RWDirectory);
        setModDirectory(new File(RWDirectory + "//Mods//"));
        savePref();
      }
    }
  }