List of usage examples for javax.swing JFileChooser setCurrentDirectory
@BeanProperty(preferred = true, description = "The directory that the JFileChooser is showing files of.") public void setCurrentDirectory(File dir)
From source file:tauargus.utils.TauArgusUtils.java
public static void getDataDirFromRegistry(javax.swing.JFileChooser fileChooser) { String hs = SystemUtils.getRegString("general", "datadir", ""); if (!hs.equals("")) { File file = new File(hs); fileChooser.setCurrentDirectory(file); }//from w w w. ja v a 2s .c om }
From source file:ui.FtpDialog.java
private void uploadFileBtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_uploadFileBtActionPerformed if (connected) { JFileChooser uploadFileChooser = new JFileChooser(); uploadFileChooser.setPreferredSize(new Dimension(650, 450)); File rootDirectory = new File("C:\\"); uploadFileChooser .setCurrentDirectory(uploadFileChooser.getFileSystemView().getParentDirectory(rootDirectory)); uploadFileChooser.setDialogTitle("File to upload"); int result = uploadFileChooser.showOpenDialog(this); switch (result) { case JFileChooser.APPROVE_OPTION: selectedFile = uploadFileChooser.getSelectedFile(); Trace.trc("File to upload: " + selectedFile.getName() + " File size: " + FileUtils.byteCountToDisplaySize(selectedFile.length())); if (connected) { if (!selectedFile.equals(null)) { try { input = new FileInputStream(selectedFile); } catch (IOException e) { e.printStackTrace(); }//from w w w . j a v a 2 s. c om pb = new ProgressBar(); pb.execute(); uploadFileChooser.setVisible(false); } else { JOptionPane.showMessageDialog(rootFrame, "No file to upload has been chosen!", "Error", JOptionPane.ERROR_MESSAGE); } } else { JOptionPane.showMessageDialog(rootFrame, "Not connected to a server, cannot upload file!", "Error", JOptionPane.ERROR_MESSAGE); } break; case JFileChooser.CANCEL_OPTION: Trace.trc("Closing file chooser dialog"); break; case JFileChooser.ERROR_OPTION: Trace.trc("An error occured"); break; } } else { JOptionPane.showMessageDialog(rootFrame, "Not connected to a server, cannot upload file!", "Error", JOptionPane.ERROR_MESSAGE); } }
From source file:uiuc.dm.miningTools.ui.ParametersSelectionFrame.java
@Override public void actionPerformed(ActionEvent e) { String selectedFunction = (String) functionCombo.getSelectedItem(); if (e.getSource() == functionCombo) { if (selectedFunction.equals(comboOptions.getFunctionOptions()[0])) { // show necessary input arguments for computing distance matrix showPanel(displayInstructionPanel); hidePanel(performancePanel); hidePanel(miningFunctionParamsSelectionPanel); hidePanel(plotDensityMapPanel); } else if (selectedFunction.equals(comboOptions.getFunctionOptions()[1])) { // show necessary input arguments for computing sigLevel showPanel(miningFunctionParamsSelectionPanel, MINING_FUNC_PARAMS_SELECTION_PANEL_TITLE); showPanel(sigLevelParamsPanel); showPanel(displayInstructionPanel); hidePanel(plotMapParamsPanel); hidePanel(performancePanel); hidePanel(this.followingParamsPanel); hidePanel(this.plotDensityMapPanel); } else if (selectedFunction.equals(comboOptions.getFunctionOptions()[2])) { // show necessary input arguments for ploting a map showPanel(miningFunctionParamsSelectionPanel, MINING_FUNC_PARAMS_SELECTION_PANEL_TITLE); showPanel(plotMapParamsPanel); hidePanel(sigLevelParamsPanel); hidePanel(performancePanel); hidePanel(displayInstructionPanel); hidePanel(this.followingParamsPanel); hidePanel(this.plotDensityMapPanel); } else if (selectedFunction.equals(comboOptions.getFunctionOptions()[3])) { showPanel(miningFunctionParamsSelectionPanel, MINING_FUNC_PARAMS_SELECTION_PANEL_TITLE); showPanel(this.followingParamsPanel); showPanel(displayInstructionPanel); hidePanel(plotMapParamsPanel); hidePanel(sigLevelParamsPanel); hidePanel(performancePanel); hidePanel(this.plotDensityMapPanel); } else if (selectedFunction.equals(comboOptions.getFunctionOptions()[4])) { showPanel(miningFunctionParamsSelectionPanel, MINING_FUNC_PARAMS_SELECTION_PANEL_TITLE); showPanel(this.plotDensityMapPanel); hidePanel(this.followingParamsPanel); hidePanel(displayInstructionPanel); hidePanel(plotMapParamsPanel); hidePanel(sigLevelParamsPanel); hidePanel(performancePanel); }/* w ww. j a v a 2 s. co m*/ } if (e.getSource() == useLocalCopyButton) { useLocalCopyButton.setEnabled(false); loadDatasetButton.setEnabled(false); downloadOnlineButton.setEnabled(false); stats.setText(""); showPanel(downloadDatasetProgressPanel); datasetCombo.setEnabled(false); downloadDatasetProgressBar.setValue(0); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); showPanel(selectTimespanPanel); showPanel(displayStatsPanel, DISPLAY_STATS_PANEL_TITLE); stats.setText("Fetching License Terms from server ..."); String selectedDatasetName = (String) datasetCombo.getSelectedItem(); downloadTask = new DownloadDatasetTask(selectedDatasetName); downloadTask.addPropertyChangeListener(this); downloadTask.execute(); } if (e.getSource() == downloadOnlineButton) { setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); useLocalCopyButton.setEnabled(false); loadDatasetButton.setEnabled(false); downloadOnlineButton.setEnabled(false); hidePanel(interpolationParamsSelectionPanel); hidePanel(miningFunctionSelectionPanel); hidePanel(miningFunctionParamsSelectionPanel); hidePanel(displayInstructionPanel); hidePanel(performancePanel); hidePanel(displayStatsPanel); hidePanel(selectIndividualsPanel); hidePanel(selectTimespanPanel); stats.setText(""); showPanel(downloadDatasetProgressPanel); showPanel(displayStatsPanel, DISPLAY_STATS_PANEL_TITLE); instructionLabel.setText(""); datasetCombo.setEnabled(false); downloadDatasetProgressBar.setValue(0); stats.setText("Fetching License Terms from server ..."); String selectedDatasetName = (String) datasetCombo.getSelectedItem(); downloadTask = new DownloadDatasetTask(selectedDatasetName, true); downloadTask.addPropertyChangeListener(this); downloadTask.execute(); } if (e.getSource() == loadDatasetButton) { if (useLocalCopyButton != null) { useLocalCopyButton.setEnabled(false); } if (downloadOnlineButton != null) { downloadOnlineButton.setEnabled(false); } loadDatasetButton.setEnabled(false); JFileChooser fc = new JFileChooser(); String workingDir = System.getProperty("user.dir"); fc.setCurrentDirectory(new File(workingDir)); int returnVal = fc.showOpenDialog(ParametersSelectionFrame.this); if (returnVal == JFileChooser.APPROVE_OPTION) { final File file = fc.getSelectedFile(); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); System.out.println("Opening " + file.getName()); downloadDatasetProgressBar.setVisible(true); downloadDatasetProgressBar.setIndeterminate(true); downloadDatasetProgressBar.setStringPainted(false); hidePanel(interpolationParamsSelectionPanel); hidePanel(miningFunctionSelectionPanel); hidePanel(miningFunctionParamsSelectionPanel); hidePanel(displayInstructionPanel); hidePanel(performancePanel); hidePanel(displayStatsPanel); hidePanel(selectIndividualsPanel); hidePanel(selectTimespanPanel); stats.setText(""); showPanel(downloadDatasetProgressPanel); showPanel(displayStatsPanel, DISPLAY_STATS_PANEL_TITLE); instructionLabel.setText(""); LoadDatasetTask loadDatasetTask = new LoadDatasetTask(file.getAbsolutePath()) { @Override public void done() { if (this.isFailToParse()) { stats.setText(this.getErrorMsg()); downloadDatasetProgressPanel.setVisible(false); hidePanel(interpolationParamsSelectionPanel); hidePanel(miningFunctionSelectionPanel); hidePanel(miningFunctionParamsSelectionPanel); hidePanel(displayInstructionPanel); hidePanel(performancePanel); hidePanel(selectIndividualsPanel); hidePanel(selectTimespanPanel); } else { trajsMap = this.getTrajsMap(); ArrayList<Trajectory> trajs = new ArrayList(trajsMap.values()); Dataset dataset = new Dataset(); dataset.storeData(trajs, trajsMap); dataset.setDatasetName(file.getName()); curSelectedDatasetName = file.getName(); initIndividualNames(); downloadDatasetProgressPanel.setVisible(false); showStats(dataset); initSelectTimespanRange(dataset.getStartTime(), dataset.getEndTime()); showPanel(selectTimespanPanel); showPanel(interpolationParamsSelectionPanel, INTERPOLATE_PARAMS_PANEL_TITLE); showPanel(selectIndividualsPanel); showPanel(selectTimespanPanel); setCursor(null); //turn off the wait cursor downloadDatasetProgressBar.setIndeterminate(false); downloadDatasetProgressBar.setStringPainted(true); } } }; loadDatasetTask.addPropertyChangeListener(this); loadDatasetTask.execute(); } else { System.out.println("Open command cancelled by user."); } loadDatasetButton.setEnabled(true); setCursor(null); if (useLocalCopyButton != null) { useLocalCopyButton.setEnabled(true); } if (downloadOnlineButton != null) { downloadOnlineButton.setEnabled(true); } } if (e.getSource() == goButton) { showPanel(performancePanel); // String selectedDatasetName = (String) datasetCombo // .getSelectedItem(); String selectedDatasetName = curSelectedDatasetName; instructionLabel.setText("Loading ..."); String displayMethod = (String) displayMethodCombo.getSelectedItem(); String gap = (String) gapCombo.getSelectedItem(); String thresGap = (String) thresGapCombo.getSelectedItem(); String numRound = (String) numRoundCombo.getSelectedItem(); String distThres = distThresTextedField.getText(); /*Fei*/ String ml = (String) this.minIntervalLengthField.getText(); String lMax = (String) this.lMaxLabelTextedField.getText(); String dMax = (String) this.dMaxLabelTextedField.getText(); /**/ boolean needInterpolation = this.interpFlag; try { MiningFunctionParameters params; instructionLabel.setText("Running mining algorithm ..."); params = new MiningFunctionParameters(); params.setSelectedDatasetName(selectedDatasetName); params.setSelectedFunction(selectedFunction); params.setDisplayMethod(displayMethod); params.setNeedInterpolation(needInterpolation); params.setGap(gap); params.setThresGap(thresGap); params.setNumRound(numRound); params.setDistThres(distThres); /*Fei*/ int lmax_int = (int) Math.floor(Double.parseDouble(lMax)); params.setlMax("" + lmax_int); params.setdMax(dMax); params.setMinL(ml); /**/ params.setStartTime(selectStartTimePicker.getDate()); params.setEndTime(selectEndTimePicker.getDate()); ArrayList<Trajectory> trajs = getSelectedTrajectories(selectedIndividualIndicesForDv); List<Trajectory> subTrajs = getSubTrajectory(trajs, selectStartTimePicker.getDate(), selectEndTimePicker.getDate()); if (selectedFunction.equalsIgnoreCase("Following mining") && trajs.size() != 2) { JOptionPane.showMessageDialog(this.contentPane, "Please select two animals for following mining."); } else if (!selectedFunction.equalsIgnoreCase("Following mining") && needInterpolation == false) { JOptionPane.showMessageDialog(this.contentPane, "Selected function requires interpolation. Please check the interpolation option."); } else if (!selectedFunction.equalsIgnoreCase("Plotting") && trajs.size() < 2) { JOptionPane.showMessageDialog(this.contentPane, "Please select at least two animals."); } else { boolean dothejob = false; int dialogresult = JOptionPane.YES_OPTION; if (this.aveSampling >= 1 && selectedFunction.equalsIgnoreCase("Following mining")) { dialogresult = JOptionPane.showConfirmDialog(this.contentPane, "Recommend to use dataset having higher sampling rate (less than 1 minper sample) for this function. \n Do you still want to proceed?", "", JOptionPane.YES_NO_OPTION); } if (dialogresult == JOptionPane.YES_OPTION) dothejob = true; if (dothejob) { goButton.setEnabled(false); disablePanel(datasetSelectionPanel); disablePanel(interpolationParamsSelectionPanel); disablePanel(miningFunctionSelectionPanel); disablePanel(miningFunctionParamsSelectionPanel); disablePanel(selectIndividualsPanel); disablePanel(sigLevelParamsPanel); disablePanel(selectTimespanPanel); /*Fei*/ disablePanel(this.followingParamsPanel); /**/ JFrame dvPanel = new DataVisualization(subTrajs, params, this); dvPanel.setLocation(this.getX() + this.getWidth(), this.getY()); dvPanel.setVisible(true); } //this.saveKmlButtonF.setVisible(true); } } catch (Exception ex) { Logger.getLogger(ParametersSelectionFrame.class.getName()).log(Level.SEVERE, null, ex); } } if (e.getSource() == saveDensityMapButton) { String selectedDatasetName = curSelectedDatasetName; String displayMethod = (String) displayMethodCombo.getSelectedItem(); MiningFunctionParameters params = new MiningFunctionParameters(); String gap = (String) gapCombo.getSelectedItem(); String thresGap = (String) thresGapCombo.getSelectedItem(); boolean needInterpolation = false; params.setSelectedDatasetName(selectedDatasetName); params.setSelectedFunction(selectedFunction); params.setDisplayMethod(displayMethod); params.setNeedInterpolation(needInterpolation); params.setGap(gap); params.setThresGap(thresGap); ArrayList<Trajectory> trajs = getSelectedTrajectories(selectedIndividualIndicesForDv); List<Trajectory> subTrajs = getSubTrajectory(trajs, selectStartTimePicker.getDate(), selectEndTimePicker.getDate()); JFrame dvPanel = new DataVisualization(subTrajs, params, this); dvPanel.setLocation(this.getX() + this.getWidth(), this.getY()); dvPanel.setVisible(true); } if (e.getSource() == selectIndividualsButton) { ArrayList<String> selectedNames = ListDialog.showDialog(this, selectIndividualsButton, "All the individuals in the data set: ( hold Ctrl key to select multiple objects)", "Select individuals: ", individualNames, selectedIndividualIndicesForDv, "Index 1234567890"); selectedIndividualIndicesForDv = getSelectedIndices(selectedNames); ArrayList<Trajectory> trajs = getSelectedTrajectories(selectedIndividualIndicesForDv); updateTimeSpanRange(trajs); } if (e.getSource() == saveKmlButton) { String selectedDatasetName = curSelectedDatasetName; String displayMethod = (String) displayMethodCombo.getSelectedItem(); String gap = (String) gapCombo.getSelectedItem(); String thresGap = (String) thresGapCombo.getSelectedItem(); String numRound = (String) numRoundCombo.getSelectedItem(); String distThres = distThresTextedField.getText(); boolean needInterpolation = this.interpFlag; MiningFunctionParameters params = new MiningFunctionParameters(); params.setSelectedDatasetName(selectedDatasetName); params.setSelectedFunction(selectedFunction); params.setDisplayMethod(displayMethod); params.setNeedInterpolation(needInterpolation); params.setGap(gap); params.setThresGap(thresGap); params.setNumRound(numRound); params.setDistThres(distThres); params.setStartTime(selectStartTimePicker.getDate()); params.setEndTime(selectEndTimePicker.getDate()); DateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_HHmmss"); //get current date time with Date() Date date = new Date(); String outputPath = "result/" + "Plot_" + params.getSelectedDatasetName().substring(0, 4).replace(" ", "_") + "_" + dateFormat.format(date) + "/"; new File(outputPath).mkdirs(); ArrayList<Trajectory> trajs = getSelectedTrajectories(selectedIndividualIndicesForDv); List<Trajectory> subTrajs = getSubTrajectory(trajs, selectStartTimePicker.getDate(), selectEndTimePicker.getDate()); JFrame computeKML = new GenerateKMLFile(trajsMap, params, outputPath, subTrajs); computeKML.setVisible(true); } }
From source file:uk.co.modularaudio.componentdesigner.mainframe.actions.OpenFileAction.java
@Override public void actionPerformed(final ActionEvent e) { log.debug("OpenFileAction called."); try {/*from w w w .j ava 2 s. co m*/ int dirtyCheckVal = mainFrameActions.rackNotDirtyOrUserConfirmed(); if (dirtyCheckVal == JOptionPane.YES_OPTION) { // Need to save it - call the save saveFileAction.actionPerformed(e); // Simulate the cancel in the save action if the rack is still dirty. dirtyCheckVal = (fc.isRackDirty() ? JOptionPane.CANCEL_OPTION : JOptionPane.NO_OPTION); } // We don't check for cancel, as it will just fall through if (dirtyCheckVal == JOptionPane.NO_OPTION) { if (fc.isRendering()) { playStopAction.actionPerformed(e); } final JFileChooser openFileChooser = new JFileChooser(); final String patchesDir = upc.getUserPreferencesMVCController().getModel().getUserPatchesModel() .getValue(); openFileChooser.setCurrentDirectory(new File(patchesDir)); final int retVal = openFileChooser.showOpenDialog(mainFrame); if (retVal == JFileChooser.APPROVE_OPTION) { final File f = openFileChooser.getSelectedFile(); if (f != null) { if (log.isDebugEnabled()) { log.debug("Attempting to load from file " + f.getAbsolutePath()); } fc.loadRackFromFile(f.getAbsolutePath()); } } } } catch (final Exception ex) { final String msg = "Exception caught performing open file action: " + ex.toString(); log.error(msg, ex); } }
From source file:uk.co.modularaudio.componentdesigner.mainframe.actions.SaveAsFileAction.java
@Override public void actionPerformed(final ActionEvent e) { log.debug("SaveFileAsAction called"); try {/*from ww w . ja v a 2 s . c o m*/ final JFileChooser saveFileChooser = new JFileChooser(); final String rackDataModelName = fc.getRackDataModelName(); final CDFileSaveAccessory fileSaveAccessory = new CDFileSaveAccessory(rackDataModelName); saveFileChooser.setAccessory(fileSaveAccessory); final String patchesDir = upc.getUserPreferencesMVCController().getModel().getUserPatchesModel() .getValue(); saveFileChooser.setCurrentDirectory(new File(patchesDir)); final int retVal = saveFileChooser.showSaveDialog(mainFrame); if (retVal == JFileChooser.APPROVE_OPTION) { final File f = saveFileChooser.getSelectedFile(); if (f != null) { final String rackName = fileSaveAccessory.getFileName(); if (log.isDebugEnabled()) { log.debug( "Attempting to save to file as " + f.getAbsolutePath() + " with name " + rackName); } fc.saveRackToFile(f.getAbsolutePath(), rackName); } } } catch (final Exception ex) { final String msg = "Exception caught performing save file as action: " + ex.toString(); log.error(msg, ex); } }
From source file:uk.co.modularaudio.mads.base.sampleplayer.ui.SingleSamplePlayerSelectFileUiJComponent.java
@Override public void receiveEvent(final ActionEvent e) { final JFileChooser openFileChooser = new JFileChooser(); final String musicDir = advancedComponentsFrontController.getSoundfileMusicRoot(); openFileChooser.setCurrentDirectory(new File(musicDir)); final int retVal = openFileChooser.showOpenDialog(this); if (retVal == JFileChooser.APPROVE_OPTION) { // Store the directory we navigated to so next open uses it. Will be // specific to the control instance of course final File f = openFileChooser.getSelectedFile(); if (f != null) { if (log.isDebugEnabled()) { log.debug("Attempting to use audio file " + f.getPath()); }/*from www . jav a 2 s . c o m*/ passChangeToInstanceData(f.getAbsolutePath()); } } }
From source file:uk.co.modularaudio.mads.subrack.ui.SubRackMadUiInstance.java
public void saveSubRack(final Component parent) throws DatastoreException, IOException, RecordNotFoundException, MAConstraintViolationException { final JFileChooser saveFileChooser = new JFileChooser(); final CDFileSaveAccessory cdSaveFileNameAccessory = new CDFileSaveAccessory( rackService.getRackName(subRackDataModel)); saveFileChooser.setAccessory(cdSaveFileNameAccessory); final String subRackPatchDir = userPreferencesService.getUserSubRackPatchesDir(); saveFileChooser.setCurrentDirectory(new File(subRackPatchDir)); final int retVal = saveFileChooser.showSaveDialog(parent); if (retVal == JFileChooser.APPROVE_OPTION) { final File f = saveFileChooser.getSelectedFile(); if (f != null) { if (log.isDebugEnabled()) { log.debug("Attempting to save patch to file " + f.getAbsolutePath() + " with name " + cdSaveFileNameAccessory.getFileName()); }/*from w w w.j av a2 s. c om*/ rackService.setRackName(subRackDataModel, cdSaveFileNameAccessory.getFileName()); rackMarshallingService.saveSubRackToFile(subRackDataModel, f.getAbsolutePath()); // Only set dirty to false after successful save rackService.setRackDirty(subRackDataModel, false); } } }
From source file:uk.co.modularaudio.mads.subrack.ui.SubRackMadUiInstance.java
public void choosePatch(final Component parent) throws DatastoreException, IOException, RecordNotFoundException, MAConstraintViolationException { // Open a choose file dialog and then attempt to load // the rack from there. // if successfull, pass it to the MI final JFileChooser openFileChooser = new JFileChooser(); final String subRackPatchDir = userPreferencesService.getUserSubRackPatchesDir(); openFileChooser.setCurrentDirectory(new File(subRackPatchDir)); final int retVal = openFileChooser.showOpenDialog(parent); if (retVal == JFileChooser.APPROVE_OPTION) { final File f = openFileChooser.getSelectedFile(); if (f != null) { final Runnable r = new LoadNewSubrackRunnable(rackMarshallingService, f.getAbsolutePath(), this); jobExecutorService.submitJob(r); }//from w ww .j a v a 2 s . c om } }
From source file:unimelb.distributed_project.gui.JacardSimilarityMeasurePanel.java
/** * Browse button action perform function for word2vecFilePath1. * * @param e ActionEvent object// w ww . j ava 2 s. co m */ private void browseButton1ActionPerformed(ActionEvent e) { JFileChooser jFileChooser = new JFileChooser(); jFileChooser.setCurrentDirectory(new File("/home")); int result = jFileChooser.showOpenDialog(new JFrame()); if (result == JFileChooser.APPROVE_OPTION) { File selectedFile = jFileChooser.getSelectedFile(); word2vecFilePath1 = selectedFile.getPath(); word2vecFilePath1TextField.setText(""); word2vecFilePath1TextField.setText(word2vecFilePath1); log.debug("Selected file: " + word2vecFilePath1); } else if (!word2vecFilePath1TextField.getText().equals("")) { log.debug("Selected file: " + word2vecFilePath2); } else { JOptionPane.showMessageDialog(this.mainFrame, "Please suggest where the word2vec text file is", "file is not selected", JOptionPane.ERROR_MESSAGE); } }
From source file:unimelb.distributed_project.gui.JacardSimilarityMeasurePanel.java
/** * Browse button action perform function for word2vecFilePath2. * * @param e ActionEvent object/*w w w . ja v a2 s . c o m*/ */ private void browseButton2ActionPerformed(ActionEvent e) { JFileChooser jFileChooser = new JFileChooser(); jFileChooser.setCurrentDirectory(new File("/home")); int result = jFileChooser.showOpenDialog(new JFrame()); if (result == JFileChooser.APPROVE_OPTION) { File selectedFile = jFileChooser.getSelectedFile(); word2vecFilePath2 = selectedFile.getPath(); word2vecFilePath2TextField.setText(""); word2vecFilePath2TextField.setText(word2vecFilePath2); log.debug("Selected file: " + word2vecFilePath2); } else if (!word2vecFilePath2TextField.getText().equals("")) { log.debug("Selected file: " + word2vecFilePath2); } else { JOptionPane.showMessageDialog(this.mainFrame, "Please suggest where the word2vec text file is", "file is not selected", JOptionPane.ERROR_MESSAGE); } }