Java Code Examples for javax.swing.JFileChooser#FILES_ONLY

The following examples show how to use javax.swing.JFileChooser#FILES_ONLY . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectButtonActionPerformed
    if (!isSane())
        return;

    int selectionType = importer.canImportDirectories() ? JFileChooser.FILES_AND_DIRECTORIES : JFileChooser.FILES_ONLY;
    String[][] filetypes = importer.getFileExtensions(properties.getImportOpensZipFiles());

    File importFile = SelectFile.selectFile(this, "Select " + importer.getFormatName() + " file to import",
            properties.getDefaultImportDir(), false, false, selectionType, filetypes);
    if (importFile != null) {
        filenameTextField.setText(importFile.getPath());
        // Tell the user that the data in the tree importer is obsolete.
        treeImporter.clear();
        try {
            properties.setDefaultImportDir(importFile.getParentFile().getCanonicalPath());
        } catch (IOException ex) {
            // we may ignore this
        }
    }
}
 
Example 2
Source Project: uima-uimaj   File: FileSelector.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void focusLost(FocusEvent aEvent) {
  if (aEvent.getComponent() == this.field) {
    String path = this.getSelected();
    if (path.length() == 0) {
      path = System.getProperty("user.dir");
    }
    File file = new File(path);

    if (this.fileChooser.getFileSelectionMode() == JFileChooser.FILES_ONLY && file.isDirectory()) {
      this.fileChooser.setCurrentDirectory(file);
    } else {
      this.fileChooser.setSelectedFile(file);
    }
  }
  if (externalFl != null) {
    externalFl.focusLost(aEvent);
  }

}
 
Example 3
Source Project: uima-uimaj   File: FileSelector.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Sets the selected.
 *
 * @param s the new selected
 */
public void setSelected(String s) {
  field.setText(s);
  previousValue = s;
  if (s == null || s.length() == 0) {
    s = System.getProperty("user.dir");
  }
  File file = new File(s);

  //only modify file chooser if it has already been created
  if (this.fileChooser != null) {
    if (this.fileChooser.getFileSelectionMode() == JFileChooser.FILES_ONLY && file.isDirectory()) {
      this.fileChooser.setCurrentDirectory(file);
    } else {
      this.fileChooser.setSelectedFile(file);
    }
  }
}
 
Example 4
Source Project: uima-uimaj   File: FileSelector.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void focusLost(FocusEvent aEvent) {
  if (aEvent.getComponent() == this.field) {
    //only modify file chooser if it has already been created
    if (this.fileChooser != null) {
      String path = this.getSelected();
      if (path.length() == 0) {
        path = System.getProperty("user.dir");
      }
      File file = new File(path);

      if (this.fileChooser.getFileSelectionMode() == JFileChooser.FILES_ONLY && file.isDirectory()) {
        this.fileChooser.setCurrentDirectory(file);
      } else {
        this.fileChooser.setSelectedFile(file);
      }
    }
  }

}
 
Example 5
Source Project: incubator-iotdb   File: MainPanel.java    License: Apache License 2.0 5 votes vote down vote up
MainPanel(LogVisualizer logVisualizer, ExecutePlanCallback executePlanCallback,
    Properties properties, PropertyChangeCallback propertyChangeCallback) {
  this.visualizer = logVisualizer;
  this.propertyChangeCallback = propertyChangeCallback;

  setLayout(null);

  logFileSelectionBox = new FileSelectionBox("LogFilePath", this::onLogFileSelected,
      properties.getProperty(GuiPropertyKeys.DEFAULT_LOG_FILE_PATH.getKey()), JFileChooser.FILES_AND_DIRECTORIES);
  logFileSelectionBox.setLocation(0, 0);
  logFileSelectionBox.setSize(380, 40);

  parserPropertyBox = new FileSelectionBox("ParserPropertyFilePath",
      this::onParserPropertySelected, properties.getProperty(GuiPropertyKeys
      .DEFAULT_PARSER_FILE_PATH.getKey()), JFileChooser.FILES_ONLY);
  parserPropertyBox.setLocation(0, 45);
  parserPropertyBox.setSize(380, 40);

  loadLogBox = new LoadLogBox(logVisualizer);
  loadLogBox.setLocation(450, 0);
  loadLogBox.setSize(300, 50);

  planBox = new PlanBox(logVisualizer, executePlanCallback, properties.getProperty(GuiPropertyKeys
      .DEFAULT_PLAN_PATH.getKey()), propertyChangeCallback);
  planBox.setLocation(0, 100);
  planBox.setSize(750, 430);

  add(logFileSelectionBox);
  add(parserPropertyBox);
  add(loadLogBox);
  add(planBox);
}
 
Example 6
Source Project: netbeans   File: FileChooserBuilderTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test of setFilesOnly method, of class FileChooserBuilder.
 */
public void testSetFilesOnly() {
    FileChooserBuilder instance = new FileChooserBuilder("y");
    boolean filesOnly = instance.createFileChooser().getFileSelectionMode() == JFileChooser.FILES_ONLY;
    assertFalse(filesOnly);
    instance.setFilesOnly(true);
    filesOnly = instance.createFileChooser().getFileSelectionMode() == JFileChooser.FILES_ONLY;
    assertTrue(filesOnly);
}
 
Example 7
public CognizantITSFileChooser(Image i, String title, SelectionMode selMode, File startIn, FileFilter selector) {
    super(startIn);
    ICON_14 = new ImageIcon(i.getScaledInstance(13, 13, 4));
    this.selector = selector;
    setDialogTitle(title);
    setMultiSelectionEnabled(false);
    setFileSelectionMode(selMode.ordinal());
    setAcceptAllFileFilterUsed(false);
    if (JFileChooser.FILES_ONLY != selMode.ordinal()) {
        addPropertyChangeListener((PropertyChangeListener) this);
    }
}
 
Example 8
public MinecraftJarBrowserLine(Frame parent)
{
	// Auto fill this with the found minecraft jar
	File minecraftJar = Minecraft.findMinecraftJar();

	// TODO: Handle minecraft jar not findable
	// ..
	
	line = new FileBrowserLine(parent, "Minecraft.jar:", "Open", minecraftJar, JFileChooser.FILES_ONLY, new JarFileFilter());
	line.setFileListener( new FileChangedHandler() );
	
	onInternalFileChanged();
}
 
Example 9
Source Project: uima-uimaj   File: FileSelector.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets the selected.
 *
 * @param s the new selected
 */
public void setSelected(String s) {
  s = s.trim();
  field.setText(s);
  if (s.length() == 0) {
    s = System.getProperty("user.dir");
  }
  File file = new File(s);

  if (this.fileChooser.getFileSelectionMode() == JFileChooser.FILES_ONLY && file.isDirectory()) {
    this.fileChooser.setCurrentDirectory(file);
  } else {
    this.fileChooser.setSelectedFile(file);
  }
}
 
Example 10
Source Project: netbeans   File: FileEditor.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * This method is called by the IDE to pass
 * the environment to the property editor.
 * @param env Environment passed by the ide.
 */
public void attachEnv(PropertyEnv env) {
    this.env = env;

    // clearing to defaults
    directories = true;
    files = true;
    fileFilter = null;
    fileHiding = false;

    Object dirs = env.getFeatureDescriptor().getValue(PROPERTY_SHOW_DIRECTORIES);
    if (dirs instanceof Boolean) {
        directories = ((Boolean)dirs).booleanValue();
    } // XXX else if != null, warn
    Object fil = env.getFeatureDescriptor().getValue(PROPERTY_SHOW_FILES);
    if (fil instanceof Boolean) {
        files = ((Boolean)fil).booleanValue();
    } // XXX else if != null, warn
    Object filter = env.getFeatureDescriptor().getValue(PROPERTY_FILTER);
    if (filter instanceof FilenameFilter) {
        fileFilter = new DelegatingFilenameFilter((FilenameFilter)filter);
    } else if (filter instanceof javax.swing.filechooser.FileFilter) {
        fileFilter = (javax.swing.filechooser.FileFilter)filter;
    } else if (filter instanceof java.io.FileFilter) {
        fileFilter = new DelegatingFileFilter((java.io.FileFilter)filter);
    } // XXX else if != null, warn

    Object curDir = env.getFeatureDescriptor().getValue(PROPERTY_CURRENT_DIR);
    if (curDir instanceof File) {
        currentDirectory = (File)curDir;
        if(! currentDirectory.isDirectory()) {
            Logger.getAnonymousLogger().warning("java.io.File will not accept currentDir=" + currentDirectory); // NOI18N
            currentDirectory = null;
        }
    } // XXX else if != null, warn

    Object baseDir = env.getFeatureDescriptor().getValue(PROPERTY_BASE_DIR);
    if(baseDir instanceof File) {
        baseDirectory = (File)baseDir;
        // As baseDir accept only directories in their absolute form.
        if(!baseDirectory.isDirectory() || !baseDirectory.isAbsolute()) {
            Logger.getAnonymousLogger().warning("java.io.File will not accept baseDir=" + baseDirectory); // NOI18N
            baseDirectory = null;
        }
    } // XXX else if != null, warn
    if (files) {
        mode = directories ? JFileChooser.FILES_AND_DIRECTORIES : 
            JFileChooser.FILES_ONLY;
    } else {
        mode = directories ? JFileChooser.DIRECTORIES_ONLY :
            JFileChooser.FILES_AND_DIRECTORIES; // both false, what now? XXX warn
    }
    
    Object fileHide = env.getFeatureDescriptor().getValue(PROPERTY_FILE_HIDING);
    if (fileHide instanceof Boolean) {
        fileHiding = ((Boolean)fileHide).booleanValue();
    }
    
    if (env.getFeatureDescriptor() instanceof Node.Property){
        Node.Property prop = (Node.Property)env.getFeatureDescriptor();
        editable = prop.canWrite();
    }
}
 
Example 11
public static FileChooserActionListener createFileChooserActionListener(final JTextComponent textComponent, final Component parent) {
	return new FileChooserActionListener(textComponent, JFileChooser.FILES_ONLY, parent);
}
 
Example 12
@Override
protected int getFileChooserSelectionMode() {
  return JFileChooser.FILES_ONLY;
}