javax.swing.JFileChooser.getFileSelectionMode()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(123)

本文整理了Java中javax.swing.JFileChooser.getFileSelectionMode()方法的一些代码示例,展示了JFileChooser.getFileSelectionMode()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JFileChooser.getFileSelectionMode()方法的具体详情如下:
包路径:javax.swing.JFileChooser
类名称:JFileChooser
方法名:getFileSelectionMode

JFileChooser.getFileSelectionMode介绍

暂无

代码示例

代码示例来源:origin: org.gephi/directory-chooser

/** Returns dirchooser for DIRECTORIES_ONLY, default filechooser for other
 * selection modes.
 */
private static Class<? extends FileChooserUI> getCurChooser (JFileChooser fc) {
  if (fc.getFileSelectionMode() == JFileChooser.DIRECTORIES_ONLY) {
    return DirectoryChooserUI.class;
  }
  return Module.getOrigChooser();
}

代码示例来源:origin: org.apache.uima/uimaj-tools

/**
 * 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);
 }
}

代码示例来源:origin: org.apache.uima/uimaj-tools

/**
 * 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);
  }
 }
}

代码示例来源:origin: org.gephi/directory-chooser

public Vector<File> buildList(String text, File[] children) {
  Vector<File> files = new Vector<>(children.length);
  
  for(int i = children.length - 1; i >= 0; i--) {
    File completion = children[i];
    
    if(fileChooser.accept(completion)) {
      String path = completion.getAbsolutePath();
      
      if (path.regionMatches(true, 0, text, 0, text.length())) {
        
        if(fileChooser.getFileSelectionMode() == JFileChooser.DIRECTORIES_ONLY) {
          if(completion.isDirectory()) {
            files.add(completion);
          }
        } else if(fileChooser.getFileSelectionMode() == JFileChooser.FILES_ONLY) {
          if(completion.isFile()) {
            files.add(completion);
          }
        } else if(fileChooser.getFileSelectionMode() == JFileChooser.FILES_AND_DIRECTORIES) {
          files.add(completion);
        }
      }
    }
  }
  
  Collections.sort(files, DirectoryNode.FILE_NAME_COMPARATOR);
  return files;
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

@Override
public Object getValue() {
 String path = getAsText();
 if (path != null && path.length() > 0) {
  return new File(path);
 }
 JFileChooser embeddedEditor = (JFileChooser) m_fileEditor.getCustomEditor();
 if (embeddedEditor.getFileSelectionMode() == JFileChooser.DIRECTORIES_ONLY) {
  return new File(".");
 } else {
  return new File("");
 }
}

代码示例来源:origin: Waikato/weka-trunk

@Override
public Object getValue() {
 String path = getAsText();
 if (path != null && path.length() > 0) {
  return new File(path);
 }
 JFileChooser embeddedEditor = (JFileChooser) m_fileEditor.getCustomEditor();
 if (embeddedEditor.getFileSelectionMode() == JFileChooser.DIRECTORIES_ONLY) {
  return new File(".");
 } else {
  return new File("");
 }
}

代码示例来源:origin: org.apache.uima/uimaj-tools

@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);
   }
  }
 }
}

代码示例来源:origin: org.apache.uima/uimaj-tools

@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);
 }
}

代码示例来源:origin: joel-costigliola/assertj-swing

@RunsInCurrentThread
private static void checkSelectionMode(JFileChooser fileChooser, File file) {
 int mode = fileChooser.getFileSelectionMode();
 if (mode == FILES_ONLY && !file.isFile()) {
  throw cannotSelectFile(file, "the file chooser can only open files");
 }
 if (mode == DIRECTORIES_ONLY && !file.isDirectory()) {
  throw cannotSelectFile(file, "the file chooser can only open directories");
 }
}

代码示例来源:origin: UISpec4J/UISpec4J

public void process(JFileChooser fileChooser) {
 int actualMode = fileChooser.getFileSelectionMode();
 if (actualMode != expectedMode) {
  AssertAdapter.fail(getMessage(actualMode));
 }
}

代码示例来源:origin: Waikato/weka-trunk

public void setCurrentDirectory(File directory) {
 String tmpString = directory.toString();
 if (Environment.containsEnvVariables(tmpString)) {
  try {
   tmpString = m_env.substitute(tmpString);
  } catch (Exception ex) {
   // ignore
  }
 }
 File tmp2 = new File((new File(tmpString)).getAbsolutePath());
 JFileChooser embeddedEditor = (JFileChooser) m_fileEditor.getCustomEditor();
 if (tmp2.isDirectory()) {
  embeddedEditor.setCurrentDirectory(tmp2);
  if (embeddedEditor.getFileSelectionMode() == JFileChooser.DIRECTORIES_ONLY) {
   super.setAsText(directory.toString());
  }
 } else {
  embeddedEditor.setSelectedFile(tmp2);
  if (embeddedEditor.getFileSelectionMode() == JFileChooser.FILES_ONLY) {
   super.setAsText(directory.toString());
  }
 }
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

public void setCurrentDirectory(File directory) {
 String tmpString = directory.toString();
 if (Environment.containsEnvVariables(tmpString)) {
  try {
   tmpString = m_env.substitute(tmpString);
  } catch (Exception ex) {
   // ignore
  }
 }
 File tmp2 = new File((new File(tmpString)).getAbsolutePath());
 JFileChooser embeddedEditor = (JFileChooser) m_fileEditor.getCustomEditor();
 if (tmp2.isDirectory()) {
  embeddedEditor.setCurrentDirectory(tmp2);
  if (embeddedEditor.getFileSelectionMode() == JFileChooser.DIRECTORIES_ONLY) {
   super.setAsText(directory.toString());
  }
 } else {
  embeddedEditor.setSelectedFile(tmp2);
  if (embeddedEditor.getFileSelectionMode() == JFileChooser.FILES_ONLY) {
   super.setAsText(directory.toString());
  }
 }
}

代码示例来源:origin: org.gephi/directory-chooser

int mode = chooser.getFileSelectionMode();
if (mode == JFileChooser.DIRECTORIES_ONLY) {
  for (int i = 0; i < files.length; i++) {

代码示例来源:origin: abbot/abbot

/** Sets the selected file. */
public void actionSetSelectedFile(Component c, final File file) {
  final JFileChooser chooser = (JFileChooser)c;
  int mode = chooser.getFileSelectionMode();
  if (mode == JFileChooser.FILES_ONLY && file.isDirectory()) {
    String msg = Strings.get("tester.JFileChooser.files_only");
    throw new ActionFailedException(msg); 
  }
  if (mode == JFileChooser.DIRECTORIES_ONLY && !file.isDirectory()) {
    String msg = Strings.get("tester.JFileChooser.dirs_only");
    throw new ActionFailedException(msg);
  }
  invokeAndWait(new Runnable() { public void run() {
    chooser.setSelectedFile(file);
  }});
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/toniclf

&& ((File) objects[0]).isDirectory()
  && chooser.isTraversable(((File) objects[0]))
  && (chooser.getFileSelectionMode()
    == JFileChooser.FILES_ONLY
    || !fsv.isFileSystem(((File) objects[0]))))
&& file.isDirectory()
&& chooser.isTraversable(file)
&& (chooser.getFileSelectionMode() == JFileChooser.FILES_ONLY
  || !fsv.isFileSystem(file)))

代码示例来源:origin: net.anwiba.commons/anwiba-commons-swing-core

return;
if (fileChooser.getFileSelectionMode() != JFileChooser.DIRECTORIES_ONLY) {
 return;

相关文章

JFileChooser类方法