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

The following examples show how to use javax.swing.JFileChooser#setAccessory() . 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: ImageChooser.java    From nextreports-designer with Apache License 2.0 6 votes vote down vote up
public static String showDialog(Component parent, String title, String initialImage) {
			
	JFileChooser fc = new JFileChooser();
       ImagePreviewPanel previewPane = new ImagePreviewPanel();
       fc.setAccessory(previewPane);
       fc.addPropertyChangeListener(previewPane);
       fc.setDialogTitle(I18NSupport.getString("image.title"));
       fc.setAcceptAllFileFilterUsed(false);
       fc.addChoosableFileFilter(new ImageFilter());
       
       int returnVal = fc.showOpenDialog(Globals.getMainFrame());
       if (returnVal == JFileChooser.APPROVE_OPTION) {
           final File f = fc.getSelectedFile();
           if (f != null) {
           	 try {
                    FileUtil.copyToDir(f, new File(Globals.getCurrentReportAbsolutePath()).getParentFile(), true);                
                } catch (IOException e) {
                    e.printStackTrace();  
                }
           	return f.getName();
           }            
       } 
       return null;        		       
}
 
Example 2
Source File: PreviewPane.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public PreviewPane(JFileChooser chooser) {
    chooser.setAccessory(this);
    chooser.addPropertyChangeListener(this);
    setLayout(new BorderLayout(5, 5));
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    previewDetails = new JLabel("Preview:");
    add(previewDetails, BorderLayout.NORTH);
    label = new JLabel();
    label.setBackground(Color.WHITE);
    label.setPreferredSize(new Dimension(200, 200));
    maxImgWidth = 195;
    label.setOpaque(false);
    label.setBorder(BorderFactory.createEtchedBorder());
    add(label, BorderLayout.CENTER);
}
 
Example 3
Source File: ImageExportUtils.java    From chipster with MIT License 5 votes vote down vote up
public static JFileChooser getSaveFileChooser() {
	
	JFileChooser fileChooser = ImportUtils.getFixedFileChooser();
	
	String[] extensions = { "png" };
	fileChooser.setFileFilter(new GeneralFileFilter("PNG Image Files", extensions));
	fileChooser.setSelectedFile(new File("exported-image.png"));
	fileChooser.setAcceptAllFileFilterUsed(false);
	fileChooser.setMultiSelectionEnabled(false);		
	fileChooser.setApproveButtonText("Save");
	fileChooser.setAccessory(new ResolutionAccessory());
	
	return fileChooser;
}
 
Example 4
Source File: RemoteSessionChooserFactory.java    From chipster with MIT License 5 votes vote down vote up
public JFileChooser getRemoteSessionChooser() throws MalformedURLException, JMSException, FileBrokerException, AuthCancelledException {
	JFileChooser remoteSessionFileChooser = populateFileChooserFromServer();
	remoteSessionFileChooser.setSelectedFile(new File("session"));
	remoteSessionFileChooser.setPreferredSize(new Dimension(800, 600));
	remoteSessionFileChooser.setAccessory(new RemoteSessionAccessory(remoteSessionFileChooser, app.getSessionManager(), app));
	ServerFileUtils.hideJFileChooserButtons(remoteSessionFileChooser);
		
	return remoteSessionFileChooser;
}
 
Example 5
Source File: DevMenuContentPanel.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
private static File getSaveGameFile() {
    final JFileChooser fileChooser = new JFileChooser(MagicFileSystem.getDataPath().toFile());
    fileChooser.setDialogTitle("Load & resume saved game");
    fileChooser.setFileFilter(TEST_FILE_FILTER);
    fileChooser.setAcceptAllFileFilterUsed(false);
    // Add the description preview pane
    fileChooser.setAccessory(new DeckDescriptionPreview(fileChooser));
    final int action = fileChooser.showOpenDialog(ScreenController.getFrame());
    if (action == JFileChooser.APPROVE_OPTION) {
        return fileChooser.getSelectedFile();
    } else {
        return null;
    }
}
 
Example 6
Source File: FileManager.java    From bigtable-sql with Apache License 2.0 5 votes vote down vote up
public boolean open(boolean appendToExisting)
{
    boolean result = false;
   JFileChooser chooser = _fileChooserManager.getFileChooser();
   chooser.setAccessory(new ChooserPreviewer());

   SquirrelPreferences prefs = _sqlPanelAPI.getSession().getApplication().getSquirrelPreferences();
   Frame frame = SessionUtils.getOwningFrame(_sqlPanelAPI);


   if (prefs.isFileOpenInPreviousDir())
   {
      String fileName = prefs.getFilePreviousDir();
      if (fileName != null)
      {
         chooser.setCurrentDirectory(new File(fileName));
      }
   }
   else
   {
      String dirName = prefs.getFileSpecifiedDir();
      if (dirName != null)
      {
         chooser.setCurrentDirectory(new File(dirName));
      }
   }
   _sqlPanelAPI.getSession().selectMainTab(ISession.IMainPanelTabIndexes.SQL_TAB);
   if (chooser.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION)
   {
       result = true;
      File selectedFile = chooser.getSelectedFile();
      if (!appendToExisting) {
          _sqlPanelAPI.setEntireSQLScript("");
      }
      loadScript(selectedFile);
      
   }
   return result;
}
 
Example 7
Source File: FileChooserDemo.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
/**
    * Creates the preview file chooser button.
    *
    * @return the j button
    */
   public JButton createPreviewFileChooserButton() {
Action a = new AbstractAction(getString("FileChooserDemo.previewbutton")) {
    public void actionPerformed(ActionEvent e) {
	JFileChooser fc = createFileChooser();

	// Add filefilter & fileview
               javax.swing.filechooser.FileFilter filter = createFileFilter(
                   getString("FileChooserDemo.filterdescription"),
                   "jpg", "gif");
	ExampleFileView fileView = new ExampleFileView();
	fileView.putIcon("jpg", jpgIcon);
	fileView.putIcon("gif", gifIcon);
	fc.setFileView(fileView);
	fc.addChoosableFileFilter(filter);
	fc.setFileFilter(filter);
	
	// add preview accessory
	fc.setAccessory(new FilePreviewer(fc));

	// show the filechooser
	int result = fc.showOpenDialog(getDemoPanel());
	
	// if we selected an image, load the image
	if(result == JFileChooser.APPROVE_OPTION) {
	    loadImage(fc.getSelectedFile().getPath());
	}
    }
};
return createButton(a);
   }
 
Example 8
Source File: GltfBrowserApplication.java    From JglTF with MIT License 5 votes vote down vote up
/**
 * Default constructor
 */
GltfBrowserApplication()
{
    frame = new JFrame("GltfBrowser");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    GltfTransferHandler transferHandler = 
        new GltfTransferHandler(this);
    frame.setTransferHandler(transferHandler);

    recentUrisMenu = new RecentUrisMenu(
        GltfBrowserApplication.class.getSimpleName(),
        uri -> openUriInBackground(uri));
    
    menuBar = new JMenuBar();
    menuBar.add(createFileMenu());
    frame.setJMenuBar(menuBar);
    
    openFileChooser = new JFileChooser(".");
    openFileChooser.setFileFilter(
        new FileNameExtensionFilter(
            "glTF Files (.gltf, .glb)", "gltf", "glb"));
    
    importObjFileChooser = new JFileChooser(".");
    
    objImportAccessoryPanel = new ObjImportAccessoryPanel();
    importObjFileChooser.setAccessory(objImportAccessoryPanel);
    importObjFileChooser.setFileFilter(
        new FileNameExtensionFilter(
            "OBJ files (.obj)", "obj"));
    
    saveFileChooser = new JFileChooser(".");
    
    desktopPane = new JDesktopPane();
    frame.getContentPane().add(desktopPane);
    
    frame.setSize(1000,700);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}
 
Example 9
Source File: StdFileDialog.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link StdFileDialog}.
 *
 * @param comp           The parent {@link Component} of the dialog. May be {@code null}.
 * @param title          The title to use. May be {@code null}.
 * @param accessoryPanel An extra panel to show. May be {@code null}.
 * @param filters        The file filters to make available. If there are none, then the {@code
 *                       showAllFilter} flag will be forced to {@code true}.
 * @return The chosen {@link Path} or {@code null}.
 */
public static Path showOpenDialog(Component comp, String title, JComponent accessoryPanel, FileNameExtensionFilter... filters) {
    Preferences  prefs  = Preferences.getInstance();
    JFileChooser dialog = new JFileChooser(prefs.getLastDir().toFile());
    dialog.setDialogTitle(title);
    if (filters != null && filters.length > 0) {
        dialog.setAcceptAllFileFilterUsed(false);
        for (FileNameExtensionFilter filter : filters) {
            dialog.addChoosableFileFilter(filter);
        }
    } else {
        dialog.setAcceptAllFileFilterUsed(true);
    }
    if (accessoryPanel != null) {
        dialog.setAccessory(accessoryPanel);
    }
    int result = dialog.showOpenDialog(comp);
    if (result != JFileChooser.ERROR_OPTION) {
        File current = dialog.getCurrentDirectory();
        if (current != null) {
            prefs.setLastDir(current.toPath());
        }
    }
    if (result == JFileChooser.APPROVE_OPTION) {
        Path path = dialog.getSelectedFile().toPath().normalize().toAbsolutePath();
        prefs.addRecentFile(path);
        return path;
    }
    return null;
}
 
Example 10
Source File: MultiRepAnalysis.java    From sc2gears with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new MultiRepAnalysis
 * @param arguments optional arguments to define the files and folders to analyze<br>
 * 		the <b>first</b>  element can be an optional replay source to load<br>
 * 		the <b>second</b> element can be an optional replay list to load<br>
 * 		the <b>third</b>  element can be a File array to perform the Multi-rep analysis on
 */
public MultiRepAnalysis( final Object... arguments ) {
	super( arguments.length == 0 ? Language.getText( "module.multiRepAnal.opening" ) : null ); // This title does not have a role as this internal frame is not displayed until replays are chosen, and then title is changed anyway
	
	setFrameIcon( Icons.CHART_UP_COLOR );
	
	if ( arguments.length == 0 ) {
		final JFileChooser fileChooser = new JFileChooser( GeneralUtils.getDefaultReplayFolder() );
		fileChooser.setDialogTitle( Language.getText( "module.multiRepAnal.openTitle" ) );
		fileChooser.setFileFilter( GuiUtils.SC2_REPLAY_FILTER );
		fileChooser.setAccessory( GuiUtils.createReplayFilePreviewAccessory( fileChooser ) );
		fileChooser.setFileView( GuiUtils.SC2GEARS_FILE_VIEW );
		fileChooser.setFileSelectionMode( JFileChooser.FILES_AND_DIRECTORIES );
		fileChooser.setMultiSelectionEnabled( true );
		if ( fileChooser.showOpenDialog( MainFrame.INSTANCE ) == JFileChooser.APPROVE_OPTION )
			this.files = fileChooser.getSelectedFiles();
		else {
			dispose();
			this.files = null;
			return;
		}
	}
	else {
		if ( arguments.length > 0 && arguments[ 0 ] != null ) {
			// Replay source
			this.files = loadReplaySourceFile( (File) arguments[ 0 ] );
		}
		else if ( arguments.length > 1 && arguments[ 1 ] != null ) {
			// Replay list
			// TODO this can be sped up by reading the replay list by hand and only use the file name!
			final List< Object[] > dataList = ReplaySearch.loadReplayListFile( (File) arguments[ 1 ] );
			this.files = new File[ dataList.size() ];
			for ( int i = dataList.size() - 1; i >= 0; i-- )
				this.files[ i ] = new File( (String) dataList.get( i )[ ReplaySearch.COLUMN_FILE_NAME ] );
		}
		else if ( arguments.length > 2 && arguments[ 2 ] != null ) {
			// Replays to open
			this.files = (File[]) arguments[ 2 ];
		}
		else
			throw new RuntimeException( "The source for Multi-rep analysis is incorrectly specified!" );
	}
	
	setTitle( Language.getText( "module.multiRepAnal.title", counter.incrementAndGet() ) );
	
	buildGUI();
}
 
Example 11
Source File: AntArtifactChooser.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Shows dialog with the artifact chooser 
 * @return null if canceled selected jars if some jars selected
 */
static AntArtifactItem[] showDialog( String[] artifactTypes, Project master, Component parent ) {
    
    JFileChooser chooser = ProjectChooser.projectChooser();
    chooser.setDialogTitle( NbBundle.getMessage( AntArtifactChooser.class, "LBL_AACH_Title" ) ); // NOI18N
    chooser.setApproveButtonText( NbBundle.getMessage( AntArtifactChooser.class, "LBL_AACH_SelectProject" ) ); // NOI18N
    chooser.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage (AntArtifactChooser.class,"AD_AACH_SelectProject"));
    AntArtifactChooser accessory = new AntArtifactChooser( artifactTypes, chooser );
    chooser.setAccessory( accessory );
    chooser.setPreferredSize( new Dimension( 650, 380 ) );        
    File defaultFolder = null;
    FileObject defFo = master.getProjectDirectory();
    if (defFo != null) {
        defFo = defFo.getParent();
        if (defFo != null) {
            defaultFolder = FileUtil.toFile(defFo);
        }
    }
    chooser.setCurrentDirectory (getLastUsedArtifactFolder(defaultFolder));

    int option = chooser.showOpenDialog( parent ); // Show the chooser
          
    if ( option == JFileChooser.APPROVE_OPTION ) {

        File dir = chooser.getSelectedFile();
        dir = FileUtil.normalizeFile (dir);
        Project selectedProject = accessory.getProject( dir );

        if ( selectedProject == null ) {
            return null;
        }
        
        if ( selectedProject.getProjectDirectory().equals( master.getProjectDirectory() ) ) {
            DialogDisplayer.getDefault().notify( new NotifyDescriptor.Message( 
                NbBundle.getMessage( AntArtifactChooser.class, "MSG_AACH_RefToItself" ),
                NotifyDescriptor.INFORMATION_MESSAGE ) );
            return null;
        }
        
        if ( ProjectUtils.hasSubprojectCycles( master, selectedProject ) ) {
            DialogDisplayer.getDefault().notify( new NotifyDescriptor.Message( 
                NbBundle.getMessage( AntArtifactChooser.class, "MSG_AACH_Cycles" ),
                NotifyDescriptor.INFORMATION_MESSAGE ) );
            return null;
        }

        boolean noSuitableOutput = true;
        for (String type : artifactTypes) {
            if (AntArtifactQuery.findArtifactsByType(selectedProject, type).length > 0) {
                noSuitableOutput = false;
                break;
            }
        }
        if (noSuitableOutput) {
            DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
                    NbBundle.getMessage (AntArtifactChooser.class,"MSG_NO_JAR_OUTPUT")));
            return null;
        }
        
        setLastUsedArtifactFolder (FileUtil.normalizeFile(chooser.getCurrentDirectory()));
        
        Object[] tmp = new Object[accessory.jListArtifacts.getModel().getSize()];
        int count = 0;
        for(int i = 0; i < tmp.length; i++) {
            if (accessory.jListArtifacts.isSelectedIndex(i)) {
                tmp[count] = accessory.jListArtifacts.getModel().getElementAt(i);
                count++;
            }
        }
        AntArtifactItem artifactItems[] = new AntArtifactItem[count];
        System.arraycopy(tmp, 0, artifactItems, 0, count);
        return artifactItems;
    }
    else {
        return null; 
    }
            
}
 
Example 12
Source File: MainPanel.java    From swift-explorer with Apache License 2.0 4 votes vote down vote up
protected void onCreateStoredObject() 
 {
 	List<StoredObject> sltObj = getSelectedStoredObjects() ;
 	if (sltObj != null && sltObj.size() > 1)
 		return ; // should never happen, because in such a case the menu is disable
 	StoredObject parentObject = (sltObj == null || sltObj.isEmpty()) ? (null) : (sltObj.get(0)) ;
 	
     Container container = getSelectedContainer();
     JFileChooser chooser = new JFileChooser();
     chooser.setMultiSelectionEnabled(true);
     chooser.setCurrentDirectory(lastFolder);
     
     final JPanel optionPanel = getOptionPanel ();
     chooser.setAccessory(optionPanel);
     AbstractButton overwriteCheck = setOverwriteOption (optionPanel) ;
     
     if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) 
     {
         File[] selectedFiles = chooser.getSelectedFiles();
         try 
         {
         	boolean overwriteAll = overwriteCheck.isSelected() ;
         	if (overwriteAll)
         	{
         		if (!confirm(getLocalizedString("confirm_overwrite_any_existing_files")))
         			return ;
         	}
	ops.uploadFiles(container, parentObject, selectedFiles, overwriteAll, getNewSwiftStopRequester (), callback);
	
	// We open the progress window, for it is likely that this operation
	// will take a while
	//if (selectedFiles != null /*&& selectedFiles.length > 1*/)
	//{
           //onProgressButton () ;
	//}
} 
         catch (IOException e) 
{
	logger.error("Error occurred while uploading a files.", e);
}
         lastFolder = chooser.getCurrentDirectory();
     }
 }
 
Example 13
Source File: MainPanel.java    From swift-explorer with Apache License 2.0 4 votes vote down vote up
protected void onUploadDirectory() 
 {
 	List<StoredObject> sltObj = getSelectedStoredObjects() ;
 	if (sltObj != null && sltObj.size() > 1)
 		return ; // should never happen, because in such a case the menu is disable
 	StoredObject parentObject = (sltObj == null || sltObj.isEmpty()) ? (null) : (sltObj.get(0)) ;
 	
     final Container container = getSelectedContainer();
     final JFileChooser chooser = new JFileChooser();
     chooser.setMultiSelectionEnabled(false);
     chooser.setCurrentDirectory(lastFolder);
     chooser.setFileSelectionMode( JFileChooser.DIRECTORIES_ONLY);
     
     final JPanel optionPanel = getOptionPanel ();
     chooser.setAccessory(optionPanel);
     AbstractButton overwriteCheck = setOverwriteOption (optionPanel) ;
     
     if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) 
     {
         final File selectedDir = chooser.getSelectedFile();
         try 
         {
         	boolean overwriteAll = overwriteCheck.isSelected() ;
         	if (overwriteAll)
         	{
         		if (!confirm(getLocalizedString("confirm_overwrite_any_existing_files")))
         			return ;
         	}
	ops.uploadDirectory(container, parentObject, selectedDir, overwriteAll, getNewSwiftStopRequester (), callback);
	
	// We open the progress window, for it is likely that this operation
	// will take a while
          //onProgressButton () ;
} 
         catch (IOException e) 
{
	logger.error("Error occurred while uploading a directory.", e);
}
         lastFolder = chooser.getCurrentDirectory();
     }
 }
 
Example 14
Source File: RelativePathAccessory.java    From RobotBuilder with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void attachTo(JFileChooser chooser) {
    chooser.setAccessory(this);
    chooser.addPropertyChangeListener(this);
}
 
Example 15
Source File: PreviewPane.java    From scifio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Constructs a preview pane for the given file chooser. */
public PreviewPane(final Context context, final JFileChooser jc) {
	super();

	context.inject(this);

	// create view
	setBorder(new EmptyBorder(0, 10, 0, 10));
	setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
	iconLabel = new JLabel();
	iconLabel.setMinimumSize(new java.awt.Dimension(128, -1));
	iconLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
	add(iconLabel);
	add(Box.createVerticalStrut(7));
	formatLabel = new JLabel();
	formatLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
	add(formatLabel);
	add(Box.createVerticalStrut(5));
	resLabel = new JLabel();
	resLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
	add(resLabel);
	zctLabel = new JLabel();
	zctLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
	add(zctLabel);
	typeLabel = new JLabel();
	typeLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
	add(typeLabel);

	// smaller font for most labels
	Font font = formatLabel.getFont();
	font = font.deriveFont(font.getSize2D() - 3);
	formatLabel.setFont(font);
	resLabel.setFont(font);
	zctLabel.setFont(font);
	typeLabel.setFont(font);

	// populate model
	icon = null;
	iconText = formatText = resText = npText = typeText = "";
	iconTip = formatTip = resTip = zctTip = typeTip = null;

	if (jc != null) {
		jc.setAccessory(this);
		jc.addPropertyChangeListener(this);

		refresher = new Runnable() {

			@Override
			public void run() {
				iconLabel.setIcon(icon);
				iconLabel.setText(iconText);
				iconLabel.setToolTipText(iconTip);
				formatLabel.setText(formatText);
				formatLabel.setToolTipText(formatTip);
				resLabel.setText(resText);
				resLabel.setToolTipText(resTip);
				zctLabel.setText(npText);
				zctLabel.setToolTipText(zctTip);
				typeLabel.setText(typeText);
				typeLabel.setToolTipText(typeTip);
			}
		};

		// start separate loader thread
		loaderAlive = true;
		loader = new Thread(this, "Preview");
		loader.start();
	}
}
 
Example 16
Source File: ImportDiffAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static void importDiff(VCSContext ctx) {
    final File roots[] = HgUtils.getActionRoots(ctx);
    if (roots == null || roots.length == 0) return;
    final File root = Mercurial.getInstance().getRepositoryRoot(roots[0]);

    final JFileChooser fileChooser = new AccessibleJFileChooser(NbBundle.getMessage(ImportDiffAction.class, "ACSD_ImportBrowseFolder"), null);   // NO I18N
    fileChooser.setDialogTitle(NbBundle.getMessage(ImportDiffAction.class, "ImportBrowse_title"));                                            // NO I18N
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.setDialogType(JFileChooser.OPEN_DIALOG);
    fileChooser.setApproveButtonMnemonic(NbBundle.getMessage(ImportDiffAction.class, "Import").charAt(0));                      // NO I18N
    fileChooser.setApproveButtonText(NbBundle.getMessage(ImportDiffAction.class, "Import"));                                        // NO I18N
    fileChooser.setCurrentDirectory(new File(HgModuleConfig.getDefault().getImportFolder()));
    JPanel panel = new JPanel();
    final JRadioButton asPatch = new JRadioButton(NbBundle.getMessage(ImportDiffAction.class, "CTL_Import_PatchOption")); //NOI18N
    org.openide.awt.Mnemonics.setLocalizedText(asPatch, asPatch.getText()); // NOI18N
    final JRadioButton asBundle = new JRadioButton(NbBundle.getMessage(ImportDiffAction.class, "CTL_Import_BundleOption")); //NOI18N
    org.openide.awt.Mnemonics.setLocalizedText(asBundle, asBundle.getText()); // NOI18N
    ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.add(asBundle);
    buttonGroup.add(asPatch);
    asPatch.setSelected(true);
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    panel.add(asPatch);
    panel.add(asBundle);
    fileChooser.setAccessory(panel);

    DialogDescriptor dd = new DialogDescriptor(fileChooser, NbBundle.getMessage(ImportDiffAction.class, "ImportBrowse_title"));              // NO I18N
    dd.setOptions(new Object[0]);
    final Dialog dialog = DialogDisplayer.getDefault().createDialog(dd);
    fileChooser.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String state = e.getActionCommand();
            if (state.equals(JFileChooser.APPROVE_SELECTION)) {
                final File patchFile = fileChooser.getSelectedFile();

                HgModuleConfig.getDefault().setImportFolder(patchFile.getParent());
                RequestProcessor rp = Mercurial.getInstance().getRequestProcessor(root);
                ImportDiffProgressSupport.Kind kind;
                if (asBundle.isSelected()) {
                    kind = ImportDiffProgressSupport.Kind.BUNDLE;
                } else if (asPatch.isSelected()) {
                    kind = ImportDiffProgressSupport.Kind.PATCH;
                } else {
                    kind = null;
                }
                HgProgressSupport support = new ImportDiffProgressSupport(root, patchFile, true, kind);
                support.start(rp, root, org.openide.util.NbBundle.getMessage(ImportDiffAction.class, "LBL_ImportDiff_Progress")); // NOI18N
            }
            dialog.dispose();
        }
    });
    dialog.setVisible(true);
}
 
Example 17
Source File: RemoteSessionChooserFactory.java    From chipster with MIT License 4 votes vote down vote up
public JFileChooser getManagementChooser() throws MalformedURLException, JMSException, FileBrokerException, AuthCancelledException {

		JFileChooser sessionFileChooser = null;

		// fetch current sessions to show in the dialog and create it
		sessionFileChooser = populateFileChooserFromServer();



		// tune GUI
		sessionFileChooser.setDialogTitle("Manage");

		sessionFileChooser.setPreferredSize(new Dimension(800, 600));
		sessionFileChooser.setAccessory(new RemoteSessionAccessory(sessionFileChooser, app.getSessionManager(), app));		

		// hide buttons that we don't need
		ServerFileUtils.hideJFileChooserButtons(sessionFileChooser);
		ServerFileUtils.hideApproveButton(sessionFileChooser);
		ServerFileUtils.setCancelButtonText(sessionFileChooser, "Close");

		return sessionFileChooser;
	}
 
Example 18
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;

}