Java Code Examples for javax.swing.JFileChooser#putClientProperty()

The following examples show how to use javax.swing.JFileChooser#putClientProperty() . 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 check out the related API usage on the sidebar.
Example 1
Source File: RemoteSessionChooserFactory.java    From chipster with MIT License 6 votes vote down vote up
public static ServerFileSystemView updateRemoteSessions(SessionManager sessionManager,
		JFileChooser sessionFileChooser, boolean excludeExampleSessions) throws FileBrokerException, MalformedURLException, AuthCancelledException {
	List<DbSession> sessions = sessionManager.listRemoteSessions();
	
	// hide example sessions
	if (excludeExampleSessions) {
		List<DbSession> sessionsToHide = new LinkedList<DbSession>();
		for (DbSession session: sessions) {
			if (session.getName().startsWith(DerbyMetadataServer.DEFAULT_EXAMPLE_SESSION_FOLDER)) {
				sessionsToHide.add(session);
			}
		}
		sessions.removeAll(sessionsToHide);
	}
		
	ServerFileSystemView view = ServerFileSystemView.parseFromPaths(ServerFile.SERVER_SESSION_ROOT_FOLDER, sessions);		
	sessionFileChooser.setFileSystemView(view);
	// without this the GUI doesn't update when a session is removed
	sessionFileChooser.setCurrentDirectory(null);
	sessionFileChooser.setCurrentDirectory(view.getRoot());		
	sessionFileChooser.putClientProperty("sessions", sessions);
	// without this removed sessions are shown after folder change
	sessionFileChooser.updateUI();
	return view;
}
 
Example 2
Source File: SikulixFileChooser.java    From SikuliX1 with MIT License 4 votes vote down vote up
private void processDialog(int selectionMode, String last_dir, String title, int mode, Object[] filters,
                           Object[] result) {
  JFileChooser fchooser = new JFileChooser();
  File fileChoosen = null;
  FileFilter filterChoosen = null;
  if (!last_dir.isEmpty()) {
    fchooser.setCurrentDirectory(new File(last_dir));
  }
  fchooser.setSelectedFile(null);
  fchooser.setDialogTitle(title);
  String btnApprove = "Select";
  if (fromPopFile) {
    fchooser.setFileSelectionMode(DIRSANDFILES);
    fchooser.setAcceptAllFileFilterUsed(true);
  } else {
    fchooser.setFileSelectionMode(selectionMode);
    if (mode == FileDialog.SAVE) {
      fchooser.setDialogType(JFileChooser.SAVE_DIALOG);
      btnApprove = "Save";
    }
    if (filters.length == 0) {
      fchooser.setAcceptAllFileFilterUsed(true);
    } else {
      fchooser.setAcceptAllFileFilterUsed(false);
      for (Object filter : filters) {
        fchooser.setFileFilter((FileFilter) filter);
      }
    }
  }
  if (Settings.isMac()) {
    fchooser.putClientProperty("JFileChooser.packageIsTraversable", "always");
  }
  int dialogResponse = fchooser.showDialog(parentFrame, btnApprove);
  if (dialogResponse != JFileChooser.APPROVE_OPTION) {
    fileChoosen = null;
  } else {
    fileChoosen = fchooser.getSelectedFile();
  }
  result[0] = fileChoosen;
  if (filters.length > 0) {
    result[1] = fchooser.getFileFilter();
  }
}
 
Example 3
Source File: J2SEPlatformCustomizer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static boolean select(
    final PathModel model,
    final File[] currentDir,
    final Component parentComponent) {
    final JFileChooser chooser = new JFileChooser ();
    chooser.setMultiSelectionEnabled (true);
    String title = null;
    String message = null;
    String approveButtonName = null;
    String approveButtonNameMne = null;
    if (model.type == SOURCES) {
        title = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_OpenSources");
        message = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_Sources");
        approveButtonName = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_OpenSources");
        approveButtonNameMne = NbBundle.getMessage (J2SEPlatformCustomizer.class,"MNE_OpenSources");
    } else if (model.type == JAVADOC) {
        title = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_OpenJavadoc");
        message = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_Javadoc");
        approveButtonName = NbBundle.getMessage (J2SEPlatformCustomizer.class,"TXT_OpenJavadoc");
        approveButtonNameMne = NbBundle.getMessage (J2SEPlatformCustomizer.class,"MNE_OpenJavadoc");
    }
    chooser.setDialogTitle(title);
    chooser.setApproveButtonText(approveButtonName);
    chooser.setApproveButtonMnemonic (approveButtonNameMne.charAt(0));
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    if (Utilities.isMac()) {
        //New JDKs and JREs are bundled into package, allow JFileChooser to navigate in
        chooser.putClientProperty("JFileChooser.packageIsTraversable", "always");   //NOI18N
    }
    //#61789 on old macosx (jdk 1.4.1) these two method need to be called in this order.
    chooser.setAcceptAllFileFilterUsed( false );
    chooser.setFileFilter (new ArchiveFileFilter(message,new String[] {"ZIP","JAR"}));   //NOI18N
    if (currentDir[0] != null) {
        chooser.setCurrentDirectory(currentDir[0]);
    }
    if (chooser.showOpenDialog(parentComponent) == JFileChooser.APPROVE_OPTION) {
        File[] fs = chooser.getSelectedFiles();
        boolean addingFailed = false;
        for (File f : fs) {
            //XXX: JFileChooser workaround (JDK bug #5075580), double click on folder returns wrong file
            // E.g. for /foo/src it returns /foo/src/src
            // Try to convert it back by removing last invalid name component
            if (!f.exists()) {
                File parent = f.getParentFile();
                if (parent != null && f.getName().equals(parent.getName()) && parent.exists()) {
                    f = parent;
                }
            }
            if (f.exists()) {
                addingFailed|=!model.addPath (f);
            }
        }
        if (addingFailed) {
            new NotifyDescriptor.Message (NbBundle.getMessage(J2SEPlatformCustomizer.class,"TXT_CanNotAddResolve"),
                    NotifyDescriptor.ERROR_MESSAGE);
        }
        currentDir[0] = FileUtil.normalizeFile(chooser.getCurrentDirectory());
        return true;
    }
    return false;
}
 
Example 4
Source File: ProjectChooserAccessory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Factory method for project chooser
 */
public static JFileChooser createProjectChooser( boolean defaultAccessory ) {

    ProjectManager.getDefault().clearNonProjectCache(); // #41882

    OpenProjectListSettings opls = OpenProjectListSettings.getInstance();
    JFileChooser chooser = new ProjectFileChooser();
    chooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY );

    if ("GTK".equals(javax.swing.UIManager.getLookAndFeel().getID())) { // NOI18N
        // see BugTraq #5027268
        chooser.putClientProperty("GTKFileChooser.showDirectoryIcons", Boolean.TRUE); // NOI18N
        //chooser.putClientProperty("GTKFileChooser.showFileIcons", Boolean.TRUE); // NOI18N
    }

    chooser.setApproveButtonText( NbBundle.getMessage( ProjectChooserAccessory.class, "BTN_PrjChooser_ApproveButtonText" ) ); // NOI18N
    chooser.setApproveButtonMnemonic( NbBundle.getMessage( ProjectChooserAccessory.class, "MNM_PrjChooser_ApproveButtonText" ).charAt (0) ); // NOI18N
    chooser.setApproveButtonToolTipText (NbBundle.getMessage( ProjectChooserAccessory.class, "BTN_PrjChooser_ApproveButtonTooltipText")); // NOI18N
    // chooser.setMultiSelectionEnabled( true );
    chooser.setDialogTitle( NbBundle.getMessage( ProjectChooserAccessory.class, "LBL_PrjChooser_Title" ) ); // NOI18N
    //#61789 on old macosx (jdk 1.4.1) these two method need to be called in this order.
    chooser.setAcceptAllFileFilterUsed( false );
    chooser.setFileFilter( ProjectDirFilter.INSTANCE );

    // A11Y
    chooser.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ProjectChooserAccessory.class, "AN_ProjectChooserAccessory"));
    chooser.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ProjectChooserAccessory.class, "AD_ProjectChooserAccessory"));


    if ( defaultAccessory ) {
        chooser.setAccessory(new ProjectChooserAccessory(chooser, opls.isOpenSubprojects()));
    }

    File currDir = null;
    String dir = opls.getLastOpenProjectDir();
    if ( dir != null ) {
        File d = new File( dir );
        if ( d.exists() && d.isDirectory() ) {
            currDir = d;
        }
    }

    FileUtil.preventFileChooserSymlinkTraversal(chooser, currDir);
    new ProjectFileView(chooser);

    return chooser;

}
 
Example 5
Source File: ImportUtils.java    From chipster with MIT License 3 votes vote down vote up
/**
 * <p>
 * Returns a file chooser that should not trip the bug with Java and Windows
 * XP zip/rar folder feature. Also checks and reports with a modal dialog if
 * there are zips on desktop, as the does not seem to work in all
 * environments. For more information about the bug see e.g. #5050516 at
 * bugs.sun.com.
 * </p>
 * 
 * <p>
 * <strong>You must always use this!</strong>
 * </p>
 * 
 * @return a safe file chooser
 */
public static JFileChooser getFixedFileChooser(File file) {

	JFileChooser fileChooser = file != null ? new JFileChooser(file) : new JFileChooser();
	fileChooser.putClientProperty("FileChooser.useShellFolder", Boolean.FALSE);

	return fileChooser;
}